362 lines
18 KiB
C#
362 lines
18 KiB
C#
// Copyright (c) 2017- schick Informatik
|
|
// Description: Helper class to read data from "Dakosy"-Style Excel Sheets
|
|
//
|
|
|
|
using log4net;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using bsmd.database;
|
|
|
|
namespace ENI2.Excel
|
|
{
|
|
internal static class DakosyUtil
|
|
{
|
|
private static readonly ILog _log = LogManager.GetLogger(typeof(DakosyUtil));
|
|
|
|
internal static bool ProcessSheet(ExcelReader reader, out string readMessage, MessageCore messageCore, List<Message.NotificationClass> notificationClasses)
|
|
{
|
|
bool result = true;
|
|
readMessage = "";
|
|
|
|
// Test if an Id is found in the sheet. If so, it has to match the id of the current core
|
|
string visitTransitId = reader.ReadCellAsText("main", "C12");
|
|
if (visitTransitId != null)
|
|
{
|
|
MessageCore aMessageCore = null;
|
|
if (bsmd.database.Util.IsVisitId(visitTransitId))
|
|
{
|
|
aMessageCore = DBManager.Instance.GetMessageCoreByVisitId(visitTransitId);
|
|
}
|
|
else if (bsmd.database.Util.IsTransitId(visitTransitId))
|
|
{
|
|
aMessageCore = DBManager.Instance.GetMessageCoreByTransitId(visitTransitId);
|
|
}
|
|
|
|
if ((aMessageCore == null) || (aMessageCore.Id.Value != messageCore.Id.Value))
|
|
{
|
|
readMessage = "Id not matching in import sheet";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// load messages if already present
|
|
List<Message> messages = DBManager.Instance.GetMessagesForCore(messageCore, DBManager.MessageLoad.ALL);
|
|
messages.Sort();
|
|
|
|
// now parse all data into the message classes
|
|
try
|
|
{
|
|
|
|
foreach (Message message in messages)
|
|
{
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.AGNT) && notificationClasses.Contains(Message.NotificationClass.AGNT))
|
|
{ if (ScanAGNT(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.ATA) && notificationClasses.Contains(Message.NotificationClass.ATA))
|
|
{ if (ScanATA(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.ATD) && notificationClasses.Contains(Message.NotificationClass.ATD))
|
|
{ if (ScanATD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.BKRA) && notificationClasses.Contains(Message.NotificationClass.BKRA))
|
|
{ if (ScanBKRA(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.BKRD) && notificationClasses.Contains(Message.NotificationClass.BKRD))
|
|
{ if (ScanBKRD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.BPOL) && notificationClasses.Contains(Message.NotificationClass.BPOL))
|
|
{ if (ScanBPOL(message, messages, messageCore, reader)) ExcelReader.SaveMessage(message); }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.CREW) && notificationClasses.Contains(Message.NotificationClass.CREW))
|
|
{ if (ScanCREW(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.CREWD) && notificationClasses.Contains(Message.NotificationClass.CREWD))
|
|
{ if (ScanCREWD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.HAZA) && notificationClasses.Contains(Message.NotificationClass.HAZA))
|
|
{ if (ScanHAZA(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.HAZD) && notificationClasses.Contains(Message.NotificationClass.HAZD))
|
|
{ if (ScanHAZD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.INFO) && notificationClasses.Contains(Message.NotificationClass.INFO))
|
|
{ if (ScanINFO(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.LADG) && notificationClasses.Contains(Message.NotificationClass.LADG))
|
|
{ if (ScanLADG(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.MDH) && notificationClasses.Contains(Message.NotificationClass.MDH))
|
|
{ if (ScanMDH(message, messages, messageCore, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.NAME) && notificationClasses.Contains(Message.NotificationClass.NAME))
|
|
{ if (ScanNAME(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.NOA_NOD) && notificationClasses.Contains(Message.NotificationClass.NOA_NOD))
|
|
{ if (ScanNOA_NOD(message, messageCore, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.PAS) && notificationClasses.Contains(Message.NotificationClass.PAS))
|
|
{ if (ScanPAS(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.PASD) && notificationClasses.Contains(Message.NotificationClass.PASD))
|
|
{ if (ScanPASD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.POBA) && notificationClasses.Contains(Message.NotificationClass.POBA))
|
|
{ if (ScanPOBA(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.POBD) && notificationClasses.Contains(Message.NotificationClass.POBD))
|
|
{ if (ScanPOBD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.PRE72H) && notificationClasses.Contains(Message.NotificationClass.PRE72H))
|
|
{ if (ScanPRE72H(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.SEC) && notificationClasses.Contains(Message.NotificationClass.SEC))
|
|
{ if (ScanSEC(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.SERV) && notificationClasses.Contains(Message.NotificationClass.SERV))
|
|
{ if (ScanSERV(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.STAT) && notificationClasses.Contains(Message.NotificationClass.STAT))
|
|
{ if (ScanSTAT(message, messageCore, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.STO) && notificationClasses.Contains(Message.NotificationClass.STO))
|
|
{ if (ScanSTO(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.TIEFA) && notificationClasses.Contains(Message.NotificationClass.TIEFA))
|
|
{ if (ScanTIEFA(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.TIEFD) && notificationClasses.Contains(Message.NotificationClass.TIEFD))
|
|
{ if (ScanTIEFD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.TOWA) && notificationClasses.Contains(Message.NotificationClass.TOWA))
|
|
{ if (ScanTOWA(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.TOWD) && notificationClasses.Contains(Message.NotificationClass.TOWD))
|
|
{ if (ScanTOWD(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.WAS) && notificationClasses.Contains(Message.NotificationClass.WAS))
|
|
{ if (ScanWAS(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
if ((message.MessageNotificationClass == Message.NotificationClass.WAS_RCPT) && notificationClasses.Contains(Message.NotificationClass.WAS_RCPT))
|
|
{ if (ScanWAS_RCPT(message, reader)) ExcelReader.SaveMessage(message); continue; }
|
|
|
|
}
|
|
|
|
DBManager.Instance.Save(messageCore); // muss das eigentlich sein?
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
readMessage = ex.Message;
|
|
result = false;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private static bool ScanWAS_RCPT(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanWAS(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanTOWD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanTOWA(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanTIEFD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanTIEFA(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanSTO(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanSTAT(Message statMessage, MessageCore core, ExcelReader reader)
|
|
{
|
|
if (statMessage.Elements.Count == 0)
|
|
{
|
|
STAT newSTAT = new STAT();
|
|
newSTAT.MessageHeader = statMessage;
|
|
statMessage.Elements.Add(newSTAT);
|
|
}
|
|
STAT stat = statMessage.Elements[0] as STAT;
|
|
stat.ShipName = reader.ReadCellAsText("ship", "C8");
|
|
stat.CallSign = reader.ReadCellAsText("ship", "C9");
|
|
core.IMO = reader.ReadCellAsText("ship", "C10");
|
|
core.ENI = reader.ReadCellAsText("ship", "C11");
|
|
DBManager.Instance.Save(core);
|
|
stat.MMSINumber = reader.ReadCellAsText("ship", "C12");
|
|
stat.Flag = reader.ReadCellAsText("ship", "C13");
|
|
stat.LengthOverall_MTR = reader.ReadCellAsDecimal("ship", "C14");
|
|
stat.Beam_MTR = reader.ReadCellAsDecimal("ship", "C15");
|
|
stat.GrossTonnage = (int?) reader.ReadCellAsDecimal("ship", "C16");
|
|
stat.PortOfRegistry = reader.ReadCellAsText("ship", "C17");
|
|
stat.InmarsatCallNumber = string.Format("{0} {1} {2} {3} {4}",
|
|
reader.ReadCellAsText("ship", "C18"),
|
|
reader.ReadCellAsText("ship", "C19"),
|
|
reader.ReadCellAsText("ship", "C20"),
|
|
reader.ReadCellAsText("ship", "C21"),
|
|
reader.ReadCellAsText("ship", "C22")
|
|
).Trim();
|
|
stat.ShipType = reader.ReadCellAsText("ship", "C23");
|
|
stat.TransportMode = reader.ReadCellAsText("ship", "C24");
|
|
|
|
stat.ISMCompanyName = reader.ReadCellAsText("ship", "C26");
|
|
stat.ISMCompanyId = reader.ReadCellAsText("ship", "C27");
|
|
string street = reader.ReadCellAsText("ship", "C28");
|
|
string number = reader.ReadCellAsText("ship", "C29");
|
|
stat.ISMCompanyStreetAndNumber = string.Format("{0} {1}", street, number).Trim();
|
|
stat.ISMCompanyPostalCode = reader.ReadCellAsText("ship", "C30");
|
|
stat.ISMCompanyCity = reader.ReadCellAsText("ship", "C31");
|
|
stat.ISMCompanyCountry = reader.ReadCellAsText("ship", "C32");
|
|
|
|
return true;
|
|
}
|
|
|
|
private static bool ScanSERV(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanSEC(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanPRE72H(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanPOBD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanPOBA(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanPASD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanPAS(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanNOA_NOD(Message message, MessageCore messageCore, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#region NAME
|
|
|
|
private static bool ScanNAME(Message nameMessage, ExcelReader reader)
|
|
{
|
|
if (nameMessage.Elements.Count == 0)
|
|
{
|
|
NAME newNAME = new NAME();
|
|
newNAME.MessageHeader = nameMessage;
|
|
nameMessage.Elements.Add(newNAME);
|
|
}
|
|
NAME name = nameMessage.Elements[0] as NAME;
|
|
name.NameOfMaster = reader.ReadCellAsText("port message", "C11");
|
|
if (name.NameOfMaster.IsNullOrEmpty() && name.IsNew)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
private static bool ScanMDH(Message message, List<Message> messages, MessageCore messageCore, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanLADG(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanINFO(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanHAZD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanHAZA(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanCREWD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanCREW(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanBPOL(Message message, List<Message> messages, MessageCore messageCore, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanBKRD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanBKRA(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanATD(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static bool ScanATA(Message message, ExcelReader reader)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#region AGNT
|
|
|
|
private static bool ScanAGNT(Message agntMessage, ExcelReader reader)
|
|
{
|
|
if (agntMessage.Elements.Count == 0)
|
|
{
|
|
AGNT newAgnt = new AGNT();
|
|
newAgnt.MessageHeader = agntMessage;
|
|
agntMessage.Elements.Add(newAgnt);
|
|
}
|
|
|
|
AGNT agnt = agntMessage.Elements[0] as AGNT;
|
|
agnt.AgentCompanyName = reader.ReadCellAsText("main", "C32");
|
|
agnt.AgentCity = reader.ReadCellAsText("main", "C36");
|
|
agnt.AgentCountry = reader.ReadCellAsText("main", "C37");
|
|
agnt.AgentEMail = reader.ReadCellAsText("main", "C42");
|
|
agnt.AgentFax = reader.ReadCellAsText("main", "C41");
|
|
agnt.AgentFirstName = reader.ReadCellAsText("main", "C39");
|
|
agnt.AgentLastName = reader.ReadCellAsText("main", "C38");
|
|
agnt.AgentPhone = reader.ReadCellAsText("main", "C40");
|
|
agnt.AgentPostalCode = reader.ReadCellAsText("main", "C35");
|
|
string street = reader.ReadCellAsText("main", "C33") ?? "";
|
|
string number = reader.ReadCellAsText("main", "C34") ?? "";
|
|
agnt.AgentStreetAndNumber = string.Format("{0} {1}", street, number);
|
|
|
|
if (agnt.AgentLastName.IsNullOrEmpty()) agnt.AgentLastName = "-";
|
|
|
|
// wird nicht mehr entfernt, egal welche Felder gelesen werden
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|