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();
Loaded += EditLADGDialog_Loaded;
if (_nstList == null)
_nstList = LocalizedLookup.GetNST2007List();
_nstList = LADG_NST2007.GetNST2007List();
}
public LADG LADG { get; set; }

View File

@ -232,26 +232,6 @@ namespace ENI2
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()
{
List<string> result = new List<string>();

View File

@ -115,7 +115,7 @@
</MenuItem>
<MenuItem x:Name="menuItemLADGNST2007" Header="LADG NST2007" Click="radioButton_Click">
<MenuItem.Icon>
<Image Source="Resources/nav_refresh_blue.png" />
<Image Source="Resources/containership.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>

View File

@ -21,7 +21,7 @@ namespace bsmd.database
private static List<PortArea> _allPortAreaRows;
private static Dictionary<string, PortArea> _allPortAreasByCode;
private static List<LADG_NST2007> _allLADGNST2007Rows;
private static Dictionary<string, LADG_NST2007> _allLADGNST2007ByCode;
private static Dictionary<string, LADG_NST2007> _allLADGNST2007ByDescription;
#endregion
@ -168,7 +168,7 @@ namespace bsmd.database
public static async Task<Dictionary<string, LADG_NST2007>> GetLADGNST2007DictAsync(bool forceReload = false)
{
await EnsureLADGNST2007LoadedAsync(forceReload);
return _allLADGNST2007ByCode;
return _allLADGNST2007ByDescription;
}
public static Dictionary<string, LADG_NST2007> 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<List<AGNT_Template>> 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<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)
{
if (!nst.NST2007.IsNullOrEmpty())
byCode[nst.NST2007] = nst;
if (!nst.Description.IsNullOrEmpty())
byDescription[nst.Description] = nst;
}
_allLADGNST2007Rows = rows;
_allLADGNST2007ByCode = byCode;
_allLADGNST2007ByDescription = byDescription;
}
finally
{

View File

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