// Copyright (c) 2022 - schick Informatik // Description: Helper class to read data from "Dakosy"-Style Excel Sheets // using System; using System.Collections.Generic; using bsmd.database; namespace ENI2.Excel { internal static class DakosyUtil { internal static bool ProcessSheet(ExcelReader reader, out string readMessage, MessageCore messageCore, List notificationClasses) { bool result = true; readMessage = ""; // Test if an Id is found in the sheet. If so, it has to match the id of the current core string visitTransitId = reader.ReadCellAsText("main", "C12"); if (visitTransitId != null) { MessageCore aMessageCore = null; if (bsmd.database.Util.IsVisitId(visitTransitId)) { aMessageCore = DBManager.Instance.GetMessageCoreByVisitId(visitTransitId); } else if (bsmd.database.Util.IsTransitId(visitTransitId)) { aMessageCore = DBManager.Instance.GetMessageCoreByTransitId(visitTransitId); } if ((aMessageCore == null) || (aMessageCore.Id.Value != messageCore.Id.Value)) { readMessage = "Id not matching in import sheet"; return false; } } string imo = reader.ReadCellAsText("ship", "C10"); if(!imo.IsNullOrEmpty() && !imo.Equals(messageCore.IMO)) { readMessage = "IMO not matching in import sheet"; return false; } string eni = reader.ReadCellAsText("ship", "C11"); if (!eni.IsNullOrEmpty() && !eni.Equals(messageCore.IMO)) { readMessage = "ENI not matching in import sheet"; return false; } // load messages if already present List messages = DBManager.Instance.GetMessagesForCore(messageCore, DBManager.MessageLoad.ALL); messages.Sort(); // now parse all data into the message classes try { foreach (Message message in messages) { if ((message.MessageNotificationClass == Message.NotificationClass.AGNT) && notificationClasses.Contains(Message.NotificationClass.AGNT)) { if (ScanAGNT(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.ATA) && notificationClasses.Contains(Message.NotificationClass.ATA)) { if (ScanATA(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.ATD) && notificationClasses.Contains(Message.NotificationClass.ATD)) { if (ScanATD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.BKRA) && notificationClasses.Contains(Message.NotificationClass.BKRA)) { if (ScanBKRA(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.BKRD) && notificationClasses.Contains(Message.NotificationClass.BKRD)) { if (ScanBKRD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.BPOL) && notificationClasses.Contains(Message.NotificationClass.BPOL)) { if (ScanBPOL(message, reader)) ExcelReader.SaveMessage(message); } if ((message.MessageNotificationClass == Message.NotificationClass.CREW) && notificationClasses.Contains(Message.NotificationClass.CREW)) { if (ScanCREW(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.CREWD) && notificationClasses.Contains(Message.NotificationClass.CREWD)) { if (ScanCREWD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.HAZA) && notificationClasses.Contains(Message.NotificationClass.HAZA)) { if (ScanHAZA(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.HAZD) && notificationClasses.Contains(Message.NotificationClass.HAZD)) { if (ScanHAZD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.INFO) && notificationClasses.Contains(Message.NotificationClass.INFO)) { if (ScanINFO(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.LADG) && notificationClasses.Contains(Message.NotificationClass.LADG)) { if (ScanLADG(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.MDH) && notificationClasses.Contains(Message.NotificationClass.MDH)) { if (ScanMDH(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.NAME) && notificationClasses.Contains(Message.NotificationClass.NAME)) { if (ScanNAME(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.NOA_NOD) && notificationClasses.Contains(Message.NotificationClass.NOA_NOD)) { if (ScanNOA_NOD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.PAS) && notificationClasses.Contains(Message.NotificationClass.PAS)) { if (ScanPAS(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.PASD) && notificationClasses.Contains(Message.NotificationClass.PASD)) { if (ScanPASD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.POBA) && notificationClasses.Contains(Message.NotificationClass.POBA)) { if (ScanPOBA(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.POBD) && notificationClasses.Contains(Message.NotificationClass.POBD)) { if (ScanPOBD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.PRE72H) && notificationClasses.Contains(Message.NotificationClass.PRE72H)) { if (ScanPRE72H(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.SEC) && notificationClasses.Contains(Message.NotificationClass.SEC)) { if (ScanSEC(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.SERV) && notificationClasses.Contains(Message.NotificationClass.SERV)) { if (ScanSERV(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.STAT) && notificationClasses.Contains(Message.NotificationClass.STAT)) { if (ScanSTAT(message, messageCore, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.STO) && notificationClasses.Contains(Message.NotificationClass.STO)) { if (ScanSTO(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.TIEFA) && notificationClasses.Contains(Message.NotificationClass.TIEFA)) { if (ScanTIEFA(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.TIEFD) && notificationClasses.Contains(Message.NotificationClass.TIEFD)) { if (ScanTIEFD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.TOWA) && notificationClasses.Contains(Message.NotificationClass.TOWA)) { if (ScanTOWA(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.TOWD) && notificationClasses.Contains(Message.NotificationClass.TOWD)) { if (ScanTOWD(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.WAS) && notificationClasses.Contains(Message.NotificationClass.WAS)) { if (ScanWAS(message, reader)) ExcelReader.SaveMessage(message); continue; } if ((message.MessageNotificationClass == Message.NotificationClass.WAS_RCPT) && notificationClasses.Contains(Message.NotificationClass.WAS_RCPT)) { if (ScanWAS_RCPT(message, reader)) ExcelReader.SaveMessage(message); continue; } } DBManager.Instance.Save(messageCore); // muss das eigentlich sein? } catch (Exception ex) { readMessage = ex.Message; result = false; } return result; } #region WAS_RCPT private static bool ScanWAS_RCPT(Message was_rcptMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 20; i++) { string idNumber = reader.ReadCellAsText("waste delivery receipt", string.Format("B{0}", i + 9)); if (idNumber.IsNullOrEmpty()) continue; if (!(was_rcptMessage.GetSublistElementWithIdentifier(i.ToString()) is WAS_RCPT wasr)) { wasr = new WAS_RCPT(); wasr.Identifier = i.ToString(); wasr.MessageHeader = was_rcptMessage; was_rcptMessage.Elements.Add(wasr); } wasr.IdentificationNumber = idNumber; wasr.PortReceptionFacilityName = reader.ReadCellAsText("waste delivery receipt", string.Format("C{0}", i + 9)); wasr.PortReceptionFacilityProviderName = reader.ReadCellAsText("waste delivery receipt", string.Format("D{0}", i + 9)); wasr.WasteDeliveryDateFrom = reader.ReadCellAsDateTime("waste delivery receipt", string.Format("E{0}", i + 9)); wasr.WasteDeliveryDateTo = reader.ReadCellAsDateTime("waste delivery receipt", string.Format("F{0}", i + 9)); // now for the love of god this ist so stupid but I have no better way ReadWasteReceived(wasr, "101", string.Format("G{0}", i + 9), null, reader); ReadWasteReceived(wasr, "102", string.Format("H{0}", i + 9), null, reader); ReadWasteReceived(wasr, "103", string.Format("I{0}", i + 9), null, reader); ReadWasteReceived(wasr, "104", string.Format("J{0}", i + 9), null, reader); ReadWasteReceived(wasr, "105", string.Format("K{0}", i + 9), null, reader); ReadWasteReceived(wasr, "201", string.Format("L{0}", i + 9), string.Format("M{0}", i + 9) , reader); ReadWasteReceived(wasr, "202", string.Format("N{0}", i + 9), string.Format("O{0}", i + 9), reader); ReadWasteReceived(wasr, "203", string.Format("P{0}", i + 9), string.Format("Q{0}", i + 9), reader); ReadWasteReceived(wasr, "204", string.Format("R{0}", i + 9), string.Format("S{0}", i + 9), reader); ReadWasteReceived(wasr, "401", string.Format("T{0}", i + 9), null, reader); ReadWasteReceived(wasr, "501", string.Format("U{0}", i + 9), null, reader); ReadWasteReceived(wasr, "502", string.Format("V{0}", i + 9), null, reader); ReadWasteReceived(wasr, "503", string.Format("W{0}", i + 9), null, reader); ReadWasteReceived(wasr, "504", string.Format("X{0}", i + 9), null, reader); ReadWasteReceived(wasr, "505", string.Format("Y{0}", i + 9), null, reader); ReadWasteReceived(wasr, "506", string.Format("Z{0}", i + 9), null, reader); ReadWasteReceived(wasr, "507", string.Format("AA{0}", i + 9), null, reader); ReadWasteReceived(wasr, "508", string.Format("AB{0}", i + 9), null, reader); ReadWasteReceived(wasr, "509", string.Format("AC{0}", i + 9), null, reader); ReadWasteReceived(wasr, "510", string.Format("AD{0}", i + 9), string.Format("AE{0}", i + 9), reader); ReadWasteReceived(wasr, "511", string.Format("AF{0}", i + 9), string.Format("AG{0}", i + 9), reader); ReadWasteReceived(wasr, "601", string.Format("AH{0}", i + 9), null, reader); ReadWasteReceived(wasr, "602", string.Format("AI{0}", i + 9), null, reader); ReadWasteReceived(wasr, "991", string.Format("AJ{0}", i + 9), null, reader); ReadWasteReceived(wasr, "999", string.Format("AK{0}", i + 9), string.Format("AL{0}", i + 9), reader); ReadTreatmentFacility(wasr, string.Format("AM{0}", i + 9), reader); ReadTreatmentFacility(wasr, string.Format("AN{0}", i + 9), reader); ReadTreatmentFacility(wasr, string.Format("AO{0}", i + 9), reader); result = true; } return result; } private static void ReadWasteReceived(WAS_RCPT was_rcpt, string wasteCode, string amountCell, string descriptionCell, ExcelReader reader) { double? amount = reader.ReadCellAsDecimal("waste delivery receipt", amountCell); if (amount.HasValue) { WasteReceived wr = new WasteReceived(); wr.Identifier = (was_rcpt.WasteReceived.Count + 1).ToString(); wr.WAS_RCPT = was_rcpt; was_rcpt.WasteReceived.Add(wr); wr.WasteCode = wasteCode; wr.AmountWasteReceived_MTQ = amount; if(!descriptionCell.IsNullOrEmpty()) { wr.WasteDescription = reader.ReadCellAsText("waste delivery receipt", descriptionCell); } } } private static void ReadTreatmentFacility(WAS_RCPT was_rcpt, string facCell, ExcelReader reader) { string tfpText = reader.ReadCellAsText("waste delivery receipt", facCell); if(!tfpText.IsNullOrEmpty()) { TreatmentFacilityProvider tfp = new TreatmentFacilityProvider(); tfp.Identifier = (was_rcpt.TreatmentFacilityProvider.Count + 1).ToString(); tfp.WAS_RCPT = was_rcpt; tfp.TreatmentFacilityProviderName = tfpText; was_rcpt.TreatmentFacilityProvider.Add(tfp); } } #endregion #region WAS private static bool ScanWAS(Message wasMessage, ExcelReader reader) { if (wasMessage.Elements.Count == 0) { WAS newWAS = new WAS(); newWAS.MessageHeader = wasMessage; wasMessage.Elements.Add(newWAS); } WAS was = wasMessage.Elements[0] as WAS; was.WasteDisposalValidExemption = reader.ReadCellAsBool("waste", "C8"); was.ConfirmationOfCorrectness = true; was.ConfirmationOfSufficiency = true; if(!(was.WasteDisposalValidExemption ?? false)) { was.LastWasteDisposalPort = reader.ReadCellAsText("waste", "C10"); was.LastWasteDisposalDate = reader.ReadCellAsDateTime("waste", "C11"); was.NextWasteDisposalPort = reader.ReadCellAsText("waste", "C12"); for (int i = 1; i <= 25; i++) { if (!(was.GetSublistElementWithIdentifier(i.ToString()) is Waste waste)) { waste = new Waste(); waste.Identifier = i.ToString(); waste.WAS = was; was.Waste.Add(waste); } waste.WasteType = (int?)reader.ReadCellAsDecimal("waste", string.Format("C{0}", i + 18)); waste.WasteDescription = reader.ReadCellAsText("waste", string.Format("D{0}", i + 18)); waste.WasteDisposalAmount_MTQ = reader.ReadCellAsDecimal("waste", string.Format("E{0}", i + 18)); waste.WasteCapacity_MTQ = reader.ReadCellAsDecimal("waste", string.Format("F{0}", i + 18)); waste.WasteAmountRetained_MTQ = reader.ReadCellAsDecimal("waste", string.Format("G{0}", i + 18)); waste.WasteDisposalPort = reader.ReadCellAsText("waste", string.Format("H{0}", i + 18)); waste.WasteAmountGeneratedTillNextPort_MTQ = reader.ReadCellAsDecimal("waste", string.Format("I{0}", i + 18)); } was.WasteDisposalServiceProvider.Clear(); for (int i = 1; i < 1000; i++) { string wsdpName = reader.ReadCellAsText("waste", string.Format("B{0}", i + 45)); if (wsdpName.IsNullOrEmpty()) break; WasteDisposalServiceProvider wdsp = new WasteDisposalServiceProvider(); wdsp.Identifier = i.ToString(); wdsp.WAS = was; was.WasteDisposalServiceProvider.Add(wdsp); wdsp.WasteDisposalServiceProviderName = wsdpName; } } return true; } #endregion #region TOWD private static bool ScanTOWD(Message towdMessage, ExcelReader reader) { bool result = false; for (int i = 1; i < 10000; i++) { string towdName = reader.ReadCellAsText("towage on departure", string.Format("B{0}", 10 + i)); if (towdName.IsNullOrEmpty()) break; if (!(towdMessage.GetSublistElementWithIdentifier(i.ToString()) is TOWD towd)) { towd = new TOWD(); towd.MessageHeader = towdMessage; towd.Identifier = i.ToString(); towdMessage.Elements.Add(towd); } towd.TowageOnDepartureName = towdName; towd.TowageOnDepartureFlag = reader.ReadCellAsText("towage on departure", string.Format("C{0}", 10 + i)); towd.TowageOnDepartureOperatorCompanyName = reader.ReadCellAsText("towage on departure", string.Format("D{0}", 10 + i)); towd.TowageOnDepartureOperatorStreetNameAndNumber = reader.ReadCellAsText("towage on departure", string.Format("E{0}", 10 + i)); towd.TowageOnDepartureOperatorPostalCode = reader.ReadCellAsText("towage on departure", string.Format("F{0}", 10 + i)); towd.TowageOnDepartureOperatorCity = reader.ReadCellAsText("towage on departure", string.Format("G{0}", 10 + i)); towd.TowageOnDepartureOperatorCountry = reader.ReadCellAsText("towage on departure", string.Format("H{0}", 10 + i)); towd.TowageOnDepartureOperatorPhone = reader.ReadCellAsText("towage on departure", string.Format("J{0}", 10 + i)); towd.TowageOnDepartureOperatorEmail = reader.ReadCellAsText("towage on departure", string.Format("K{0}", 10 + i)); towd.TowageOnDepartureDraught_DMT = reader.ReadCellAsDecimal("towage on departure", string.Format("L{0}", 10 + i)); towd.TowageOnDepartureLengthOverall_MTR = reader.ReadCellAsDecimal("towage on departure", string.Format("M{0}", 10 + i)); towd.TowageOnDepartureBeam_MTR = reader.ReadCellAsDecimal("towage on departure", string.Format("N{0}", 10 + i)); towd.TowageOnDepartureRemarks = reader.ReadCellAsText("towage on departure", string.Format("O{0}", 10 + i)); result = true; } return result; } #endregion #region TOWA private static bool ScanTOWA(Message towaMessage, ExcelReader reader) { bool result = false; for (int i = 1; i < 10000; i++) { string towaName = reader.ReadCellAsText("towage on arrival", string.Format("B{0}", 10 + i)); if (towaName.IsNullOrEmpty()) break; if (!(towaMessage.GetSublistElementWithIdentifier(i.ToString()) is TOWA towa)) { towa = new TOWA(); towa.MessageHeader = towaMessage; towa.Identifier = i.ToString(); towaMessage.Elements.Add(towa); } towa.TowageOnArrivalName = towaName; towa.TowageOnArrivalFlag = reader.ReadCellAsText("towage on arrival", string.Format("C{0}", 10 + i)); towa.TowageOnArrivalOperatorCompanyName = reader.ReadCellAsText("towage on arrival", string.Format("D{0}", 10 + i)); towa.TowageOnArrivalOperatorStreetNameAndNumber = reader.ReadCellAsText("towage on arrival", string.Format("E{0}", 10 + i)); towa.TowageOnArrivalOperatorPostalCode = reader.ReadCellAsText("towage on arrival", string.Format("F{0}", 10 + i)); towa.TowageOnArrivalOperatorCity = reader.ReadCellAsText("towage on arrival", string.Format("G{0}", 10 + i)); towa.TowageOnArrivalOperatorCountry = reader.ReadCellAsText("towage on arrival", string.Format("H{0}", 10 + i)); towa.TowageOnArrivalOperatorPhone = reader.ReadCellAsText("towage on arrival", string.Format("J{0}", 10 + i)); towa.TowageOnArrivalOperatorEmail = reader.ReadCellAsText("towage on arrival", string.Format("K{0}", 10 + i)); towa.TowageOnArrivalGrossTonnage = (int?) reader.ReadCellAsDecimal("towage on arrival", string.Format("L{0}", 10 + i)); towa.TowageOnArrivalLengthOverall_MTR = reader.ReadCellAsDecimal("towage on arrival", string.Format("M{0}", 10 + i)); towa.TowageOnArrivalBeam_MTR = reader.ReadCellAsDecimal("towage on arrival", string.Format("N{0}", 10 + i)); towa.TowageOnArrivalPurposeOfCall = reader.ReadCellAsText("towage on arrival", string.Format("O{0}", 10 + i)); towa.TowageOnArrivalDraught_DMT = reader.ReadCellAsDecimal("towage on arrival", string.Format("P{0}", 10 + i)); towa.TowageOnArrivalRemarks = reader.ReadCellAsText("towage on arrival", string.Format("Q{0}", 10 + i)); result = true; } return result; } #endregion #region TIEFD private static bool ScanTIEFD(Message tiefdMessage, ExcelReader reader) { if (tiefdMessage.Elements.Count == 0) { TIEFD newTIEFD = new TIEFD(); newTIEFD.MessageHeader = tiefdMessage; tiefdMessage.Elements.Add(newTIEFD); } TIEFD tiefd = tiefdMessage.Elements[0] as TIEFD; tiefd.DraughtUponDeparture_DMT = reader.ReadCellAsDecimal("traffic message on departure", "C14"); return tiefd.DraughtUponDeparture_DMT.HasValue; } #endregion #region TIEFA private static bool ScanTIEFA(Message tiefaMessage, ExcelReader reader) { if (tiefaMessage.Elements.Count == 0) { TIEFA newTIEFA = new TIEFA(); newTIEFA.MessageHeader = tiefaMessage; tiefaMessage.Elements.Add(newTIEFA); } TIEFA tiefa = tiefaMessage.Elements[0] as TIEFA; tiefa.DraughtUponArrival_DMT = reader.ReadCellAsDecimal("traffic message on arrival", "C14"); return tiefa.DraughtUponArrival_DMT.HasValue; } #endregion #region STO private static bool ScanSTO(Message message, ExcelReader reader) { return false; // not reported on dakosy sheet } #endregion #region STAT private static bool ScanSTAT(Message statMessage, MessageCore core, ExcelReader reader) { if (statMessage.Elements.Count == 0) { STAT newSTAT = new STAT(); newSTAT.MessageHeader = statMessage; statMessage.Elements.Add(newSTAT); } STAT stat = statMessage.Elements[0] as STAT; stat.ShipName = reader.ReadCellAsText("ship", "C8"); 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"); stat.LengthOverall_MTR = reader.ReadCellAsDecimal("ship", "C14"); stat.Beam_MTR = reader.ReadCellAsDecimal("ship", "C15"); stat.GrossTonnage = (int?) reader.ReadCellAsDecimal("ship", "C16"); stat.PortOfRegistry = reader.ReadCellAsText("ship", "C17"); stat.InmarsatCallNumber = string.Format("{0} {1} {2} {3} {4}", reader.ReadCellAsText("ship", "C18"), reader.ReadCellAsText("ship", "C19"), reader.ReadCellAsText("ship", "C20"), reader.ReadCellAsText("ship", "C21"), reader.ReadCellAsText("ship", "C22") ).Trim(); stat.ShipType = reader.ReadCellAsText("ship", "C23"); stat.TransportMode = reader.ReadCellAsText("ship", "C24"); stat.ISMCompanyName = reader.ReadCellAsText("ship", "C26"); stat.ISMCompanyId = reader.ReadCellAsText("ship", "C27"); string street = reader.ReadCellAsText("ship", "C28"); string number = reader.ReadCellAsText("ship", "C29"); stat.ISMCompanyStreetAndNumber = string.Format("{0} {1}", street, number).Trim(); stat.ISMCompanyPostalCode = reader.ReadCellAsText("ship", "C30"); stat.ISMCompanyCity = reader.ReadCellAsText("ship", "C31"); stat.ISMCompanyCountry = reader.ReadCellAsText("ship", "C32"); return true; } #endregion #region SERV private static bool ScanSERV(Message servMessage, ExcelReader reader) { 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; } #endregion #region SEC private static bool ScanSEC(Message secMessage, ExcelReader reader) { if (secMessage.Elements.Count == 0) { SEC newSEC = new SEC(); newSEC.MessageHeader = secMessage; secMessage.Elements.Add(newSEC); } SEC sec = secMessage.Elements[0] as SEC; sec.CurrentShipSecurityLevel = (byte?)reader.ReadCellAsDecimal("security", "D7"); sec.SECSimplification = reader.ReadCellAsBool("security", "D9"); sec.KielCanalPassagePlanned = reader.ReadCellAsBool("security", "I7") ?? false; if(sec.KielCanalPassagePlanned ?? false) { DateTime? incoming = reader.ReadCellAsDateTime("security", "I9"); if (incoming.HasValue) sec.KielCanalPassagePlannedIncomming = new DateTime(incoming.Value.Year, incoming.Value.Month, incoming.Value.Day, 11, 11, 0).ToUniversalTime(); DateTime? outgoing = reader.ReadCellAsDateTime("security", "I12"); if(outgoing.HasValue) sec.KielCanalPassagePlannedOutgoing = new DateTime(outgoing.Value.Year, outgoing.Value.Month, outgoing.Value.Day, 11, 11, 0).ToUniversalTime(); } if(sec.SECSimplification ?? false) { sec.PortOfCallWhereCompleteSECNotified = reader.ReadCellAsText("security", "D10")?.Substring(0, 5); } else { sec.CSOLastName = reader.ReadCellAsText("security", "D12"); sec.CSOFirstName = reader.ReadCellAsText("security", "D13"); sec.CSOPhone = reader.ReadCellAsText("security", "D14"); sec.CSOFax = reader.ReadCellAsText("security", "D15"); sec.CSOEMail = reader.ReadCellAsText("security", "D16"); sec.ValidISSCOnBoard = reader.ReadCellAsBool("security", "D17"); sec.ReasonsForNoValidISSC = reader.ReadCellAsText("security", "D18"); string isscType = reader.ReadCellAsText("security", "D19"); if(!isscType.IsNullOrEmpty()) { if (isscType.Equals("full", StringComparison.OrdinalIgnoreCase)) sec.ISSCType = 0; if (isscType.Equals("interim", StringComparison.OrdinalIgnoreCase)) sec.ISSCType = 1; } string issuerType = reader.ReadCellAsText("security", "D20"); if(!issuerType.IsNullOrEmpty()) { if (issuerType.Equals("ADMINISTRATION", StringComparison.OrdinalIgnoreCase)) sec.ISSCIssuerType = 0; if (issuerType.Equals("RSO", StringComparison.OrdinalIgnoreCase)) sec.ISSCIssuerType = 1; } sec.ISSCIssuerName = reader.ReadCellAsText("security", "D21"); sec.ISSCDateOfExpiration = reader.ReadCellAsDateTime("security", "D22"); sec.ApprovedSecurityPlanOnBoard = reader.ReadCellAsBool("security", "D23"); sec.PortFacilityOfArrival = reader.ReadCellAsText("security", "D24"); string generalDoC = reader.ReadCellAsText("security", "D25"); if(!generalDoC.IsNullOrEmpty()) { if(generalDoC.Equals("container", StringComparison.OrdinalIgnoreCase)) sec.GeneralDescriptionOfCargo = 0; if (generalDoC.Equals("vehicles", StringComparison.OrdinalIgnoreCase)) sec.GeneralDescriptionOfCargo = 1; if (generalDoC.Equals("conventional_general_cargo", StringComparison.OrdinalIgnoreCase)) sec.GeneralDescriptionOfCargo = 2; if (generalDoC.Equals("dry_cargo_in_bulk", StringComparison.OrdinalIgnoreCase)) sec.GeneralDescriptionOfCargo = 3; if (generalDoC.Equals("liquid_cargo_in_bulk", StringComparison.OrdinalIgnoreCase)) sec.GeneralDescriptionOfCargo = 4; if (generalDoC.Equals("empty", StringComparison.OrdinalIgnoreCase)) sec.GeneralDescriptionOfCargo = 5; } for (int i = 1; i <= 10; i++) { if (!(sec.GetPortFacilityWithIdentifier(i.ToString()) is LastTenPortFacilitiesCalled l10fc)) { l10fc = new LastTenPortFacilitiesCalled(); l10fc.Identifier = i.ToString(); l10fc.SEC = sec; sec.LastTenPortFacilitesCalled.Add(l10fc); } l10fc.PortFacilityPortName = reader.ReadCellAsText("security", String.Format("B{0}", i + 30)); l10fc.PortFacilityPortCountry = reader.ReadCellAsText("security", String.Format("C{0}", i + 30)); l10fc.PortFacilityPortLoCode = reader.ReadCellAsText("security", String.Format("D{0}", i + 30)); l10fc.PortFacilityDateOfArrival = reader.ReadCellAsDateTime("security", String.Format("E{0}", i + 30)); l10fc.PortFacilityDateOfDeparture = reader.ReadCellAsDateTime("security", String.Format("F{0}", i + 30)); l10fc.PortFacilityShipSecurityLevel = (byte?) reader.ReadCellAsDecimal("security", String.Format("G{0}", i + 30)); l10fc.PortFacilitySecurityMattersToReport = reader.ReadCellAsText("security", String.Format("H{0}", i + 30)); l10fc.PortFacilityGISISCode = reader.ReadCellAsText("security", String.Format("I{0}", i + 30)); l10fc.PortFacilityGISISCodeLocode = reader.ReadCellAsText("security", String.Format("J{0}", i + 30)); // keinen "leeren" Hafen anlegen, wenn der Eintrag leer war (trifft anscheinend bei Neubauten zu, siehe E-Mail Christin vom 20./22.6.17 if (l10fc.PortFacilityPortName.IsNullOrEmpty() && l10fc.PortFacilityPortLoCode.IsNullOrEmpty() && l10fc.PortFacilityPortCountry.IsNullOrEmpty()) sec.LastTenPortFacilitesCalled.Remove(l10fc); } for (int i = 1; i <= 10; i++) { if (!(sec.GetShipToShipWithIdentifier(i.ToString()) is ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2sActivity)) { s2sActivity = new ShipToShipActivitiesDuringLastTenPortFacilitiesCalled(); s2sActivity.Identifier = i.ToString(); s2sActivity.SEC = sec; sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Add(s2sActivity); } s2sActivity.ShipToShipActivityLocationName = reader.ReadCellAsText("security", string.Format("B{0}", i + 45)); s2sActivity.ShipToShipActivityLocationLoCode = reader.ReadCellAsText("security", string.Format("C{0}", i + 45)); s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = (int?) reader.ReadCellAsDecimal("security", string.Format("D{0}", i + 45)); s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = (int?) reader.ReadCellAsDecimal("security", string.Format("E{0}", i + 45)); s2sActivity.ShipToShipActivityDateFrom = reader.ReadCellAsDateTime("security", string.Format("F{0}", i + 45)); s2sActivity.ShipToShipActivityDateTo = reader.ReadCellAsDateTime("security", string.Format("G{0}", i + 45)); s2sActivity.ShipToShipActivityTypeCode = (int?) reader.ReadCellAsDecimal("security", string.Format("H{0}", i + 45)); s2sActivity.ShipToShipActivitySecurityMattersToReport = reader.ReadCellAsText("security", string.Format("I{0}", i + 45)); if (s2sActivity.ShipToShipActivityLocationName.IsNullOrEmpty() && s2sActivity.ShipToShipActivityLocationLoCode.IsNullOrEmpty() && !(s2sActivity.ShipToShipActivityLocationCoordinatesLatitude.HasValue && s2sActivity.ShipToShipActivityLocationCoordinatesLongitude.HasValue)) sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Remove(s2sActivity); } } return true; } #endregion #region PRE72H private static bool ScanPRE72H(Message pre72hMessage, ExcelReader reader) { if (pre72hMessage.Elements.Count == 0) { PRE72H newPRE72H = new PRE72H(); newPRE72H.MessageHeader = pre72hMessage; pre72hMessage.Elements.Add(newPRE72H); } PRE72H pre72h = pre72hMessage.Elements[0] as PRE72H; pre72h.Tanker = reader.ReadCellAsBool("port state control", "C8"); if(pre72h.Tanker ?? false) { string hull = reader.ReadCellAsText("port state control", "C10"); if (hull.Equals("single_hull", StringComparison.OrdinalIgnoreCase)) pre72h.TankerHullConfiguration = 0; if (hull.Equals("single_hull_with_sbt", StringComparison.OrdinalIgnoreCase)) pre72h.TankerHullConfiguration = 1; if (hull.Equals("double_hull", StringComparison.OrdinalIgnoreCase)) pre72h.TankerHullConfiguration = 2; string condition = reader.ReadCellAsText("port state control", "C11"); if (condition.Equals("full", StringComparison.OrdinalIgnoreCase)) pre72h.ConditionCargoBallastTanks = 0; if (condition.Equals("empty", StringComparison.OrdinalIgnoreCase)) pre72h.ConditionCargoBallastTanks = 1; if (condition.Equals("inerted", StringComparison.OrdinalIgnoreCase)) pre72h.ConditionCargoBallastTanks = 2; pre72h.NatureOfCargo = reader.ReadCellAsText("port state control", "C12"); pre72h.VolumeOfCargo = reader.ReadCellAsDecimal("port state control", "C13"); } pre72h.PlannedOperations = reader.ReadTextFromDropdown("port state control", "C14"); pre72h.PlannedWorks = reader.ReadCellAsText("port state control", "C15"); pre72h.DateOfLastExpandedInspection = reader.ReadCellAsDateTime("port state control", "C16"); pre72h.PlannedPeriodOfStay_HUR = reader.ReadCellAsDecimal("port state control", "C17"); if (pre72h.PlannedWorks.IsNullOrEmpty()) pre72h.PlannedWorks = "n"; return true; } #endregion #region POBD private static bool ScanPOBD(Message pobdMessage, ExcelReader reader) { if (pobdMessage.Elements.Count == 0) { POBD newPOBD = new POBD(); newPOBD.MessageHeader = pobdMessage; pobdMessage.Elements.Add(newPOBD); } POBD pobd = pobdMessage.Elements[0] as POBD; pobd.TotalPersonsOnBoardUponDeparture = (int?)reader.ReadCellAsDecimal("traffic message on departure", "C8"); pobd.TotalCrewMembersOnBoardUponDeparture = (int?)reader.ReadCellAsDecimal("traffic message on departure", "C9"); pobd.TotalPassengersOnBoardUponDeparture = (int?)reader.ReadCellAsDecimal("traffic message on departure", "C10"); pobd.TotalStowawaysOnBoardUponDeparture = (int?)reader.ReadCellAsDecimal("traffic message on departure", "C11"); return true; } #endregion #region POBA private static bool ScanPOBA(Message pobaMessage, ExcelReader reader) { if (pobaMessage.Elements.Count == 0) { POBA newPOBA = new POBA(); newPOBA.MessageHeader = pobaMessage; pobaMessage.Elements.Add(newPOBA); } POBA poba = pobaMessage.Elements[0] as POBA; poba.TotalPersonsOnBoardUponArrival = (int?) reader.ReadCellAsDecimal("traffic message on arrival", "C8"); poba.TotalCrewMembersOnBoardUponArrival = (int?) reader.ReadCellAsDecimal("traffic message on arrival", "C9"); poba.TotalPassengersOnBoardUponArrival = (int?) reader.ReadCellAsDecimal("traffic message on arrival", "C10"); poba.TotalStowawaysOnBoardUponArrival = (int?) reader.ReadCellAsDecimal("traffic message on arrival", "C11"); return true; } #endregion #region PASD private static bool ScanPASD(Message pasdMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 1000; i++) { string lastName = reader.ReadCellAsText("passenger departure", string.Format("B{0}", i + 16)); if (lastName.IsNullOrEmpty()) break; if (!(pasdMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is PAS pas)) { pas = new PASD(); pas.Identifier = (i + 1).ToString(); pas.MessageHeader = pasdMessage; pasdMessage.Elements.Add(pas); } pas.NotificationSchengen = reader.ReadCellAsBool("passenger departure", "C10"); pas.NotificationPAX = reader.ReadCellAsBool("passenger departure", "C11"); pas.PassengerLastName = lastName; pas.PassengerFirstName = reader.ReadCellAsText("passenger departure", string.Format("C{0}", i + 16)); pas.PassengerPlaceOfBirth = reader.ReadCellAsText("passenger departure", string.Format("D{0}", i + 16)); pas.PassengerCountryOfBirth = reader.ReadCellAsText("passenger departure", string.Format("E{0}", i + 16)); pas.PassengerDateOfBirth = reader.ReadCellAsDateTime("passenger departure", string.Format("F{0}", i + 16)); pas.PassengerGender = ParseGender(reader.ReadCellAsText("passenger departure", string.Format("G{0}", i + 16))); pas.PassengerNationality = reader.ReadCellAsText("passenger departure", string.Format("H{0}", i + 16)); pas.PassengerIdentityDocumentIssuingState = reader.ReadCellAsText("passenger departure", string.Format("O{0}", i + 16)); pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime("passenger departure", string.Format("P{0}", i + 16)); if (pas.NotificationPAX ?? false) { pas.EmergencyCare = reader.ReadCellAsText("passenger departure", string.Format("Q{0}", i + 16)); pas.EmergencyContactNumber = reader.ReadCellAsText("passenger departure", string.Format("R{0}", i + 16)); } if (pas.NotificationSchengen ?? false) { pas.PassengerIdentityDocumentType = ParseDocumentType(reader.ReadCellAsText("passenger departure", string.Format("I{0}", i + 16))); pas.PassengerIdentityDocumentId = reader.ReadCellAsText("passenger departure", string.Format("J{0}", i + 16)); pas.PassengerVisaNumber = reader.ReadCellAsText("passenger departure", string.Format("K{0}", i + 16)); pas.PassengerPortOfEmbarkation = reader.ReadCellAsText("passenger departure", string.Format("L{0}", i + 16)); pas.PassengerPortOfDisembarkation = reader.ReadCellAsText("passenger departure", string.Format("M{0}", i + 16)); pas.PassengerInTransit = reader.ReadCellAsBool("passenger departure", string.Format("N{0}", i + 16)); } result = true; } return result; } #endregion #region PAS private static bool ScanPAS(Message pasMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 1000; i++) { string lastName = reader.ReadCellAsText("passenger arrival", string.Format("B{0}", i + 16)); if (lastName.IsNullOrEmpty()) break; if (!(pasMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is PAS pas)) { pas = new PAS(); pas.Identifier = (i + 1).ToString(); pas.MessageHeader = pasMessage; pasMessage.Elements.Add(pas); } pas.NotificationSchengen = reader.ReadCellAsBool("passenger arrival", "C10"); pas.NotificationPAX = reader.ReadCellAsBool("passenger arrival", "C11"); pas.PassengerLastName = lastName; pas.PassengerFirstName = reader.ReadCellAsText("passenger arrival", string.Format("C{0}", i + 16)); pas.PassengerPlaceOfBirth = reader.ReadCellAsText("passenger arrival", string.Format("D{0}", i + 16)); pas.PassengerCountryOfBirth = reader.ReadCellAsText("passenger arrival", string.Format("E{0}", i + 16)); pas.PassengerDateOfBirth = reader.ReadCellAsDateTime("passenger arrival", string.Format("F{0}", i + 16)); pas.PassengerGender = ParseGender(reader.ReadCellAsText("passenger arrival", string.Format("G{0}", i + 16))); pas.PassengerNationality = reader.ReadCellAsText("passenger arrival", string.Format("H{0}", i + 16)); pas.PassengerIdentityDocumentIssuingState = reader.ReadCellAsText("passenger arrival", string.Format("O{0}", i + 16)); pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime("passenger arrival", string.Format("P{0}", i + 16)); //if(pas.NotificationPAX ?? false) //{ pas.EmergencyCare = reader.ReadCellAsText("passenger arrival", string.Format("Q{0}", i + 16)); pas.EmergencyContactNumber = reader.ReadCellAsText("passenger arrival", string.Format("R{0}", i + 16)); //} //if(pas.NotificationSchengen ?? false) //{ pas.PassengerIdentityDocumentType = ParseDocumentType(reader.ReadCellAsText("passenger arrival", string.Format("I{0}", i + 16))); pas.PassengerIdentityDocumentId = reader.ReadCellAsText("passenger arrival", string.Format("J{0}", i + 16)); pas.PassengerVisaNumber = reader.ReadCellAsText("passenger arrival", string.Format("K{0}", i + 16)); pas.PassengerPortOfEmbarkation = reader.ReadCellAsText("passenger arrival", string.Format("L{0}", i + 16)); pas.PassengerPortOfDisembarkation = reader.ReadCellAsText("passenger arrival", string.Format("M{0}", i + 16)); pas.PassengerInTransit = reader.ReadCellAsBool("passenger arrival", string.Format("N{0}", i + 16)); //} result = true; } return result; } #endregion #region NOA_NOD private static bool ScanNOA_NOD(Message noa_nodMessage, ExcelReader reader) { 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; } #endregion #region NAME private static bool ScanNAME(Message nameMessage, ExcelReader reader) { if (nameMessage.Elements.Count == 0) { NAME newNAME = new NAME(); newNAME.MessageHeader = nameMessage; nameMessage.Elements.Add(newNAME); } NAME name = nameMessage.Elements[0] as NAME; name.NameOfMaster = reader.ReadCellAsText("port message", "C11"); if (name.NameOfMaster.IsNullOrEmpty() && name.IsNew) return false; return true; } #endregion #region MDH private static bool ScanMDH(Message mdhMessage, ExcelReader reader) { if (mdhMessage.Elements.Count == 0) { MDH newMDH = new MDH(); newMDH.MessageHeader = mdhMessage; mdhMessage.Elements.Add(newMDH); } MDH mdh = mdhMessage.Elements[0] as MDH; mdh.MDHSimplification = reader.ReadCellAsBool("health", "D8"); if(mdh.MDHSimplification ?? false) { mdh.PortOfCallWhereCompleteMDHNotified = reader.ReadCellAsText("health", "D9"); } else { // general fields mdh.NonAccidentalDeathsDuringVoyage = reader.ReadCellAsBool("health", "D11"); if (mdh.NonAccidentalDeathsDuringVoyage ?? false) mdh.NonAccidentalDeathsDuringVoyageCount = (int?)reader.ReadCellAsDecimal("health", "D12"); mdh.SuspisionInfectiousNature = reader.ReadCellAsBool("health", "D13"); mdh.NumberOfIllPersonsHigherThanExpected = reader.ReadCellAsBool("health", "D14"); if (mdh.NumberOfIllPersonsHigherThanExpected ?? false) mdh.NumberOfIllPersons = (int?)reader.ReadCellAsDecimal("health", "D15"); mdh.SickPersonsOnBoard = reader.ReadCellAsBool("health", "D16"); mdh.MedicalConsulted = reader.ReadCellAsBool("health", "D17"); mdh.AwareOfFurtherInfections = reader.ReadCellAsBool("health", "D18"); mdh.SickAnimalOrPetOnBoard = reader.ReadCellAsBool("health", "D20"); mdh.ValidSanitaryControlExemptionOrCertificateOnBoard = reader.ReadCellAsBool("health", "D22"); if(mdh.ValidSanitaryControlExemptionOrCertificateOnBoard ?? false) { mdh.PlaceOfIssue = reader.ReadCellAsText("health", "D23"); mdh.DateOfIssue = reader.ReadCellAsDateTime("health", "D24"); } mdh.SanitaryControlReinspectionRequired = reader.ReadCellAsBool("health", "D25"); // sanitary measures mdh.SanitaryMeasuresApplied = reader.ReadCellAsBool("health", "J8"); if (mdh.SanitaryMeasuresApplied ?? false) { for (int i = 1; i <= 10; i++) { if (!(mdh.GetSanitaryMeasuresDetailWithIdentifier(i.ToString()) is SanitaryMeasuresDetail snd)) { snd = new SanitaryMeasuresDetail(); snd.Identifier = i.ToString(); snd.MDH = mdh; mdh.SanitaryMeasuresDetails.Add(snd); } snd.SanitaryMeasuresType = reader.ReadCellAsText("health", string.Format("H{0}", i + 9)); if (snd.SanitaryMeasuresType.IsNullOrEmpty()) { mdh.SanitaryMeasuresDetails.Remove(snd); continue; } snd.SanitaryMeasuresLocation = reader.ReadCellAsText("health", string.Format("I{0}", i + 9)); snd.SanitaryMeasuresDate = reader.ReadCellAsDateTime("health", string.Format("J{0}", i + 9)); } } // stowaways mdh.StowawaysDetected = reader.ReadCellAsBool("health", "I22"); if (mdh.StowawaysDetected ?? false) { for (int i = 1; i <= 10; i++) { string stowawayLocation = reader.ReadCellAsText("health", string.Format("H{0}", i + 23)); if(!stowawayLocation.IsNullOrEmpty()) { if(!(mdh.GetStowawaysJoiningLocationWithIdentifier(i.ToString()) is StowawaysJoiningLocation sjl)) { sjl = new StowawaysJoiningLocation(); sjl.Identifier = i.ToString(); sjl.MDH = mdh; mdh.StowawaysJoiningLocations.Add(sjl); } sjl.StowawayJoiningLocation = stowawayLocation; } } } // infected area mdh.InfectedAreaVisited = reader.ReadCellAsBool("health", "L22"); if (mdh.InfectedAreaVisited ?? false) { for (int i = 1; i <= 10; i++) { string iaPort = reader.ReadCellAsText("health", string.Format("K{0}", i + 23)); if(!iaPort.IsNullOrEmpty()) { if(!(mdh.GetInfectedAreaWithIdentifier(i.ToString()) is InfectedArea ia)) { ia = new InfectedArea(); ia.Identifier = i.ToString(); ia.MDH = mdh; mdh.InfectedAreas.Add(ia); } ia.InfectedAreaPort = iaPort; ia.InfectedAreaDate = reader.ReadCellAsDateTime("health", string.Format("L{0}", i + 23)); } } } // PoC last 30 days // this crazy logic is necessary to interpret the double tables in the dakosy sheet // collect all crew members Dictionary> crewmembers = new Dictionary>(); for (int i = 1; i <= 1000; i++) { string posRef = reader.ReadCellAsText("health", string.Format("G{0}", i + 45)); if(posRef.IsNullOrEmpty()) posRef = reader.ReadCellAsText("health", string.Format("H{0}", i + 45)); if (posRef.IsNullOrEmpty()) break; // we are done with this loop string crewMember = reader.ReadCellAsText("health", string.Format("I{0}", i + 45)); if (!crewMember.IsNullOrEmpty()) { if(!crewmembers.ContainsKey(posRef)) crewmembers.Add(posRef, new List()); crewmembers[posRef].Add(crewMember); } } for (int i = 1; i <= 1000; i++) { string posRef = reader.ReadCellAsText("health", string.Format("B{0}", i + 45)); string locode = reader.ReadCellAsText("health", string.Format("C{0}", i + 45)); if (locode.IsNullOrEmpty()) break; if (!(mdh.GetSublistElementWithIdentifier((i + 1).ToString()) is PortOfCallLast30Days poc30d)) { poc30d = new PortOfCallLast30Days(); poc30d.Identifier = (i + 1).ToString(); poc30d.MDH = mdh; mdh.PortOfCallLast30Days.Add(poc30d); } poc30d.PortOfCallLast30DaysLocode = locode; poc30d.PortOfCallLast30DaysDateOfDeparture = reader.ReadCellAsDateTime("health", string.Format("D{0}", i + 45)); poc30d.PortOfCallLast30DaysCrewMembersJoined = reader.ReadCellAsBool("health", string.Format("E{0}", i + 45)); poc30d.CrewJoinedShip.Clear(); List crewJoined = new List(); if (crewmembers.ContainsKey(posRef)) { crewJoined = crewmembers[posRef]; } else if (crewmembers.ContainsKey(locode)) { crewJoined = crewmembers[locode]; } for(int j = 0; j < crewJoined.Count; j++) { PortOfCallLast30DaysCrewJoinedShip p = new PortOfCallLast30DaysCrewJoinedShip(); p.PortOfCallLast30Days = poc30d; p.Identifier = (j + 1).ToString(); poc30d.CrewJoinedShip.Add(p); p.PortOfCallLast30DaysCrewJoinedShipName = crewJoined[j]; } } } return true; } #endregion #region LADG private static bool ScanLADG(Message ladgMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 10000; i++) { string operation = reader.ReadCellAsText("cargo", string.Format("B{0}", i + 9)); byte? ladgOperation = null; if (operation.Equals("LOAD", StringComparison.OrdinalIgnoreCase)) ladgOperation = 0; if (operation.Equals("DISCHARGE", StringComparison.OrdinalIgnoreCase)) ladgOperation = 1; if (operation.Equals("TRANSIT", StringComparison.OrdinalIgnoreCase)) ladgOperation = 2; if (!ladgOperation.HasValue) break; if (!(ladgMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is LADG ladg)) { ladg = new LADG(); ladg.MessageHeader = ladgMessage; ladg.Identifier = (i + 1).ToString(); ladgMessage.Elements.Add(ladg); } ladg.CargoHandlingType = ladgOperation; ladg.CargoLACode = (int?) reader.ReadCellAsDecimal("cargo", string.Format("C{0}", i + 9)); ladg.CargoCodeNST = reader.ReadCellAsText("cargo", string.Format("D{0}", i + 9)); if(ladg.CargoCodeNST?.Length > 2) ladg.CargoCodeNST = ladg.CargoCodeNST.Substring(0, 2); ladg.CargoCodeNST_3 = reader.ReadCellAsText("cargo", string.Format("E{0}", i + 9)); ladg.CargoNumberOfItems = (int?)reader.ReadCellAsDecimal("cargo", string.Format("F{0}", i + 9)); ladg.CargoGrossQuantity_TNE = reader.ReadCellAsDecimal("cargo", string.Format("G{0}", i + 9)); ladg.PortOfLoading = reader.ReadCellAsText("cargo", string.Format("H{0}", i + 9)); ladg.PortOfDischarge = reader.ReadCellAsText("cargo", string.Format("I{0}", i + 9)); result = true; } return result; } #endregion #region INFO private static bool ScanINFO(Message infoMessage, ExcelReader reader) { 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; } #endregion #region HAZA / HAZD private static bool ScanHAZD(Message message, ExcelReader reader) { return false; // not reported on Dakosy sheet } private static bool ScanHAZA(Message message, ExcelReader reader) { return false; // not reported on Dakosy sheet } #endregion #region CREWD private static bool ScanCREWD(Message crewMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 1000; i++) { string lastName = reader.ReadCellAsText("crew departure", string.Format("B{0}", i + 15)); if (lastName.IsNullOrEmpty()) break; if (!(crewMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREW crew)) { crew = new CREWD(); crew.Identifier = (i + 1).ToString(); crew.MessageHeader = crewMessage; crewMessage.Elements.Add(crew); } crew.NotificationSchengen = reader.ReadCellAsBool("crew departure", "C10"); crew.NotificationPAX = reader.ReadCellAsBool("crew departure", "C11"); crew.CrewMemberLastName = lastName; crew.CrewMemberFirstName = reader.ReadCellAsText("crew departure", string.Format("C{0}", i + 15)); crew.CrewMemberPlaceOfBirth = reader.ReadCellAsText("crew departure", string.Format("D{0}", i + 15)); crew.CrewMemberCountryOfBirth = reader.ReadCellAsText("crew departure", string.Format("E{0}", i + 15)); crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime("crew departure", string.Format("F{0}", i + 15)); string gender = reader.ReadCellAsText("crew departure", string.Format("G{0}", i + 15)); crew.CrewMemberGender = ParseGender(gender); crew.CrewMemberNationality = reader.ReadCellAsText("crew departure", string.Format("H{0}", i + 15)); if (crew.NotificationSchengen ?? false) { string idDocType = reader.ReadCellAsText("crew departure", string.Format("I{0}", i + 15)); crew.CrewMemberIdentityDocumentType = ParseDocumentType(idDocType); crew.CrewMemberIdentityDocumentId = reader.ReadCellAsText("crew departure", string.Format("J{0}", i + 15)); crew.CrewMemberVisaNumber = reader.ReadCellAsText("crew departure", string.Format("K{0}", i + 15)); crew.CrewMemberIdentityDocumentIssuingState = reader.ReadCellAsText("crew departure", string.Format("M{0}", i + 15)); crew.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime("crew departure", string.Format("N{0}", i + 15)); } crew.CrewMemberDuty = reader.ReadCellAsText("crew departure", string.Format("L{0}", i + 15)); result = true; } return result; } #endregion #region CREW private static bool ScanCREW(Message crewMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 1000; i++) { string lastName = reader.ReadCellAsText("crew arrival", string.Format("B{0}", i + 15)); if (lastName.IsNullOrEmpty()) break; if (!(crewMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREW crew)) { crew = new CREW(); crew.Identifier = (i + 1).ToString(); crew.MessageHeader = crewMessage; crewMessage.Elements.Add(crew); } crew.NotificationSchengen = reader.ReadCellAsBool("crew arrival", "C10"); crew.NotificationPAX = reader.ReadCellAsBool("crew arrival", "C11"); crew.CrewMemberLastName = lastName; crew.CrewMemberFirstName = reader.ReadCellAsText("crew arrival", string.Format("C{0}", i + 15)); crew.CrewMemberPlaceOfBirth = reader.ReadCellAsText("crew arrival", string.Format("D{0}", i + 15)); crew.CrewMemberCountryOfBirth = reader.ReadCellAsText("crew arrival", string.Format("E{0}", i + 15)); crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime("crew arrival", string.Format("F{0}", i + 15)); string gender = reader.ReadCellAsText("crew arrival", string.Format("G{0}", i + 15)); crew.CrewMemberGender = ParseGender(gender); crew.CrewMemberNationality = reader.ReadCellAsText("crew arrival", string.Format("H{0}", i + 15)); //if(crew.NotificationSchengen ?? false) //{ string idDocType = reader.ReadCellAsText("crew arrival", string.Format("I{0}", i + 15)); crew.CrewMemberIdentityDocumentType = ParseDocumentType(idDocType); crew.CrewMemberIdentityDocumentId = reader.ReadCellAsText("crew arrival", string.Format("J{0}", i + 15)); crew.CrewMemberVisaNumber = reader.ReadCellAsText("crew arrival", string.Format("K{0}", i + 15)); crew.CrewMemberIdentityDocumentIssuingState = reader.ReadCellAsText("crew arrival", string.Format("M{0}", i + 15)); crew.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime("crew arrival", string.Format("N{0}", i + 15)); //} crew.CrewMemberDuty = reader.ReadCellAsText("crew arrival", string.Format("L{0}", i + 15)); result = true; } return result; } private static byte? ParseGender(string gender) { byte? result = null; if(!gender.IsNullOrEmpty()) { if (gender.Equals("male", StringComparison.OrdinalIgnoreCase)) result = 1; if (gender.Equals("female", StringComparison.OrdinalIgnoreCase)) result = 2; if (gender.Equals("not_applicable", StringComparison.OrdinalIgnoreCase)) result = 9; if (gender.Equals("not_known", StringComparison.OrdinalIgnoreCase)) result = 0; if (gender.Equals("other", StringComparison.OrdinalIgnoreCase)) result = 9; } return result; } private static byte? ParseDocumentType(string docType) { byte? result = null; if(!docType.IsNullOrEmpty()) { if (docType.Equals("identity_card", StringComparison.OrdinalIgnoreCase)) result = 0; if (docType.Equals("passport", StringComparison.OrdinalIgnoreCase)) result = 1; if (docType.Equals("muster_book", StringComparison.OrdinalIgnoreCase)) result = 2; if (docType.Equals("picture_id", StringComparison.OrdinalIgnoreCase)) result = 3; if (docType.Equals("residental_permit", StringComparison.OrdinalIgnoreCase)) result = 4; if (docType.Equals("other_legal_identity_document", StringComparison.OrdinalIgnoreCase)) result = 5; } return result; } #endregion #region BPOL private static bool ScanBPOL(Message bpolMessage, ExcelReader reader) { if (bpolMessage.Elements.Count == 0) { BPOL newBPOL = new BPOL(); newBPOL.MessageHeader = bpolMessage; bpolMessage.Elements.Add(newBPOL); } BPOL bpol = bpolMessage.Elements[0] as BPOL; bpol.StowawaysOnBoard = reader.ReadCellAsBool("stowaways", "C8"); if(bpol.StowawaysOnBoard ?? false) { for (int i = 1; i < 1000; i++) { string port = reader.ReadCellAsText("stowaways", string.Format("B{0}", i + 10)); if(!port.IsNullOrEmpty()) { if (!(bpol.GetSublistElementWithIdentifier(i.ToString()) is PortOfItinerary poi)) { poi = new PortOfItinerary(); poi.Identifier = i.ToString(); poi.BPOL = bpol; bpol.PortOfItineraries.Add(poi); } if (Locode.LocodeDB.LocationNameFromLocode(port) != null) { poi.PortOfItineraryLocode = port; } else { poi.PortOfItineraryName = port; } poi.PortOfItineraryETA = reader.ReadCellAsDateTime("stowaways", string.Format("C{0}", i + 10)); } } } return bpol.StowawaysOnBoard.HasValue; } #endregion #region BKRD private static bool ScanBKRD(Message brkdMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 10000; i++) { string fuelType = reader.ReadCellAsText("traffic message on departure", string.Format("B{0}", i + 28)); double? quantity = reader.ReadCellAsDecimal("traffic message on departure", string.Format("C{0}", i + 28)); if (fuelType.IsNullOrEmpty()) break; if (!(brkdMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is BRKD brkd)) { brkd = new BRKD(); brkd.MessageHeader = brkdMessage; brkd.Identifier = (i + 1).ToString(); brkdMessage.Elements.Add(brkd); } brkd.BunkerFuelType = fuelType; brkd.BunkerFuelQuantity_TNE = quantity; result = true; } return result; } #endregion #region BKRA private static bool ScanBKRA(Message bkraMessage, ExcelReader reader) { bool result = false; for (int i = 0; i < 10000; i++) { string fuelType = reader.ReadCellAsText("traffic message on arrival", string.Format("B{0}", i + 28)); double? quantity = reader.ReadCellAsDecimal("traffic message on arrival", string.Format("C{0}", i + 28)); if (fuelType.IsNullOrEmpty()) break; if (!(bkraMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is BRKA brka)) { brka = new BRKA(); brka.MessageHeader = bkraMessage; brka.Identifier = (i + 1).ToString(); bkraMessage.Elements.Add(brka); } brka.BunkerFuelType = fuelType; brka.BunkerFuelQuantity_TNE = quantity; result = true; } return result; } #endregion #region ATD private static bool ScanATD(Message atdMessage, ExcelReader reader) { if (atdMessage.Elements.Count == 0) { ATD newATD = new ATD(); newATD.MessageHeader = atdMessage; atdMessage.Elements.Add(newATD); } ATD atd = atdMessage.Elements[0] as ATD; atd.ATDPortOfCall = reader.ReadCellAsDateTime("traffic message on departure", "C20"); return atd.ATDPortOfCall.HasValue; } #endregion #region ATA private static bool ScanATA(Message ataMessage, ExcelReader reader) { if (ataMessage.Elements.Count == 0) { ATA newATA = new ATA(); newATA.MessageHeader = ataMessage; ataMessage.Elements.Add(newATA); } ATA ata = ataMessage.Elements[0] as ATA; ata.ATAPortOfCall = reader.ReadCellAsDateTime("traffic message on arrival", "C20"); return ata.ATAPortOfCall.HasValue; } #endregion #region AGNT private static bool ScanAGNT(Message agntMessage, ExcelReader reader) { if (agntMessage.Elements.Count == 0) { AGNT newAgnt = new AGNT(); newAgnt.MessageHeader = agntMessage; agntMessage.Elements.Add(newAgnt); } AGNT agnt = agntMessage.Elements[0] as AGNT; agnt.AgentCompanyName = reader.ReadCellAsText("main", "C32"); agnt.AgentCity = reader.ReadCellAsText("main", "C36"); agnt.AgentCountry = reader.ReadCellAsText("main", "C37"); agnt.AgentEMail = reader.ReadCellAsText("main", "C42"); agnt.AgentFax = reader.ReadCellAsText("main", "C41"); agnt.AgentFirstName = reader.ReadCellAsText("main", "C39"); agnt.AgentLastName = reader.ReadCellAsText("main", "C38"); agnt.AgentPhone = reader.ReadCellAsText("main", "C40"); agnt.AgentPostalCode = reader.ReadCellAsText("main", "C35"); string street = reader.ReadCellAsText("main", "C33") ?? ""; string number = reader.ReadCellAsText("main", "C34") ?? ""; agnt.AgentStreetAndNumber = string.Format("{0} {1}", street, number); if (agnt.AgentLastName.IsNullOrEmpty()) agnt.AgentLastName = "-"; // wird nicht mehr entfernt, egal welche Felder gelesen werden return true; } #endregion } }