Dakosy TOWA, TOWD, BPOL

This commit is contained in:
Daniel Schick 2022-05-09 08:24:33 +02:00
parent 39a314eeba
commit 5acd9b98b7

View File

@ -1,21 +1,16 @@
// Copyright (c) 2017- schick Informatik
// Copyright (c) 2022 - schick Informatik
// Description: Helper class to read data from "Dakosy"-Style Excel Sheets
//
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using bsmd.database;
namespace ENI2.Excel
{
internal static class DakosyUtil
{
private static readonly ILog _log = LogManager.GetLogger(typeof(DakosyUtil));
{
internal static bool ProcessSheet(ExcelReader reader, out string readMessage, MessageCore messageCore, List<Message.NotificationClass> notificationClasses)
{
@ -64,7 +59,7 @@ namespace ENI2.Excel
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 (ScanBPOL(message, reader)) ExcelReader.SaveMessage(message); }
if ((message.MessageNotificationClass == Message.NotificationClass.CREW) && notificationClasses.Contains(Message.NotificationClass.CREW))
{ if (ScanCREW(message, reader)) ExcelReader.SaveMessage(message); continue; }
if ((message.MessageNotificationClass == Message.NotificationClass.CREWD) && notificationClasses.Contains(Message.NotificationClass.CREWD))
@ -277,16 +272,87 @@ namespace ENI2.Excel
#endregion
private static bool ScanTOWD(Message message, ExcelReader reader)
#region TOWD
private static bool ScanTOWD(Message towdMessage, ExcelReader reader)
{
throw new NotImplementedException();
bool result = false;
for (int i = 1; i < 10000; i++)
{
string towdName = reader.ReadCellAsText("towage on departure", string.Format("B{0}", 10 + i));
if (towdName.IsNullOrEmpty()) break;
if (!(towdMessage.GetSublistElementWithIdentifier(i.ToString()) is TOWD towd))
{
towd = new TOWD();
towd.MessageHeader = towdMessage;
towd.Identifier = i.ToString();
towdMessage.Elements.Add(towd);
}
towd.TowageOnDepartureName = towdName;
towd.TowageOnDepartureFlag = reader.ReadCellAsText("towage on departure", string.Format("C{0}", 10 + i));
towd.TowageOnDepartureOperatorCompanyName = reader.ReadCellAsText("towage on departure", string.Format("D{0}", 10 + i));
towd.TowageOnDepartureOperatorStreetNameAndNumber = reader.ReadCellAsText("towage on departure", string.Format("E{0}", 10 + i));
towd.TowageOnDepartureOperatorPostalCode = reader.ReadCellAsText("towage on departure", string.Format("F{0}", 10 + i));
towd.TowageOnDepartureOperatorCity = reader.ReadCellAsText("towage on departure", string.Format("G{0}", 10 + i));
towd.TowageOnDepartureOperatorCountry = reader.ReadCellAsText("towage on departure", string.Format("H{0}", 10 + i));
towd.TowageOnDepartureOperatorPhone = reader.ReadCellAsText("towage on departure", string.Format("J{0}", 10 + i));
towd.TowageOnDepartureOperatorEmail = reader.ReadCellAsText("towage on departure", string.Format("K{0}", 10 + i));
towd.TowageOnDepartureDraught_DMT = reader.ReadCellAsDecimal("towage on departure", string.Format("L{0}", 10 + i));
towd.TowageOnDepartureLengthOverall_MTR = reader.ReadCellAsDecimal("towage on departure", string.Format("M{0}", 10 + i));
towd.TowageOnDepartureBeam_MTR = reader.ReadCellAsDecimal("towage on departure", string.Format("N{0}", 10 + i));
towd.TowageOnDepartureRemarks = reader.ReadCellAsText("towage on departure", string.Format("O{0}", 10 + i));
result = true;
}
return result;
}
private static bool ScanTOWA(Message message, ExcelReader reader)
#endregion
#region TOWA
private static bool ScanTOWA(Message towaMessage, ExcelReader reader)
{
throw new NotImplementedException();
bool result = false;
for (int i = 1; i < 10000; i++)
{
string towaName = reader.ReadCellAsText("towage on arrival", string.Format("B{0}", 10 + i));
if (towaName.IsNullOrEmpty()) break;
if (!(towaMessage.GetSublistElementWithIdentifier(i.ToString()) is TOWA towa))
{
towa = new TOWA();
towa.MessageHeader = towaMessage;
towa.Identifier = i.ToString();
towaMessage.Elements.Add(towa);
}
towa.TowageOnArrivalName = towaName;
towa.TowageOnArrivalFlag = reader.ReadCellAsText("towage on arrival", string.Format("C{0}", 10 + i));
towa.TowageOnArrivalOperatorCompanyName = reader.ReadCellAsText("towage on arrival", string.Format("D{0}", 10 + i));
towa.TowageOnArrivalOperatorStreetNameAndNumber = reader.ReadCellAsText("towage on arrival", string.Format("E{0}", 10 + i));
towa.TowageOnArrivalOperatorPostalCode = reader.ReadCellAsText("towage on arrival", string.Format("F{0}", 10 + i));
towa.TowageOnArrivalOperatorCity = reader.ReadCellAsText("towage on arrival", string.Format("G{0}", 10 + i));
towa.TowageOnArrivalOperatorCountry = reader.ReadCellAsText("towage on arrival", string.Format("H{0}", 10 + i));
towa.TowageOnArrivalOperatorPhone = reader.ReadCellAsText("towage on arrival", string.Format("J{0}", 10 + i));
towa.TowageOnArrivalOperatorEmail = reader.ReadCellAsText("towage on arrival", string.Format("K{0}", 10 + i));
towa.TowageOnArrivalGrossTonnage = (int?) reader.ReadCellAsDecimal("towage on arrival", string.Format("L{0}", 10 + i));
towa.TowageOnArrivalLengthOverall_MTR = reader.ReadCellAsDecimal("towage on arrival", string.Format("M{0}", 10 + i));
towa.TowageOnArrivalBeam_MTR = reader.ReadCellAsDecimal("towage on arrival", string.Format("N{0}", 10 + i));
towa.TowageOnArrivalPurposeOfCall = reader.ReadCellAsText("towage on arrival", string.Format("O{0}", 10 + i));
towa.TowageOnArrivalDraught_DMT = reader.ReadCellAsDecimal("towage on arrival", string.Format("P{0}", 10 + i));
towa.TowageOnArrivalRemarks = reader.ReadCellAsText("towage on arrival", string.Format("Q{0}", 10 + i));
result = true;
}
return result;
}
#endregion
#region TIEFD
private static bool ScanTIEFD(Message tiefdMessage, ExcelReader reader)
{
if (tiefdMessage.Elements.Count == 0)
@ -300,6 +366,10 @@ namespace ENI2.Excel
return tiefd.DraughtUponDeparture_DMT.HasValue;
}
#endregion
#region TIEFA
private static bool ScanTIEFA(Message tiefaMessage, ExcelReader reader)
{
if (tiefaMessage.Elements.Count == 0)
@ -313,11 +383,19 @@ namespace ENI2.Excel
return tiefa.DraughtUponArrival_DMT.HasValue;
}
#endregion
#region STO
private static bool ScanSTO(Message message, ExcelReader reader)
{
throw new NotImplementedException();
return false; // not reported on dakosy sheet
}
#endregion
#region STAT
private static bool ScanSTAT(Message statMessage, MessageCore core, ExcelReader reader)
{
if (statMessage.Elements.Count == 0)
@ -361,6 +439,10 @@ namespace ENI2.Excel
return true;
}
#endregion
#region SERV
private static bool ScanSERV(Message servMessage, ExcelReader reader)
{
bool result = false;
@ -388,6 +470,10 @@ namespace ENI2.Excel
return result;
}
#endregion
#region SEC
private static bool ScanSEC(Message secMessage, ExcelReader reader)
{
if (secMessage.Elements.Count == 0)
@ -501,6 +587,8 @@ namespace ENI2.Excel
return true;
}
#endregion
#region PRE72H
private static bool ScanPRE72H(Message pre72hMessage, ExcelReader reader)
@ -546,6 +634,8 @@ namespace ENI2.Excel
#endregion
#region POBD
private static bool ScanPOBD(Message pobdMessage, ExcelReader reader)
{
if (pobdMessage.Elements.Count == 0)
@ -564,6 +654,10 @@ namespace ENI2.Excel
return true;
}
#endregion
#region POBA
private static bool ScanPOBA(Message pobaMessage, ExcelReader reader)
{
if (pobaMessage.Elements.Count == 0)
@ -582,6 +676,10 @@ namespace ENI2.Excel
return true;
}
#endregion
#region PASD
private static bool ScanPASD(Message pasdMessage, ExcelReader reader)
{
bool result = false;
@ -632,6 +730,10 @@ namespace ENI2.Excel
return result;
}
#endregion
#region PAS
private static bool ScanPAS(Message pasMessage, ExcelReader reader)
{
bool result = false;
@ -682,6 +784,10 @@ namespace ENI2.Excel
return result;
}
#endregion
#region NOA_NOD
private static bool ScanNOA_NOD(Message noa_nodMessage, ExcelReader reader)
{
if (noa_nodMessage.Elements.Count == 0)
@ -724,6 +830,8 @@ namespace ENI2.Excel
return true;
}
#endregion
#region NAME
private static bool ScanNAME(Message nameMessage, ExcelReader reader)
@ -985,16 +1093,20 @@ namespace ENI2.Excel
#endregion
#region HAZA / HAZD
private static bool ScanHAZD(Message message, ExcelReader reader)
{
throw new NotImplementedException();
return false; // not reported on Dakosy sheet
}
private static bool ScanHAZA(Message message, ExcelReader reader)
{
throw new NotImplementedException();
return false; // not reported on Dakosy sheet
}
#endregion
#region CREWD
private static bool ScanCREWD(Message crewMessage, ExcelReader reader)
@ -1122,11 +1234,50 @@ namespace ENI2.Excel
#endregion
private static bool ScanBPOL(Message message, List<Message> messages, MessageCore messageCore, ExcelReader reader)
#region BPOL
private static bool ScanBPOL(Message bpolMessage, ExcelReader reader)
{
throw new NotImplementedException();
if (bpolMessage.Elements.Count == 0)
{
BPOL newBPOL = new BPOL();
newBPOL.MessageHeader = bpolMessage;
bpolMessage.Elements.Add(newBPOL);
}
BPOL bpol = bpolMessage.Elements[0] as BPOL;
bpol.StowawaysOnBoard = reader.ReadCellAsBool("stowaways", "C8");
if(bpol.StowawaysOnBoard ?? false)
{
for (int i = 1; i < 1000; i++)
{
string port = reader.ReadCellAsText("stowaways", string.Format("B{0}", i + 10));
if(!port.IsNullOrEmpty())
{
if (!(bpol.GetSublistElementWithIdentifier(i.ToString()) is PortOfItinerary poi))
{
poi = new PortOfItinerary();
poi.Identifier = i.ToString();
poi.BPOL = bpol;
bpol.PortOfItineraries.Add(poi);
}
if (Locode.LocodeDB.LocationNameFromLocode(port) != null)
{
poi.PortOfItineraryLocode = port;
} else
{
poi.PortOfItineraryName = port;
}
poi.PortOfItineraryETA = reader.ReadCellAsDateTime("stowaways", string.Format("C{0}", i + 10));
}
}
}
return bpol.StowawaysOnBoard.HasValue;
}
#endregion
#region BKRD
private static bool ScanBKRD(Message brkdMessage, ExcelReader reader)
{
bool result = false;
@ -1153,6 +1304,10 @@ namespace ENI2.Excel
return result;
}
#endregion
#region BKRA
private static bool ScanBKRA(Message bkraMessage, ExcelReader reader)
{
bool result = false;
@ -1179,6 +1334,10 @@ namespace ENI2.Excel
return result;
}
#endregion
#region ATD
private static bool ScanATD(Message atdMessage, ExcelReader reader)
{
if (atdMessage.Elements.Count == 0)
@ -1192,6 +1351,10 @@ namespace ENI2.Excel
return atd.ATDPortOfCall.HasValue;
}
#endregion
#region ATA
private static bool ScanATA(Message ataMessage, ExcelReader reader)
{
if (ataMessage.Elements.Count == 0)
@ -1205,6 +1368,8 @@ namespace ENI2.Excel
return ata.ATAPortOfCall.HasValue;
}
#endregion
#region AGNT
private static bool ScanAGNT(Message agntMessage, ExcelReader reader)