git_bsmd/ENI2/Excel/DakosyUtil.cs
2022-05-04 10:48:52 +02:00

685 lines
37 KiB
C#

// Copyright (c) 2017- schick Informatik
// Description: Helper class to read data from "Dakosy"-Style Excel Sheets
//
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using bsmd.database;
namespace ENI2.Excel
{
internal static class DakosyUtil
{
private static readonly ILog _log = LogManager.GetLogger(typeof(DakosyUtil));
internal static bool ProcessSheet(ExcelReader reader, out string readMessage, MessageCore messageCore, List<Message.NotificationClass> 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;
}
}
// load messages if already present
List<Message> 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, messages, messageCore, 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, messages, messageCore, 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, messageCore, 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;
}
private static bool ScanWAS_RCPT(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanWAS(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanTOWD(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanTOWA(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
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;
}
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;
}
private static bool ScanSTO(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
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;
}
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;
}
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");
if(sec.KielCanalPassagePlanned ?? false)
{
sec.KielCanalPassagePlannedIncomming = reader.ReadCellAsDateTime("security", "I9");
sec.KielCanalPassagePlannedOutgoing = reader.ReadCellAsDateTime("security", "I12");
}
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 (isscType.Equals("ADMINISTRATION", StringComparison.OrdinalIgnoreCase)) sec.ISSCIssuerType = 0;
if (isscType.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;
}
private static bool ScanPRE72H(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
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;
}
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;
}
private static bool ScanPASD(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanPAS(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanNOA_NOD(Message noa_nodMessage, MessageCore messageCore, 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;
}
#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
private static bool ScanMDH(Message message, List<Message> messages, MessageCore messageCore, ExcelReader reader)
{
throw new NotImplementedException();
}
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))?.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;
}
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;
}
private static bool ScanHAZD(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanHAZA(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanCREWD(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanCREW(Message message, ExcelReader reader)
{
throw new NotImplementedException();
}
private static bool ScanBPOL(Message message, List<Message> messages, MessageCore messageCore, ExcelReader reader)
{
throw new NotImplementedException();
}
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;
}
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;
}
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;
}
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;
}
#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
}
}