From a1eb65c8340cf32223210be571e2e7112e230c9c Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 19 Feb 2026 13:54:47 +0100 Subject: [PATCH] Adjusted usage of NST2007 lookup in LADG dialog --- ENI2/EditControls/EditLADGDialog.xaml.cs | 2 +- ENI2/LocalizedLookup.cs | 22 +------ ENI2/MainWindow.xaml | 32 +++++----- ENI2/MainWindow.xaml.cs | 76 ++++++++++++------------ bsmd.database/DBManagerAsync.cs | 18 +++--- bsmd.database/LADG_NST2007.cs | 27 +++------ 6 files changed, 74 insertions(+), 103 deletions(-) diff --git a/ENI2/EditControls/EditLADGDialog.xaml.cs b/ENI2/EditControls/EditLADGDialog.xaml.cs index 0431da55..2f9192d6 100644 --- a/ENI2/EditControls/EditLADGDialog.xaml.cs +++ b/ENI2/EditControls/EditLADGDialog.xaml.cs @@ -38,7 +38,7 @@ namespace ENI2.EditControls InitializeComponent(); Loaded += EditLADGDialog_Loaded; if (_nstList == null) - _nstList = LocalizedLookup.GetNST2007List(); + _nstList = LADG_NST2007.GetNST2007List(); } public LADG LADG { get; set; } diff --git a/ENI2/LocalizedLookup.cs b/ENI2/LocalizedLookup.cs index caa1ad0c..7cd95508 100644 --- a/ENI2/LocalizedLookup.cs +++ b/ENI2/LocalizedLookup.cs @@ -230,27 +230,7 @@ namespace ENI2 } reader.Close(); return results; - } - - public static List> GetNST2007List() - { - List> result = new List>(); - - string query = string.Format("SELECT Description, NST2007 FROM LADG_NST2007 ORDER BY Description"); - SQLiteCommand cmd = new SQLiteCommand(query, _con); - IDataReader reader = cmd.ExecuteReader(); - while (reader.Read()) - { - if (reader.IsDBNull(0)) continue; - string desc = reader.GetString(0); - string code = reader.GetString(1); - KeyValuePair kvp = new KeyValuePair(desc, code); - result.Add(kvp); - } - - reader.Close(); - return result; - } + } public static List getMVSHLocodes() { diff --git a/ENI2/MainWindow.xaml b/ENI2/MainWindow.xaml index 8da28058..da966215 100644 --- a/ENI2/MainWindow.xaml +++ b/ENI2/MainWindow.xaml @@ -103,22 +103,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/ENI2/MainWindow.xaml.cs b/ENI2/MainWindow.xaml.cs index d49484fb..77ec02f7 100644 --- a/ENI2/MainWindow.xaml.cs +++ b/ENI2/MainWindow.xaml.cs @@ -39,11 +39,11 @@ namespace ENI2 private ServerStatusControl statusControl; private readonly SucheControl sucheControl; private CompareExcelDialog compareExcelDialog; - private EasyPeasyControl easyPeasyControl; - private WASExemptionsControl wasExemptionsControl; - private HazardMaterialControl hazardMaterialControl; - private PortAreaControl portAreaControl; - private LADG_NST2007Control ladgNst2007Control; + private EasyPeasyControl easyPeasyControl; + private WASExemptionsControl wasExemptionsControl; + private HazardMaterialControl hazardMaterialControl; + private PortAreaControl portAreaControl; + private LADG_NST2007Control ladgNst2007Control; private bool dbConnected; private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0); @@ -337,39 +337,39 @@ namespace ENI2 } this.rootContainer.Children.Add(this.easyPeasyControl); } - else if (sender == this.menuItemWASExemptions) - { - if(this.wasExemptionsControl == null) - { - this.wasExemptionsControl = new WASExemptionsControl(); - } - this.rootContainer.Children.Add(this.wasExemptionsControl); - } - else if (sender == this.menuItemHazardMaterials) - { - if (this.hazardMaterialControl == null) - { - this.hazardMaterialControl = new HazardMaterialControl(); - } - this.rootContainer.Children.Add(this.hazardMaterialControl); - } - else if (sender == this.menuItemPortAreas) - { - if (this.portAreaControl == null) - { - this.portAreaControl = new PortAreaControl(); - } - 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.menuItemWASExemptions) + { + if(this.wasExemptionsControl == null) + { + this.wasExemptionsControl = new WASExemptionsControl(); + } + this.rootContainer.Children.Add(this.wasExemptionsControl); + } + else if (sender == this.menuItemHazardMaterials) + { + if (this.hazardMaterialControl == null) + { + this.hazardMaterialControl = new HazardMaterialControl(); + } + this.rootContainer.Children.Add(this.hazardMaterialControl); + } + else if (sender == this.menuItemPortAreas) + { + if (this.portAreaControl == null) + { + this.portAreaControl = new PortAreaControl(); + } + 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); + } + } private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev) { diff --git a/bsmd.database/DBManagerAsync.cs b/bsmd.database/DBManagerAsync.cs index ae23cbc3..dad47024 100644 --- a/bsmd.database/DBManagerAsync.cs +++ b/bsmd.database/DBManagerAsync.cs @@ -21,7 +21,7 @@ namespace bsmd.database private static List _allPortAreaRows; private static Dictionary _allPortAreasByCode; private static List _allLADGNST2007Rows; - private static Dictionary _allLADGNST2007ByCode; + private static Dictionary _allLADGNST2007ByDescription; #endregion @@ -168,7 +168,7 @@ namespace bsmd.database public static async Task> GetLADGNST2007DictAsync(bool forceReload = false) { await EnsureLADGNST2007LoadedAsync(forceReload); - return _allLADGNST2007ByCode; + return _allLADGNST2007ByDescription; } public static Dictionary GetLADGNST2007Dict(bool forceReload = false) @@ -179,7 +179,7 @@ namespace bsmd.database public static void InvalidateLADGNST2007Cache() { _allLADGNST2007Rows = null; - _allLADGNST2007ByCode = null; + _allLADGNST2007ByDescription = null; } public static async Task> GetAGNTTemplatesAsync() @@ -266,13 +266,13 @@ namespace bsmd.database if (forceReload) InvalidateLADGNST2007Cache(); - if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByCode != null)) + if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByDescription != null)) return; await _ladgNst2007LoadLock.WaitAsync(); try { - if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByCode != null)) + if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByDescription != null)) return; SqlCommand cmd = new SqlCommand(); @@ -290,15 +290,15 @@ namespace bsmd.database } } - Dictionary byCode = new Dictionary(StringComparer.OrdinalIgnoreCase); + Dictionary byDescription = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (LADG_NST2007 nst in rows) { - if (!nst.NST2007.IsNullOrEmpty()) - byCode[nst.NST2007] = nst; + if (!nst.Description.IsNullOrEmpty()) + byDescription[nst.Description] = nst; } _allLADGNST2007Rows = rows; - _allLADGNST2007ByCode = byCode; + _allLADGNST2007ByDescription = byDescription; } finally { diff --git a/bsmd.database/LADG_NST2007.cs b/bsmd.database/LADG_NST2007.cs index f82a7a74..ad393710 100644 --- a/bsmd.database/LADG_NST2007.cs +++ b/bsmd.database/LADG_NST2007.cs @@ -26,25 +26,16 @@ namespace bsmd.database #endregion - #region public static methods + #region public static methods - public static bool NST2007Exists(string nst2007) - { - if (nst2007.IsNullOrEmpty()) - return false; - - return DBManagerAsync.GetLADGNST2007Dict().ContainsKey(nst2007); - } - - public static string GetDescription(string nst2007) - { - if (nst2007.IsNullOrEmpty()) - return null; - - if (DBManagerAsync.GetLADGNST2007Dict().TryGetValue(nst2007, out LADG_NST2007 value)) - return value.Description; - - return null; + public static List> GetNST2007List() + { + List> result = new List>(); + foreach (LADG_NST2007 item in DBManagerAsync.GetLADGNST2007Dict().Values) + { + result.Add(new KeyValuePair(item.Description, item.NST2007)); + } + return result; } #endregion