Adjusted usage of NST2007 lookup in LADG dialog

This commit is contained in:
Daniel Schick 2026-02-19 13:54:47 +01:00
parent acc4fde897
commit a1eb65c834
6 changed files with 74 additions and 103 deletions

View File

@ -38,7 +38,7 @@ namespace ENI2.EditControls
InitializeComponent(); InitializeComponent();
Loaded += EditLADGDialog_Loaded; Loaded += EditLADGDialog_Loaded;
if (_nstList == null) if (_nstList == null)
_nstList = LocalizedLookup.GetNST2007List(); _nstList = LADG_NST2007.GetNST2007List();
} }
public LADG LADG { get; set; } public LADG LADG { get; set; }

View File

@ -230,27 +230,7 @@ namespace ENI2
} }
reader.Close(); reader.Close();
return results; return results;
} }
public static List<KeyValuePair<string, string>> GetNST2007List()
{
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
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<string, string> kvp = new KeyValuePair<string, string>(desc, code);
result.Add(kvp);
}
reader.Close();
return result;
}
public static List<string> getMVSHLocodes() public static List<string> getMVSHLocodes()
{ {

View File

@ -103,22 +103,22 @@
<Image Source="Resources/garbage.png" /> <Image Source="Resources/garbage.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem x:Name="menuItemHazardMaterials" Header="Hazard materials" Click="radioButton_Click"> <MenuItem x:Name="menuItemHazardMaterials" Header="Hazard materials" Click="radioButton_Click">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="Resources/sign_warning.png" /> <Image Source="Resources/sign_warning.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem x:Name="menuItemPortAreas" Header="Port areas" Click="radioButton_Click"> <MenuItem x:Name="menuItemPortAreas" Header="Port areas" Click="radioButton_Click">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="Resources/anchor.png" /> <Image Source="Resources/anchor.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem x:Name="menuItemLADGNST2007" Header="LADG NST2007" Click="radioButton_Click"> <MenuItem x:Name="menuItemLADGNST2007" Header="LADG NST2007" Click="radioButton_Click">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="Resources/nav_refresh_blue.png" /> <Image Source="Resources/containership.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
</MenuItem> </MenuItem>
<MenuItem x:Name="menuItemMaersk" Header="{x:Static p:Resources.textPOLists}" Click="radioButton_Click" Visibility="Hidden" /> <MenuItem x:Name="menuItemMaersk" Header="{x:Static p:Resources.textPOLists}" Click="radioButton_Click" Visibility="Hidden" />
<MenuItem x:Name="menuItemValueMappings" Header="{x:Static p:Resources.textExcelValueMappings}" Click="radioButton_Click" Visibility="Hidden" /> <MenuItem x:Name="menuItemValueMappings" Header="{x:Static p:Resources.textExcelValueMappings}" Click="radioButton_Click" Visibility="Hidden" />
<MenuItem x:Name="menuItemEasyPeasy" Header="{x:Static p:Resources.textEasyPeasy}" Click="radioButton_Click" Visibility="Hidden" /> <MenuItem x:Name="menuItemEasyPeasy" Header="{x:Static p:Resources.textEasyPeasy}" Click="radioButton_Click" Visibility="Hidden" />

View File

@ -39,11 +39,11 @@ namespace ENI2
private ServerStatusControl statusControl; private ServerStatusControl statusControl;
private readonly SucheControl sucheControl; private readonly SucheControl sucheControl;
private CompareExcelDialog compareExcelDialog; private CompareExcelDialog compareExcelDialog;
private EasyPeasyControl easyPeasyControl; private EasyPeasyControl easyPeasyControl;
private WASExemptionsControl wasExemptionsControl; private WASExemptionsControl wasExemptionsControl;
private HazardMaterialControl hazardMaterialControl; private HazardMaterialControl hazardMaterialControl;
private PortAreaControl portAreaControl; private PortAreaControl portAreaControl;
private LADG_NST2007Control ladgNst2007Control; private LADG_NST2007Control ladgNst2007Control;
private bool dbConnected; private bool dbConnected;
private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0); private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0);
@ -337,39 +337,39 @@ namespace ENI2
} }
this.rootContainer.Children.Add(this.easyPeasyControl); this.rootContainer.Children.Add(this.easyPeasyControl);
} }
else if (sender == this.menuItemWASExemptions) else if (sender == this.menuItemWASExemptions)
{ {
if(this.wasExemptionsControl == null) if(this.wasExemptionsControl == null)
{ {
this.wasExemptionsControl = new WASExemptionsControl(); this.wasExemptionsControl = new WASExemptionsControl();
} }
this.rootContainer.Children.Add(this.wasExemptionsControl); this.rootContainer.Children.Add(this.wasExemptionsControl);
} }
else if (sender == this.menuItemHazardMaterials) else if (sender == this.menuItemHazardMaterials)
{ {
if (this.hazardMaterialControl == null) if (this.hazardMaterialControl == null)
{ {
this.hazardMaterialControl = new HazardMaterialControl(); this.hazardMaterialControl = new HazardMaterialControl();
} }
this.rootContainer.Children.Add(this.hazardMaterialControl); this.rootContainer.Children.Add(this.hazardMaterialControl);
} }
else if (sender == this.menuItemPortAreas) else if (sender == this.menuItemPortAreas)
{ {
if (this.portAreaControl == null) if (this.portAreaControl == null)
{ {
this.portAreaControl = new PortAreaControl(); this.portAreaControl = new PortAreaControl();
} }
this.rootContainer.Children.Add(this.portAreaControl); this.rootContainer.Children.Add(this.portAreaControl);
} }
else if (sender == this.menuItemLADGNST2007) else if (sender == this.menuItemLADGNST2007)
{ {
if (this.ladgNst2007Control == null) if (this.ladgNst2007Control == null)
{ {
this.ladgNst2007Control = new LADG_NST2007Control(); this.ladgNst2007Control = new LADG_NST2007Control();
} }
this.rootContainer.Children.Add(this.ladgNst2007Control); this.rootContainer.Children.Add(this.ladgNst2007Control);
} }
} }
private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev) private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev)
{ {

View File

@ -21,7 +21,7 @@ namespace bsmd.database
private static List<PortArea> _allPortAreaRows; private static List<PortArea> _allPortAreaRows;
private static Dictionary<string, PortArea> _allPortAreasByCode; private static Dictionary<string, PortArea> _allPortAreasByCode;
private static List<LADG_NST2007> _allLADGNST2007Rows; private static List<LADG_NST2007> _allLADGNST2007Rows;
private static Dictionary<string, LADG_NST2007> _allLADGNST2007ByCode; private static Dictionary<string, LADG_NST2007> _allLADGNST2007ByDescription;
#endregion #endregion
@ -168,7 +168,7 @@ namespace bsmd.database
public static async Task<Dictionary<string, LADG_NST2007>> GetLADGNST2007DictAsync(bool forceReload = false) public static async Task<Dictionary<string, LADG_NST2007>> GetLADGNST2007DictAsync(bool forceReload = false)
{ {
await EnsureLADGNST2007LoadedAsync(forceReload); await EnsureLADGNST2007LoadedAsync(forceReload);
return _allLADGNST2007ByCode; return _allLADGNST2007ByDescription;
} }
public static Dictionary<string, LADG_NST2007> GetLADGNST2007Dict(bool forceReload = false) public static Dictionary<string, LADG_NST2007> GetLADGNST2007Dict(bool forceReload = false)
@ -179,7 +179,7 @@ namespace bsmd.database
public static void InvalidateLADGNST2007Cache() public static void InvalidateLADGNST2007Cache()
{ {
_allLADGNST2007Rows = null; _allLADGNST2007Rows = null;
_allLADGNST2007ByCode = null; _allLADGNST2007ByDescription = null;
} }
public static async Task<List<AGNT_Template>> GetAGNTTemplatesAsync() public static async Task<List<AGNT_Template>> GetAGNTTemplatesAsync()
@ -266,13 +266,13 @@ namespace bsmd.database
if (forceReload) if (forceReload)
InvalidateLADGNST2007Cache(); InvalidateLADGNST2007Cache();
if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByCode != null)) if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByDescription != null))
return; return;
await _ladgNst2007LoadLock.WaitAsync(); await _ladgNst2007LoadLock.WaitAsync();
try try
{ {
if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByCode != null)) if ((_allLADGNST2007Rows != null) && (_allLADGNST2007ByDescription != null))
return; return;
SqlCommand cmd = new SqlCommand(); SqlCommand cmd = new SqlCommand();
@ -290,15 +290,15 @@ namespace bsmd.database
} }
} }
Dictionary<string, LADG_NST2007> byCode = new Dictionary<string, LADG_NST2007>(StringComparer.OrdinalIgnoreCase); Dictionary<string, LADG_NST2007> byDescription = new Dictionary<string, LADG_NST2007>(StringComparer.OrdinalIgnoreCase);
foreach (LADG_NST2007 nst in rows) foreach (LADG_NST2007 nst in rows)
{ {
if (!nst.NST2007.IsNullOrEmpty()) if (!nst.Description.IsNullOrEmpty())
byCode[nst.NST2007] = nst; byDescription[nst.Description] = nst;
} }
_allLADGNST2007Rows = rows; _allLADGNST2007Rows = rows;
_allLADGNST2007ByCode = byCode; _allLADGNST2007ByDescription = byDescription;
} }
finally finally
{ {

View File

@ -26,25 +26,16 @@ namespace bsmd.database
#endregion #endregion
#region public static methods #region public static methods
public static bool NST2007Exists(string nst2007) public static List<KeyValuePair<string, string>> GetNST2007List()
{ {
if (nst2007.IsNullOrEmpty()) List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
return false; foreach (LADG_NST2007 item in DBManagerAsync.GetLADGNST2007Dict().Values)
{
return DBManagerAsync.GetLADGNST2007Dict().ContainsKey(nst2007); result.Add(new KeyValuePair<string, string>(item.Description, item.NST2007));
} }
return result;
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;
} }
#endregion #endregion