diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index fe1eb57a..b093b377 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -36,8 +36,8 @@ 5.4.0.0 true publish.html - 1 - 7.2.0.1 + 2 + 7.2.0.2 false true true diff --git a/ENI2/Excel/ExcelReader.cs b/ENI2/Excel/ExcelReader.cs index c1f49d0c..bd21b971 100644 --- a/ENI2/Excel/ExcelReader.cs +++ b/ENI2/Excel/ExcelReader.cs @@ -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(); + val = val.ToUpper(); string portName = LocodeDB.PortNameFromLocode(val); + if (!justPorts) portName = LocodeDB.NameFromLocode(val); if (portName.IsNullOrEmpty()) { _log.WarnFormat("unknown Locode {0}", val); diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index 1f5bfb10..7c6be159 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -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"); diff --git a/bsmd.ExcelReadService/LocodeDB.cs b/bsmd.ExcelReadService/LocodeDB.cs index c8f40e7a..cf6ac2e6 100644 --- a/bsmd.ExcelReadService/LocodeDB.cs +++ b/bsmd.ExcelReadService/LocodeDB.cs @@ -146,6 +146,38 @@ namespace ENI2.Locode return result; } + /// + /// Get Name from LOCODE (any! type of locode, not just ports) + /// + 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; + } + /// /// Get Portname from LOCODE ///