1073 lines
52 KiB
C#
1073 lines
52 KiB
C#
// Copyright (c) 2017- schick Informatik
|
|
// Description:
|
|
//
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
using bsmd.database;
|
|
|
|
namespace ENI2.Excel
|
|
{
|
|
internal class ExcelWriter : ExcelBase
|
|
{
|
|
|
|
#region Fields
|
|
|
|
private readonly string _saveFilePath;
|
|
|
|
#endregion
|
|
|
|
#region Construction
|
|
|
|
public ExcelWriter(string filePath) : base(filePath)
|
|
{
|
|
string refFilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Excel\Reference_Sheet_DE.xlsx");
|
|
this._workBook = _excelWorkbooks.Open(refFilePath, 0, true, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false);
|
|
|
|
this.InitNameFields();
|
|
_saveFilePath = filePath;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public void WriteData(List<Message> messages, MessageCore core, out string resultMessage)
|
|
{
|
|
resultMessage = "";
|
|
|
|
foreach (Message message in messages)
|
|
{
|
|
try
|
|
{
|
|
switch(message.MessageNotificationClass)
|
|
{
|
|
case Message.NotificationClass.AGNT:
|
|
if (message.Elements[0] is AGNT agnt) this.WriteMessage(agnt);
|
|
break;
|
|
case Message.NotificationClass.ATA:
|
|
if (message.Elements[0] is ATA ata) this.WriteMessage(ata);
|
|
break;
|
|
case Message.NotificationClass.ATD:
|
|
if (message.Elements[0] is ATD atd) this.WriteMessage(atd);
|
|
break;
|
|
case Message.NotificationClass.BKRA:
|
|
this.WriteBKRA(message);
|
|
break;
|
|
case Message.NotificationClass.BKRD:
|
|
this.WriteBKRD(message);
|
|
break;
|
|
case Message.NotificationClass.BPOL:
|
|
if (message.Elements[0] is BPOL bpol)
|
|
{
|
|
this.WriteMessage(bpol);
|
|
this.WriteItineraries(bpol);
|
|
}
|
|
break;
|
|
case Message.NotificationClass.CREW:
|
|
this.WriteCREW(message, true);
|
|
break;
|
|
case Message.NotificationClass.CREWD:
|
|
this.WriteCREW(message, false);
|
|
break;
|
|
case Message.NotificationClass.HAZA:
|
|
this.WriteHAZ(message, true);
|
|
break;
|
|
case Message.NotificationClass.HAZD:
|
|
this.WriteHAZ(message, false);
|
|
break;
|
|
case Message.NotificationClass.INFO:
|
|
if (message.Elements[0] is INFO info) this.WriteMessage(info);
|
|
break;
|
|
case Message.NotificationClass.LADG:
|
|
this.WriteLADG(message);
|
|
break;
|
|
case Message.NotificationClass.MDH:
|
|
if (message.Elements[0] is MDH mdh)
|
|
{
|
|
this.WriteMessage(mdh);
|
|
this.WriteMDH(mdh);
|
|
}
|
|
break;
|
|
case Message.NotificationClass.NAME:
|
|
if (message.Elements[0] is NAME name) this.WriteMessage(name);
|
|
break;
|
|
case Message.NotificationClass.NOA_NOD:
|
|
if (message.Elements[0] is NOA_NOD noa_nod) this.WriteNOA_NOD(noa_nod, core.IsTransit);
|
|
break;
|
|
case Message.NotificationClass.PAS:
|
|
this.WritePAS(message, true);
|
|
break;
|
|
case Message.NotificationClass.PASD:
|
|
this.WritePAS(message, false);
|
|
break;
|
|
case Message.NotificationClass.POBA:
|
|
if (message.Elements[0] is POBA poba) this.WriteMessage(poba);
|
|
break;
|
|
case Message.NotificationClass.POBD:
|
|
if (message.Elements[0] is POBD pobd) this.WriteMessage(pobd);
|
|
break;
|
|
case Message.NotificationClass.PRE72H:
|
|
if (message.Elements[0] is PRE72H pre72h) this.WriteMessage(pre72h);
|
|
break;
|
|
case Message.NotificationClass.SEC:
|
|
if (message.Elements[0] is SEC sec) this.WriteMessage(sec);
|
|
this.WriteSEC(message);
|
|
break;
|
|
case Message.NotificationClass.SERV:
|
|
this.WriteSERV(message);
|
|
break;
|
|
case Message.NotificationClass.STAT:
|
|
if (message.Elements[0] is STAT stat) this.WriteMessage(stat);
|
|
break;
|
|
case Message.NotificationClass.STO:
|
|
this.WriteSTO(message);
|
|
break;
|
|
case Message.NotificationClass.TIEFA:
|
|
if (message.Elements[0] is TIEFA tiefa) this.WriteMessage(tiefa);
|
|
break;
|
|
case Message.NotificationClass.TIEFD:
|
|
if (message.Elements[0] is TIEFD tiefd) this.WriteMessage(tiefd);
|
|
break;
|
|
case Message.NotificationClass.TOWA:
|
|
WriteTOWA(message);
|
|
break;
|
|
case Message.NotificationClass.TOWD:
|
|
WriteTOWD(message);
|
|
break;
|
|
case Message.NotificationClass.WAS:
|
|
if (message.Elements[0] is WAS was) this.WriteMessage(was);
|
|
WriteWAS(message);
|
|
break;
|
|
|
|
default:
|
|
_log.InfoFormat("skip writing message class {0}", message.MessageNotificationClassDisplay);
|
|
break;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
resultMessage += string.Format("{2}:{0}{1}", ex.Message, Environment.NewLine, message.MessageNotificationClassDisplay);
|
|
}
|
|
}
|
|
|
|
WriteCore(core);
|
|
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
this._workBook.SaveAs(_saveFilePath, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange,
|
|
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
|
|
this._workBook.Saved = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private excel field writing
|
|
|
|
// generische Methode zum Schreiben der Felder nach Excel für Meldeklassen, die kein
|
|
// Listentyp sind
|
|
private void WriteMessage(DatabaseEntity dbEntity)
|
|
{
|
|
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;
|
|
bool success = true;
|
|
|
|
if (property.PropertyType == typeof(DateTime?))
|
|
{
|
|
success = this.WriteDate(lookupNameAttribute.LookupName, property.GetValue(dbEntity));
|
|
}
|
|
else if (property.PropertyType == typeof(double?))
|
|
{
|
|
success = this.WriteNumber(lookupNameAttribute.LookupName, property.GetValue(dbEntity));
|
|
}
|
|
else if (property.PropertyType == typeof(string))
|
|
{
|
|
success = this.WriteText(lookupNameAttribute.LookupName, property.GetValue(dbEntity));
|
|
}
|
|
else if (property.PropertyType == typeof(int?))
|
|
{
|
|
success = this.WriteNumber(lookupNameAttribute.LookupName, property.GetValue(dbEntity));
|
|
}
|
|
else if (property.PropertyType == typeof(byte?))
|
|
{
|
|
success = this.WriteNumber(lookupNameAttribute.LookupName, property.GetValue(dbEntity));
|
|
}
|
|
else if (property.PropertyType == typeof(Boolean?))
|
|
{
|
|
object boolVal = property.GetValue(dbEntity);
|
|
if(boolVal != null)
|
|
success = this.WriteBoolean(lookupNameAttribute.LookupName, boolVal);
|
|
}
|
|
else
|
|
{
|
|
string message = string.Format("unhandled property type: {0} for lookup {1}", property.PropertyType, lookupNameAttribute.LookupName);
|
|
_log.Warn(message);
|
|
}
|
|
|
|
if (!success)
|
|
{
|
|
string message = string.Format("Sheet does not contain lookup field {0}", lookupNameAttribute.LookupName);
|
|
_log.Error(message);
|
|
System.Diagnostics.Trace.WriteLine(message);
|
|
// throw new FormatException(message);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void WriteCore(MessageCore core)
|
|
{
|
|
WriteText("ID", core.IsTransit ? core.TransitId : core.VisitId);
|
|
WriteText("Visit.PortOfCall", core.PoC);
|
|
WriteText("Visit.IMONumber", core.IMO);
|
|
WriteText("ReferenceNumber", core.HerbergReportType);
|
|
WriteText("ShipMail", core.HerbergEmailContactReportingVessel);
|
|
}
|
|
|
|
#region list / special message classes
|
|
|
|
#region LADG
|
|
|
|
private void WriteLADG(Message ladgMessage)
|
|
{
|
|
for (int i = 0; i < Math.Min(ladgMessage.NumberOfExcelRows, ladgMessage.Elements.Count); 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);
|
|
|
|
LADG ladg = ladgMessage.Elements[i] as LADG;
|
|
if (ladg.CargoHandlingType.HasValue)
|
|
{
|
|
switch (ladg.CargoHandlingType)
|
|
{
|
|
case 1: WriteText(lnCHT, "load"); break;
|
|
case 2: WriteText(lnCHT, "discharge"); break;
|
|
case 3: WriteText(lnCHT, "transit"); break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
WriteText(lnType, ladg.CargoCodeNST);
|
|
WriteText(lnZusatz, ladg.CargoCodeNST_3);
|
|
WriteNumber(lnCNOI, ladg.CargoNumberOfItems);
|
|
WriteNumber(lnCGQ, ladg.CargoGrossQuantity_TNE);
|
|
WriteText(lnLoad, ladg.PortOfLoading);
|
|
WriteText(lnDis, ladg.PortOfDischarge);
|
|
WriteNumber(lnLACode, ladg.CargoLACode);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region BKRA
|
|
|
|
private void WriteBKRA(Message bkraMessage)
|
|
{
|
|
for (int i = 0; i < Math.Min(bkraMessage.NumberOfExcelRows, bkraMessage.Elements.Count); i++)
|
|
{
|
|
string lnQuantity = string.Format("BKRA.BunkerFuelQuantity_TNE_{0}", i + 1);
|
|
string lnType = string.Format("BKRA.BunkerFuelType_{0}", i + 1);
|
|
BRKA brka = bkraMessage.Elements[i] as BRKA;
|
|
WriteNumber(lnQuantity, brka.BunkerFuelQuantity_TNE);
|
|
WriteText(lnType, brka.BunkerFuelType);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region BKRD
|
|
|
|
private void WriteBKRD(Message bkrdMessage)
|
|
{
|
|
for (int i = 0; i < Math.Min(bkrdMessage.NumberOfExcelRows, bkrdMessage.Elements.Count); i++)
|
|
{
|
|
string lnQuantity = string.Format("BKRD.BunkerFuelQuantity_TNE_{0}", i + 1);
|
|
string lnType = string.Format("BKRD.BunkerFuelType_{0}", i + 1);
|
|
BRKD brkd = bkrdMessage.Elements[i] as BRKD;
|
|
WriteNumber(lnQuantity, brkd.BunkerFuelQuantity_TNE);
|
|
WriteText(lnType, brkd.BunkerFuelType);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region BPOL
|
|
|
|
private void WriteItineraries(BPOL bpol)
|
|
{
|
|
for (int i = 0; i < Math.Min(10, bpol.PortOfItineraries.Count); i++)
|
|
{
|
|
string bpolName = string.Format("BPOL.PortOfItineraryName_{0}", i + 1);
|
|
string bpolLocode = string.Format("BPOL.PortOfItineraryLoCode_{0}", i + 1);
|
|
string bpolETADate = string.Format("BPOL.PortOfItineraryETADate_{0}", i + 1);
|
|
string bpolETATime = string.Format("BPOL.PortOfItineraryETATime_{0}", i + 1);
|
|
PortOfItinerary poi = bpol.PortOfItineraries[i];
|
|
WriteText(bpolName, poi.PortOfItineraryName);
|
|
WriteText(bpolLocode, poi.PortOfItineraryLocode);
|
|
if (poi.PortOfItineraryETA.HasValue)
|
|
{
|
|
WriteDate(bpolETADate, poi.PortOfItineraryETA.Value);
|
|
WriteTime(bpolETATime, poi.PortOfItineraryETA.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CREW
|
|
|
|
private void WriteCREW(Message crewMessage, bool isArrival)
|
|
{
|
|
for(int i = 0; i<Math.Min(crewMessage.NumberOfExcelRows, crewMessage.Elements.Count); i++)
|
|
{
|
|
string crewLastName = string.Format("CREW{1}.CrewMemberLastName_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewFirstName = string.Format("CREW{1}.CrewMemberFirstName_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewGender = string.Format("CREW{1}.CrewMemberGender_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewNationality = string.Format("CREW{1}.CrewMemberNationality_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewDuty = string.Format("CREW{1}.CrewMemberDuty_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewPlaceOfBirth = string.Format("CREW{1}.CrewMemberPlaceOfBirth_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewDateOfBirth = string.Format("CREW{1}.CrewMemberDateOfBirth_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewIdentDocType = string.Format("CREW{1}.CrewMemberIdentityDocumentType_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewIdentDocId = string.Format("CREW{1}.CrewMemberIdentityDocumentId_{0}", i + 1, isArrival ? "" : "D");
|
|
string crewVisaNo = string.Format("CREW{1}.CrewMemberVisaNumber_{0}", i + 1, isArrival ? "" : "D");
|
|
CREW crew = crewMessage.Elements[i] as CREW; // das funktioniert weil CREWD von CREW ableitet..
|
|
WriteText(crewLastName, crew.CrewMemberLastName);
|
|
WriteText(crewFirstName, crew.CrewMemberFirstName);
|
|
WriteGender(crewGender, crew.CrewMemberGender);
|
|
WriteText(crewNationality, crew.CrewMemberNationality);
|
|
WriteText(crewDuty, crew.CrewMemberDuty);
|
|
WriteText(crewPlaceOfBirth, crew.CrewMemberPlaceOfBirth);
|
|
if(crew.CrewMemberDateOfBirth.HasValue)
|
|
WriteDate(crewDateOfBirth, crew.CrewMemberDateOfBirth.Value);
|
|
WriteIdentityDocumentType(crewIdentDocType, crew.CrewMemberIdentityDocumentType);
|
|
WriteText(crewIdentDocId, crew.CrewMemberIdentityDocumentId);
|
|
WriteText(crewVisaNo, crew.CrewMemberVisaNumber);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region HAZ
|
|
|
|
private void WriteHAZ(Message hazMessage, bool isArrival)
|
|
{
|
|
string noDPGOnBoard = isArrival ? "HAZA.DGOnBoard" : "HAZD.DGOnBoard";
|
|
string dpgManifestOnBoard = isArrival ? "HAZA.DPGManifestOnBoardOnArrival" : "HAZD.DPGManifestOnBoardOnDeparture";
|
|
string dpgContactFamilyName = isArrival ? "HAZA.DPGContactFamilyName" : "HAZD.DPGContactFamilyName";
|
|
string dpgContactPhone = isArrival ? "HAZA.DPGContactPhone" : "HAZD.DPGContactPhone";
|
|
string mouBaltic = isArrival ? "HAZA.MOUBaltic" : "HAZD.MOUBaltic";
|
|
string shipClass = isArrival ? "HAZA.INFShipClass" : "HAZD.INFShipClass";
|
|
HAZ haz = hazMessage.Elements[0] as HAZ;
|
|
WriteBoolean(noDPGOnBoard, haz.NoDPGOnBoardOnArrival);
|
|
WriteBoolean(dpgManifestOnBoard, haz.DPGManifestOnBoardOnArrival);
|
|
WriteText(dpgContactFamilyName, haz.DPGContactFamilyName);
|
|
WriteText(dpgContactPhone, haz.DPGContactPhone);
|
|
WriteBoolean(mouBaltic, haz.MOUBaltic);
|
|
switch(haz.INFShipClass)
|
|
{
|
|
case 0: WriteText(shipClass, "INF1"); break;
|
|
case 1: WriteText(shipClass, "INF2"); break;
|
|
case 2: WriteText(shipClass, "INF3"); break;
|
|
}
|
|
|
|
#region IMDB
|
|
|
|
for (int i = 0; i < Math.Min(haz.IMDGPositions.Count, 10); i++)
|
|
{
|
|
string imdg_unno = string.Format("HAZA.IMDG.UNNumber_{0}", i + 1);
|
|
string imdg_properShippingName = string.Format("HAZA.IMDG.ProperShippingName_{0}", i + 1);
|
|
string imdg_imoClass = string.Format("HAZA.IMDG.IMOClass_{0}", i + 1);
|
|
string imdg_packingGroup = string.Format("HAZA.IMDG.PackingGroup_{0}", i + 1);
|
|
string imdg_marinePollutant = string.Format("HAZA.IMDG.MarinePollutant_{0}", i + 1);
|
|
string imdg_flashpoint = string.Format("HAZA.IMDG.Flashpoint_CEL_{0}", i + 1);
|
|
string imdg_numberOfPackages = string.Format("HAZA.IMDG.NumberOfPackages_{0}", i + 1);
|
|
string imdg_packageType = string.Format("HAZA.IMDG.PackageType_{0}", i + 1);
|
|
string imdg_limitedQuantities = string.Format("HAZA.IMDG.LimitedQuantities_{0}", i + 1);
|
|
string imdg_exceptedQuantities = string.Format("HAZA.IMDG.ExceptedQuantities_{0}", i + 1);
|
|
string imdg_netQuantity = string.Format("HAZA.IMDG.NetQuantity_KGM_{0}", i + 1);
|
|
string imdg_grossQuantity = string.Format("HAZA.IMDG.GrossQuantity_KGM_{0}", i + 1);
|
|
string imdg_number = string.Format("HAZA.IMDG.Number_{0}", i + 1);
|
|
string imdg_stowagePosition = string.Format("HAZA.IMDG.StowagePosition_{0}", i + 1);
|
|
string imdg_portOfLoading = string.Format("HAZA.IMDG.PortOfLoading_{0}", i + 1);
|
|
string imdg_portOfDischarge = string.Format("HAZA.IMDG.PortOfDischarge_{0}", i + 1);
|
|
string imdg_containerNumber = string.Format("HAZA.IMDG.ContainerNumber_{0}", i + 1);
|
|
IMDGPosition imdgPosition = haz.IMDGPositions[i];
|
|
WriteText(imdg_unno, imdgPosition.UNNumber);
|
|
WriteText(imdg_properShippingName, imdgPosition.ProperShippingName);
|
|
WriteText(imdg_imoClass, imdgPosition.IMOClass);
|
|
if (imdgPosition.PackingGroup.HasValue)
|
|
{
|
|
switch (imdgPosition.PackingGroup.Value)
|
|
{
|
|
case 0: WriteText(imdg_packingGroup, "I"); break;
|
|
case 1: WriteText(imdg_packingGroup, "II"); break;
|
|
case 2: WriteText(imdg_packingGroup, "III"); break;
|
|
}
|
|
}
|
|
WriteBoolean(imdg_marinePollutant, imdgPosition.MarinePollutant);
|
|
WriteText(imdg_flashpoint, imdgPosition.Flashpoint_CEL);
|
|
if (imdgPosition.NumberOfPackages.HasValue)
|
|
WriteNumber(imdg_numberOfPackages, imdgPosition.NumberOfPackages.Value);
|
|
WriteText(imdg_packageType, imdgPosition.PackageType);
|
|
WriteBoolean(imdg_limitedQuantities, imdgPosition.LimitedQuantities);
|
|
WriteBoolean(imdg_exceptedQuantities, imdgPosition.ExceptedQuantities);
|
|
if (imdgPosition.NetQuantity_KGM.HasValue)
|
|
WriteNumber(imdg_netQuantity, imdgPosition.NetQuantity_KGM.Value);
|
|
if (imdgPosition.GrossQuantity_KGM.HasValue)
|
|
WriteNumber(imdg_grossQuantity, imdgPosition.GrossQuantity_KGM.Value);
|
|
WriteText(imdg_number, imdgPosition.VehicleLicenseNumber);
|
|
WriteText(imdg_stowagePosition, imdgPosition.StowagePosition);
|
|
WriteText(imdg_portOfLoading, imdgPosition.PortOfLoading);
|
|
WriteText(imdg_portOfDischarge, imdgPosition.PortOfDischarge);
|
|
WriteText(imdg_containerNumber, imdgPosition.ContainerNumber);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IBC
|
|
|
|
for (int i = 0; i < Math.Min(haz.IBCPositions.Count, 5); i++)
|
|
{
|
|
string ibc_productName = string.Format("HAZA.IBC.ProductName_{0}", i + 1);
|
|
string ibc_pollutionCategory = string.Format("HAZA.IBC.PollutionCategory_{0}", i + 1);
|
|
string ibc_flash = string.Format("HAZA.IBC.FlashpointInformation_{0}", i + 1);
|
|
string ibc_quantity = string.Format("HAZA.IBC.Quantity_KGM_{0}", i + 1);
|
|
string ibc_stowagePosition = string.Format("HAZA.IBC.StowagePosition_{0}", i + 1);
|
|
string ibc_portOfLoading = string.Format("HAZA.IBC.PortOfLoading_{0}", i + 1);
|
|
string ibc_portOfDischarge = string.Format("HAZA.IBC.PortOfDischarge_{0}", i + 1);
|
|
IBCPosition ibcPosition = haz.IBCPositions[i];
|
|
WriteText(ibc_productName, ibcPosition.ProductName);
|
|
if(ibcPosition.PollutionCategory.HasValue)
|
|
{
|
|
switch(ibcPosition.PollutionCategory.Value)
|
|
{
|
|
case 0: WriteText(ibc_pollutionCategory, "X"); break;
|
|
case 1: WriteText(ibc_pollutionCategory, "Y"); break;
|
|
case 2: WriteText(ibc_pollutionCategory, "Z"); break;
|
|
case 3: WriteText(ibc_pollutionCategory, "OS"); break;
|
|
}
|
|
}
|
|
WriteText(ibc_flash, ibcPosition.Flashpoint_CEL);
|
|
if (ibcPosition.Quantity_KGM.HasValue)
|
|
WriteNumber(ibc_quantity, ibcPosition.Quantity_KGM.Value);
|
|
WriteText(ibc_stowagePosition, ibcPosition.StowagePosition);
|
|
WriteText(ibc_portOfLoading, ibcPosition.PortOfLoading);
|
|
WriteText(ibc_portOfDischarge, ibcPosition.PortOfDischarge);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IGC
|
|
|
|
for (int i = 0; i < Math.Min(haz.IGCPositions.Count, 5); i++)
|
|
{
|
|
string igc_productName = string.Format("HAZA.IGC.ProductName_{0}", i + 1);
|
|
string igc_quantity = string.Format("HAZA.IGC.Quantity_KGM_{0}", i + 1);
|
|
string igc_stowagePosition = string.Format("HAZA.IGC.StowagePosition_{0}", i + 1);
|
|
string igc_portOfLoading = string.Format("HAZA.IGC.PortOfLoading_{0}", i + 1);
|
|
string igc_portOfDischarge = string.Format("HAZA.IGC.PortOfDischarge_{0}", i + 1);
|
|
IGCPosition igcPosition = haz.IGCPositions[i];
|
|
WriteText(igc_productName, igcPosition.ProductName);
|
|
if (igcPosition.Quantity_KGM.HasValue)
|
|
WriteNumber(igc_quantity, igcPosition.Quantity_KGM.Value);
|
|
WriteText(igc_stowagePosition, igcPosition.StowagePosition);
|
|
WriteText(igc_portOfLoading, igcPosition.PortOfLoading);
|
|
WriteText(igc_portOfDischarge, igcPosition.PortOfDischarge);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IMSBC
|
|
|
|
for (int i = 0; i < Math.Min(haz.IMSBCPositions.Count, 5); i++)
|
|
{
|
|
string imsbc_bcsn = string.Format("HAZA.IMSBC.BulkCargoShippingName_{0}", i + 1);
|
|
string imsbc_mhb = string.Format("HAZA.IMSBC.MHB_{0}", i + 1);
|
|
string imsbc_quantity = string.Format("HAZA.IMSBC.Quantity_KGM_{0}", i + 1);
|
|
string imsbc_stowagePosition = string.Format("HAZA.IMSBC.StowagePosition_{0}", i + 1);
|
|
string imsbc_portOfLoading = string.Format("HAZA.IMSBC.PortOfLoading_{0}", i + 1);
|
|
string imsbc_portOfDischarge = string.Format("HAZA.IMSBC.PortOfDischarge_{0}", i + 1);
|
|
IMSBCPosition imsbcPosition = haz.IMSBCPositions[i];
|
|
WriteText(imsbc_bcsn, imsbcPosition.BulkCargoShippingName);
|
|
WriteBoolean(imsbc_mhb, imsbcPosition.MHB);
|
|
if (imsbcPosition.Quantity_KGM.HasValue)
|
|
WriteNumber(imsbc_quantity, imsbcPosition.Quantity_KGM.Value);
|
|
WriteText(imsbc_stowagePosition, imsbcPosition.StowagePosition);
|
|
WriteText(imsbc_portOfLoading, imsbcPosition.PortOfLoading);
|
|
WriteText(imsbc_portOfDischarge, imsbcPosition.PortOfDischarge);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region MARPOL
|
|
|
|
for (int i = 0; i < Math.Min(haz.MARPOLPositions.Count, 5); i++)
|
|
{
|
|
string marpol_name = string.Format("HAZA.MARPOL.Name_{0}", i + 1);
|
|
string marpol_flash = string.Format("HAZA.MARPOL.Flashpoint_CEL_{0}", i + 1);
|
|
string marpol_quantity = string.Format("HAZA.MARPOL.Quantity_KGM_{0}", i + 1);
|
|
string marpol_stowagePosition = string.Format("HAZA.MARPOL.StowagePosition_{0}", i + 1);
|
|
string marpol_portOfLoading = string.Format("HAZA.MARPOL.PortOfLoading_{0}", i + 1);
|
|
string marpol_portOfDischarge = string.Format("HAZA.MARPOL.PortOfDischarge_{0}", i + 1);
|
|
MARPOL_Annex_I_Position marpolPosition = haz.MARPOLPositions[i];
|
|
WriteText(marpol_name, marpolPosition.Name);
|
|
WriteText(marpol_flash, marpolPosition.Flashpoint_CEL);
|
|
if (marpolPosition.Quantity_KGM.HasValue)
|
|
WriteNumber(marpol_quantity, marpolPosition.Quantity_KGM.Value);
|
|
WriteText(marpol_stowagePosition, marpolPosition.StowagePosition);
|
|
WriteText(marpol_portOfLoading, marpolPosition.PortOfLoading);
|
|
WriteText(marpol_portOfDischarge, marpolPosition.PortOfDischarge);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region MDH
|
|
|
|
private void WriteMDH(MDH mdh)
|
|
{
|
|
#region POC
|
|
|
|
for(int i = 0; i < Math.Min(mdh.NumberOfExcelRows, mdh.PortOfCallLast30Days.Count); 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);
|
|
PortOfCallLast30Days poc30d = mdh.PortOfCallLast30Days[i];
|
|
WriteText(portName, Locode.LocodeDB.LocationNameFromLocode(poc30d.PortOfCallLast30DaysLocode));
|
|
if (poc30d.PortOfCallLast30DaysLocode.Length == 5)
|
|
WriteText(portCountry, poc30d.PortOfCallLast30DaysLocode.Substring(0, 2));
|
|
WriteText(locode, poc30d.PortOfCallLast30DaysLocode);
|
|
WriteBoolean(crewJoined, poc30d.PortOfCallLast30DaysCrewMembersJoined);
|
|
WriteText(crewName, poc30d.CrewMembersJoinedText);
|
|
if (poc30d.PortOfCallLast30DaysDateOfDeparture.HasValue)
|
|
WriteDate(depDate, poc30d.PortOfCallLast30DaysDateOfDeparture.Value);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SanitaryMeasures
|
|
|
|
for(int i = 0; i < Math.Min(mdh.SanitaryMeasuresDetails.Count, 3); i++)
|
|
{
|
|
string smType = string.Format("MDH.SanitaryMeasuresType_{0}", i + 1);
|
|
string smLocation = string.Format("MDH.SanitaryMeasuresLocation_{0}", i + 1);
|
|
string smDate = string.Format("MDH.SanitaryMeasuresDate_{0}", i + 1);
|
|
SanitaryMeasuresDetail smd = mdh.SanitaryMeasuresDetails[i];
|
|
WriteText(smType, smd.SanitaryMeasuresType);
|
|
WriteText(smLocation, smd.SanitaryMeasuresLocation);
|
|
if (smd.SanitaryMeasuresDate.HasValue)
|
|
WriteDate(smDate, smd.SanitaryMeasuresDate.Value);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InfectedAreas
|
|
|
|
for(int i = 0; i < Math.Min(mdh.InfectedAreas.Count, 3); i++)
|
|
{
|
|
string iaPort = string.Format("MDH.InfectedAreaPort_{0}", i + 1);
|
|
string iaDate = string.Format("MDH.InfectedAreaDate_{0}", i + 1);
|
|
InfectedArea ia = mdh.InfectedAreas[i];
|
|
WriteText(iaPort, ia.InfectedAreaPort);
|
|
if (ia.InfectedAreaDate.HasValue)
|
|
WriteDate(iaDate, ia.InfectedAreaDate.Value);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StowawayJoiningLocation
|
|
|
|
for(int i = 0; i < Math.Min(mdh.StowawaysJoiningLocations.Count, 3); i++)
|
|
{
|
|
string sjlLookup = string.Format("MDH.StowawaysJoiningLocation_{0}", i + 1);
|
|
StowawaysJoiningLocation sjl = mdh.StowawaysJoiningLocations[i];
|
|
WriteText(sjlLookup, sjl.StowawayJoiningLocation);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region NOA_NOD
|
|
|
|
private void WriteNOA_NOD(NOA_NOD noa_nod, bool isTransit)
|
|
{
|
|
if(noa_nod.ETAToPortOfCall.HasValue)
|
|
{
|
|
WriteDate("NOA_NOD.ETADateToPortOfCall", noa_nod.ETAToPortOfCall.Value);
|
|
WriteTime("NOA_NOD.ETATimeToPortOfCall", noa_nod.ETAToPortOfCall.Value);
|
|
}
|
|
|
|
if(isTransit)
|
|
{
|
|
if(noa_nod.ETDFromKielCanal.HasValue)
|
|
{
|
|
WriteDate("NOA_NOD.ETDDateFromPortOfCall", noa_nod.ETDFromKielCanal.Value);
|
|
WriteTime("NOA_NOD.ETDTimeFromPortOfCall", noa_nod.ETDFromKielCanal.Value);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(int i = 0; i < Math.Min(noa_nod.NumberOfExcelRows, noa_nod.CallPurposes.Count); i++)
|
|
{
|
|
string callPurposeDescriptionKey = string.Format("NOA_NOD.CallPuposeDescription_{0}", i + 1);
|
|
string callPurposeCodeKey = string.Format("NOA_NOD.CallPurposeCode_{0}", i + 1);
|
|
CallPurpose cp = noa_nod.CallPurposes[i];
|
|
WriteText(callPurposeDescriptionKey, cp.CallPurposeDescription);
|
|
WriteText(callPurposeCodeKey, cp.CallPurposeCode);
|
|
}
|
|
|
|
if (noa_nod.ETDFromPortOfCall.HasValue)
|
|
{
|
|
WriteDate("NOA_NOD.ETDDateFromPortOfCall", noa_nod.ETDFromPortOfCall.Value);
|
|
WriteTime("NOA_NOD.ETDTimeFromPortOfCall", noa_nod.ETDFromPortOfCall.Value);
|
|
}
|
|
}
|
|
|
|
WriteText("NOA_NOD.LastPort", noa_nod.LastPort);
|
|
WriteText("NOA_NOD.NextPort", noa_nod.NextPort);
|
|
|
|
if(noa_nod.ETDFromLastPort.HasValue)
|
|
{
|
|
WriteDate("NOA_NOD.ETDDateFromLastPort", noa_nod.ETDFromLastPort.Value);
|
|
WriteTime("NOA_NOD.ETDTimeFromLastPort", noa_nod.ETDFromLastPort.Value);
|
|
}
|
|
|
|
if(noa_nod.ETAToNextPort.HasValue)
|
|
{
|
|
WriteDate("NOA_NOD.ETADateToNextPort", noa_nod.ETAToNextPort.Value);
|
|
WriteTime("NOA_NOD.ETATimeToNextPort", noa_nod.ETAToNextPort.Value);
|
|
}
|
|
|
|
WriteBoolean("NOA_NOD.IsAnchored", noa_nod.IsAnchored);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PAS
|
|
|
|
private void WritePAS(Message pasMessage, bool isArrival)
|
|
{
|
|
for(int i = 0; i < Math.Min(pasMessage.NumberOfExcelRows, pasMessage.Elements.Count); i++)
|
|
{
|
|
string pasLastName = string.Format("PAS{1}.PassengerLastName_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasFirstName = string.Format("PAS{1}.PassengerFirstName_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasGender = string.Format("PAS{1}.PassengerGender_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasNationality = string.Format("PAS{1}.PassengerNationality_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasEmbarkation = string.Format("PAS{1}.PassengerPortOfEmbarkation_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasDebarkation = string.Format("PAS{1}.PassengerPortOfDisembarkation_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasTransit = string.Format("PAS{1}.PassengerInTransit_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasPlaceOfBirth = string.Format("PAS{1}.PassengerPlaceOfBirth_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasDateOfBirth = string.Format("PAS{1}.PassengerDateOfBirth_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasIdentDocType = string.Format("PAS{1}.PassengerIdentityDocumentType_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasIdentDocId = string.Format("PAS{1}.PassengerIdentityDocumentId_{0}", i + 1, isArrival ? "" : "D");
|
|
string pasVisaNo = string.Format("PAS{1}.PassengerVisaNumber_{0}", i + 1, isArrival ? "" : "D");
|
|
PAS pas = pasMessage.Elements[i] as PAS; // PASD is derived from PAS daher ok!
|
|
WriteText(pasLastName, pas.PassengerLastName);
|
|
WriteText(pasFirstName, pas.PassengerFirstName);
|
|
WriteGender(pasGender, pas.PassengerGender);
|
|
WriteText(pasNationality, pas.PassengerNationality);
|
|
WriteText(pasEmbarkation, pas.PassengerPortOfEmbarkation);
|
|
WriteText(pasDebarkation, pas.PassengerPortOfDisembarkation);
|
|
WriteBoolean(pasTransit, pas.PassengerInTransit);
|
|
WriteText(pasPlaceOfBirth, pas.PassengerPlaceOfBirth);
|
|
if(pas.PassengerDateOfBirth.HasValue)
|
|
WriteDate(pasDateOfBirth, pas.PassengerDateOfBirth);
|
|
WriteIdentityDocumentType(pasIdentDocType, pas.PassengerIdentityDocumentType);
|
|
WriteText(pasIdentDocId, pas.PassengerIdentityDocumentId);
|
|
WriteText(pasVisaNo, pas.PassengerVisaNumber);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SEC
|
|
|
|
private void WriteSEC(Message secMessage)
|
|
{
|
|
if (secMessage.Elements.Count == 0) return;
|
|
SEC sec = secMessage.Elements[0] as SEC;
|
|
if(sec.ISSCType.HasValue)
|
|
{
|
|
switch(sec.ISSCType.Value)
|
|
{
|
|
case 0: WriteText("SEC.ISSCType", "full"); break;
|
|
case 1: WriteText("SEC.ISSCType", "interim"); break;
|
|
}
|
|
}
|
|
|
|
if (sec.CurrentShipSecurityLevel.HasValue)
|
|
WriteText("SEC.CurrentShipSecurityLevel", sec.CurrentShipSecurityLevel.Value.ToString());
|
|
|
|
WriteText("SEC.ISSCIssuerType", sec.ISSCIssuerTypeDisplay);
|
|
|
|
if(sec.GeneralDescriptionOfCargo.HasValue)
|
|
{
|
|
switch(sec.GeneralDescriptionOfCargo.Value)
|
|
{
|
|
case 0: WriteText("SEC.GeneralDescriptionOfCargo", "container"); break;
|
|
case 1: WriteText("SEC.GeneralDescriptionOfCargo", "vehicles"); break;
|
|
case 2: WriteText("SEC.GeneralDescriptionOfCargo", "convent"); break;
|
|
case 3: WriteText("SEC.GeneralDescriptionOfCargo", "dry"); break;
|
|
case 4: WriteText("SEC.GeneralDescriptionOfCargo", "liquid"); break;
|
|
case 5: WriteText("SEC.GeneralDescriptionOfCargo", "empty"); break;
|
|
}
|
|
}
|
|
|
|
WriteBoolean("SEC.KielCanalPassagePlanned_Arrival", sec.KielCanalPassagePlannedIncomming.HasValue);
|
|
WriteBoolean("SEC.KielCanalPassagePlanned_Departure", sec.KielCanalPassagePlannedOutgoing.HasValue);
|
|
if(sec.KielCanalPassagePlannedIncomming.HasValue)
|
|
{
|
|
WriteDate("SEC.ETADateKielCanalPassagePlannedIncomming", sec.KielCanalPassagePlannedIncomming.Value);
|
|
WriteTime("SEC.ETATimeKielCanalPassagePlannedIncomming", sec.KielCanalPassagePlannedIncomming.Value);
|
|
}
|
|
if(sec.KielCanalPassagePlannedOutgoing.HasValue)
|
|
{
|
|
WriteDate("SEC.ETADateKielCanalPassagePlannedOutgoing", sec.KielCanalPassagePlannedOutgoing.Value);
|
|
WriteTime("SEC.ETATimeKielCanalPassagePlannedOutgoing", sec.KielCanalPassagePlannedOutgoing.Value);
|
|
}
|
|
|
|
for(int i = 0; i < Math.Min(sec.LastTenPortFacilitesCalled.Count, 10); i++)
|
|
{
|
|
string portName = string.Format("SEC.PortFacilityPortName_{0}", i + 1);
|
|
string portCountry = string.Format("SEC.PortFacilityPortCountry_{0}", i + 1);
|
|
string portLocode = string.Format("SEC.PortFacilityPortLoCode_{0}", i + 1);
|
|
string portDateOfArrival = string.Format("SEC.PortFacilityDateOfArrival_{0}", i + 1);
|
|
string portDateOfDeparture = string.Format("SEC.PortFacilityDateOfDeparture_{0}", i + 1);
|
|
string portShipSecLevel = string.Format("SEC.PortFacilityShipSecurityLevel_{0}", i + 1);
|
|
string portGISISCode = string.Format("SEC.PortFacilityGISISCode_{0}", i + 1);
|
|
string portSecMatters = string.Format("SEC.PortFacilitySecurityMattersToReport_{0}", i + 1);
|
|
LastTenPortFacilitiesCalled l10 = sec.LastTenPortFacilitesCalled[i];
|
|
WriteText(portName, l10.PortFacilityPortName);
|
|
WriteText(portCountry, l10.PortFacilityPortCountry);
|
|
WriteText(portLocode, l10.PortFacilityPortLoCode);
|
|
if (l10.PortFacilityDateOfArrival.HasValue)
|
|
WriteDate(portDateOfArrival, l10.PortFacilityDateOfArrival.Value);
|
|
if (l10.PortFacilityDateOfDeparture.HasValue)
|
|
WriteDate(portDateOfDeparture, l10.PortFacilityDateOfDeparture.Value);
|
|
if (l10.PortFacilityShipSecurityLevel.HasValue)
|
|
WriteText(portShipSecLevel, l10.PortFacilityShipSecurityLevel.Value.ToString());
|
|
WriteText(portGISISCode, l10.PortFacilityGISISCode);
|
|
WriteText(portSecMatters, l10.PortFacilitySecurityMattersToReport);
|
|
}
|
|
|
|
for(int i = 0; i < Math.Min(sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Count, 10); i++)
|
|
{
|
|
string s2sName = string.Format("SEC.ShipToShipActivityLocationName_{0}", i + 1);
|
|
string s2sLocode = string.Format("SEC.ShipToShipActivityLocationLoCode_{0}", i + 1);
|
|
string s2sLatitude = string.Format("SEC.ShipToShipActivityLocationCoordinatesLatitude_{0}", i + 1);
|
|
string s2sLongitude = string.Format("SEC.ShipToShipActivityLocationCoordinatesLongitude_{0}", i + 1);
|
|
string s2sFromDate = string.Format("SEC.ShipToShipActivityDateFrom_{0}", i + 1);
|
|
string s2sToDate = string.Format("SEC.ShipToShipActivityDateTo_{0}", i + 1);
|
|
string s2sSec = string.Format("SEC.ShipToShipActivitySecurityMattersToReport_{0}", i + 1);
|
|
string s2sActivityString = string.Format("SEC.ShipToShipActivityType_{0}", i + 1);
|
|
ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2s = sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled[i];
|
|
WriteText(s2sName, s2s.ShipToShipActivityLocationName);
|
|
WriteText(s2sLocode, s2s.ShipToShipActivityLocationLoCode);
|
|
if(s2s.ShipToShipActivityLocationCoordinatesLatitude.HasValue)
|
|
WriteNumber(s2sLatitude, s2s.ShipToShipActivityLocationCoordinatesLatitude.Value);
|
|
if (s2s.ShipToShipActivityLocationCoordinatesLongitude.HasValue)
|
|
WriteNumber(s2sLongitude, s2s.ShipToShipActivityLocationCoordinatesLongitude.Value);
|
|
if (s2s.ShipToShipActivityDateFrom.HasValue)
|
|
WriteDate(s2sFromDate, s2s.ShipToShipActivityDateFrom.Value);
|
|
if (s2s.ShipToShipActivityDateTo.HasValue)
|
|
WriteDate(s2sToDate, s2s.ShipToShipActivityDateTo.Value);
|
|
WriteText(s2sSec, s2s.ShipToShipActivitySecurityMattersToReport);
|
|
if (s2s.ShipToShipActivityTypeCode.HasValue)
|
|
WriteText(s2sActivityString, s2s.ShipToShipActivityTypeCode.Value.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region SERV
|
|
|
|
private void WriteSERV(Message servMessage)
|
|
{
|
|
if(servMessage.Elements.Count > 0)
|
|
{
|
|
SERV serv = servMessage.Elements[0] as SERV;
|
|
WriteMessage(serv);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region STO
|
|
|
|
private void WriteSTO(Message stoMessage)
|
|
{
|
|
for(int i = 0; i < Math.Min(stoMessage.Elements.Count, stoMessage.NumberOfExcelRows); i++)
|
|
{
|
|
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);
|
|
|
|
STO sto = stoMessage.Elements[i] as STO;
|
|
|
|
WriteText(stoName, sto.Name);
|
|
if (sto.Quantity.HasValue)
|
|
WriteNumber(stoQuantity, sto.Quantity.Value);
|
|
WriteText(stoQuantityUnit, sto.QuantityUnit);
|
|
WriteText(stoLocationOnBoard, sto.LocationOnBoard);
|
|
WriteText(stoOfficialUse, sto.OfficialUse);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TOWA
|
|
|
|
private void WriteTOWA(Message towaMessage)
|
|
{
|
|
for(int i = 0; i < Math.Min(towaMessage.Elements.Count, towaMessage.NumberOfExcelRows); i++)
|
|
{
|
|
string tName = string.Format("TOWA.TowageOnArrivalName_{0}", i + 1);
|
|
string tFlag = string.Format("TOWA.TowageOnArrivalFlag_{0}", i + 1);
|
|
string tPoC = string.Format("TOWA.TowageOnArrivalPurposeOfCall_{0}", i + 1);
|
|
string tDraft = string.Format("TOWA.TowageOnArrivalDraught_DMT_{0}", i + 1);
|
|
string tGT = string.Format("TOWA.TowageOnArrivalGrossTonnage_{0}", i + 1);
|
|
string tLen = string.Format("TOWA.TowageOnArrivalLengthOverall_MTR_{0}", i + 1);
|
|
string tBeam = string.Format("TOWA.TowageOnArrivalBeam_MTR_{0}", i + 1);
|
|
string tOp = string.Format("TOWA.TowageOnArrivalOperatorCompanyName_{0}", i + 1);
|
|
|
|
TOWA towa = towaMessage.Elements[i] as TOWA;
|
|
|
|
WriteText(tName, towa.TowageOnArrivalName);
|
|
WriteText(tFlag, towa.TowageOnArrivalFlag);
|
|
WriteText(tPoC, towa.TowageOnArrivalPurposeOfCall);
|
|
if (towa.TowageOnArrivalDraught_DMT.HasValue)
|
|
WriteNumber(tDraft, towa.TowageOnArrivalDraught_DMT.Value);
|
|
if (towa.TowageOnArrivalGrossTonnage.HasValue)
|
|
WriteNumber(tGT, towa.TowageOnArrivalGrossTonnage.Value);
|
|
if (towa.TowageOnArrivalLengthOverall_MTR.HasValue)
|
|
WriteNumber(tLen, towa.TowageOnArrivalLengthOverall_MTR.Value);
|
|
if (towa.TowageOnArrivalBeam_MTR.HasValue)
|
|
WriteNumber(tBeam, towa.TowageOnArrivalBeam_MTR.Value);
|
|
WriteText(tOp, towa.TowageOnArrivalOperatorCompanyName);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TOWD
|
|
|
|
private void WriteTOWD(Message towdMessage)
|
|
{
|
|
for(int i = 0; i < Math.Min(towdMessage.Elements.Count, towdMessage.NumberOfExcelRows); i++)
|
|
{
|
|
string tName = string.Format("TOWD.TowageOnDepartureName_{0}", i + 1);
|
|
string tFlag = string.Format("TOWD.TowageOnDepartureFlag_{0}", i + 1);
|
|
string tDraft = string.Format("TOWD.TowageOnDepartureDraught_DMT_{0}", i + 1);
|
|
string tLen = string.Format("TOWD.TowageOnDepartureLengthOverall_MTR_{0}", i + 1);
|
|
string tBeam = string.Format("TOWD.TowageOnDepartureBeam_MTR_{0}", i + 1);
|
|
string tOp = string.Format("TOWD.TowageOnDepartureOperatorCompanyName_{0}", i + 1);
|
|
|
|
TOWD towd = towdMessage.Elements[i] as TOWD;
|
|
|
|
WriteText(tName, towd.TowageOnDepartureName);
|
|
WriteText(tFlag, towd.TowageOnDepartureFlag);
|
|
if (towd.TowageOnDepartureDraught_DMT.HasValue)
|
|
WriteNumber(tDraft, towd.TowageOnDepartureDraught_DMT.Value);
|
|
if (towd.TowageOnDepartureLengthOverall_MTR.HasValue)
|
|
WriteNumber(tLen, towd.TowageOnDepartureLengthOverall_MTR.Value);
|
|
if (towd.TowageOnDepartureBeam_MTR.HasValue)
|
|
WriteNumber(tBeam, towd.TowageOnDepartureBeam_MTR.Value);
|
|
WriteText(tOp, towd.TowageOnDepartureOperatorCompanyName);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region WAS
|
|
|
|
private void WriteWAS(Message wasMessage)
|
|
{
|
|
if (wasMessage.Elements.Count == 0) return;
|
|
WAS was = wasMessage.Elements[0] as WAS;
|
|
|
|
WriteText("WAS.WasteDisposalDelivery", was.WasteDisposalDelivery);
|
|
WriteText("WAS.LastWasteDisposalPort", was.LastWasteDisposalPort);
|
|
WriteText("WAS.WasteDisposalServiceProviderName", was.WasteDisposalServiceProviderText);
|
|
|
|
for(int i = 0; i < Math.Min(was.NumberOfExcelRows, was.Waste.Count); i++)
|
|
{
|
|
string wastetype = string.Format("WAS.WasteType_{0}", i + 1);
|
|
string wasteCode = string.Format("WAS.WasteCode_{0}", i + 1);
|
|
string wasteDescription = string.Format("WAS.WasteDescription_{0}", i + 1);
|
|
string wasteAmount = string.Format("WAS.WasteDisposalAmount_MTQ_{0}", i + 1);
|
|
string wasteCapacity = string.Format("WAS.WasteCapacity_MTQ_{0}", i + 1);
|
|
string wasteRetained = string.Format("WAS.WasteAmountRetained_MTQ_{0}", i + 1);
|
|
string wastePort = string.Format("WAS.WasteDisposalPort_{0}", i + 1);
|
|
string amountGen = string.Format("WAS.WasteAmountGeneratedTillNextPort_MTQ_{0}", i + 1);
|
|
string wasteDis = string.Format("WAS.WasteDisposedAtLastPort_MTQ_{0}", i + 1);
|
|
|
|
Waste waste = was.Waste[i];
|
|
|
|
if(waste.WasteType.HasValue)
|
|
WriteNumber(wasteCode, waste.WasteType.Value);
|
|
WriteText(wastetype, waste.WasteTypeDisplay);
|
|
WriteText(wasteDescription, waste.WasteDescription);
|
|
if (waste.WasteDisposalAmount_MTQ.HasValue)
|
|
WriteNumber(wasteAmount, waste.WasteDisposalAmount_MTQ.Value);
|
|
if (waste.WasteCapacity_MTQ.HasValue)
|
|
WriteNumber(wasteCapacity, waste.WasteCapacity_MTQ.Value);
|
|
if (waste.WasteAmountRetained_MTQ.HasValue)
|
|
WriteNumber(wasteRetained, waste.WasteAmountRetained_MTQ.Value);
|
|
WriteText(wastePort, waste.WasteDisposalPort);
|
|
if (waste.WasteAmountGeneratedTillNextPort_MTQ.HasValue)
|
|
WriteNumber(amountGen, waste.WasteAmountGeneratedTillNextPort_MTQ.Value);
|
|
if (waste.WasteDisposedAtLastPort_MTQ.HasValue)
|
|
WriteNumber(wasteDis, waste.WasteDisposedAtLastPort_MTQ.Value);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region write simple things
|
|
|
|
private void WriteIdentityDocumentType(string label, byte? docType)
|
|
{
|
|
if(docType.HasValue)
|
|
{
|
|
switch(docType.Value)
|
|
{
|
|
case 1: WriteText(label, "identity_card"); break;
|
|
case 2: WriteText(label, "passport"); break;
|
|
case 3: WriteText(label, "muster_book"); break;
|
|
case 4: WriteText(label, "picture_id"); break;
|
|
case 5: WriteText(label, "residential_permit"); break;
|
|
case 6: WriteText(label, "other_legal_identity_document"); break;
|
|
default: WriteText(label, "ic"); break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void WriteGender(string label, byte? gender)
|
|
{
|
|
if(gender.HasValue)
|
|
{
|
|
if (gender == 0) WriteText(label, "m");
|
|
if (gender == 1) WriteText(label, "w");
|
|
if (gender == 2) WriteText(label, "d");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region write value types
|
|
|
|
private bool WriteBoolean(string lookupName, object v)
|
|
{
|
|
bool result = _nameDict.ContainsKey(lookupName);
|
|
bool? b = (bool?) v;
|
|
if (result && b.HasValue)
|
|
{
|
|
_nameDict[lookupName].RefersToRange.Value = b.Value ? "Y" : "N";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private bool WriteText(string lookupName, object v)
|
|
{
|
|
bool result = _nameDict.ContainsKey(lookupName);
|
|
|
|
if(result)
|
|
{
|
|
_nameDict[lookupName].RefersToRange.Value = v;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private bool WriteNumber(string lookupName, object v)
|
|
{
|
|
bool result = _nameDict.ContainsKey(lookupName);
|
|
|
|
if (result)
|
|
{
|
|
_nameDict[lookupName].RefersToRange.Value = v;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private bool WriteDate(string lookupName, object v)
|
|
{
|
|
bool result = _nameDict.ContainsKey(lookupName);
|
|
|
|
if (result)
|
|
{
|
|
if(v != null)
|
|
{
|
|
_nameDict[lookupName].RefersToRange.Value = ((DateTime) v).ToOADate(); // Test this I dont believe it
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private bool WriteTime(string lookupName, object v)
|
|
{
|
|
bool result = _nameDict.ContainsKey(lookupName);
|
|
|
|
if (result)
|
|
{
|
|
if (v != null)
|
|
{
|
|
_nameDict[lookupName].RefersToRange.Value = ((DateTime)v).ToShortTimeString();
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|