diff --git a/ENI2/Controls/SERVTemplatesControl.xaml b/ENI2/Controls/SERVTemplatesControl.xaml
new file mode 100644
index 00000000..3862978b
--- /dev/null
+++ b/ENI2/Controls/SERVTemplatesControl.xaml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ENI2/Controls/SERVTemplatesControl.xaml.cs b/ENI2/Controls/SERVTemplatesControl.xaml.cs
new file mode 100644
index 00000000..4f8e14ab
--- /dev/null
+++ b/ENI2/Controls/SERVTemplatesControl.xaml.cs
@@ -0,0 +1,131 @@
+using bsmd.database;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+
+namespace ENI2.Controls
+{
+ ///
+ /// Interaction logic for SERVTemplatesControl.xaml
+ ///
+ public partial class SERVTemplatesControl : UserControl
+ {
+ private readonly ObservableCollection _templates = new ObservableCollection();
+
+ public SERVTemplatesControl()
+ {
+ InitializeComponent();
+ this.dataGridSERVTemplates.ItemsSource = _templates;
+
+ var view = CollectionViewSource.GetDefaultView(_templates);
+ view.SortDescriptions.Add(new SortDescription(nameof(SERV_Template.ServiceName), ListSortDirection.Ascending));
+
+ _ = LoadTemplatesAsync();
+
+ this.dataGridSERVTemplates.ContextMenu = new ContextMenu();
+ MenuItem addItem = new MenuItem
+ {
+ Header = Properties.Resources.textAdd,
+ Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Resources/add.png")) }
+ };
+ addItem.Click += AddItem_Click;
+ this.dataGridSERVTemplates.ContextMenu.Items.Add(addItem);
+
+ MenuItem delItem = new MenuItem
+ {
+ Header = Properties.Resources.textDelete,
+ Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }
+ };
+ delItem.Click += DelItem_Click;
+ this.dataGridSERVTemplates.ContextMenu.Items.Add(delItem);
+ }
+
+ private async Task LoadTemplatesAsync()
+ {
+ List items = await DBManagerAsync.GetSERVTemplatesAsync(true);
+ foreach (SERV_Template item in items)
+ {
+ _templates.Add(item);
+ }
+ }
+
+ private void buttonSave_Click(object sender, RoutedEventArgs e)
+ {
+ _ = SaveTemplatesAsync();
+ }
+
+ private void buttonAdd_Click(object sender, RoutedEventArgs e)
+ {
+ AddNewTemplate();
+ }
+
+ private void dataGridSERVTemplates_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
+ {
+ if (e.Row?.Item is SERV_Template item)
+ {
+ item.IsDirty = true;
+ }
+ }
+
+ private void AddItem_Click(object sender, RoutedEventArgs e)
+ {
+ AddNewTemplate();
+ }
+
+ private async void DelItem_Click(object sender, RoutedEventArgs e)
+ {
+ if (this.dataGridSERVTemplates.SelectedItems.Count > 0)
+ {
+ if (MessageBox.Show("Are you sure to delete the selected values?", Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) ==
+ MessageBoxResult.Yes)
+ {
+ var selectedItems = new List();
+ foreach (SERV_Template item in this.dataGridSERVTemplates.SelectedItems)
+ selectedItems.Add(item);
+
+ foreach (SERV_Template item in selectedItems)
+ {
+ int result = await DBManagerAsync.DeleteAsync(item);
+ if (result == 1 || item.IsNew)
+ {
+ _templates.Remove(item);
+ }
+ }
+ }
+ }
+ }
+
+ private void AddNewTemplate()
+ {
+ var item = new SERV_Template
+ {
+ IsDirty = true
+ };
+ _templates.Add(item);
+ this.dataGridSERVTemplates.SelectedItem = item;
+ this.dataGridSERVTemplates.ScrollIntoView(item);
+ }
+
+ private async Task SaveTemplatesAsync()
+ {
+ int totalSaves = 0;
+ foreach (SERV_Template item in _templates)
+ {
+ if (item.IsNew || item.IsDirty)
+ {
+ totalSaves += await DBManagerAsync.SaveAsync(item);
+ }
+ }
+
+ if (totalSaves > 0)
+ {
+ MessageBox.Show($"{totalSaves} SERV templates saved", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ }
+ }
+}
diff --git a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml
index 61071e28..c059da6c 100644
--- a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml
+++ b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml
@@ -118,23 +118,6 @@
-
-
-
-
-
diff --git a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs
index b8da8be2..91f3b17d 100644
--- a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs
+++ b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs
@@ -176,11 +176,7 @@ namespace ENI2.DetailViewControls
Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
}
- this.comboBoxGroup.ItemsSource = _servTemplates;
-
- this.buttonDeleteTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
- this.buttonEditTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
- this.buttonNewTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
+ this.comboBoxGroup.ItemsSource = _servTemplates;
#endregion
@@ -386,8 +382,7 @@ namespace ENI2.DetailViewControls
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(this.comboBoxGroup.SelectedItem is SERV_Template st)
- {
- this.buttonDeleteTemplate.IsEnabled = true;
+ {
this.buttonSetTemplate.IsEnabled = true;
this._currentTemplate = st;
}
@@ -422,56 +417,6 @@ namespace ENI2.DetailViewControls
}
}
- private void buttonNewTemplate_Click(object sender, RoutedEventArgs e)
- {
- SERV_Template newTemplate = new SERV_Template();
- EditSERVDialog esd = new EditSERVDialog();
- esd.AddVisible = false;
- esd.SERV_Template = newTemplate;
- if(esd.ShowDialog() ?? false)
- {
- _ = DBManagerAsync.SaveAsync(esd.SERV_Template);
- this.comboBoxGroup.ItemsSource = null;
- _servTemplates.Add(newTemplate);
- _servTemplates.Sort();
- this.comboBoxGroup.ItemsSource = _servTemplates;
- }
- }
-
- private void buttonEditTemplate_Click(object sender, RoutedEventArgs e)
- {
- if (this.comboBoxGroup.SelectedItem is SERV_Template st)
- {
- EditSERVDialog editSERVDialog = new EditSERVDialog();
- editSERVDialog.AddVisible = false;
- editSERVDialog.SERV_Template = st;
- if (editSERVDialog.ShowDialog() ?? false)
- {
- _ = DBManagerAsync.SaveAsync(st);
- this.comboBoxGroup.ItemsSource = null;
- _servTemplates.Sort();
- this.comboBoxGroup.ItemsSource = _servTemplates;
- }
- }
- }
-
- private void buttonDeleteTemplate_Click(object sender, RoutedEventArgs e)
- {
- if (_currentTemplate != null)
- {
- if (MessageBox.Show("Delete this template?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
- {
- this.comboBoxGroup.SelectedItem = null;
- this.comboBoxGroup.ItemsSource = null;
- _ = DBManagerAsync.DeleteAsync(_currentTemplate);
- _servTemplates.Remove(_currentTemplate);
- this.buttonDeleteTemplate.IsEnabled = false;
- this.comboBoxGroup.ItemsSource = _servTemplates;
- this.buttonSetTemplate.IsEnabled = false;
- }
- }
- }
-
#endregion
#region other event handler
diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj
index be0d906e..7b7fdef9 100644
--- a/ENI2/ENI2.csproj
+++ b/ENI2/ENI2.csproj
@@ -331,18 +331,21 @@
ValueMappingsControl.xaml
-
- HazardMaterialControl.xaml
-
-
- PortAreaControl.xaml
-
-
- LADG_NST2007Control.xaml
-
-
- WASExemptionsControl.xaml
-
+
+ HazardMaterialControl.xaml
+
+
+ PortAreaControl.xaml
+
+
+ LADG_NST2007Control.xaml
+
+
+ SERVTemplatesControl.xaml
+
+
+ WASExemptionsControl.xaml
+
ChangePasswordDialog.xaml
@@ -662,22 +665,26 @@
Designer
MSBuild:Compile
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
-
-
- Designer
- MSBuild:Compile
-
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -1274,4 +1281,4 @@
-->
-
+
\ No newline at end of file
diff --git a/ENI2/MainWindow.xaml b/ENI2/MainWindow.xaml
index da966215..fd1b5ec4 100644
--- a/ENI2/MainWindow.xaml
+++ b/ENI2/MainWindow.xaml
@@ -118,6 +118,11 @@
+
diff --git a/ENI2/MainWindow.xaml.cs b/ENI2/MainWindow.xaml.cs
index 77ec02f7..85443d84 100644
--- a/ENI2/MainWindow.xaml.cs
+++ b/ENI2/MainWindow.xaml.cs
@@ -41,9 +41,10 @@ namespace ENI2
private CompareExcelDialog compareExcelDialog;
private EasyPeasyControl easyPeasyControl;
private WASExemptionsControl wasExemptionsControl;
- private HazardMaterialControl hazardMaterialControl;
- private PortAreaControl portAreaControl;
- private LADG_NST2007Control ladgNst2007Control;
+ private HazardMaterialControl hazardMaterialControl;
+ private PortAreaControl portAreaControl;
+ private LADG_NST2007Control ladgNst2007Control;
+ private SERVTemplatesControl servTemplatesControl;
private bool dbConnected;
private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0);
@@ -361,15 +362,23 @@ namespace ENI2
}
this.rootContainer.Children.Add(this.portAreaControl);
}
- else if (sender == this.menuItemLADGNST2007)
- {
- if (this.ladgNst2007Control == null)
- {
- this.ladgNst2007Control = new LADG_NST2007Control();
- }
- this.rootContainer.Children.Add(this.ladgNst2007Control);
- }
- }
+ else if (sender == this.menuItemLADGNST2007)
+ {
+ if (this.ladgNst2007Control == null)
+ {
+ this.ladgNst2007Control = new LADG_NST2007Control();
+ }
+ this.rootContainer.Children.Add(this.ladgNst2007Control);
+ }
+ else if (sender == this.menuItemSERVTemplates)
+ {
+ if (this.servTemplatesControl == null)
+ {
+ this.servTemplatesControl = new SERVTemplatesControl();
+ }
+ this.rootContainer.Children.Add(this.servTemplatesControl);
+ }
+ }
private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev)
{
diff --git a/ENI2/SheetDisplayControls/PortControl.xaml b/ENI2/SheetDisplayControls/PortControl.xaml
index d5101c92..d09ac035 100644
--- a/ENI2/SheetDisplayControls/PortControl.xaml
+++ b/ENI2/SheetDisplayControls/PortControl.xaml
@@ -200,22 +200,6 @@
-
-
-
-
_allPortAreaRows;
private static Dictionary _allPortAreasByCode;
private static List _allLADGNST2007Rows;
private static Dictionary _allLADGNST2007ByDescription;
+ private static List _allSERVTemplates;
#endregion
@@ -43,6 +45,8 @@ namespace bsmd.database
InvalidatePortAreaCache();
if ((result == 1) && (entity is LADG_NST2007))
InvalidateLADGNST2007Cache();
+ if ((result == 1) && (entity is SERV_Template))
+ InvalidateSERVTemplatesCache();
return result;
}
@@ -58,6 +62,8 @@ namespace bsmd.database
InvalidatePortAreaCache();
if ((result == 1) && (entity is LADG_NST2007))
InvalidateLADGNST2007Cache();
+ if ((result == 1) && (entity is SERV_Template))
+ InvalidateSERVTemplatesCache();
return result;
}
}
@@ -191,13 +197,15 @@ namespace bsmd.database
return (await at.LoadListAsync(reader)).ConvertAll(x => (AGNT_Template)x);
}
- public static async Task> GetSERVTemplatesAsync()
+ public static async Task> GetSERVTemplatesAsync(bool forceReload = false)
{
- SqlCommand cmd = new SqlCommand();
- SERV_Template st = new SERV_Template();
- st.PrepareLoadCommand(cmd, Message.LoadFilter.ALL);
- SqlDataReader reader = await PerformCommandAsync(cmd);
- return (await st.LoadListAsync(reader)).ConvertAll(x => (SERV_Template)x);
+ await EnsureSERVTemplatesLoadedAsync(forceReload);
+ return new List(_allSERVTemplates);
+ }
+
+ public static void InvalidateSERVTemplatesCache()
+ {
+ _allSERVTemplates = null;
}
@@ -306,6 +314,32 @@ namespace bsmd.database
}
}
+ private static async Task EnsureSERVTemplatesLoadedAsync(bool forceReload)
+ {
+ if (forceReload)
+ InvalidateSERVTemplatesCache();
+
+ if (_allSERVTemplates != null)
+ return;
+
+ await _servTemplateLoadLock.WaitAsync();
+ try
+ {
+ if (_allSERVTemplates != null)
+ return;
+
+ SqlCommand cmd = new SqlCommand();
+ SERV_Template st = new SERV_Template();
+ st.PrepareLoadCommand(cmd, Message.LoadFilter.ALL);
+ SqlDataReader reader = await PerformCommandAsync(cmd);
+ _allSERVTemplates = (await st.LoadListAsync(reader)).ConvertAll(x => (SERV_Template)x);
+ }
+ finally
+ {
+ _servTemplateLoadLock.Release();
+ }
+ }
+
#endregion
#region async DB access methods
diff --git a/bsmd.database/SERV_Template.cs b/bsmd.database/SERV_Template.cs
index 8e47d51a..25128768 100644
--- a/bsmd.database/SERV_Template.cs
+++ b/bsmd.database/SERV_Template.cs
@@ -5,9 +5,6 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace bsmd.database
{
@@ -110,7 +107,6 @@ namespace bsmd.database
#endregion
-
#region IComparable implementation
public int CompareTo(object obj)