From 9b06decc430733080cf23778def66807cd62142c Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Mon, 2 May 2022 09:55:42 +0200 Subject: [PATCH] Added INFO, NOA_NOD, SERV --- ENI2/Excel/DakosyUtil.cs | 97 ++++++++++++++++++++++++++++++++++++--- ENI2/Excel/ExcelReader.cs | 27 +++++++++++ 2 files changed, 118 insertions(+), 6 deletions(-) diff --git a/ENI2/Excel/DakosyUtil.cs b/ENI2/Excel/DakosyUtil.cs index ec389fdd..60f6c723 100644 --- a/ENI2/Excel/DakosyUtil.cs +++ b/ENI2/Excel/DakosyUtil.cs @@ -175,6 +175,7 @@ namespace ENI2.Excel stat.CallSign = reader.ReadCellAsText("ship", "C9"); core.IMO = reader.ReadCellAsText("ship", "C10"); core.ENI = reader.ReadCellAsText("ship", "C11"); + core.PoC = reader.ReadCellAsText("port message", "C8"); DBManager.Instance.Save(core); stat.MMSINumber = reader.ReadCellAsText("ship", "C12"); stat.Flag = reader.ReadCellAsText("ship", "C13"); @@ -204,9 +205,31 @@ namespace ENI2.Excel return true; } - private static bool ScanSERV(Message message, ExcelReader reader) + private static bool ScanSERV(Message servMessage, ExcelReader reader) { - throw new NotImplementedException(); + bool result = false; + + for(int i=0;i<10000;i++) + { + string serviceName = reader.ReadCellAsText("port message", string.Format("B{0}", i + 50)); + string serviceBeneficiary = reader.ReadCellAsText("port message", string.Format("C{0}", i + 50)); + string serviceInvoiceRecipient = reader.ReadCellAsText("port message", string.Format("D{0}", i + 50)); + if (serviceName.IsNullOrEmpty() && serviceBeneficiary.IsNullOrEmpty()) break; + + if (!(servMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is SERV serv)) + { + serv = new SERV(); + serv.MessageHeader = servMessage; + serv.Identifier = (i + 1).ToString(); + servMessage.Elements.Add(serv); + } + serv.ServiceName = serviceName; + serv.ServiceBeneficiary = serviceBeneficiary; + serv.ServiceInvoiceRecipient = serviceInvoiceRecipient; + result = true; + } + + return result; } private static bool ScanSEC(Message message, ExcelReader reader) @@ -239,9 +262,46 @@ namespace ENI2.Excel throw new NotImplementedException(); } - private static bool ScanNOA_NOD(Message message, MessageCore messageCore, ExcelReader reader) + private static bool ScanNOA_NOD(Message noa_nodMessage, MessageCore messageCore, ExcelReader reader) { - throw new NotImplementedException(); + if (noa_nodMessage.Elements.Count == 0) + { + NOA_NOD newNAME = new NOA_NOD(); + newNAME.MessageHeader = noa_nodMessage; + noa_nodMessage.Elements.Add(newNAME); + } + + NOA_NOD noa_nod = noa_nodMessage.Elements[0] as NOA_NOD; + noa_nod.ETAToPortOfCall = reader.ReadCellAsDateTime("port message", "C26"); + noa_nod.ETDFromPortOfCall = reader.ReadCellAsDateTime("port message", "C27"); + // read call purposes + for (int i = 0; i < 9; i++) + { + int? callPurposeCode = (int?) reader.ReadCellAsDecimal("port message", string.Format("B{0}", 29 + i)); + string callPurposeDescription = reader.ReadCellAsText("port message", string.Format("C{0}", 29 + i)); + + if (callPurposeCode.HasValue) + { + if (!(noa_nod.GetSublistElementWithIdentifier(i.ToString()) is CallPurpose callPurpose)) + { + callPurpose = new CallPurpose(); + callPurpose.NOA_NOD = noa_nod; + callPurpose.Identifier = i.ToString(); + noa_nod.CallPurposes.Add(callPurpose); + } + callPurpose.CallPurposeCode = callPurposeCode.Value; + callPurpose.CallPurposeDescription = callPurposeDescription; + } + } + noa_nod.ETAToKielCanal = reader.ReadCellAsDateTime("port message", "C39"); + noa_nod.ETDFromKielCanal = reader.ReadCellAsDateTime("port message", "C40"); + + noa_nod.LastPort = reader.ReadCellAsText("port message", "C42"); + noa_nod.ETDFromLastPort = reader.ReadCellAsDateTime("port message", "C43"); + noa_nod.NextPort = reader.ReadCellAsText("port message", "C44"); + noa_nod.ETAToNextPort = reader.ReadCellAsDateTime("port message", "C45"); + + return true; } #region NAME @@ -274,9 +334,34 @@ namespace ENI2.Excel throw new NotImplementedException(); } - private static bool ScanINFO(Message message, ExcelReader reader) + private static bool ScanINFO(Message infoMessage, ExcelReader reader) { - throw new NotImplementedException(); + if (infoMessage.Elements.Count == 0) + { + INFO newINFO = new INFO(); + newINFO.MessageHeader = infoMessage; + infoMessage.Elements.Add(newINFO); + } + + INFO info = infoMessage.Elements[0] as INFO; + string shippingArea = reader.ReadCellAsText("port message", "C14"); + if (shippingArea.Equals("NORTH_BALTIC_SEA", StringComparison.OrdinalIgnoreCase)) info.ShippingArea = 0; + if (shippingArea.Equals("EUROPE", StringComparison.OrdinalIgnoreCase)) info.ShippingArea = 1; + if (shippingArea.Equals("OVERSEAS", StringComparison.OrdinalIgnoreCase)) info.ShippingArea = 2; + info.RequestedPositionInPortOfCall = reader.ReadCellAsText("port message", "C15"); + info.SpecialRequirementsOfShipAtBerth = reader.ReadCellAsText("port message", "C16"); + info.ConstructionCharacteristicsOfShip = reader.ReadCellAsText("port message", "C17"); + info.BowThrusterPower = reader.ReadCellAsText("port message", "C18"); + info.SternThrusterPower = reader.ReadCellAsText("port message", "C19"); + info.FumigatedBulkCargoBool = reader.ReadCellAsBool("port message", "C20"); + info.DeplacementSummerDraught_TNE = reader.ReadCellAsDecimal("port message", "C21"); + string portArea = reader.ReadCellAsText("port message", "C22")?.Trim().ToUpper(); + if (!portArea.IsNullOrEmpty() && DBManager.Instance.GetPortAreaDict().ContainsKey(portArea)) + info.PortArea = portArea; + else + info.PortArea = ""; + + return true; } private static bool ScanHAZD(Message message, ExcelReader reader) diff --git a/ENI2/Excel/ExcelReader.cs b/ENI2/Excel/ExcelReader.cs index 4eb84bc5..6ec51cce 100644 --- a/ENI2/Excel/ExcelReader.cs +++ b/ENI2/Excel/ExcelReader.cs @@ -576,6 +576,18 @@ namespace ENI2.Excel return null; } + internal bool? ReadCellAsBool(string sheetName, string range) + { + string boolString = ReadCellAsText(sheetName, range); + if (!boolString.IsNullOrEmpty()) + { + if (boolString.Equals("TRUE", StringComparison.OrdinalIgnoreCase)) return true; + if (boolString.Equals("FALSE", StringComparison.OrdinalIgnoreCase)) return false; + return null; + } + else return null; + } + internal double? ReadCellAsDecimal(string sheetName, string range) { try @@ -610,6 +622,21 @@ namespace ENI2.Excel return null; } + internal DateTime? ReadCellAsDateTime(string sheetName, string range) + { + string dateString = ReadCellAsText(sheetName, range); + if (dateString != null) + { + CultureInfo provider = CultureInfo.InvariantCulture; + const string format = "yyyy/MM/dd HH:mm"; + if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) + return tmpDate; + + return null; + } + else return null; + } + #endregion