STAT PortOfRegistry: hier sind alle Locodes, nicht nur Häfen erlaubt

This commit is contained in:
Daniel Schick 2022-05-31 07:58:33 +02:00
parent 9cb40ad699
commit 151f351ac2
4 changed files with 38 additions and 5 deletions

View File

@ -36,8 +36,8 @@
<MinimumRequiredVersion>5.4.0.0</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.html</WebPage>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>7.2.0.1</ApplicationVersion>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>7.2.0.2</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>

View File

@ -90,13 +90,14 @@ namespace ENI2.Excel
return new string(val.Where(c => !Char.IsWhiteSpace(c)).ToArray());
}
internal string ReadLoCode(string lookup)
internal string ReadLoCode(string lookup, bool justPorts = true)
{
string val = this.ReadText(lookup);
if (!val.IsNullOrEmpty())
{
val = val.ToUpper();
string portName = LocodeDB.PortNameFromLocode(val);
if (!justPorts) portName = LocodeDB.NameFromLocode(val);
if (portName.IsNullOrEmpty())
{
_log.WarnFormat("unknown Locode {0}", val);

View File

@ -978,7 +978,7 @@ namespace ENI2.Excel
}
}
stat.PortOfRegistry = reader.ReadLoCode("STAT.PortOfRegistry");
stat.PortOfRegistry = reader.ReadLoCode("STAT.PortOfRegistry", false);
if (stat.PortOfRegistry.Length == 5)
stat.Flag = stat.PortOfRegistry.Substring(0, 2);
stat.MMSINumber = reader.ReadTextNoWhitespace("STAT.MMSINumber");

View File

@ -146,6 +146,38 @@ namespace ENI2.Locode
return result;
}
/// <summary>
/// Get Name from LOCODE (any! type of locode, not just ports)
/// </summary>
public static string NameFromLocode(string locode)
{
if (locode.IsNullOrEmpty()) return null;
if (locode.Length != 5) return null;
string result = null;
try
{
string locodeUpper = locode.ToUpper();
string query = string.Format("SELECT locodes.name_wo_diacritics FROM locodes JOIN countries ON locodes.country_id = countries.ID WHERE locodes.city_code = '{0}' AND countries.code = '{1}'",
locodeUpper.Substring(2), locodeUpper.Substring(0, 2));
SQLiteCommand cmd = new SQLiteCommand(query, _con);
IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (!reader.IsDBNull(0))
result = reader.GetString(0);
break;
}
reader.Close();
cmd.Dispose();
}
catch (Exception ex)
{
_log.WarnFormat("Error on locode lookup: {0}", ex.Message);
}
return result;
}
/// <summary>
/// Get Portname from LOCODE
/// </summary>