git_bsmd/ENI2/Excel/ExcelUtil.cs
Daniel Schick 144c38661d Addon zu ValueMapping
Auch wenn ein key in InvalidKeys ist soll das Mapping (temporär) gespeichert werden.
Dazu wird ein Eintrag hinzugefügt, aber nicht gespeichert. Das wird womöglich Probleme
geben wenn der Anwender hinterher die Mapping Seite öffnet und dann speichert?
2023-06-12 09:03:39 +02:00

2880 lines
142 KiB
C#

//
// Class: Util
// Current CLR: 4.0.30319.34209
// System: Microsoft Visual Studio 10.0
// Author: dani
// Created: 6/17/2015 7:12:38 AM
//
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
using bsmd.database;
using ENI2.EditControls;
using ENI2.Locode;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace ENI2.Excel
{
public static class ExcelUtil
{
#region fields
private static readonly ILog _log = LogManager.GetLogger(typeof(ExcelUtil));
#endregion
#region Process Sheet (normal BSMD sheet import)
internal static bool ProcessSheet(ExcelReader reader, out string readMessage, MessageCore messageCore, List<Message.NotificationClass> notificationClasses)
{
bool result = true;
bool isOldVersion = false;
readMessage = "";
MessageCore aMessageCore = ExcelUtil.LookupCoreById(reader);
if ((aMessageCore == null) || (aMessageCore.Id.Value != messageCore.Id.Value))
{
readMessage = "Id not matching in import sheet";
return false;
}
string imoeni = reader.ReadText("Visit.IMONumber")?.Trim();
if (!aMessageCore.IMO.IsNullOrEmpty() && !aMessageCore.IMO.Equals(imoeni))
{
readMessage = "IMO not matching in import sheet";
return false;
}
if (!aMessageCore.ENI.IsNullOrEmpty() && !aMessageCore.ENI.Equals(imoeni))
{
readMessage = "ENI not matching in import sheet";
return false;
}
// load messages if already present
List<Message> messages = DBManager.Instance.GetMessagesForCore(messageCore, DBManager.MessageLoad.ALL);
int? testCode = (int?)reader.ReadNumber("WAS.WasteCode_1");
if (testCode > 999) isOldVersion = true;
messages.Sort();
// parse selected 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, isOldVersion)) 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, isOldVersion)) 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, isOldVersion)) 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, messages, 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, isOldVersion)) ExcelReader.SaveMessage(message); continue; }
if ((message.MessageNotificationClass == Message.NotificationClass.TIEFD) && notificationClasses.Contains(Message.NotificationClass.TIEFD))
{ if (ScanTIEFD(message, reader, isOldVersion)) 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, isOldVersion)) 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;
}
#endregion Process Sheet (normal BSMD sheet import)
#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;
ExcelUtil.ScanMessage(ata, reader);
if (!ata.ATAPortOfCall.HasValue)
{
ata.ATAPortOfCall = reader.ReadDateTime("ATA.ATADatePortOfCall", "ATA.ATATimePortOfCall");
}
return !(!ata.ATAPortOfCall.HasValue && ataMessage.IsNew);
}
#endregion ATA
#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;
ExcelUtil.ScanMessage(atd, reader);
if (!atd.ATDPortOfCall.HasValue)
{
atd.ATDPortOfCall = reader.ReadDateTime("ATD.ATDDatePortOfCall", "ATD.ATDTimePortOfCall");
}
return !(!atd.ATDPortOfCall.HasValue && atdMessage.IsNew);
}
#endregion ATD
#region TIEFA
private static bool ScanTIEFA(Message tiefaMessage, ExcelReader reader, bool isOldVersion)
{
if (tiefaMessage.Elements.Count == 0)
{
TIEFA newTIEFA = new TIEFA();
newTIEFA.MessageHeader = tiefaMessage;
tiefaMessage.Elements.Add(newTIEFA);
}
TIEFA tiefa = tiefaMessage.Elements[0] as TIEFA;
ScanMessage(tiefa, reader);
if (!tiefa.DraughtUponArrival_DMT.HasValue && tiefaMessage.IsNew)
return false;
if (tiefa.DraughtUponArrival_DMT.HasValue && !isOldVersion)
tiefa.DraughtUponArrival_DMT = tiefa.DraughtUponArrival_DMT.Value * 10; // m to dm
return true;
}
#endregion TIEFA
#region TIEFD
private static bool ScanTIEFD(Message tiefdMessage, ExcelReader reader, bool isOldVersion)
{
if (tiefdMessage.Elements.Count == 0)
{
TIEFD newTIEFD = new TIEFD();
newTIEFD.MessageHeader = tiefdMessage;
tiefdMessage.Elements.Add(newTIEFD);
}
TIEFD tiefd = tiefdMessage.Elements[0] as TIEFD;
ScanMessage(tiefd, reader);
if (!tiefd.DraughtUponDeparture_DMT.HasValue && tiefdMessage.IsNew)
return false;
if (tiefd.DraughtUponDeparture_DMT.HasValue && !isOldVersion)
tiefd.DraughtUponDeparture_DMT = tiefd.DraughtUponDeparture_DMT.Value * 10; // m to dm
return true;
}
#endregion TIEFD
#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;
ExcelUtil.ScanMessage(name, reader);
if (name.NameOfMaster.IsNullOrEmpty() && name.IsNew)
return false;
return true;
}
#endregion NAME
#region BPOL
private static bool ScanBPOL(Message bpolMessage, List<Message> messages, MessageCore messageCore, 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;
ExcelUtil.ScanMessage(bpol, reader);
// 19.12.16: Einschleicher-Feld von Klasse POBA übernehmen (anderes ist nicht im Sheet!)
// (1.12.21: bezweifle ob das so wie gedacht funktioniert..)
Message pobaMessage = ExcelUtil.GetMessageWithType(messages, messageCore, Message.NotificationClass.POBA);
if (pobaMessage.Elements.Count > 0)
{
POBA poba = pobaMessage.Elements[0] as POBA;
bpol.StowawaysOnBoard = (poba.TotalStowawaysOnBoardUponArrival ?? 0) > 0;
}
bpol.DeleteElements();
// PortOfItinerary
for (int i = 1; i <= 10; i++)
{
string bpolName = string.Format("BPOL.PortOfItineraryName_{0}", i);
string bpolLocode = string.Format("BPOL.PortOfItineraryLoCode_{0}", i);
string bpolETADate = string.Format("BPOL.PortOfItineraryETADate_{0}", i);
string bpolETATime = string.Format("BPOL.PortOfItineraryETATime_{0}", i);
string bpolNameValue = reader.ReadText(bpolName)?.Trim();
string bpolLocodeValue = reader.ReadLoCode(bpolLocode);
if (!bpolNameValue.IsNullOrEmpty() || !bpolLocodeValue.IsNullOrEmpty())
{
if (!(bpol.GetSublistElementWithIdentifier(i.ToString()) is PortOfItinerary poi))
{
poi = new PortOfItinerary();
poi.BPOL = bpol;
poi.Identifier = i.ToString();
bpol.PortOfItineraries.Add(poi);
}
poi.PortOfItineraryName = bpolNameValue;
poi.PortOfItineraryLocode = bpolLocodeValue;
// falls nur Locode angegeben wurde, Portname aus Locode ermitteln
if (poi.PortOfItineraryName.IsNullOrEmpty() && !poi.PortOfItineraryLocode.IsNullOrEmpty() && (poi.PortOfItineraryLocode.Length == 5))
{
poi.PortOfItineraryName = LocodeDB.PortNameFromLocode(poi.PortOfItineraryLocode);
}
poi.PortOfItineraryETA = reader.ReadDateTime(bpolETADate, bpolETATime);
}
}
return true;
}
#endregion BPOL
#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;
ScanMessage(poba, reader);
if (((poba.TotalPersonsOnBoardUponArrival ?? 0) == 0) && poba.IsNew)
return false;
if (!poba.TotalPassengersOnBoardUponArrival.HasValue) poba.TotalPassengersOnBoardUponArrival = 0;
if (!poba.TotalStowawaysOnBoardUponArrival.HasValue) poba.TotalStowawaysOnBoardUponArrival = 0;
return true;
}
#endregion POBA
#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;
ScanMessage(pobd, reader);
if (((pobd.TotalPersonsOnBoardUponDeparture ?? 0) == 0) && pobd.IsNew)
return false;
if (!pobd.TotalPassengersOnBoardUponDeparture.HasValue) pobd.TotalPassengersOnBoardUponDeparture = 0;
if (!pobd.TotalStowawaysOnBoardUponDeparture.HasValue) pobd.TotalStowawaysOnBoardUponDeparture = 0;
return true;
}
#endregion POBD
#region HAZA
private static bool ScanHAZA(Message hazaMessage, ExcelReader reader, bool isOldVersion)
{
if (hazaMessage.Elements.Count == 0)
{
HAZ newHaza = new HAZ();
newHaza.IsDeparture = false;
newHaza.MessageHeader = hazaMessage;
hazaMessage.Elements.Add(newHaza);
}
HAZ haza = hazaMessage.Elements[0] as HAZ;
haza.NoDPGOnBoardOnArrival = !reader.ReadBoolean("HAZA.DGOnBoard");
haza.DPGManifestOnBoardOnArrival = reader.ReadBoolean("HAZA.DPGManifestOnBoardOnArrival");
haza.DPGContactFamilyName = reader.ReadText("HAZA.DPGContactFamilyName");
haza.DPGContactPhone = reader.ReadText("HAZA.DPGContactPhone");
haza.MOUBaltic = reader.ReadBoolean("HAZA.MOUBaltic");
string shipClass = reader.ReadText("HAZA.INFShipClass");
if (!shipClass.IsNullOrEmpty())
{
if (shipClass.Contains('1')) haza.INFShipClass = 0;
if (shipClass.Contains('2')) haza.INFShipClass = 1;
if (shipClass.Contains('3')) haza.INFShipClass = 2;
}
#region IMDG
for (int i = 1; i <= 10; i++)
{
string imdg_unno = string.Format("HAZA.IMDG.UNNumber_{0}", i);
string imdg_properShippingName = string.Format("HAZA.IMDG.ProperShippingName_{0}", i);
string imdg_imoClass = string.Format("HAZA.IMDG.IMOClass_{0}", i);
string imdg_packingGroup = string.Format("HAZA.IMDG.PackingGroup_{0}", i);
string imdg_marinePollutant = string.Format("HAZA.IMDG.MarinePollutant_{0}", i);
string imdg_flashpoint = string.Format("HAZA.IMDG.Flashpoint_CEL_{0}", i);
string imdg_numberOfPackages = string.Format("HAZA.IMDG.NumberOfPackages_{0}", i);
string imdg_packageType = string.Format("HAZA.IMDG.PackageType_{0}", i);
string imdg_limitedQuantities = string.Format("HAZA.IMDG.LimitedQuantities_{0}", i);
string imdg_exceptedQuantities = string.Format("HAZA.IMDG.ExceptedQuantities_{0}", i);
string imdg_netQuantity = string.Format("HAZA.IMDG.NetQuantity_KGM_{0}", i);
string imdg_grossQuantity = string.Format("HAZA.IMDG.GrossQuantity_KGM_{0}", i);
string imdg_number = string.Format("HAZA.IMDG.Number_{0}", i);
string imdg_stowagePosition = string.Format("HAZA.IMDG.StowagePosition_{0}", i);
string imdg_portOfLoading = string.Format("HAZA.IMDG.PortOfLoading_{0}", i);
string imdg_portOfDischarge = string.Format("HAZA.IMDG.PortOfDischarge_{0}", i);
string imdg_containerNumber = string.Format("HAZA.IMDG.ContainerNumber_{0}", i);
string imdg_remarks = string.Format("HAZA.IMDG.Remarks_{0}", i);
string unNumber = reader.ReadText(imdg_unno);
if (unNumber.IsNullOrEmpty()) // if unnumber is not set ignore this row
{
continue;
}
string posIdent = string.Format("IMDG-{0}", i);
IMDGPosition imdgPosition = haza.GetIMDGPositionWithIdentifier(posIdent);
if (imdgPosition == null)
{
imdgPosition = new IMDGPosition();
imdgPosition.HAZ = haza;
imdgPosition.Identifier = posIdent;
haza.IMDGPositions.Add(imdgPosition);
}
imdgPosition.UNNumber = unNumber;
imdgPosition.ProperShippingName = reader.ReadText(imdg_properShippingName);
imdgPosition.IMOClass = reader.ReadText(imdg_imoClass);
imdgPosition.PackingGroup = reader.ReadPackingGroup(imdg_packingGroup);
imdgPosition.MarinePollutant = reader.ReadBoolean(imdg_marinePollutant);
imdgPosition.Flashpoint_CEL = reader.ReadText(imdg_flashpoint);
imdgPosition.NumberOfPackages = (int?)reader.ReadNumber(imdg_numberOfPackages);
imdgPosition.PackageType = reader.ReadText(imdg_packageType);
imdgPosition.LimitedQuantities = reader.ReadBoolean(imdg_limitedQuantities);
imdgPosition.ExceptedQuantities = reader.ReadBoolean(imdg_exceptedQuantities);
imdgPosition.NetQuantity_KGM = reader.ReadNumber(imdg_netQuantity);
imdgPosition.GrossQuantity_KGM = reader.ReadNumber(imdg_grossQuantity);
imdgPosition.VehicleLicenseNumber = reader.ReadText(imdg_number);
imdgPosition.StowagePosition = reader.ReadText(imdg_stowagePosition);
imdgPosition.PortOfLoading = reader.ReadLoCode(imdg_portOfLoading);
imdgPosition.PortOfDischarge = reader.ReadLoCode(imdg_portOfDischarge);
imdgPosition.ContainerNumber = reader.ReadText(imdg_containerNumber);
imdgPosition.Remarks = reader.ReadText(imdg_remarks);
}
#endregion IMDG
#region IBC
for (int i = 1; i <= 5; i++)
{
string ibc_productName = string.Format("HAZA.IBC.ProductName_{0}", i);
string ibc_pollutionCategory = string.Format("HAZA.IBC.PollutionCategory_{0}", i);
string ibc_flash = string.Format("HAZA.IBC.Flashpoint_CEL_{0}", i);
if (isOldVersion)
ibc_flash = string.Format("HAZA.IBC.FlashpointInformation_{0}", i);
string ibc_quantity = string.Format("HAZA.IBC.Quantity_KGM_{0}", i);
string ibc_stowagePosition = string.Format("HAZA.IBC.StowagePosition_{0}", i);
string ibc_portOfLoading = string.Format("HAZA.IBC.PortOfLoading_{0}", i);
string ibc_portOfDischarge = string.Format("HAZA.IBC.PortOfDischarge_{0}", i);
string ibc_hazards = string.Format("HAZA.IBC.Hazards_{0}", i);
string ibc_specrefs = string.Format("HAZA.IBC.SpecRef15_19_{0}", i);
string ibc_remarks = string.Format("HAZA.IBC.Remarks_{0}", i);
string productName = reader.ReadText(ibc_productName);
if (productName.IsNullOrEmpty()) continue;
string posIdent = string.Format("IBC-{0}", i);
IBCPosition ibcPosition = haza.GetIBCPositionWithIdentifier(posIdent);
if (ibcPosition == null)
{
ibcPosition = new IBCPosition();
ibcPosition.Identifier = posIdent;
ibcPosition.HAZ = haza;
haza.IBCPositions.Add(ibcPosition);
}
ibcPosition.ProductName = productName;
string pollutionCategory = reader.ReadText(ibc_pollutionCategory);
if (!pollutionCategory.IsNullOrEmpty())
{
if (pollutionCategory.Equals("X", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 0;
if (pollutionCategory.Equals("Y", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 1;
if (pollutionCategory.Equals("Z", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 2;
if (pollutionCategory.Equals("OS", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 3;
}
ibcPosition.Flashpoint_CEL = reader.ReadText(ibc_flash);
if (!ibcPosition.Flashpoint_CEL.IsNullOrEmpty())
{
if (ibcPosition.Flashpoint_CEL != "-")
{
if (double.TryParse(ibcPosition.Flashpoint_CEL, out double flashval))
{
if (flashval > 60) ibcPosition.FlashpointInformation = 1; // GT60CEL
else ibcPosition.FlashpointInformation = 2; // LE60CEL
}
}
}
ibcPosition.Quantity_KGM = (int?)reader.ReadNumber(ibc_quantity);
ibcPosition.StowagePosition = reader.ReadText(ibc_stowagePosition);
ibcPosition.PortOfLoading = reader.ReadLoCode(ibc_portOfLoading);
ibcPosition.PortOfDischarge = reader.ReadLoCode(ibc_portOfDischarge);
ibcPosition.Hazards = reader.ReadHazards(ibc_hazards);
ibcPosition.SpecRef15_19 = reader.ReadBoolean(ibc_specrefs);
ibcPosition.Remarks = reader.ReadText(ibc_remarks);
}
#endregion IBC
#region IGC
for (int i = 1; i <= 5; i++)
{
string igc_productName = string.Format("HAZA.IGC.ProductName_{0}", i);
string igc_quantity = string.Format("HAZA.IGC.Quantity_KGM_{0}", i);
string igc_stowagePosition = string.Format("HAZA.IGC.StowagePosition_{0}", i);
string igc_portOfLoading = string.Format("HAZA.IGC.PortOfLoading_{0}", i);
string igc_portOfDischarge = string.Format("HAZA.IGC.PortOfDischarge_{0}", i);
string igc_unnumber = string.Format("HAZA.IGC.UNNumber_{0}", i);
string igc_imoclass = string.Format("HAZA.IGC.IMOClass_{0}", i);
string igc_remarks = string.Format("HAZA.IGC.Remarks_{0}", i);
string productName = reader.ReadText(igc_productName);
if (productName.IsNullOrEmpty()) continue;
string posIdent = string.Format("IGC-{0}", i);
IGCPosition igcPosition = haza.GetIGCPositionWithIdentifier(posIdent);
if (igcPosition == null)
{
igcPosition = new IGCPosition();
igcPosition.Identifier = posIdent;
igcPosition.HAZ = haza;
haza.IGCPositions.Add(igcPosition);
}
igcPosition.ProductName = productName;
igcPosition.Quantity_KGM = reader.ReadNumber(igc_quantity);
igcPosition.StowagePosition = reader.ReadText(igc_stowagePosition);
igcPosition.PortOfLoading = reader.ReadLoCode(igc_portOfLoading);
igcPosition.PortOfDischarge = reader.ReadLoCode(igc_portOfDischarge);
igcPosition.UNNumber = reader.ReadText(igc_unnumber);
igcPosition.IMOClass = reader.ReadText(igc_imoclass);
igcPosition.Remarks = reader.ReadText(igc_remarks);
}
#endregion IGC
#region IMSBC
for (int i = 1; i <= 5; i++)
{
string imsbc_bcsn = string.Format("HAZA.IMSBC.BulkCargoShippingName_{0}", i);
string imsbc_mhb = string.Format("HAZA.IMSBC.MHB_{0}", i);
string imsbc_quantity = string.Format("HAZA.IMSBC.Quantity_KGM_{0}", i);
string imsbc_stowagePosition = string.Format("HAZA.IMSBC.StowagePosition_{0}", i);
string imsbc_portOfLoading = string.Format("HAZA.IMSBC.PortOfLoading_{0}", i);
string imsbc_portOfDischarge = string.Format("HAZA.IMSBC.PortOfDischarge_{0}", i);
string imsbc_hazardclass = string.Format("HAZA.IMSBC.IMOHazardClass_{0}", i);
string imsbc_unnumber = string.Format("HAZA.IMSBC.UNNumber_{0}", i);
string imsbc_imoclass = string.Format("HAZA.IMSBC.IMOClass_{0}", i);
string imsbc_remarks = string.Format("HAZA.IMSBC.Remarks_{0}", i);
string bcsn = reader.ReadText(imsbc_bcsn);
if (bcsn.IsNullOrEmpty()) continue;
string posIdent = string.Format("IMSBC-{0}", i);
IMSBCPosition imsbcPosition = haza.GetIMSBCPositionWithIdentifier(posIdent);
if (imsbcPosition == null)
{
imsbcPosition = new IMSBCPosition();
imsbcPosition.Identifier = posIdent;
imsbcPosition.HAZ = haza;
haza.IMSBCPositions.Add(imsbcPosition);
}
imsbcPosition.BulkCargoShippingName = bcsn;
imsbcPosition.MHB = reader.ReadBoolean(imsbc_mhb);
imsbcPosition.Quantity_KGM = reader.ReadNumber(imsbc_quantity);
imsbcPosition.StowagePosition = reader.ReadText(imsbc_stowagePosition);
imsbcPosition.PortOfLoading = reader.ReadLoCode(imsbc_portOfLoading);
imsbcPosition.PortOfDischarge = reader.ReadLoCode(imsbc_portOfDischarge);
imsbcPosition.IMOHazardClass = reader.ReadHazardClass(imsbc_hazardclass);
imsbcPosition.UNNumber = reader.ReadText(imsbc_unnumber);
imsbcPosition.IMOClass = reader.ReadText(imsbc_imoclass);
imsbcPosition.Remarks = reader.ReadText(imsbc_remarks);
}
#endregion IMSBC
#region MARPOL
for (int i = 1; i <= 5; i++)
{
string marpol_name = string.Format("HAZA.MARPOL.Name_{0}", i);
string marpol_flash = string.Format("HAZA.MARPOL.Flashpoint_CEL_{0}", i);
string marpol_quantity = string.Format("HAZA.MARPOL.Quantity_KGM_{0}", i);
string marpol_stowagePosition = string.Format("HAZA.MARPOL.StowagePosition_{0}", i);
string marpol_portOfLoading = string.Format("HAZA.MARPOL.PortOfLoading_{0}", i);
string marpol_portOfDischarge = string.Format("HAZA.MARPOL.PortOfDischarge_{0}", i);
string marpol_remarks = string.Format("HAZA.MARPOL.Remarks_{0}", i);
string name = reader.ReadText(marpol_name);
if (name.IsNullOrEmpty()) continue;
string posIdent = string.Format("MARPOL-{0}", i);
MARPOL_Annex_I_Position marpolPosition = haza.GetMARPOLPositionWithIdentifier(posIdent);
if (marpolPosition == null)
{
marpolPosition = new MARPOL_Annex_I_Position();
marpolPosition.Identifier = posIdent;
marpolPosition.HAZ = haza;
haza.MARPOLPositions.Add(marpolPosition);
}
marpolPosition.Name = name;
marpolPosition.Flashpoint_CEL = reader.ReadText(marpol_flash);
// Früher bei NULL: NF // Ableitung Flashpoint-Info: Christin, 22.3.2017
// jetzt bei leerer Flashpoint_CEL: Flashpointinformation NULL: Basti, 13.7.2020
if (marpolPosition.Flashpoint_CEL.IsNullOrEmpty()) { marpolPosition.FlashpointInformation = null; }
else
{
if (double.TryParse(marpolPosition.Flashpoint_CEL, out double flashval))
{
if (flashval > 60) marpolPosition.FlashpointInformation = 1; // GT60CEL
else marpolPosition.FlashpointInformation = 2; // LE60CEL
}
}
marpolPosition.Quantity_KGM = reader.ReadNumber(marpol_quantity);
marpolPosition.StowagePosition = reader.ReadText(marpol_stowagePosition);
marpolPosition.PortOfLoading = reader.ReadLoCode(marpol_portOfLoading);
marpolPosition.PortOfDischarge = reader.ReadLoCode(marpol_portOfDischarge);
marpolPosition.Remarks = reader.ReadText(marpol_remarks);
}
#endregion MARPOL
if (haza.HasPositions) // Christin 22.3.17: Felder bei Positionen immer fest ausfüllen
{
haza.NoDPGOnBoardOnArrival = false;
}
return true;
}
#endregion HAZA
#region HAZD
private static bool ScanHAZD(Message hazdMessage, ExcelReader reader)
{
if (hazdMessage.Elements.Count == 0)
{
HAZ newHazd = new HAZ();
newHazd.IsDeparture = true;
newHazd.MessageHeader = hazdMessage;
hazdMessage.Elements.Add(newHazd);
}
HAZ hazd = hazdMessage.Elements[0] as HAZ;
hazd.NoDPGOnBoardOnArrival = !reader.ReadBoolean("HAZD.DGOnBoard");
hazd.DPGManifestOnBoardOnArrival = reader.ReadBoolean("HAZD.DPGManifestOnBoardOnDeparture");
hazd.DPGContactFamilyName = reader.ReadText("HAZD.DPGContactFamilyName");
hazd.DPGContactPhone = reader.ReadText("HAZD.DPGContactPhone");
hazd.MOUBaltic = reader.ReadBoolean("HAZD.MOUBaltic");
string shipClass = reader.ReadText("HAZD.INFShipClass");
if (!shipClass.IsNullOrEmpty())
{
if (shipClass.Contains('1')) hazd.INFShipClass = 0;
if (shipClass.Contains('2')) hazd.INFShipClass = 1;
if (shipClass.Contains('3')) hazd.INFShipClass = 2;
}
#region IMDG
for (int i = 1; i <= 10; i++)
{
string imdg_unno = string.Format("HAZD.IMDG.UNNumber_{0}", i);
string imdg_properShippingName = string.Format("HAZD.IMDG.ProperShippingName_{0}", i);
string imdg_imoClass = string.Format("HAZD.IMDG.IMOClass_{0}", i);
string imdg_packingGroup = string.Format("HAZD.IMDG.PackingGroup_{0}", i);
string imdg_marinePollutant = string.Format("HAZD.IMDG.MarinePollutant_{0}", i);
string imdg_flashpoint = string.Format("HAZD.IMDG.Flashpoint_CEL_{0}", i);
string imdg_numberOfPackages = string.Format("HAZD.IMDG.NumberOfPackages_{0}", i);
string imdg_packageType = string.Format("HAZD.IMDG.PackageType_{0}", i);
string imdg_limitedQuantities = string.Format("HAZD.IMDG.LimitedQuantities_{0}", i);
string imdg_exceptedQuantities = string.Format("HAZD.IMDG.ExceptedQuantities_{0}", i);
string imdg_netQuantity = string.Format("HAZD.IMDG.NetQuantity_KGM_{0}", i);
string imdg_grossQuantity = string.Format("HAZD.IMDG.GrossQuantity_KGM_{0}", i);
string imdg_number = string.Format("HAZD.IMDG.Number_{0}", i);
string imdg_stowagePosition = string.Format("HAZD.IMDG.StowagePosition_{0}", i);
string imdg_portOfLoading = string.Format("HAZD.IMDG.PortOfLoading_{0}", i);
string imdg_portOfDischarge = string.Format("HAZD.IMDG.PortOfDischarge_{0}", i);
string imdg_containerNumber = string.Format("HAZD.IMDG.ContainerNumber_{0}", i);
string imdg_remarks = string.Format("HAZD.IMDG.Remarks_{0}", i);
string unNumber = reader.ReadText(imdg_unno);
if (unNumber.IsNullOrEmpty()) continue; // if unnumber is not set ignore this row
string posIdent = string.Format("IMDG-{0}", i);
IMDGPosition imdgPosition = hazd.GetIMDGPositionWithIdentifier(posIdent);
if (imdgPosition == null)
{
imdgPosition = new IMDGPosition();
imdgPosition.HAZ = hazd;
imdgPosition.Identifier = posIdent;
hazd.IMDGPositions.Add(imdgPosition);
}
imdgPosition.UNNumber = unNumber;
imdgPosition.ProperShippingName = reader.ReadText(imdg_properShippingName);
imdgPosition.IMOClass = reader.ReadText(imdg_imoClass);
imdgPosition.PackingGroup = reader.ReadPackingGroup(imdg_packingGroup);
imdgPosition.MarinePollutant = reader.ReadBoolean(imdg_marinePollutant);
imdgPosition.Flashpoint_CEL = reader.ReadText(imdg_flashpoint);
imdgPosition.NumberOfPackages = (int?)reader.ReadNumber(imdg_numberOfPackages);
imdgPosition.PackageType = reader.ReadText(imdg_packageType);
imdgPosition.LimitedQuantities = reader.ReadBoolean(imdg_limitedQuantities);
imdgPosition.ExceptedQuantities = reader.ReadBoolean(imdg_exceptedQuantities);
imdgPosition.NetQuantity_KGM = reader.ReadNumber(imdg_netQuantity);
imdgPosition.GrossQuantity_KGM = reader.ReadNumber(imdg_grossQuantity);
imdgPosition.VehicleLicenseNumber = reader.ReadText(imdg_number);
imdgPosition.StowagePosition = reader.ReadText(imdg_stowagePosition);
imdgPosition.PortOfLoading = reader.ReadLoCode(imdg_portOfLoading);
imdgPosition.PortOfDischarge = reader.ReadLoCode(imdg_portOfDischarge);
imdgPosition.ContainerNumber = reader.ReadText(imdg_containerNumber);
imdgPosition.Remarks = reader.ReadText(imdg_remarks);
}
#endregion IMDG
#region IBC
for (int i = 1; i <= 5; i++)
{
string ibc_productName = string.Format("HAZD.IBC.ProductName_{0}", i);
string ibc_pollutionCategory = string.Format("HAZD.IBC.PollutionCategory_{0}", i);
string ibc_flash = string.Format("HAZD.IBC.Flashpoint_CEL_{0}", i);
string ibc_quantity = string.Format("HAZD.IBC.Quantity_KGM_{0}", i);
string ibc_stowagePosition = string.Format("HAZD.IBC.StowagePosition_{0}", i);
string ibc_portOfLoading = string.Format("HAZD.IBC.PortOfLoading_{0}", i);
string ibc_portOfDischarge = string.Format("HAZD.IBC.PortOfDischarge_{0}", i);
string ibc_hazards = string.Format("HAZD.IBC.Hazards_{0}", i);
string ibc_specref = string.Format("HAZD.IBC.SpecRef15_19_{0}", i);
string ibc_remarks = string.Format("HAZD.IBC.Remarks_{0}", i);
string productName = reader.ReadText(ibc_productName);
if (productName.IsNullOrEmpty()) continue;
string posIdent = string.Format("IBC-{0}", i);
IBCPosition ibcPosition = hazd.GetIBCPositionWithIdentifier(posIdent);
if (ibcPosition == null)
{
ibcPosition = new IBCPosition();
ibcPosition.Identifier = posIdent;
ibcPosition.HAZ = hazd;
hazd.IBCPositions.Add(ibcPosition);
}
ibcPosition.ProductName = productName;
string pollutionCategory = reader.ReadText(ibc_pollutionCategory);
if (!pollutionCategory.IsNullOrEmpty())
{
if (pollutionCategory.Equals("X", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 0;
if (pollutionCategory.Equals("Y", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 1;
if (pollutionCategory.Equals("Z", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 2;
if (pollutionCategory.Equals("OS", StringComparison.OrdinalIgnoreCase)) ibcPosition.PollutionCategory = 3;
}
ibcPosition.Flashpoint_CEL = reader.ReadText(ibc_flash);
if (!ibcPosition.Flashpoint_CEL.IsNullOrEmpty())
{
if (ibcPosition.Flashpoint_CEL != "-")
{
if (double.TryParse(ibcPosition.Flashpoint_CEL, out double flashval))
{
if (flashval > 60) ibcPosition.FlashpointInformation = 1; // GT60CEL
else ibcPosition.FlashpointInformation = 2; // LE60CEL
}
}
}
ibcPosition.Quantity_KGM = (int?)reader.ReadNumber(ibc_quantity);
ibcPosition.StowagePosition = reader.ReadText(ibc_stowagePosition);
ibcPosition.PortOfLoading = reader.ReadLoCode(ibc_portOfLoading);
ibcPosition.PortOfDischarge = reader.ReadLoCode(ibc_portOfDischarge);
ibcPosition.Hazards = reader.ReadHazards(ibc_hazards);
ibcPosition.SpecRef15_19 = reader.ReadBoolean(ibc_specref);
ibcPosition.Remarks = reader.ReadText(ibc_remarks);
}
#endregion IBC
#region IGC
for (int i = 1; i <= 5; i++)
{
string igc_productName = string.Format("HAZD.IGC.ProductName_{0}", i);
string igc_quantity = string.Format("HAZD.IGC.Quantity_KGM_{0}", i);
string igc_stowagePosition = string.Format("HAZD.IGC.StowagePosition_{0}", i);
string igc_portOfLoading = string.Format("HAZD.IGC.PortOfLoading_{0}", i);
string igc_portOfDischarge = string.Format("HAZD.IGC.PortOfDischarge_{0}", i);
string igc_unnumber = string.Format("HAZD.IGC.UNNumber_{0}", i);
string igc_imoclass = string.Format("HAZD.IGC.IMOClass_{0}", i);
string igc_remarks = string.Format("HAZD.IGC.Remarks_{0}", i);
string productName = reader.ReadText(igc_productName);
if (productName.IsNullOrEmpty()) continue;
string posIdent = string.Format("IGC-{0}", i);
IGCPosition igcPosition = hazd.GetIGCPositionWithIdentifier(posIdent);
if (igcPosition == null)
{
igcPosition = new IGCPosition();
igcPosition.Identifier = posIdent;
igcPosition.HAZ = hazd;
hazd.IGCPositions.Add(igcPosition);
}
igcPosition.ProductName = productName;
igcPosition.Quantity_KGM = reader.ReadNumber(igc_quantity);
igcPosition.StowagePosition = reader.ReadText(igc_stowagePosition);
igcPosition.PortOfLoading = reader.ReadLoCode(igc_portOfLoading);
igcPosition.PortOfDischarge = reader.ReadLoCode(igc_portOfDischarge);
igcPosition.UNNumber = reader.ReadText(igc_unnumber);
igcPosition.IMOClass = reader.ReadText(igc_imoclass);
igcPosition.Remarks = reader.ReadText(igc_remarks);
}
#endregion IGC
#region IMSBC
for (int i = 1; i <= 5; i++)
{
string imsbc_bcsn = string.Format("HAZD.IMSBC.BulkCargoShippingName_{0}", i);
string imsbc_mhb = string.Format("HAZD.IMSBC.MHB_{0}", i);
string imsbc_quantity = string.Format("HAZD.IMSBC.Quantity_KGM_{0}", i);
string imsbc_stowagePosition = string.Format("HAZD.IMSBC.StowagePosition_{0}", i);
string imsbc_portOfLoading = string.Format("HAZD.IMSBC.PortOfLoading_{0}", i);
string imsbc_portOfDischarge = string.Format("HAZD.IMSBC.PortOfDischarge_{0}", i);
string imsbc_hazardclass = string.Format("HAZD.IMSBC.IMOHazardClass_{0}", i);
string imsbc_unnumber = string.Format("HAZD.IMSBC.UNNumber_{0}", i);
string imsbc_imoclass = string.Format("HAZD.IMSBC.IMOClass_{0}", i);
string imsbc_remarks = string.Format("HAZD.IMSBC.Remarks_{0}", i);
string bcsn = reader.ReadText(imsbc_bcsn);
if (bcsn.IsNullOrEmpty()) continue;
string posIdent = string.Format("IMSBC-{0}", i);
IMSBCPosition imsbcPosition = hazd.GetIMSBCPositionWithIdentifier(posIdent);
if (imsbcPosition == null)
{
imsbcPosition = new IMSBCPosition();
imsbcPosition.Identifier = posIdent;
imsbcPosition.HAZ = hazd;
hazd.IMSBCPositions.Add(imsbcPosition);
}
imsbcPosition.BulkCargoShippingName = bcsn;
imsbcPosition.MHB = reader.ReadBoolean(imsbc_mhb);
imsbcPosition.Quantity_KGM = reader.ReadNumber(imsbc_quantity);
imsbcPosition.StowagePosition = reader.ReadText(imsbc_stowagePosition);
imsbcPosition.PortOfLoading = reader.ReadLoCode(imsbc_portOfLoading);
imsbcPosition.PortOfDischarge = reader.ReadLoCode(imsbc_portOfDischarge);
imsbcPosition.IMOHazardClass = reader.ReadHazardClass(imsbc_hazardclass);
imsbcPosition.UNNumber = reader.ReadText(imsbc_unnumber);
imsbcPosition.IMOClass = reader.ReadText(imsbc_imoclass);
imsbcPosition.Remarks = reader.ReadText(imsbc_remarks);
}
#endregion IMSBC
#region MARPOL
for (int i = 1; i <= 5; i++)
{
string marpol_name = string.Format("HAZD.MARPOL.Name_{0}", i);
string marpol_flash = string.Format("HAZD.MARPOL.Flashpoint_CEL_{0}", i);
string marpol_quantity = string.Format("HAZD.MARPOL.Quantity_KGM_{0}", i);
string marpol_stowagePosition = string.Format("HAZD.MARPOL.StowagePosition_{0}", i);
string marpol_portOfLoading = string.Format("HAZD.MARPOL.PortOfLoading_{0}", i);
string marpol_portOfDischarge = string.Format("HAZD.MARPOL.PortOfDischarge_{0}", i);
string marpol_remarks = string.Format("HAZD.MARPOL.Remarks_{0}", i);
string name = reader.ReadText(marpol_name);
if (name.IsNullOrEmpty()) continue;
string posIdent = string.Format("MARPOL-{0}", i);
MARPOL_Annex_I_Position marpolPosition = hazd.GetMARPOLPositionWithIdentifier(posIdent);
if (marpolPosition == null)
{
marpolPosition = new MARPOL_Annex_I_Position();
marpolPosition.Identifier = posIdent;
marpolPosition.HAZ = hazd;
hazd.MARPOLPositions.Add(marpolPosition);
}
marpolPosition.Name = name;
marpolPosition.Flashpoint_CEL = reader.ReadText(marpol_flash);
if (marpolPosition.Flashpoint_CEL.IsNullOrEmpty())
{
marpolPosition.FlashpointInformation = 0;
} // NF // Ableitung Flashpoint-Info: Christin, 22.3.2017
else
{
if (double.TryParse(marpolPosition.Flashpoint_CEL, out double flashval))
{
if (flashval > 60) marpolPosition.FlashpointInformation = 1; // GT60CEL
else marpolPosition.FlashpointInformation = 2; // LE60CEL
}
}
marpolPosition.Quantity_KGM = reader.ReadNumber(marpol_quantity);
marpolPosition.StowagePosition = reader.ReadText(marpol_stowagePosition);
marpolPosition.PortOfLoading = reader.ReadLoCode(marpol_portOfLoading);
marpolPosition.PortOfDischarge = reader.ReadLoCode(marpol_portOfDischarge);
marpolPosition.Remarks = reader.ReadText(marpol_remarks);
}
#endregion MARPOL
if (hazd.HasPositions) // Christin 22.3.17: Felder bei Positionen immer fest ausfüllen
{
hazd.NoDPGOnBoardOnArrival = false;
}
return true;
}
#endregion HAZD
#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;
ExcelUtil.ScanMessage(info, reader);
string portArea = reader.ReadText("INFO.PortArea")?.ToUpper();
if (!portArea.IsNullOrEmpty() && DBManager.Instance.GetPortAreaDict().ContainsKey(portArea))
info.PortArea = portArea;
else
info.PortArea = "";
info.ShippingArea = reader.ReadShippingArea("INFO.ShippingArea"); // enum read func
bool? fumigatedBulkCargo = reader.ReadBoolean("INFO.FumigatedBulkCargo");
info.FumigatedBulkCargo = (byte)((fumigatedBulkCargo ?? false) ? 1 : 0);
return true;
}
#endregion INFO
#region STAT
private static bool ScanSTAT(Message statMessage, MessageCore messageCore, List<Message> messages, 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;
ScanMessage(stat, reader);
foreach (Message preMessage in messages)
{
if (preMessage.MessageNotificationClass == Message.NotificationClass.PRE72H)
{
if (preMessage.Elements.Count > 0)
{
PRE72H pre72h = preMessage.Elements[0] as PRE72H;
pre72h.Tanker = stat.IsTanker;
ExcelReader.SaveMessage(preMessage);
}
}
}
if (!stat.Flag.IsNullOrEmpty()) stat.Flag = stat.Flag.ToUpper();
if (!stat.PortOfRegistry.IsNullOrEmpty()) stat.PortOfRegistry = stat.PortOfRegistry.ToUpper();
stat.MMSINumber = reader.ReadTextNoWhitespace("STAT.MMSINumber");
stat.CallSign = reader.ReadTextNoWhitespace("STAT.CallSign");
stat.ISMCompanyId = reader.ReadTextNoWhitespace("STAT.ISMCompanyId");
if (!stat.ISMCompanyId.IsNullOrEmpty())
{
// strip "ISM" at the beginning if it is there (27.12.21)
if (stat.ISMCompanyId.StartsWith("imo", StringComparison.OrdinalIgnoreCase))
stat.ISMCompanyId = stat.ISMCompanyId.Substring(3);
if (stat.ISMCompanyId.Length < 7)
{ // zero - fill
while (stat.ISMCompanyId.Length < 7)
stat.ISMCompanyId = "0" + stat.ISMCompanyId;
}
}
string transportMode = reader.ReadText("STAT.TransportMode");
if (transportMode != null)
{
if (transportMode.Contains("maritime", StringComparison.OrdinalIgnoreCase)) stat.TransportMode = "1";
if (transportMode.Equals("1")) stat.TransportMode = transportMode;
if (transportMode.Contains("inland", StringComparison.OrdinalIgnoreCase)) stat.TransportMode = "8";
if (transportMode.Equals("8")) stat.TransportMode = transportMode;
}
// Vessel Email as HerbergEmail sichern
messageCore.HerbergEmailContactReportingVessel = reader.ReadText("ShipMail");
return true;
}
#endregion STAT
#region NOA_NOD
private static bool ScanNOA_NOD(Message noa_nodMessage, MessageCore messageCore, ExcelReader reader)
{
if (noa_nodMessage.Elements.Count == 0)
{
NOA_NOD newNoa_nod = new NOA_NOD();
newNoa_nod.MessageHeader = noa_nodMessage;
noa_nodMessage.Elements.Add(newNoa_nod);
}
NOA_NOD noa_nod = noa_nodMessage.Elements[0] as NOA_NOD;
DateTime? eta = reader.ReadDateTime("NOA_NOD.ETADateToPortOfCall", "NOA_NOD.ETATimeToPortOfCall");
if (messageCore.IsTransit)
{
if (eta.HasValue)
noa_nod.ETAToKielCanal = eta;
}
else
{
if (eta.HasValue)
noa_nod.ETAToPortOfCall = eta;
for (int i = 1; i <= noa_nod.NumberOfExcelRows; i++)
{
string callPurposeDescriptionKey = string.Format("NOA_NOD.CallPuposeDescription_{0}", i);
string callPurposeCodeKey = string.Format("NOA_NOD.CallPurposeCode_{0}", i);
string callPurposeDescription = reader.ReadText(callPurposeDescriptionKey);
string callPurposeCode = reader.ReadText(callPurposeCodeKey);
if (!callPurposeCode.IsNullOrEmpty())
{
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 = ((int?)reader.ReadNumber(callPurposeCodeKey)) ?? 0;
if (callPurposeDescription.IsNullOrEmpty())
{
if(Util.GlobalStructures.Edifact8025.ContainsKey(callPurpose.CallPurposeCode))
callPurpose.CallPurposeDescription = Util.GlobalStructures.Edifact8025[callPurpose.CallPurposeCode];
}
else
{
callPurpose.CallPurposeDescription = callPurposeDescription;
}
}
}
}
string lastPort = reader.ReadText("NOA_NOD.LastPort")?.Trim().ToUpper();
if (lastPort != null)
{
if (LocodeDB.SSNPortNameFromLocode(lastPort) != null)
{
noa_nod.LastPort = lastPort;
}
else
{
List<string> lastPorts = LocodeDB.AllLocodesForCityName(lastPort);
if (lastPorts.Count == 1)
noa_nod.LastPort = lastPorts[0];
else
_log.WarnFormat("{0} results in {1} possible LOCODES", lastPort, lastPorts.Count);
}
}
string nextPort = reader.ReadText("NOA_NOD.NextPort")?.Trim().ToUpper();
if (!nextPort.IsNullOrEmpty() && (nextPort.Length > 5))
nextPort = nextPort.Substring(0, 5); //trunc
noa_nod.NextPort = nextPort;
if (messageCore.IsTransit)
{
noa_nod.ETDFromKielCanal = reader.ReadDateTime("NOA_NOD.ETDDateFromPortOfCall", "NOA_NOD.ETDTimeFromPortOfCall");
}
else
{
noa_nod.ETDFromPortOfCall = reader.ReadDateTime("NOA_NOD.ETDDateFromPortOfCall", "NOA_NOD.ETDTimeFromPortOfCall");
}
noa_nod.ETDFromLastPort = reader.ReadDateTime("NOA_NOD.ETDDateFromLastPort", "NOA_NOD.ETDTimeFromLastPort");
noa_nod.ETAToNextPort = reader.ReadDateTime("NOA_NOD.ETADateToNextPort", "NOA_NOD.ETATimeToNextPort");
// DK
noa_nod.IsAnchored = reader.ReadBoolean("NOA_NOD.IsAnchored");
return true;
}
#endregion NOA_NOD
#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;
ExcelUtil.ScanMessage(agnt, reader);
if (agnt.AgentLastName.IsNullOrEmpty()) agnt.AgentLastName = "-";
// wird nicht mehr entfernt, egal welche Felder gelesen werden
return true;
}
#endregion AGNT
#region WAS
private static bool ScanWAS(Message wasMessage, ExcelReader reader, bool isOldVersion)
{
if (wasMessage.Elements.Count == 0)
{
WAS newWAS = new WAS();
newWAS.MessageHeader = wasMessage;
wasMessage.Elements.Add(newWAS);
}
WAS was = wasMessage.Elements[0] as WAS;
was.DeleteElements();
ScanMessage(was, reader);
was.LastWasteDisposalPort = reader.ReadSSNLocode("WAS.LastWasteDisposalPort");
was.NextWasteDisposalPort = reader.ReadSSNLocode("WAS.NextWasteDisposalPort");
was.ConfirmationOfCorrectness = true; // wir haben immer Recht (NSW7.0)
was.ConfirmationOfSufficiency = true;
string wastedispServProvName = reader.ReadText("WAS.WasteDisposalServiceProviderName");
if (wastedispServProvName != null)
{
if (was.WasteDisposalServiceProvider.Count == 0)
{
WasteDisposalServiceProvider wdsp = new WasteDisposalServiceProvider();
wdsp.Identifier = "1";
wdsp.WAS = was;
was.WasteDisposalServiceProvider.Add(wdsp);
}
was.WasteDisposalServiceProvider[0].WasteDisposalServiceProviderName = wastedispServProvName;
}
// Waste 1 - 25
int maxWaste = isOldVersion ? 15 : was.NumberOfExcelRows;
for (int i = 1; i <= maxWaste; i++)
{
//string wastetype = string.Format("WAS.WasteType_{0}", i);
string wasteCode = string.Format("WAS.WasteCode_{0}", i);
string wasteDescription = string.Format("WAS.WasteDescription_{0}", i);
string wasteAmount = string.Format("WAS.WasteDisposalAmount_MTQ_{0}", i);
string wasteCapacity = string.Format("WAS.WasteCapacity_MTQ_{0}", i);
string wasteRetained = string.Format("WAS.WasteAmountRetained_MTQ_{0}", i);
string wastePort = string.Format("WAS.WasteDisposalPort_{0}", i);
string amountGen = string.Format("WAS.WasteAmountGeneratedTillNextPort_MTQ_{0}", 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.ReadNumber(wasteCode);
// Waste description Spezialfälle für DK
waste.WasteDescription = reader.ReadText(wasteDescription);
if (waste.WasteDescription.IsNullOrEmpty())
{
if ((reader.Mode == ExcelReader.CountryMode.DE) && waste.IsDashWasteCode)
{
waste.WasteDescription = "-";
}
else if (reader.Mode == ExcelReader.CountryMode.DK)
{
waste.WasteDescription = "-";
if (i == 6) waste.WasteDescription = "Domestic waste";
if (i == 9) waste.WasteDescription = "Operational waste";
}
}
else
{
if (reader.Mode == ExcelReader.CountryMode.DK)
{
if (i == 6)
waste.WasteDescription = string.Format("Domestic waste - {0}", waste.WasteDescription);
if (i == 9)
waste.WasteDescription = string.Format("Operational waste - {0}", waste.WasteDescription);
}
}
// RM am 24.1.18, ich hoffe das stimmt so wie sie meint..
if ((reader.Mode == ExcelReader.CountryMode.DK) && (i == 9))
{
_log.DebugFormat("DK: Changing Waste code {0} to 2300 for line {1}", waste.WasteType, i);
waste.WasteType = 2300;
}
// falls ein altes Sheet eingelesen wird, diese Felder automatisch mappen
if (waste.WasteType == 1100) waste.WasteType = 102;
if (waste.WasteType == 1200) waste.WasteType = 101;
if (waste.WasteType == 1300) waste.WasteType = 999;
if (waste.WasteType == 2100) waste.WasteType = 502;
if (waste.WasteType == 2200) waste.WasteType = 501;
if (waste.WasteType == 2300) waste.WasteType = 503;
if (waste.WasteType == 2311) waste.WasteType = 504;
if (waste.WasteType == 2308) waste.WasteType = 505;
if (waste.WasteType == 2313) waste.WasteType = 506;
if (waste.WasteType == 2309) waste.WasteType = 507;
if (waste.WasteType == 3000) waste.WasteType = 401;
waste.WasteDisposalAmount_MTQ = reader.ReadNumberDefaultZero(wasteAmount);
waste.WasteCapacity_MTQ = reader.ReadNumberDefaultZero(wasteCapacity);
waste.WasteAmountRetained_MTQ = reader.ReadNumberDefaultZero(wasteRetained);
waste.WasteDisposalPort = reader.ReadSSNLocode(wastePort); // aka RemainingWasteDisposalPort
if (waste.WasteDisposalPort.IsNullOrEmpty())
{
waste.WasteDisposalPort = "ZZUKN";
}
waste.WasteAmountGeneratedTillNextPort_MTQ = reader.ReadNumberDefaultZero(amountGen);
if (!waste.WasteType.HasValue || (waste.WasteType > 999))
{
was.Waste.Remove(waste);
}
}
was.AddMissingWaste();
return true;
}
#endregion WAS
#region WAS_RCPT
private static bool ScanWAS_RCPT(Message was_rcptMessage, ExcelReader reader)
{
was_rcptMessage.DeleteElements();
for (int i = 1; i <= was_rcptMessage.NumberOfExcelRows; i++)
{
string wasrcpt_identNumber = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.IdentificationNumber", i);
string wasrcpt_portreceptFacilityName = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.PortReceptionFacilityName", i);
string wasrcpt_portreceptFacilityProviderName = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.PortReceptionFacilityProviderName", i);
string wasrcpt_treatmentFacility = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.TreatmentFacilityProviderName", i);
string wasrcpt_delFromDate = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.WasteDeliveryDateFromDate", i);
string wasrcpt_delFromTime = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.WasteDeliveryDateFromTime", i);
string wasrcpt_delToDate = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.WasteDeliveryDateToDate", i);
string wasrcpt_delToTime = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.WasteDeliveryDateToTime", i);
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);
}
else
{
wasr.DeleteElements();
}
wasr.IdentificationNumber = reader.ReadText(wasrcpt_identNumber);
wasr.PortReceptionFacilityName = reader.ReadText(wasrcpt_portreceptFacilityName);
wasr.PortReceptionFacilityProviderName = reader.ReadText(wasrcpt_portreceptFacilityProviderName);
string treatmentFacility = reader.ReadText(wasrcpt_treatmentFacility);
if (!treatmentFacility.IsNullOrEmpty())
{
TreatmentFacilityProvider tfp = new TreatmentFacilityProvider();
tfp.WAS_RCPT = wasr;
tfp.Identifier = "1";
wasr.TreatmentFacilityProvider.Add(tfp);
tfp.TreatmentFacilityProviderName = treatmentFacility;
}
wasr.WasteDeliveryDateFrom = reader.ReadDateTime(wasrcpt_delFromDate, wasrcpt_delFromTime);
wasr.WasteDeliveryDateTo = reader.ReadDateTime(wasrcpt_delToDate, wasrcpt_delToTime);
// read waste deliveries
for (int j = 1; j <= wasr.NumberOfExcelRows; j++)
{
string wtype = string.Format("WAS_RCPT.WasteDeliveryReceipt.WasteCode_{0}", j);
string wDescr = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.WasteDescription_{1}", i, j);
string wAmount = string.Format("WAS_RCPT.WasteDeliveryReceipt_{0}.AmountWasteReceived_MTQ_{1}", i, j);
WasteReceived wr = new WasteReceived();
wr.WAS_RCPT = wasr;
wasr.WasteReceived.Add(wr);
wr.Identifier = j.ToString();
wr.WasteCode = reader.ReadText(wtype); // hier muss immer was stehen, ist ein festes Beschreibungsfeld
wr.WasteDescription = reader.ReadText(wDescr);
if (wr.WasteDescription.IsNullOrEmpty() && (wr.WasteCode != null))
{
if (wr.WasteCode.Equals("999") || wr.WasteCode.Equals("201") || wr.WasteCode.Equals("202") || wr.WasteCode.Equals("203") ||
wr.WasteCode.Equals("204") || wr.WasteCode.Equals("510") || wr.WasteCode.Equals("511"))
wr.WasteDescription = "-";
}
wr.AmountWasteReceived_MTQ = reader.ReadNumber(wAmount) ?? (double?)0; // Default ist 0, nicht nix ;-)
}
// only add message when an identification number was given
if (wasr.IdentificationNumber.IsNullOrEmpty())
was_rcptMessage.Elements.Remove(wasr);
}
return true;
}
#endregion WAS_RCPT
#region MDH
private static bool ScanMDH(Message mdhMessage, List<Message> messages, MessageCore messageCore, 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.DeleteElements();
ExcelUtil.ScanMessage(mdh, reader);
// lt. Mail von Christin am 28.9.2016
mdh.MDHSimplification = false;
mdh.PortOfCallWhereCompleteMDHNotified = "";
string kuerzelErsteZelle = reader.ReadText("MDH.PortOfCallLast30DaysLocode_1");
try
{
#region PoC last 30 days
// lt. Mail von Christin am 11.10.2016
// "SEC" Mode, die Werte aus last10PortFacilitesCalled (SEC) werden übernommen
// das funktioniert, da SEC vor MDH gelesen wird
if (!kuerzelErsteZelle.IsNullOrEmpty() && kuerzelErsteZelle.Equals("sec", StringComparison.OrdinalIgnoreCase))
{
Message secMessage = ExcelUtil.GetMessageWithType(messages, messageCore, Message.NotificationClass.SEC);
if (secMessage.Elements.Count > 0)
{
SEC sec = secMessage.Elements[0] as SEC;
int i = 1;
foreach (LastTenPortFacilitiesCalled ltpfc in sec.LastTenPortFacilitesCalled)
{
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.PortOfCallLast30DaysCrewMembersJoined = false;
poc30d.PortOfCallLast30DaysLocode = ltpfc.PortFacilityPortLoCode;
poc30d.PortOfCallLast30DaysDateOfDeparture = ltpfc.PortFacilityDateOfDeparture;
i++;
}
}
}
else // "normal mode", aus den Zellen lesen
{
// POC last 30 days
for (int i = 0; i < mdh.NumberOfExcelRows; i++)
{
string portName = string.Format("MDH.PortOfCallLast30DaysPort_{0}", i + 1);
string portCountry = string.Format("MDH.PortOfCallLast30DaysCountry_{0}", i + 1);
string locode = string.Format("MDH.PortOfCallLast30DaysLocode_{0}", i + 1);
string crewJoined = string.Format("MDH.PortOfCallLast30DaysCrewMembersJoined_{0}", i + 1);
string crewName = string.Format("MDH.PortOfCallLast30DaysCrewJoinedShipName_{0}", i + 1);
string depDate = string.Format("MDH.PortOfCallLast30DaysDateOfDeparture_{0}", i + 1);
if (!(mdh.GetSublistElementWithIdentifier((i + 1).ToString()) is PortOfCallLast30Days poc30d))
{
poc30d = new PortOfCallLast30Days();
poc30d.Identifier = (i + 1).ToString();
poc30d.MDH = mdh;
mdh.PortOfCallLast30Days.Add(poc30d);
}
string pName = reader.ReadText(portName);
string pCountry = reader.ReadText(portCountry);
poc30d.PortOfCallLast30DaysDateOfDeparture = reader.ReadDate(depDate);
poc30d.PortOfCallLast30DaysLocode = reader.ReadLoCode(locode);
// Verbesserungsvorschlag Jul/21: CrewMembersJoined Häkchen abhängig von den Namen in der Spalte
bool? PortOfCallLast30DaysCrewMembersJoinedFlag = reader.ReadBoolean(crewJoined);
string crewNameString = reader.ReadText(crewName);
poc30d.PortOfCallLast30DaysCrewMembersJoined = !crewNameString.IsNullOrEmpty();
if (poc30d.PortOfCallLast30DaysCrewMembersJoined ?? false)
{
// try different separators
string[] crew = crewNameString.Split(';');
if (crew.Length == 1)
crew = crewNameString.Split(',');
for (int j = 0; j < crew.Length; j++)
{
if (!(poc30d.GetSublistElementWithIdentifier((j + 1).ToString()) is PortOfCallLast30DaysCrewJoinedShip poc30dCrew))
{
poc30dCrew = new PortOfCallLast30DaysCrewJoinedShip();
poc30dCrew.Identifier = (j + 1).ToString();
poc30dCrew.PortOfCallLast30Days = poc30d;
poc30d.CrewJoinedShip.Add(poc30dCrew);
}
poc30dCrew.PortOfCallLast30DaysCrewJoinedShipName = crew[j];
}
}
// Leer/def. Zeilen entfernen
if (!poc30d.PortOfCallLast30DaysDateOfDeparture.HasValue && (poc30d.PortOfCallLast30DaysLocode == null))
mdh.PortOfCallLast30Days.Remove(poc30d);
}
}
#endregion PoC last 30 days
#region SanitaryMeasures
if (mdh.SanitaryMeasuresApplied ?? false)
{
for (int i = 1; i <= 3; i++)
{
string smType = string.Format("MDH.SanitaryMeasuresType_{0}", i);
string smLocation = string.Format("MDH.SanitaryMeasuresLocation_{0}", i);
string smDate = string.Format("MDH.SanitaryMeasuresDate_{0}", i);
SanitaryMeasuresDetail smd = mdh.GetSanitaryMeasuresDetailWithIdentifier(i.ToString());
if (smd == null)
{
smd = new SanitaryMeasuresDetail();
smd.Identifier = i.ToString();
mdh.SanitaryMeasuresDetails.Add(smd);
smd.MDH = mdh;
}
smd.SanitaryMeasuresType = reader.ReadText(smType);
smd.SanitaryMeasuresLocation = reader.ReadText(smLocation);
smd.SanitaryMeasuresDate = reader.ReadDate(smDate);
// dont save completely empty structs
if (!smd.SanitaryMeasuresDate.HasValue && smd.SanitaryMeasuresLocation.IsNullOrEmpty() && smd.SanitaryMeasuresType.IsNullOrEmpty())
mdh.SanitaryMeasuresDetails.Remove(smd);
}
}
#endregion SanitaryMeasures
#region InfectedArea
if (mdh.InfectedAreaVisited ?? false)
{
for (int i = 1; i <= 3; i++)
{
string iaPort = string.Format("MDH.InfectedAreaPort_{0}", i);
string iaDate = string.Format("MDH.InfectedAreaDate_{0}", i);
InfectedArea ia = mdh.GetInfectedAreaWithIdentifier(i.ToString());
if (ia == null)
{
ia = new InfectedArea();
ia.Identifier = i.ToString();
mdh.InfectedAreas.Add(ia);
ia.MDH = mdh;
}
ia.InfectedAreaPort = reader.ReadText(iaPort);
ia.InfectedAreaDate = reader.ReadDate(iaDate);
// dont save completely empty structs
if (!ia.InfectedAreaDate.HasValue && ia.InfectedAreaPort.IsNullOrEmpty())
mdh.InfectedAreas.Remove(ia);
}
}
#endregion InfectedArea
#region StowawaysJoiningLocation
if (mdh.StowawaysDetected ?? false)
{
for (int i = 1; i <= 3; i++)
{
string sjlLookup = string.Format("MDH.StowawaysJoiningLocation_{0}", i);
StowawaysJoiningLocation sjl = mdh.GetStowawaysJoiningLocationWithIdentifier(i.ToString());
if (sjl == null)
{
sjl = new StowawaysJoiningLocation();
sjl.Identifier = i.ToString();
sjl.MDH = mdh;
mdh.StowawaysJoiningLocations.Add(sjl);
}
sjl.StowawayJoiningLocation = reader.ReadText(sjlLookup);
if (sjl.StowawayJoiningLocation.IsNullOrEmpty())
{
mdh.StowawaysJoiningLocations.Remove(sjl);
}
}
}
#endregion StowawaysJoiningLocation
}
catch (Exception ex)
{
_log.ErrorFormat("Crash during reading of MDH message: {0}", ex);
return false;
}
// wird nicht wieder entfernt falls keine Daten vorliegen
return true;
}
#endregion MDH
#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;
ScanMessage(sec, reader);
reader.ReadBoolean("SEC.AreMatterToReport"); // das berücksichtigen wir derzeit nicht in der DB (implizit)
string isscType = reader.ReadText("SEC.ISSCType");
if (isscType != null)
{
if (isscType.Equals("full", StringComparison.OrdinalIgnoreCase) || isscType.Equals("1"))
sec.ISSCType = 0;
if (isscType.Equals("interim", StringComparison.OrdinalIgnoreCase) || isscType.Equals("2"))
sec.ISSCType = 1;
}
string shipsecLevel = reader.ReadText("SEC.CurrentShipSecurityLevel");
if (!shipsecLevel.IsNullOrEmpty())
{
if (shipsecLevel.Contains('1')) sec.CurrentShipSecurityLevel = 1;
if (shipsecLevel.Contains('2')) sec.CurrentShipSecurityLevel = 2;
if (shipsecLevel.Contains('3')) sec.CurrentShipSecurityLevel = 3;
}
string isscIssuerType = reader.ReadText("SEC.ISSCIssuerType");
if (isscIssuerType != null)
{
if (isscIssuerType.Equals("rso", StringComparison.OrdinalIgnoreCase) || isscIssuerType.Equals("2"))
sec.ISSCIssuerType = 1;
if (isscIssuerType.Contains("admin", StringComparison.OrdinalIgnoreCase) || isscIssuerType.Equals("1"))
sec.ISSCIssuerType = 0;
}
sec.GeneralDescriptionOfCargo = reader.ReadGeneralDescriptionOfCargo("SEC.GeneralDescriptionOfCargo");
bool? secKielArrival = reader.ReadBoolean("SEC.KielCanalPassagePlanned_Arrival");
bool? secKielDeparture = reader.ReadBoolean("SEC.KielCanalPassagePlanned_Departure");
// Leichter Umbau ("Verbesserung") der Logik Jul 21: Wenn ETA Werte drin stehen und das Flag nicht gesetzt ist
// wird es gesetzt sonst nicht gesetzt
sec.KielCanalPassagePlanned = (secKielArrival ?? false) || (secKielDeparture ?? false);
// if (sec.KielCanalPassagePlanned ?? false)
// {
sec.KielCanalPassagePlannedIncomming = reader.ReadDateTime("SEC.ETADateKielCanalPassagePlannedIncomming", "SEC.ETATimeKielCanalPassagePlannedIncomming");
sec.KielCanalPassagePlannedOutgoing = reader.ReadDateTime("SEC.ETADateKielCanalPassagePlannedOutgoing", "SEC.ETATimeKielCanalPassagePlannedOutgoing");
// }
if ((!sec.KielCanalPassagePlanned ?? false) && sec.KielCanalPassagePlannedIncomming.HasValue) sec.KielCanalPassagePlanned = true;
if ((!sec.KielCanalPassagePlanned ?? false) && sec.KielCanalPassagePlannedOutgoing.HasValue) sec.KielCanalPassagePlanned = true;
if (!sec.KielCanalPassagePlannedIncomming.HasValue && !sec.KielCanalPassagePlannedOutgoing.HasValue)
sec.KielCanalPassagePlanned = false;
// Last10PortFacilitesCalled
for (int i = 1; i <= 10; i++)
{
string portName = string.Format("SEC.PortFacilityPortName_{0}", i);
string portCountry = string.Format("SEC.PortFacilityPortCountry_{0}", i);
string portLocode = string.Format("SEC.PortFacilityPortLoCode_{0}", i);
string portDateOfArrival = string.Format("SEC.PortFacilityDateOfArrival_{0}", i);
string portDateOfDeparture = string.Format("SEC.PortFacilityDateOfDeparture_{0}", i);
string portShipSecLevel = string.Format("SEC.PortFacilityShipSecurityLevel_{0}", i);
string portGISISCode = string.Format("SEC.PortFacilityGISISCode_{0}", i);
string portSecMatters = string.Format("SEC.PortFacilitySecurityMattersToReport_{0}", 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.ReadText(portName);
l10fc.PortFacilityPortCountry = reader.ReadText(portCountry);
l10fc.PortFacilityPortLoCode = reader.ReadLoCode(portLocode);
l10fc.PortFacilityDateOfArrival = reader.ReadDate(portDateOfArrival);
l10fc.PortFacilityDateOfDeparture = reader.ReadDate(portDateOfDeparture);
string sLevel = reader.ReadText(portShipSecLevel);
if (!sLevel.IsNullOrEmpty())
{
if (sLevel.Contains('1')) l10fc.PortFacilityShipSecurityLevel = 1;
if (sLevel.Contains('2')) l10fc.PortFacilityShipSecurityLevel = 2;
if (sLevel.Contains('3')) l10fc.PortFacilityShipSecurityLevel = 3;
}
l10fc.PortFacilityGISISCode = reader.ReadTextNoWhitespace(portGISISCode);
if (l10fc.PortFacilityGISISCode.IsNullOrEmpty() || l10fc.PortFacilityGISISCode == "0")
l10fc.PortFacilityGISISCode = "0000";
if (l10fc.PortFacilityGISISCode?.Length < 4)
{
while (l10fc.PortFacilityGISISCode.Length < 4) l10fc.PortFacilityGISISCode = "0" + l10fc.PortFacilityGISISCode;
}
l10fc.PortFacilitySecurityMattersToReport = reader.ReadText(portSecMatters);
// 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);
}
// Ship2ShipActivities
for (int i = 1; i <= 10; i++)
{
string s2sName = string.Format("SEC.ShipToShipActivityLocationName_{0}", i);
string s2sLocode = string.Format("SEC.ShipToShipActivityLocationLoCode_{0}", i);
string s2sLatitude = string.Format("SEC.ShipToShipActivityLocationCoordinatesLatitude_{0}", i);
string s2sLongitude = string.Format("SEC.ShipToShipActivityLocationCoordinatesLongitude_{0}", i);
string s2sFromDate = string.Format("SEC.ShipToShipActivityDateFrom_{0}", i);
string s2sToDate = string.Format("SEC.ShipToShipActivityDateTo_{0}", i);
string s2sSec = string.Format("SEC.ShipToShipActivitySecurityMattersToReport_{0}", i);
string s2sActivityString = string.Format("SEC.ShipToShipActivityType_{0}", 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.ReadText(s2sName);
if (s2sActivity.ShipToShipActivityLocationName.IsNullOrEmpty())
{
sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Remove(s2sActivity);
continue;
}
s2sActivity.ShipToShipActivityLocationLoCode = reader.ReadLoCode(s2sLocode);
s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = (int?)reader.ReadNumber(s2sLatitude);
// keine "0" (d.h. fehlerhafte Koordinaten) ins ANSW übergeben falls im Sheet nichts ist aber der Reader das aus irgendeinem Grund liest
if (s2sActivity.ShipToShipActivityLocationCoordinatesLatitude == 0)
s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = null;
s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = (int?)reader.ReadNumber(s2sLongitude);
if (s2sActivity.ShipToShipActivityLocationCoordinatesLongitude == 0)
s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = null;
s2sActivity.ShipToShipActivityDateFrom = reader.ReadDate(s2sFromDate);
s2sActivity.ShipToShipActivityDateTo = reader.ReadDate(s2sToDate);
s2sActivity.ShipToShipActivityTypeCode = (int?)reader.ReadNumber(s2sActivityString);
reader.ReadShip2ShipActivityType(s2sActivityString); // 24.8.21 nicht Code dem Klartext zuordnen, nur das Feld kolorieren
s2sActivity.ShipToShipActivitySecurityMattersToReport = reader.ReadText(s2sSec);
}
return true;
}
#endregion SEC
#region BKRA
private static bool ScanBKRA(Message bkraMessage, ExcelReader reader)
{
bkraMessage.DeleteElements();
for (int i = 1; i <= bkraMessage.NumberOfExcelRows; i++)
{
string lnQuantity = string.Format("BKRA.BunkerFuelQuantity_TNE_{0}", i);
string lnType = string.Format("BKRA.BunkerFuelType_{0}", i);
if (!(bkraMessage.GetSublistElementWithIdentifier((i).ToString()) is BRKA bkra))
{
bkra = new BRKA();
bkra.Identifier = (i).ToString();
bkra.MessageHeader = bkraMessage;
bkraMessage.Elements.Add(bkra);
}
bkra.BunkerFuelQuantity_TNE = reader.ReadNumber(lnQuantity);
bkra.BunkerFuelType = reader.ReadText(lnType);
// dont save empty element
if (bkra.IsNew && !bkra.BunkerFuelQuantity_TNE.HasValue && bkra.BunkerFuelType.IsNullOrEmpty())
bkraMessage.Elements.Remove(bkra);
}
return true;
}
#endregion BKRA
#region BKRD
private static bool ScanBKRD(Message bkrdMessage, ExcelReader reader)
{
bkrdMessage.DeleteElements();
for (int i = 1; i <= bkrdMessage.NumberOfExcelRows; i++)
{
string lnQuantity = string.Format("BKRD.BunkerFuelQuantity_TNE_{0}", i);
string lnType = string.Format("BKRD.BunkerFuelType_{0}", i);
if (!(bkrdMessage.GetSublistElementWithIdentifier((i).ToString()) is BRKD bkrd))
{
bkrd = new BRKD();
bkrd.Identifier = (i).ToString();
bkrd.MessageHeader = bkrdMessage;
bkrdMessage.Elements.Add(bkrd);
}
bkrd.BunkerFuelQuantity_TNE = reader.ReadNumber(lnQuantity);
bkrd.BunkerFuelType = reader.ReadText(lnType);
// dont save empty element
if (bkrd.IsNew && !bkrd.BunkerFuelQuantity_TNE.HasValue && bkrd.BunkerFuelType.IsNullOrEmpty())
bkrdMessage.Elements.Remove(bkrd);
}
return true;
}
#endregion BKRD
#region TOWA
private static bool ScanTOWA(Message towaMessage, ExcelReader reader)
{
// 24.4.21: TOWA beim Excel import
bool hasTOWAMarker = false;
for (int i = 1; i <= towaMessage.NumberOfExcelRows; i++)
{
string tName = string.Format("TOWA.TowageOnArrivalName_{0}", i);
string towageName = reader.ReadText(tName);
if (!towageName.IsNullOrEmpty())
{
hasTOWAMarker = true;
break;
}
}
if (!hasTOWAMarker) return false; // no TOWA info on sheet
towaMessage.DeleteElements();
for (int i = 1; i <= towaMessage.NumberOfExcelRows; i++)
{
string tName = string.Format("TOWA.TowageOnArrivalName_{0}", i);
string tFlag = string.Format("TOWA.TowageOnArrivalFlag_{0}", i);
string tPoC = string.Format("TOWA.TowageOnArrivalPurposeOfCall_{0}", i);
string tDraft = string.Format("TOWA.TowageOnArrivalDraught_DMT_{0}", i);
string tGT = string.Format("TOWA.TowageOnArrivalGrossTonnage_{0}", i);
string tLen = string.Format("TOWA.TowageOnArrivalLengthOverall_MTR_{0}", i);
string tBeam = string.Format("TOWA.TowageOnArrivalBeam_MTR_{0}", i);
string tOp = string.Format("TOWA.TowageOnArrivalOperatorCompanyName_{0}", i);
string towageName = reader.ReadText(tName);
if (towageName.IsNullOrEmpty()) continue;
if (!(towaMessage.GetSublistElementWithIdentifier((i).ToString()) is TOWA towa))
{
towa = new TOWA();
towa.Identifier = (i).ToString();
towa.MessageHeader = towaMessage;
towaMessage.Elements.Add(towa);
}
towa.TowageOnArrivalName = towageName;
towa.TowageOnArrivalFlag = reader.ReadNationality(tFlag);
towa.TowageOnArrivalPurposeOfCall = reader.ReadText(tPoC);
towa.TowageOnArrivalDraught_DMT = reader.ReadNumber(tDraft);
if (towa.TowageOnArrivalDraught_DMT.HasValue)
towa.TowageOnArrivalDraught_DMT *= 10;
towa.TowageOnArrivalGrossTonnage = (int?)reader.ReadNumber(tGT);
towa.TowageOnArrivalLengthOverall_MTR = reader.ReadNumber(tLen);
towa.TowageOnArrivalBeam_MTR = reader.ReadNumber(tBeam);
towa.TowageOnArrivalOperatorCompanyName = reader.ReadText(tOp);
}
return true;
}
#endregion TOWA
#region TOWD
private static bool ScanTOWD(Message towdMessage, ExcelReader reader)
{
// 24.4.21: TOWD beim Excel import
bool hasTOWDMarker = false;
for (int i = 1; i <= towdMessage.NumberOfExcelRows; i++)
{
string tName = string.Format("TOWD.TowageOnDepartureName_{0}", i);
string towageName = reader.ReadText(tName);
if (!towageName.IsNullOrEmpty())
{
hasTOWDMarker = true;
break;
}
}
if (!hasTOWDMarker) return false; // no TOWD info on sheet
towdMessage.DeleteElements();
for (int i = 1; i <= towdMessage.NumberOfExcelRows; i++)
{
string tName = string.Format("TOWD.TowageOnDepartureName_{0}", i);
string tFlag = string.Format("TOWD.TowageOnDepartureFlag_{0}", i);
string tDraft = string.Format("TOWD.TowageOnDepartureDraught_DMT_{0}", i);
string tLen = string.Format("TOWD.TowageOnDepartureLengthOverall_MTR_{0}", i);
string tBeam = string.Format("TOWD.TowageOnDepartureBeam_MTR_{0}", i);
string tOp = string.Format("TOWD.TowageOnDepartureOperatorCompanyName_{0}", i);
string tPoc = string.Format("TOWD.TowageOnArrivalPurposeOfCall_{0}", i);
string tgt = string.Format("TOWD.TowageOnArrivalGrossTonnage_{0}", i);
string towageName = reader.ReadText(tName);
if (towageName.IsNullOrEmpty()) continue;
if (!(towdMessage.GetSublistElementWithIdentifier((i).ToString()) is TOWD towd))
{
towd = new TOWD();
towd.Identifier = (i).ToString();
towd.MessageHeader = towdMessage;
towdMessage.Elements.Add(towd);
}
towd.TowageOnDepartureName = towageName;
towd.TowageOnDepartureFlag = reader.ReadNationality(tFlag);
towd.TowageOnDepartureDraught_DMT = reader.ReadNumber(tDraft);
if (towd.TowageOnDepartureDraught_DMT.HasValue)
towd.TowageOnDepartureDraught_DMT *= 10;
towd.TowageOnDepartureLengthOverall_MTR = reader.ReadNumber(tLen);
towd.TowageOnDepartureBeam_MTR = reader.ReadNumber(tBeam);
towd.TowageOnDepartureOperatorCompanyName = reader.ReadText(tOp);
//towd.TowageOnD
}
return true;
}
#endregion TOWD
#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;
ScanMessage(pre72h, reader);
// diese Nachricht bleibt auch wenn sie leer ist
pre72h.ConditionCargoBallastTanks = reader.ReadConditionTanks("PRE72H.ConditionCargoBallastTanks");
pre72h.TankerHullConfiguration = reader.ReadHullConfiguration("PRE72H.TankerHullConfiguration");
pre72h.PlannedWorks = reader.ReadText("PRE72H.PlannedWorks");
if (pre72h.PlannedWorks.IsNullOrEmpty()) pre72h.PlannedWorks = "n";
return true;
}
#endregion PRE72H
#region SERV
private static bool ScanSERV(Message servMessage, ExcelReader reader)
{
if (servMessage.Elements.Count == 0)
{
SERV newSERV = new SERV();
newSERV.MessageHeader = servMessage;
newSERV.Identifier = "1";
servMessage.Elements.Add(newSERV);
}
SERV serv = servMessage.Elements[0] as SERV;
ScanMessage(serv, reader);
if (serv.ServiceBeneficiary.IsNullOrEmpty() && serv.ServiceInvoiceRecipient.IsNullOrEmpty())
return false;
return true;
}
#endregion SERV
#region STO
private static bool ScanSTO(Message stoMessage, ExcelReader reader)
{
stoMessage.DeleteElements();
for (int i = 0; i < stoMessage.NumberOfExcelRows; i++) // 10
{
string stoName = string.Format("STO.Name_{0}", i + 1);
string stoQuantity = string.Format("STO.Quantity_{0}", i + 1);
string stoQuantityUnit = string.Format("STO.QuantityUnit_{0}", i + 1);
string stoLocationOnBoard = string.Format("STO.LocationOnBoard_{0}", i + 1);
string stoOfficialUse = string.Format("STO.OfficialUse_{0}", i + 1);
if (!(stoMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is STO sto))
{
sto = new STO();
sto.Identifier = (i + 1).ToString();
sto.MessageHeader = stoMessage;
stoMessage.Elements.Add(sto);
}
sto.Name = reader.ReadTextNoWhitespace(stoName);
sto.Quantity = (int?)reader.ReadNumber(stoQuantity);
sto.QuantityUnit = reader.ReadTextNoWhitespace(stoQuantityUnit);
sto.LocationOnBoard = reader.ReadTextNoWhitespace(stoLocationOnBoard);
sto.OfficialUse = reader.ReadTextNoWhitespace(stoOfficialUse);
// dont save empty element
if (sto.IsNew && sto.Name.IsNullOrEmpty())
stoMessage.Elements.Remove(sto);
}
return true;
}
#endregion STO
#region LADG
private static bool ScanLADG(Message ladgMessage, ExcelReader reader)
{
ladgMessage.DeleteElements();
for (int i = 0; i < ladgMessage.NumberOfExcelRows; i++)
{
string lnCHT = string.Format("LADG.CargoHandlingType_{0}", i + 1);
string lnType = string.Format("LADG.CargoType_{0}", i + 1);
string lnCNOI = string.Format("LADG.CargoNumberOfItems_{0}", i + 1);
string lnCGQ = string.Format("LADG.CargoGrossQuantity_TNE_{0}", i + 1);
string lnLoad = string.Format("LADG.CargoPortOfLoading_{0}", i + 1);
string lnDis = string.Format("LADG.CargoPortOfDischarge_{0}", i + 1);
string lnLACode = string.Format("LADG.CargoLACode_{0}", i + 1);
string lnZusatz = string.Format("LADG.CargoTypeZusatz_{0}", i + 1);
if (!(ladgMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is LADG ladg))
{
ladg = new LADG();
ladg.Identifier = (i + 1).ToString();
ladg.MessageHeader = ladgMessage;
ladgMessage.Elements.Add(ladg);
}
ladg.CargoHandlingType = reader.ReadCargoHandlingType(lnCHT);
// Transit-Ladung für DE nicht übernehmen!
if ((reader.Mode == ExcelReader.CountryMode.DE) && ((ladg.CargoHandlingType ?? 0) == 2))
{
ladgMessage.Elements.Remove(ladg);
continue;
}
ladg.CargoCodeNST = reader.ReadText(lnType);
// Cargo Type Freitext in DK
if (reader.Mode == ExcelReader.CountryMode.DE)
{
if (ladg.CargoCodeNST?.Length == 1)
ladg.CargoCodeNST = "0" + ladg.CargoCodeNST;
if ((ladg.CargoCodeNST != null) && (ladg.CargoCodeNST.Length != 2))
{
ladg.CargoCodeNST = null; // stupid validation
}
else
{
if (Int32.TryParse(ladg.CargoCodeNST, out int ccnst))
{
if ((ccnst <= 0) || (ccnst > 20))
{
ladg.CargoCodeNST = null;
}
}
else
{
ladg.CargoCodeNST = null;
}
}
}
ladg.CargoLACode = reader.ReadCargoLACode(lnLACode);
ladg.CargoCodeNST_3 = reader.ReadText(lnZusatz);
if (!ladg.CargoCodeNST_3.IsNullOrEmpty())
{
if (ladg.CargoCodeNST_3.Length > 8)
{
ladg.CargoCodeNST_3 = ladg.CargoCodeNST_3.Substring(0, 8);
}
}
ladg.CargoNumberOfItems = (int?)reader.ReadNumber(lnCNOI);
ladg.CargoGrossQuantity_TNE = reader.ReadNumber(lnCGQ);
ladg.PortOfLoading = reader.ReadLoCode(lnLoad);
ladg.PortOfDischarge = reader.ReadLoCode(lnDis);
// dont save empty element
if (ladg.IsNew && !ladg.CargoHandlingType.HasValue)
ladgMessage.Elements.Remove(ladg);
}
return true;
}
#endregion LADG
#region CREW
private static bool ScanCREW(Message crewMessage, ExcelReader reader, bool isOldVersion)
{
crewMessage.DeleteElements();
string sheetTitle = "6. CREW - Arrival";
// 6. CREW - Arrival
// 5.9.22: Changed this area to work like reading from a Dakosy Sheet (by values in rows, not cell names)
if (reader.HasWorksheetNamed(sheetTitle))
{
bool? notificationSchengen = reader.ReadBoolean("CREW.NotificationSchengen");
bool? notificationPax = reader.ReadBoolean("CREW.NotificationPAX");
for (int i = 0; i < 5000; i++)
{
string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18));
string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18));
if (lastName.IsNullOrEmpty() && firstName.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 = notificationSchengen;
crew.NotificationPAX = notificationPax;
crew.CrewMemberLastName = lastName;
crew.CrewMemberFirstName = firstName;
crew.CrewMemberGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18)), out bool canceled);
if (canceled) return true;
crew.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18));
crew.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled);
if (canceled) return true;
crew.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 18));
crew.CrewMemberCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18));
if ((crew.CrewMemberCountryOfBirth != null) && (crew.CrewMemberCountryOfBirth.Length > 2)) crew.CrewMemberCountryOfBirth = null;
crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{0}", i + 18));
crew.CrewMemberIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 18)), out canceled);
if (canceled) return true;
crew.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 18));
crew.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18));
crew.CrewMemberIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 18)), out canceled);
if (canceled) return true;
if (crew.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty() && isOldVersion)
crew.CrewMemberIdentityDocumentIssuingState = "XX";
crew.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("N{0}", i + 18));
if (!crew.CrewMemberIdentityDocumentExpiryDate.HasValue && isOldVersion)
crew.CrewMemberIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
crew.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142));
if (crew.Effects.Length > 256)
crew.Effects = crew.Effects.Substring(0, 256);
Util.UIHelper.SetBusyState(); // dialog might reset busy state
}
}
else
{
sheetTitle = "5. CREW - Arrival"; // altes Anmeldeformat
if (reader.HasWorksheetNamed(sheetTitle))
{
for (int i = 0; i < 5000; i++)
{
string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 13));
string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 13));
if (lastName.IsNullOrEmpty() && firstName.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.CrewMemberLastName = lastName;
crew.CrewMemberFirstName = firstName;
crew.CrewMemberGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 13)), out bool canceled);
if (canceled) return true;
crew.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 13));
crew.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 13)), out canceled);
if (canceled) return true;
crew.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 13));
crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("I{0}", i + 13));
crew.CrewMemberIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 13)), out canceled);
if (canceled) return true;
crew.CrewMemberIdentityDocumentIssuingState = "XX";
crew.CrewMemberIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
crew.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 13));
crew.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 13));
Util.UIHelper.SetBusyState(); // dialog might reset busy state
}
}
else
{
return false; // nothing found
}
}
return true;
}
private static bool ScanCREWD(Message crewdMessage, ExcelReader reader)
{
crewdMessage.DeleteElements();
string sheetTitle = "7. CREW - Departure";
// CREW DEPARTURE
if (reader.HasWorksheetNamed(sheetTitle))
{
bool? notificationSchengen = reader.ReadBoolean("CREWD.NotificationSchengen");
bool? notificationPax = reader.ReadBoolean("CREWD.NotificationPAX");
for (int i = 0; i < 5000; i++)
{
string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18));
if (lastName.IsNullOrEmpty()) break;
if (!(crewdMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREWD crewd))
{
crewd = new CREWD();
crewd.Identifier = (i + 1).ToString();
crewd.MessageHeader = crewdMessage;
crewdMessage.Elements.Add(crewd);
}
crewd.NotificationSchengen = notificationSchengen;
crewd.NotificationPAX = notificationPax;
crewd.CrewMemberLastName = lastName;
crewd.CrewMemberFirstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18));
crewd.CrewMemberGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18)), out bool canceled);
if (canceled) return true;
crewd.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18));
crewd.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled);
if (canceled) return true;
crewd.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 18));
crewd.CrewMemberCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18));
if ((crewd.CrewMemberCountryOfBirth != null) && (crewd.CrewMemberCountryOfBirth.Length > 2)) crewd.CrewMemberCountryOfBirth = null;
crewd.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{0}", i + 18));
crewd.CrewMemberIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 18)), out canceled);
if (canceled) return true;
crewd.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 18));
crewd.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18));
crewd.CrewMemberIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 18)), out canceled);
if (canceled) return true;
if (crewd.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty())
crewd.CrewMemberIdentityDocumentIssuingState = "XX";
crewd.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("N{0}", i + 18)) ?? (DateTime?)new DateTime(2100, 12, 31);
crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142));
Util.UIHelper.SetBusyState(); // dialog might reset busy state
}
}
else
{
sheetTitle = "6. CREW - Departure"; // altes Anmeldeformat
if (reader.HasWorksheetNamed(sheetTitle))
{
for (int i = 0; i < 5000; i++)
{
string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 13));
if (lastName.IsNullOrEmpty()) break;
if (!(crewdMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREWD crewd))
{
crewd = new CREWD();
crewd.Identifier = (i + 1).ToString();
crewd.MessageHeader = crewdMessage;
crewdMessage.Elements.Add(crewd);
}
crewd.CrewMemberLastName = lastName;
crewd.CrewMemberFirstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 13));
crewd.CrewMemberGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 13)), out bool canceled);
if (canceled) return true;
crewd.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 13));
crewd.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 13)), out canceled);
if (canceled) return true;
crewd.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 13));
crewd.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("I{0}", i + 13));
crewd.CrewMemberIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 13)), out canceled);
if (canceled) return true;
crewd.CrewMemberIdentityDocumentIssuingState = "XX";
crewd.CrewMemberIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
crewd.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 13));
crewd.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 13));
Util.UIHelper.SetBusyState(); // dialog might reset busy state
}
}
else
{
return false; // nothing found
}
}
return true;
}
#endregion CREW
#region PAS
private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool isOldVersion)
{
List<PAS> newPasList = new List<PAS>();
string sheetTitle = "8. PAX - Arrival";
if (reader.HasWorksheetNamed(sheetTitle))
{
bool? notificationSchengen = reader.ReadBoolean("PAS.NotificationSchengen");
bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX");
for (int i = 0; i < 5000; i++)
{
string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 17));
string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 17));
if (lastName.IsNullOrEmpty() && firstName.IsNullOrEmpty()) break; // finish after reading last row
PAS pas = new PAS();
pas.Identifier = (i + 1).ToString();
pas.MessageHeader = pasMessage;
newPasList.Add(pas);
pas.NotificationSchengen = notificationSchengen;
pas.NotificationPAX = notificationPax;
pas.PassengerLastName = lastName;
pas.PassengerFirstName = firstName;
pas.PassengerNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 17)), out bool canceled);
if (canceled) return true;
pas.PassengerIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 17)), out canceled);
if (canceled) return true;
if (pas.PassengerIdentityDocumentIssuingState.IsNullOrEmpty())
pas.PassengerIdentityDocumentIssuingState = "XX";
pas.PassengerGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 17)), out canceled);
if (canceled) return true;
pas.PassengerPortOfEmbarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 17)), out canceled);
if (canceled) return true;
pas.PassengerPortOfDisembarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 17)), out canceled);
if (canceled) return true;
pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 17));
pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 17));
pas.PassengerCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17));
if ((pas.PassengerCountryOfBirth != null) && (pas.PassengerCountryOfBirth.Length > 2)) pas.PassengerCountryOfBirth = null;
if (canceled) return true;
DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17));
pas.PassengerDateOfBirth = dateOfBirth;
pas.PassengerIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 17)), out canceled);
if (canceled) return true;
pas.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 17));
pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("P{0}", i + 17)) ?? (DateTime?)new DateTime(2100, 12, 31);
pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("Q{0}", i + 17));
pas.EmergencyCare = reader.ReadCellAsText(sheetTitle, string.Format("R{0}", i + 17));
pas.EmergencyContactNumber = reader.ReadCellAsText(sheetTitle, string.Format("S{0}", i + 17));
Util.UIHelper.SetBusyState(); // dialog might reset busy state
}
}
else
{
sheetTitle = "7. PAX - Arrival"; // altes Excel Format
if (reader.HasWorksheetNamed(sheetTitle))
{
for (int i = 0; i < 5000; i++)
{
string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 13));
string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 13));
if (lastName.IsNullOrEmpty() && firstName.IsNullOrEmpty()) break; // finish after reading last row
PAS pas = new PAS();
pas.Identifier = (i + 1).ToString();
pas.MessageHeader = pasMessage;
newPasList.Add(pas);
pas.PassengerLastName = lastName;
pas.PassengerFirstName = firstName;
pas.PassengerNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 13)), out bool canceled);
if (canceled) return true;
pas.PassengerGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 13)), out canceled);
if (canceled) return true;
pas.PassengerPortOfEmbarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 13)), out canceled);
if (canceled) return true;
pas.PassengerPortOfDisembarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 13)), out canceled);
if (canceled) return true;
pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("I{0}", i + 13));
pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 13));
DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("K{0}", i + 13));
pas.PassengerDateOfBirth = dateOfBirth;
pas.PassengerIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 13)), out canceled);
if (canceled) return true;
pas.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 13));
pas.PassengerIdentityDocumentExpiryDate = new DateTime(2100, 12, 31);
pas.PassengerIdentityDocumentIssuingState = "XX";
pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 13));
Util.UIHelper.SetBusyState(); // dialog might reset busy state
}
}
else
{
return false;
}
}
DBManager.Instance.DeleteAllPASForMessage(pasMessage.Id);
pasMessage.Elements.Clear();
foreach (PAS pas in newPasList)
pasMessage.Elements.Add(pas);
return true;
}
#endregion PAS
#region PASD
private static bool ScanPASD(Message pasMessage, ExcelReader reader)
{
pasMessage.DeleteElements();
bool? notificationSchengen = reader.ReadBoolean("PASD.NotificationSchengen");
bool? notificationPax = reader.ReadBoolean("PASD.NotificationPAX");
for (int i = 0; i < pasMessage.NumberOfExcelRows; i++)
{
string pasLastName = string.Format("PASD.PassengerLastName_{0}", i + 1);
string pasFirstName = string.Format("PASD.PassengerFirstName_{0}", i + 1);
string pasGender = string.Format("PASD.PassengerGender_{0}", i + 1);
string pasNationality = string.Format("PASD.PassengerNationality_{0}", i + 1);
string pasEmbarkation = string.Format("PASD.PassengerPortOfEmbarkation_{0}", i + 1);
string pasDebarkation = string.Format("PASD.PassengerPortOfDisembarkation_{0}", i + 1);
string pasTransit = string.Format("PASD.PassengerInTransit_{0}", i + 1);
string pasPlaceOfBirth = string.Format("PASD.PassengerPlaceOfBirth_{0}", i + 1);
string pasDateOfBirth = string.Format("PASD.PassengerDateOfBirth_{0}", i + 1);
string pasIdentDocType = string.Format("PASD.PassengerIdentityDocumentType_{0}", i + 1);
string pasIdentDocId = string.Format("PASD.PassengerIdentityDocumentId_{0}", i + 1);
string pasVisaNo = string.Format("PASD.PassengerVisaNumber_{0}", i + 1);
string pasIssuing = string.Format("PASD.PassengerIdentityDocumentIssuingState_{0}", i + 1);
string pasExpiryDate = string.Format("PASD.PassengerIdentityDocumentExpiryDate_{0}", i + 1);
string pasCountryOfBirth = string.Format("PASD.CountryOfBirth_{0}", i + 1);
string pasEmergencyCare = string.Format("PASD.EmergencyCare_{0}", i + 1);
string pasEmergencyContact = string.Format("PASD.EmergencyContactNumber_{0}", i + 1);
string lastName = reader.ReadText(pasLastName);
if (!lastName.IsNullOrEmpty())
{
if (!(pasMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is PASD pas))
{
pas = new PASD();
pas.IsDeparture = true;
pas.Identifier = (i + 1).ToString();
pas.MessageHeader = pasMessage;
pasMessage.Elements.Add(pas);
}
pas.IsDeparture = true;
pas.NotificationSchengen = notificationSchengen;
pas.NotificationPAX = notificationPax;
pas.PassengerLastName = lastName;
pas.PassengerFirstName = reader.ReadText(pasFirstName);
pas.PassengerGender = reader.ReadGender(pasGender);
pas.PassengerNationality = reader.ReadNationality(pasNationality);
pas.PassengerPortOfEmbarkation = reader.ReadTextNoWhitespace(pasEmbarkation);
pas.PassengerPortOfDisembarkation = reader.ReadTextNoWhitespace(pasDebarkation);
pas.PassengerInTransit = reader.ReadBoolean(pasTransit);
pas.PassengerPlaceOfBirth = reader.ReadText(pasPlaceOfBirth);
pas.PassengerDateOfBirth = reader.ReadBirthDate(pasDateOfBirth);
pas.PassengerIdentityDocumentType = reader.ReadIdentityDocumentType(pasIdentDocType);
pas.PassengerIdentityDocumentId = reader.ReadText(pasIdentDocId);
pas.PassengerVisaNumber = reader.ReadText(pasVisaNo);
pas.PassengerIdentityDocumentIssuingState = reader.ReadNationality(pasIssuing);
pas.PassengerIdentityDocumentExpiryDate = reader.ReadDate(pasExpiryDate) ?? (DateTime?)new DateTime(2100, 12, 31);
pas.PassengerCountryOfBirth = reader.ReadNationality(pasCountryOfBirth);
pas.EmergencyCare = reader.ReadText(pasEmergencyCare);
pas.EmergencyContactNumber = reader.ReadText(pasEmergencyContact);
}
}
return true;
}
#endregion PASD
#region ScanMessage (generic)
private static void ScanMessage(DatabaseEntity dbEntity, ExcelReader reader)
{
Type objType = dbEntity.GetType();
List<PropertyInfo> props = new List<PropertyInfo>();
// add lookup properties to scan list
props.AddRange(objType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(LookupNameAttribute))));
foreach (PropertyInfo property in props)
{
object propValue = property.GetValue(dbEntity, null);
string value = (propValue == null) ? string.Empty : propValue.ToString();
LookupNameAttribute lookupNameAttribute = Attribute.GetCustomAttribute(property, typeof(LookupNameAttribute)) as LookupNameAttribute;
if (property.PropertyType == typeof(DateTime?))
{
DateTime? sheetValue = reader.ReadDate(lookupNameAttribute.LookupName);
if (sheetValue != null)
{
property.SetValue(dbEntity, sheetValue);
}
}
else if (property.PropertyType == typeof(double?))
{
double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName);
if (sheetValue != null)
{
property.SetValue(dbEntity, sheetValue);
}
}
else if (property.PropertyType == typeof(string))
{
string sheetValue = reader.ReadText(lookupNameAttribute.LookupName);
if (sheetValue != null)
{
property.SetValue(dbEntity, sheetValue);
}
}
else if (property.PropertyType == typeof(int?))
{
double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName);
if (sheetValue.HasValue)
{
property.SetValue(dbEntity, (int)sheetValue.Value);
}
}
else if (property.PropertyType == typeof(byte?))
{
double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName);
if (sheetValue.HasValue)
{
property.SetValue(dbEntity, (byte)sheetValue.Value);
}
}
else if (property.PropertyType == typeof(Boolean?))
{
bool? sheetValue = reader.ReadBoolean(lookupNameAttribute.LookupName);
string boolStringValue = reader.ReadText(lookupNameAttribute.LookupName);
if (sheetValue.HasValue)
{
property.SetValue(dbEntity, sheetValue);
}
}
else
{
_log.DebugFormat("unhandled property type: {0}", property.PropertyType);
}
}
}
#endregion ScanMessage (generic)
#region LookupMessageCore
/// <summary>
/// try to get the MessageCore from the open sheet by id
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
private static MessageCore LookupCoreById(ExcelReader reader)
{
MessageCore result = null;
string visitTransitId = reader.ReadTextNoWhitespace("ID");
if (visitTransitId != null)
{
if (bsmd.database.Util.IsVisitId(visitTransitId))
{
result = DBManager.Instance.GetMessageCoreByVisitId(visitTransitId);
}
else if (bsmd.database.Util.IsTransitId(visitTransitId))
{
result = DBManager.Instance.GetMessageCoreByTransitId(visitTransitId);
}
}
return result;
}
#endregion LookupMessageCore
#region GetMessageWithType
private static Message GetMessageWithType(List<Message> messages, MessageCore core, Message.NotificationClass type)
{
foreach (Message message in messages)
if (message.MessageNotificationClass == type) return message;
Message newMessage = DBManager.Instance.GetMessage(core, type);
if (newMessage == null)
{
newMessage = new Message();
newMessage.MessageNotificationClass = type;
messages.Add(newMessage);
newMessage.MessageCore = core;
newMessage.MessageCoreId = core.Id;
}
return newMessage;
}
#endregion GetMessageWithType
#region "Semi-Manual" import functions (may open interactive dialog)
public static byte? ReadGender(string gender, out bool canceled)
{
byte? result = DakosyUtil.ParseGender(gender);
canceled = false;
if (!gender.IsNullOrEmpty() && !result.HasValue)
{
// special treatment / callback
if (ValueMapping.Dicts[ValueMapping.MappingType.GENDER].ContainsKey(gender))
{
result = byte.Parse(ValueMapping.Dicts[ValueMapping.MappingType.GENDER][gender].Value); // we have mapped this before
}
else
{
FixImportDialog fid = new FixImportDialog();
fid.Value = gender;
fid.ValueType = "Gender";
fid.SelectionValues = Util.GlobalStructures.GenderDict;
if (fid.ShowDialog() ?? false)
{
if (!fid.SelectedValue.IsNullOrEmpty())
{
if (!ValueMapping.InvalidKeys[ValueMapping.MappingType.GENDER].Contains(gender))
{
string selectedValue = fid.SelectedValue;
Task<bool> createResult = Task.Run(async () => await ValueMapping.Create(ValueMapping.MappingType.GENDER, gender, selectedValue));
if (!createResult.Result)
_log.WarnFormat("Error saving gender value mapping {0} -> {1}", gender, selectedValue);
}
else
{
// add temporary
ValueMapping vm = ValueMapping.Create(ValueMapping.MappingType.GENDER);
vm.Key = gender;
vm.Value = fid.SelectedValue;
ValueMapping.Dicts[ValueMapping.MappingType.GENDER].Add(gender, vm);
}
result = byte.Parse(fid.SelectedValue);
}
}
else
{
canceled = true;
}
}
}
if (!result.HasValue)
{
result = 0; // not known
}
return result;
}
public static byte? ReadDocumentType(string documentType, out bool canceled)
{
byte? result = DakosyUtil.ParseDocumentType(documentType);
canceled = false;
if (!result.HasValue)
{
if (documentType.IsNullOrEmpty())
{
result = 5; // OTHER_LEGAL_IDENTITY_DOCUMENT (CH, 17.10.22)
}
else
{
// special treatment / callback
if (ValueMapping.Dicts[ValueMapping.MappingType.DOCUMENT_TYPE].ContainsKey(documentType))
{
result = byte.Parse(ValueMapping.Dicts[ValueMapping.MappingType.DOCUMENT_TYPE][documentType].Value); // we have mapped this before
}
else
{
FixImportDialog fid = new FixImportDialog();
fid.Value = documentType;
fid.ValueType = "Document type";
fid.SelectionValues = Util.GlobalStructures.IDDocTypeDict;
if (fid.ShowDialog() ?? false)
{
if (!fid.SelectedValue.IsNullOrEmpty())
{
if(!ValueMapping.InvalidKeys[ValueMapping.MappingType.DOCUMENT_TYPE].Contains(documentType))
{
string selectedValue = fid.SelectedValue;
Task<bool> createResult = Task.Run<bool>(async () => await ValueMapping.Create(ValueMapping.MappingType.DOCUMENT_TYPE, documentType, selectedValue));
if (!createResult.Result)
_log.WarnFormat("Error saving document type value mapping {0} -> {1}", documentType, selectedValue);
}
else
{
// add temporary
ValueMapping vm = ValueMapping.Create(ValueMapping.MappingType.DOCUMENT_TYPE);
vm.Key = documentType;
vm.Value = fid.SelectedValue;
ValueMapping.Dicts[ValueMapping.MappingType.DOCUMENT_TYPE].Add(documentType, vm);
}
result = byte.Parse(fid.SelectedValue);
}
}
else
{
canceled = true;
}
}
}
}
return result;
}
public static string ReadNationality(string nationality, out bool canceled)
{
string result = null;
canceled = false;
nationality = nationality.Trim();
if (nationality.IsNullOrEmpty())
{
result = "XX";
}
else if (CREW.NationalityDict.ContainsKey(nationality.ToUpper())) // is it already a key
{
result = nationality.ToUpper();
}
else if (CREW.NationalityDict.ContainsValue(nationality.ToUpper()))
{
result = CREW.NationalityDict.FirstOrDefault(x => x.Value.Substring(3).Equals(nationality, StringComparison.OrdinalIgnoreCase)).Key;
}
else if (ValueMapping.Dicts[ValueMapping.MappingType.COUNTRY].ContainsKey(nationality))
{
result = ValueMapping.Dicts[ValueMapping.MappingType.COUNTRY][nationality].Value;
}
else // we cannot find whatever this is..
{
FixImportDialog fid = new FixImportDialog();
fid.Value = nationality;
fid.ValueType = "Nationality";
fid.SelectionValues = CREW.NationalityDict;
if (fid.ShowDialog() ?? false)
{
if (!fid.SelectedValue.IsNullOrEmpty())
{
if(!ValueMapping.InvalidKeys[ValueMapping.MappingType.COUNTRY].Contains(nationality))
{
string selectedValue = fid.SelectedValue;
Task<bool> createResult = Task.Run(async () => await ValueMapping.Create(ValueMapping.MappingType.COUNTRY, nationality, selectedValue));
if(!createResult.Result)
_log.WarnFormat("Error saving nationality value mapping {0} -> {1}", nationality, selectedValue);
}
else
{
// add temporary
ValueMapping vm = ValueMapping.Create(ValueMapping.MappingType.COUNTRY);
vm.Key = nationality;
vm.Value = fid.SelectedValue;
ValueMapping.Dicts[ValueMapping.MappingType.COUNTRY].Add(nationality, vm);
}
result = fid.SelectedValue.Substring(0, 2); // attention manual entry
}
}
else
{
canceled = true;
}
}
return result;
}
public static string ReadLocode(string val, out bool canceled)
{
string result = null;
canceled = false;
val = val.ToUpper();
if (val.IsNullOrEmpty()) return "ZZUKN";
// check if this is a legitimate Locode
if (!LocodeDB.LocationNameFromLocode(val).IsNullOrEmpty()) return val;
// check if it is a port that we already know
// _log.WarnFormat("unknown Locode {0}", val);
// reverse search: if this is a name lookup port code
List<string> possibleLocodes = LocodeDB.AllLocodesForCityName(val);
if (possibleLocodes.Count > 1)
{
if (!ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
{
FixImportDialog fid = new FixImportDialog();
fid.Value = val;
fid.ValueType = "Locode";
Dictionary<string, string> ld = new Dictionary<string, string>();
foreach (string locode in possibleLocodes)
ld[locode] = locode;
fid.SelectionValues = ld;
if (fid.ShowDialog() ?? false)
{
string selectedValue = fid.SelectedValue;
if (!ValueMapping.InvalidKeys[ValueMapping.MappingType.LOCODE].Contains(selectedValue)) {
Task<bool> createResult = Task.Run<bool>(async () => await ValueMapping.Create(ValueMapping.MappingType.LOCODE, val, selectedValue));
if (!createResult.Result)
_log.WarnFormat("Error saving locode value mapping {0} -> {1}", val, selectedValue);
}
else
{
// add temporary
ValueMapping vm = ValueMapping.Create(ValueMapping.MappingType.LOCODE);
vm.Key = val;
vm.Value = fid.SelectedValue;
ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].Add(val, vm);
}
}
else
{
canceled = true;
}
}
if (ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
result = ValueMapping.Dicts[ValueMapping.MappingType.LOCODE][val].Value;
}
else if (possibleLocodes.Count == 1)
{
result = possibleLocodes[0];
}
else
{
if (!ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
{
// nothing found, let the user pick a locode by himself
FixImportDialog fid = new FixImportDialog();
fid.Value = val;
fid.ValueType = "Locode";
fid.LocodeMode = true;
if (fid.ShowDialog() ?? false)
{
if (!ValueMapping.InvalidKeys[ValueMapping.MappingType.LOCODE].Contains(fid.SelectedValue))
{
string selectedValue = fid.SelectedValue;
Task<bool> createResult = Task.Run(async () => await ValueMapping.Create(ValueMapping.MappingType.LOCODE, val, selectedValue));
if (!createResult.Result)
_log.WarnFormat("Error saving locode value mapping {0} -> {1}", val, selectedValue);
}
else
{
// add temporary
ValueMapping vm = ValueMapping.Create(ValueMapping.MappingType.LOCODE);
vm.Key = val;
vm.Value = fid.SelectedValue;
ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].Add(val, vm);
}
}
}
if (ValueMapping.Dicts[ValueMapping.MappingType.LOCODE].ContainsKey(val))
result = ValueMapping.Dicts[ValueMapping.MappingType.LOCODE][val].Value;
}
return result;
}
#endregion "Semi-Manual" import functions (may open interactive dialog)
}
}