From 5118ed8aaf4a0dbb86b2be29314595c4838b91b6 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 14 Dec 2022 16:18:44 +0100 Subject: [PATCH] =?UTF-8?q?Korrekturen=20lt=20R=C3=BCckmeldung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ENI2/Controls/ENIDataGrid.cs | 2 +- ENI2/Controls/ReportingPartyControl.xaml.cs | 2 +- ENI2/Excel/ExcelReader.cs | 118 ++- ENI2/Excel/ExcelUtil.cs | 1035 +++++++++++-------- ENI2/MainWindow.xaml.cs | 1 + ENI2/Properties/Resources.Designer.cs | 2 +- ENI2/Properties/Resources.resx | 2 +- 7 files changed, 655 insertions(+), 507 deletions(-) diff --git a/ENI2/Controls/ENIDataGrid.cs b/ENI2/Controls/ENIDataGrid.cs index feeab8c1..fde19681 100644 --- a/ENI2/Controls/ENIDataGrid.cs +++ b/ENI2/Controls/ENIDataGrid.cs @@ -119,7 +119,7 @@ namespace ENI2.Controls { var grid = sender as ENIDataGrid; if (Key.Delete == e.Key) - this.deleteItem(null, null); + this.deleteItem(null, null); } } diff --git a/ENI2/Controls/ReportingPartyControl.xaml.cs b/ENI2/Controls/ReportingPartyControl.xaml.cs index 94becccd..f916d83a 100644 --- a/ENI2/Controls/ReportingPartyControl.xaml.cs +++ b/ENI2/Controls/ReportingPartyControl.xaml.cs @@ -104,7 +104,7 @@ namespace ENI2.Controls { DBManager.Instance.GetReportingPartyDict().Add(Guid.NewGuid(), rp); this.ReportingParties.Add(rp); - this.dataGridReportingParties.Items.Refresh(); + this.dataGridReportingParties.Items.Refresh(); } } diff --git a/ENI2/Excel/ExcelReader.cs b/ENI2/Excel/ExcelReader.cs index d7533da1..06103366 100644 --- a/ENI2/Excel/ExcelReader.cs +++ b/ENI2/Excel/ExcelReader.cs @@ -7,27 +7,25 @@ // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. -using log4net; +using bsmd.database; +using ENI2.Locode; using Microsoft.Office.Interop.Excel; using System; using System.Collections.Generic; using System.Data; - using System.Globalization; using System.Linq; using System.Runtime.InteropServices; -using ENI2.Locode; -using bsmd.database; -using System.Text.RegularExpressions; namespace ENI2.Excel { internal class ExcelReader : ExcelBase { + internal enum ReadState + { NONE, OK, WARN, FAIL }; - internal enum ReadState { NONE, OK, WARN, FAIL }; - - internal enum SheetTypeEnum { BSMD, DAKOSY }; + internal enum SheetTypeEnum + { BSMD, DAKOSY }; private readonly SheetTypeEnum _sheetType = SheetTypeEnum.BSMD; @@ -36,15 +34,16 @@ namespace ENI2.Excel public ExcelReader(string filePath, bool openReadonly = true, bool createNameFields = true) { this._workBook = _excelWorkbooks.Open(filePath, 0, openReadonly, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false); - if(createNameFields) + if (createNameFields) this.InitNameFields(); // Determine if this is a Dakosy or BSMD Sheet - if(createNameFields) + if (createNameFields) _sheetType = (_nameDict.Count > 10) ? SheetTypeEnum.BSMD : SheetTypeEnum.DAKOSY; } - public SheetTypeEnum SheetType { get { return _sheetType; } } + public SheetTypeEnum SheetType + { get { return _sheetType; } } internal static void SaveMessage(Message message) { @@ -80,7 +79,7 @@ namespace ENI2.Excel if (result != null) { result = result.Trim(); - if(result.Length > 0) + if (result.Length > 0) { result = result.Clean(); } @@ -120,7 +119,7 @@ namespace ENI2.Excel if (!val.IsNullOrEmpty()) { val = val.ToUpper(); - string portName = LocodeDB.SSNPortNameFromLocode(val); + string portName = LocodeDB.SSNPortNameFromLocode(val); if (portName.IsNullOrEmpty()) { _log.WarnFormat("unknown Locode {0}", val); @@ -135,7 +134,7 @@ namespace ENI2.Excel string val = ReadText(lookup); if (val.IsNullOrEmpty()) return null; - if(int.TryParse(val, out int result)) + if (int.TryParse(val, out int result)) { if ((result < 10) || (result > 99)) _log.WarnFormat("invalid cargo LA code {0}", result); @@ -154,16 +153,17 @@ namespace ENI2.Excel string val = this.ReadText(lookup); if (val != null) { - if (val.Equals("m", StringComparison.CurrentCultureIgnoreCase) || val.Equals("male", StringComparison.CurrentCultureIgnoreCase)) { + if (val.Equals("m", StringComparison.CurrentCultureIgnoreCase) || val.Equals("male", StringComparison.CurrentCultureIgnoreCase)) + { result = 1; } else if (val.Equals("f", StringComparison.CurrentCultureIgnoreCase) || val.Equals("female", StringComparison.CurrentCultureIgnoreCase)) { result = 2; } - else if (val.Equals("n", StringComparison.CurrentCultureIgnoreCase) || - val.Equals("not applicable", StringComparison.CurrentCultureIgnoreCase) || - val.Equals("d", StringComparison.CurrentCultureIgnoreCase) || + else if (val.Equals("n", StringComparison.CurrentCultureIgnoreCase) || + val.Equals("not applicable", StringComparison.CurrentCultureIgnoreCase) || + val.Equals("d", StringComparison.CurrentCultureIgnoreCase) || val.Equals("diverse", StringComparison.CurrentCultureIgnoreCase)) { result = 9; @@ -173,7 +173,7 @@ namespace ENI2.Excel result = 0; } } - if(result == null) + if (result == null) { _log.ErrorFormat("error reading gender on {0}", lookup); } @@ -192,7 +192,7 @@ namespace ENI2.Excel if (val.Equals("picture_id", StringComparison.CurrentCultureIgnoreCase) || val.Equals("picture id", StringComparison.CurrentCultureIgnoreCase) || val.Equals("4")) result = 3; if (val.Equals("residental_permit", StringComparison.CurrentCultureIgnoreCase) || val.Equals("residental permit", StringComparison.CurrentCultureIgnoreCase) || val.Equals("5")) result = 4; if (val.Equals("other_legal_identity_document", StringComparison.CurrentCultureIgnoreCase) || val.Equals("other legal identity document", StringComparison.CurrentCultureIgnoreCase) || val.Equals("6")) result = 5; - if (val.Equals("ic", StringComparison.CurrentCultureIgnoreCase)) result = 0; + if (val.Equals("ic", StringComparison.CurrentCultureIgnoreCase)) result = 0; } if (!result.HasValue) @@ -243,11 +243,11 @@ namespace ENI2.Excel string val = this.ReadText(lookup); byte? result = null; - if(val != null) + if (val != null) { if ((val.IndexOf("load", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("1")) result = 0; if ((val.IndexOf("discharge", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("2")) result = 1; - if ((val.IndexOf("transit", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("3")) result = 2; + if ((val.IndexOf("transit", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("3")) result = 2; } if (!result.HasValue) @@ -275,7 +275,7 @@ namespace ENI2.Excel _log.ErrorFormat("Wrong ISO code {0}", val); val = ""; } - } + } } return val; } @@ -302,7 +302,7 @@ namespace ENI2.Excel string val = this.ReadText(lookup); byte? result = null; - if(val!= null) + if (val != null) { if (val == "I") result = 0; if (val == "1") result = 0; @@ -310,7 +310,7 @@ namespace ENI2.Excel if (val == "2") result = 1; if (val == "III") result = 2; if (val == "3") result = 2; - if (val.Equals("NONE", StringComparison.OrdinalIgnoreCase)) result = 0; + if (val.Equals("NONE", StringComparison.OrdinalIgnoreCase)) result = 0; } if (!result.HasValue) @@ -323,7 +323,7 @@ namespace ENI2.Excel { string val = this.ReadText(lookup); bool isValid = false; - if(!val.IsNullOrEmpty()) + if (!val.IsNullOrEmpty()) { if (int.TryParse(val, out int typeVal)) { @@ -371,13 +371,13 @@ namespace ENI2.Excel _log.ErrorFormat("cannot read delivery {0}", lookup); return result; - } + } internal byte? ReadHazards(string lookup) { string val = this.ReadText(lookup); byte? result = null; - if(val != null) + if (val != null) { if (val.Equals("p", StringComparison.OrdinalIgnoreCase)) return 0; if (val.Equals("s", StringComparison.OrdinalIgnoreCase)) return 1; @@ -390,7 +390,7 @@ namespace ENI2.Excel { string val = this.ReadText(lookup); byte? result = null; - if(val != null) + if (val != null) { if (val.Equals("a", StringComparison.OrdinalIgnoreCase)) return 0; if (val.Equals("b", StringComparison.OrdinalIgnoreCase)) return 1; @@ -401,8 +401,8 @@ namespace ENI2.Excel internal DateTime? ReadBirthDate(string lookup) { - DateTime? result = this.ReadDate(lookup); - if(result.HasValue) + DateTime? result = this.ReadDate(lookup); + if (result.HasValue) { if (result.Value > DateTime.Now) _log.WarnFormat("Birth date implausible for {0} : {1}", lookup, result); @@ -430,7 +430,7 @@ namespace ENI2.Excel date = DateTime.FromOADate(val); } catch (ArgumentException) { /* .. */ } - if(date == null) + if (date == null) { CultureInfo provider = CultureInfo.InvariantCulture; string dateString = val.ToString(); @@ -465,7 +465,7 @@ namespace ENI2.Excel { if ((date.Value < new DateTime(1899, 1, 1)) || (date.Value > new DateTime(2130, 1, 1))) { - date = null; // this can't be right + date = null; // this can't be right } } } @@ -485,26 +485,26 @@ namespace ENI2.Excel DateTime? etaDate = this.ReadDate(dateField); DateTime? etaTime = this.ReadTime(timeField); if (etaDate != null) - { + { if (etaTime != null) { result = new DateTime(etaDate.Value.Year, etaDate.Value.Month, etaDate.Value.Day, etaTime.Value.Hour, etaTime.Value.Minute, etaTime.Value.Second, DateTimeKind.Local); result = result.Value.ToUniversalTime(); - } + } else { result = new DateTime(etaDate.Value.Year, etaDate.Value.Month, etaDate.Value.Day, 0, 0, 0, DateTimeKind.Local); result = result.Value.ToUniversalTime(); } } - + return result; } internal DateTime? ReadTime(string lookup) { DateTime? result = null; - + try { if (_nameDict.ContainsKey(lookup)) @@ -520,7 +520,7 @@ namespace ENI2.Excel { result = DateTime.FromOADate(val); } - catch(ArgumentException) { } + catch (ArgumentException) { } if (result == null) { @@ -535,7 +535,8 @@ namespace ENI2.Excel } } - if (val is string) { + if (val is string) + { if (((string)val).EndsWith("lt", StringComparison.OrdinalIgnoreCase)) val = ((string)val).Substring(0, ((string)val).Length - 2).Trim(); else @@ -564,21 +565,21 @@ namespace ENI2.Excel if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate)) result = tmpDate; } - } + } } } catch (Exception) - { - _log.WarnFormat("error reading time for lookup {0}", lookup); + { + _log.WarnFormat("error reading time for lookup {0}", lookup); } return result; - } + } internal double ReadNumberDefaultZero(string lookup) { double? result = this.ReadNumber(lookup); - if(!result.HasValue) + if (!result.HasValue) { result = 0; } @@ -588,9 +589,9 @@ namespace ENI2.Excel internal bool? ReadBoolean(string lookup) { string val = this.ReadText(lookup); - if (val == null) + if (val == null) return null; - + if ((val == "y") || (val == "Y") || val.Equals("yes", StringComparison.OrdinalIgnoreCase) || (val == "1") || (val == "x") || (val == "X")) return true; @@ -599,17 +600,30 @@ namespace ENI2.Excel #region Dakosy-specific functions + internal bool HasWorksheetNamed(string sheetName) + { + try + { + Worksheet theWorkSheet = _workBook.Worksheets[sheetName]; + return theWorkSheet != null; + } + catch (Exception) + { + return false; + } + } + internal string ReadCellAsText(string sheetName, string range) { try { - Worksheet workSheet = (Worksheet) _workBook.Worksheets[sheetName]; + Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName]; string result = workSheet.Range[range].Text.ToString(); if (!result.IsNullOrEmpty()) result = result.Trim().Clean(); return result; } - catch(Exception e) + catch (Exception e) { _log.Warn(e.Message); } @@ -642,7 +656,6 @@ namespace ENI2.Excel Range aRange = workSheet.Range[range]; if (aRange != null) { - } } catch (Exception e) @@ -713,12 +726,11 @@ namespace ENI2.Excel return tmpDate2; return null; } - else + else return null; } - #endregion - + #endregion Dakosy-specific functions } -} +} \ No newline at end of file diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index c9d186fd..99c83bd1 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -7,14 +7,14 @@ // // 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 log4net; -using bsmd.database; -using ENI2.Locode; -using ENI2.EditControls; namespace ENI2.Excel { @@ -36,7 +36,7 @@ namespace ENI2.Excel readMessage = ""; MessageCore aMessageCore = ExcelUtil.LookupCoreById(reader); - if((aMessageCore == null) || (aMessageCore.Id.Value != messageCore.Id.Value)) + if ((aMessageCore == null) || (aMessageCore.Id.Value != messageCore.Id.Value)) { readMessage = "Id not matching in import sheet"; return false; @@ -58,7 +58,7 @@ namespace ENI2.Excel // load messages if already present List messages = DBManager.Instance.GetMessagesForCore(messageCore, DBManager.MessageLoad.ALL); - + int? testCode = (int?)reader.ReadNumber("WAS.WasteCode_1"); if (testCode > 999) isOldVersion = true; @@ -67,7 +67,6 @@ namespace ENI2.Excel // parse selected classes try { - foreach (Message message in messages) { if ((message.MessageNotificationClass == Message.NotificationClass.AGNT) && notificationClasses.Contains(Message.NotificationClass.AGNT)) @@ -128,14 +127,13 @@ namespace ENI2.Excel { 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 ((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) + catch (Exception ex) { readMessage = ex.Message; result = false; @@ -144,12 +142,12 @@ namespace ENI2.Excel return result; } - #endregion + #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(); @@ -159,20 +157,20 @@ namespace ENI2.Excel ATA ata = ataMessage.Elements[0] as ATA; ExcelUtil.ScanMessage(ata, reader); - if(!ata.ATAPortOfCall.HasValue) + if (!ata.ATAPortOfCall.HasValue) { ata.ATAPortOfCall = reader.ReadDateTime("ATA.ATADatePortOfCall", "ATA.ATATimePortOfCall"); } - return !(!ata.ATAPortOfCall.HasValue && ataMessage.IsNew); - } + return !(!ata.ATAPortOfCall.HasValue && ataMessage.IsNew); + } - #endregion + #endregion ATA #region ATD private static bool ScanATD(Message atdMessage, ExcelReader reader) - { + { if (atdMessage.Elements.Count == 0) { ATD newATD = new ATD(); @@ -187,15 +185,15 @@ namespace ENI2.Excel atd.ATDPortOfCall = reader.ReadDateTime("ATD.ATDDatePortOfCall", "ATD.ATDTimePortOfCall"); } - return !(!atd.ATDPortOfCall.HasValue && atdMessage.IsNew); + return !(!atd.ATDPortOfCall.HasValue && atdMessage.IsNew); } - #endregion + #endregion ATD #region TIEFA private static bool ScanTIEFA(Message tiefaMessage, ExcelReader reader, bool isOldVersion) - { + { if (tiefaMessage.Elements.Count == 0) { TIEFA newTIEFA = new TIEFA(); @@ -211,13 +209,13 @@ namespace ENI2.Excel return true; } - #endregion + #endregion TIEFA #region TIEFD private static bool ScanTIEFD(Message tiefdMessage, ExcelReader reader, bool isOldVersion) - { - if(tiefdMessage.Elements.Count == 0) + { + if (tiefdMessage.Elements.Count == 0) { TIEFD newTIEFD = new TIEFD(); newTIEFD.MessageHeader = tiefdMessage; @@ -227,17 +225,17 @@ namespace ENI2.Excel ScanMessage(tiefd, reader); if (!tiefd.DraughtUponDeparture_DMT.HasValue && tiefdMessage.IsNew) return false; - if (tiefd.DraughtUponDeparture_DMT.HasValue && ! isOldVersion) + if (tiefd.DraughtUponDeparture_DMT.HasValue && !isOldVersion) tiefd.DraughtUponDeparture_DMT = tiefd.DraughtUponDeparture_DMT.Value * 10; // m to dm - return true; + return true; } - #endregion + #endregion TIEFD #region NAME private static bool ScanNAME(Message nameMessage, ExcelReader reader) - { + { if (nameMessage.Elements.Count == 0) { NAME newNAME = new NAME(); @@ -251,7 +249,7 @@ namespace ENI2.Excel return true; } - #endregion + #endregion NAME #region BPOL @@ -269,7 +267,7 @@ namespace ENI2.Excel // 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); + Message pobaMessage = ExcelUtil.GetMessageWithType(messages, messageCore, Message.NotificationClass.POBA); if (pobaMessage.Elements.Count > 0) { POBA poba = pobaMessage.Elements[0] as POBA; @@ -299,10 +297,10 @@ namespace ENI2.Excel 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 = 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); } @@ -313,13 +311,13 @@ namespace ENI2.Excel return true; } - #endregion + #endregion BPOL #region POBA private static bool ScanPOBA(Message pobaMessage, ExcelReader reader) { - if(pobaMessage.Elements.Count == 0) + if (pobaMessage.Elements.Count == 0) { POBA newPoba = new POBA(); newPoba.MessageHeader = pobaMessage; @@ -337,13 +335,13 @@ namespace ENI2.Excel return true; } - #endregion + #endregion POBA #region POBD private static bool ScanPOBD(Message pobdMessage, ExcelReader reader) { - if(pobdMessage.Elements.Count == 0) + if (pobdMessage.Elements.Count == 0) { POBD newPobd = new POBD(); newPobd.MessageHeader = pobdMessage; @@ -361,14 +359,13 @@ namespace ENI2.Excel return true; } - #endregion + #endregion POBD #region HAZA private static bool ScanHAZA(Message hazaMessage, ExcelReader reader, bool isOldVersion) { - - if(hazaMessage.Elements.Count == 0) + if (hazaMessage.Elements.Count == 0) { HAZ newHaza = new HAZ(); newHaza.IsDeparture = false; @@ -380,10 +377,10 @@ namespace ENI2.Excel 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.DPGContactPhone = reader.ReadText("HAZA.DPGContactPhone"); haza.MOUBaltic = reader.ReadBoolean("HAZA.MOUBaltic"); string shipClass = reader.ReadText("HAZA.INFShipClass"); - if(!shipClass.IsNullOrEmpty()) + if (!shipClass.IsNullOrEmpty()) { if (shipClass.Contains('1')) haza.INFShipClass = 0; if (shipClass.Contains('2')) haza.INFShipClass = 1; @@ -414,14 +411,14 @@ namespace ENI2.Excel 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 + 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) + if (imdgPosition == null) { imdgPosition = new IMDGPosition(); imdgPosition.HAZ = haza; @@ -429,30 +426,30 @@ namespace ENI2.Excel haza.IMDGPositions.Add(imdgPosition); } - imdgPosition.UNNumber = unNumber; - imdgPosition.ProperShippingName = reader.ReadText(imdg_properShippingName); - imdgPosition.IMOClass = reader.ReadText(imdg_imoClass); + 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.Flashpoint_CEL = reader.ReadText(imdg_flashpoint); imdgPosition.NumberOfPackages = (int?)reader.ReadNumber(imdg_numberOfPackages); - imdgPosition.PackageType = reader.ReadText(imdg_packageType); + 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.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 + #endregion IMDG #region IBC - + for (int i = 1; i <= 5; i++) { string ibc_productName = string.Format("HAZA.IBC.ProductName_{0}", i); @@ -469,11 +466,11 @@ namespace ENI2.Excel string ibc_remarks = string.Format("HAZA.IBC.Remarks_{0}", i); string productName = reader.ReadText(ibc_productName); - if (productName.IsNullOrEmpty()) continue; + if (productName.IsNullOrEmpty()) continue; string posIdent = string.Format("IBC-{0}", i); IBCPosition ibcPosition = haza.GetIBCPositionWithIdentifier(posIdent); - if(ibcPosition == null) + if (ibcPosition == null) { ibcPosition = new IBCPosition(); ibcPosition.Identifier = posIdent; @@ -482,17 +479,17 @@ namespace ENI2.Excel } ibcPosition.ProductName = productName; - + string pollutionCategory = reader.ReadText(ibc_pollutionCategory); - if(!pollutionCategory.IsNullOrEmpty()) + 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); + ibcPosition.Flashpoint_CEL = reader.ReadText(ibc_flash); if (!ibcPosition.Flashpoint_CEL.IsNullOrEmpty()) { if (ibcPosition.Flashpoint_CEL != "-") @@ -504,20 +501,20 @@ namespace ENI2.Excel } } } - - ibcPosition.Quantity_KGM = (int ?) reader.ReadNumber(ibc_quantity); - ibcPosition.StowagePosition = reader.ReadText(ibc_stowagePosition); - ibcPosition.PortOfLoading = reader.ReadLoCode(ibc_portOfLoading); + + 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 + #endregion IBC #region IGC - + for (int i = 1; i <= 5; i++) { string igc_productName = string.Format("HAZA.IGC.ProductName_{0}", i); @@ -530,11 +527,11 @@ namespace ENI2.Excel string igc_remarks = string.Format("HAZA.IGC.Remarks_{0}", i); string productName = reader.ReadText(igc_productName); - if (productName.IsNullOrEmpty()) continue; + if (productName.IsNullOrEmpty()) continue; string posIdent = string.Format("IGC-{0}", i); IGCPosition igcPosition = haza.GetIGCPositionWithIdentifier(posIdent); - if(igcPosition == null) + if (igcPosition == null) { igcPosition = new IGCPosition(); igcPosition.Identifier = posIdent; @@ -542,20 +539,20 @@ namespace ENI2.Excel haza.IGCPositions.Add(igcPosition); } - igcPosition.ProductName = productName; + igcPosition.ProductName = productName; igcPosition.Quantity_KGM = reader.ReadNumber(igc_quantity); - igcPosition.StowagePosition = reader.ReadText(igc_stowagePosition); - igcPosition.PortOfLoading = reader.ReadLoCode(igc_portOfLoading); + 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 + #endregion IGC #region IMSBC - + for (int i = 1; i <= 5; i++) { string imsbc_bcsn = string.Format("HAZA.IMSBC.BulkCargoShippingName_{0}", i); @@ -570,11 +567,11 @@ namespace ENI2.Excel string imsbc_remarks = string.Format("HAZA.IMSBC.Remarks_{0}", i); string bcsn = reader.ReadText(imsbc_bcsn); - if (bcsn.IsNullOrEmpty()) continue; + if (bcsn.IsNullOrEmpty()) continue; string posIdent = string.Format("IMSBC-{0}", i); IMSBCPosition imsbcPosition = haza.GetIMSBCPositionWithIdentifier(posIdent); - if(imsbcPosition == null) + if (imsbcPosition == null) { imsbcPosition = new IMSBCPosition(); imsbcPosition.Identifier = posIdent; @@ -582,11 +579,11 @@ namespace ENI2.Excel haza.IMSBCPositions.Add(imsbcPosition); } - imsbcPosition.BulkCargoShippingName = bcsn; + 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.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); @@ -594,10 +591,10 @@ namespace ENI2.Excel imsbcPosition.Remarks = reader.ReadText(imsbc_remarks); } - #endregion + #endregion IMSBC #region MARPOL - + for (int i = 1; i <= 5; i++) { string marpol_name = string.Format("HAZA.MARPOL.Name_{0}", i); @@ -609,11 +606,11 @@ namespace ENI2.Excel string marpol_remarks = string.Format("HAZA.MARPOL.Remarks_{0}", i); string name = reader.ReadText(marpol_name); - if (name.IsNullOrEmpty()) continue; + if (name.IsNullOrEmpty()) continue; string posIdent = string.Format("MARPOL-{0}", i); MARPOL_Annex_I_Position marpolPosition = haza.GetMARPOLPositionWithIdentifier(posIdent); - if(marpolPosition == null) + if (marpolPosition == null) { marpolPosition = new MARPOL_Annex_I_Position(); marpolPosition.Identifier = posIdent; @@ -621,8 +618,8 @@ namespace ENI2.Excel haza.MARPOLPositions.Add(marpolPosition); } - marpolPosition.Name = name; - marpolPosition.Flashpoint_CEL = reader.ReadText(marpol_flash); + 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 @@ -637,15 +634,15 @@ namespace ENI2.Excel } marpolPosition.Quantity_KGM = reader.ReadNumber(marpol_quantity); - marpolPosition.StowagePosition = reader.ReadText(marpol_stowagePosition); + 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 - - if(haza.HasPositions) // Christin 22.3.17: Felder bei Positionen immer fest ausfüllen + #endregion MARPOL + + if (haza.HasPositions) // Christin 22.3.17: Felder bei Positionen immer fest ausfüllen { haza.NoDPGOnBoardOnArrival = false; } @@ -653,12 +650,12 @@ namespace ENI2.Excel return true; } - #endregion + #endregion HAZA #region HAZD private static bool ScanHAZD(Message hazdMessage, ExcelReader reader) - { + { if (hazdMessage.Elements.Count == 0) { HAZ newHazd = new HAZ(); @@ -666,21 +663,21 @@ namespace ENI2.Excel newHazd.MessageHeader = hazdMessage; hazdMessage.Elements.Add(newHazd); } - HAZ hazd = hazdMessage.Elements[0] as HAZ; + 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.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; + if (shipClass.Contains('3')) hazd.INFShipClass = 2; } - + #region IMDG for (int i = 1; i <= 10; i++) @@ -705,7 +702,7 @@ namespace ENI2.Excel 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 + if (unNumber.IsNullOrEmpty()) continue; // if unnumber is not set ignore this row string posIdent = string.Format("IMDG-{0}", i); IMDGPosition imdgPosition = hazd.GetIMDGPositionWithIdentifier(posIdent); @@ -717,30 +714,30 @@ namespace ENI2.Excel hazd.IMDGPositions.Add(imdgPosition); } - imdgPosition.UNNumber = unNumber; - imdgPosition.ProperShippingName = reader.ReadText(imdg_properShippingName); - imdgPosition.IMOClass = reader.ReadText(imdg_imoClass); + 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.Flashpoint_CEL = reader.ReadText(imdg_flashpoint); imdgPosition.NumberOfPackages = (int?)reader.ReadNumber(imdg_numberOfPackages); - imdgPosition.PackageType = reader.ReadText(imdg_packageType); + 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.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 + #endregion IMDG #region IBC - + for (int i = 1; i <= 5; i++) { string ibc_productName = string.Format("HAZD.IBC.ProductName_{0}", i); @@ -755,7 +752,7 @@ namespace ENI2.Excel string ibc_remarks = string.Format("HAZD.IBC.Remarks_{0}", i); string productName = reader.ReadText(ibc_productName); - if (productName.IsNullOrEmpty()) continue; + if (productName.IsNullOrEmpty()) continue; string posIdent = string.Format("IBC-{0}", i); IBCPosition ibcPosition = hazd.GetIBCPositionWithIdentifier(posIdent); @@ -767,7 +764,7 @@ namespace ENI2.Excel hazd.IBCPositions.Add(ibcPosition); } - ibcPosition.ProductName = productName; + ibcPosition.ProductName = productName; string pollutionCategory = reader.ReadText(ibc_pollutionCategory); if (!pollutionCategory.IsNullOrEmpty()) { @@ -775,35 +772,35 @@ namespace ENI2.Excel 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.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 + #endregion IBC #region IGC - + for (int i = 1; i <= 5; i++) { string igc_productName = string.Format("HAZD.IGC.ProductName_{0}", i); @@ -816,7 +813,7 @@ namespace ENI2.Excel string igc_remarks = string.Format("HAZD.IGC.Remarks_{0}", i); string productName = reader.ReadText(igc_productName); - if (productName.IsNullOrEmpty()) continue; + if (productName.IsNullOrEmpty()) continue; string posIdent = string.Format("IGC-{0}", i); IGCPosition igcPosition = hazd.GetIGCPositionWithIdentifier(posIdent); @@ -828,20 +825,20 @@ namespace ENI2.Excel hazd.IGCPositions.Add(igcPosition); } - igcPosition.ProductName = productName; + igcPosition.ProductName = productName; igcPosition.Quantity_KGM = reader.ReadNumber(igc_quantity); - igcPosition.StowagePosition = reader.ReadText(igc_stowagePosition); - igcPosition.PortOfLoading = reader.ReadLoCode(igc_portOfLoading); + 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 + #endregion IGC #region IMSBC - + for (int i = 1; i <= 5; i++) { string imsbc_bcsn = string.Format("HAZD.IMSBC.BulkCargoShippingName_{0}", i); @@ -856,7 +853,7 @@ namespace ENI2.Excel string imsbc_remarks = string.Format("HAZD.IMSBC.Remarks_{0}", i); string bcsn = reader.ReadText(imsbc_bcsn); - if (bcsn.IsNullOrEmpty()) continue; + if (bcsn.IsNullOrEmpty()) continue; string posIdent = string.Format("IMSBC-{0}", i); IMSBCPosition imsbcPosition = hazd.GetIMSBCPositionWithIdentifier(posIdent); @@ -868,11 +865,11 @@ namespace ENI2.Excel hazd.IMSBCPositions.Add(imsbcPosition); } - imsbcPosition.BulkCargoShippingName = bcsn; + 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.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); @@ -880,10 +877,10 @@ namespace ENI2.Excel imsbcPosition.Remarks = reader.ReadText(imsbc_remarks); } - #endregion + #endregion IMSBC #region MARPOL - + for (int i = 1; i <= 5; i++) { string marpol_name = string.Format("HAZD.MARPOL.Name_{0}", i); @@ -895,7 +892,7 @@ namespace ENI2.Excel string marpol_remarks = string.Format("HAZD.MARPOL.Remarks_{0}", i); string name = reader.ReadText(marpol_name); - if (name.IsNullOrEmpty()) continue; + if (name.IsNullOrEmpty()) continue; string posIdent = string.Format("MARPOL-{0}", i); MARPOL_Annex_I_Position marpolPosition = hazd.GetMARPOLPositionWithIdentifier(posIdent); @@ -907,10 +904,11 @@ namespace ENI2.Excel hazd.MARPOLPositions.Add(marpolPosition); } - marpolPosition.Name = name; - marpolPosition.Flashpoint_CEL = reader.ReadText(marpol_flash); - if (marpolPosition.Flashpoint_CEL.IsNullOrEmpty()) { - marpolPosition.FlashpointInformation = 0; + 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 { @@ -928,23 +926,23 @@ namespace ENI2.Excel marpolPosition.Remarks = reader.ReadText(marpol_remarks); } - #endregion - + #endregion MARPOL + if (hazd.HasPositions) // Christin 22.3.17: Felder bei Positionen immer fest ausfüllen { - hazd.NoDPGOnBoardOnArrival = false; + hazd.NoDPGOnBoardOnArrival = false; } return true; } - #endregion + #endregion HAZD #region INFO private static bool ScanINFO(Message infoMessage, ExcelReader reader) { - if(infoMessage.Elements.Count == 0) + if (infoMessage.Elements.Count == 0) { INFO newINFO = new INFO(); newINFO.MessageHeader = infoMessage; @@ -961,18 +959,18 @@ namespace ENI2.Excel info.ShippingArea = reader.ReadShippingArea("INFO.ShippingArea"); // enum read func bool? fumigatedBulkCargo = reader.ReadBoolean("INFO.FumigatedBulkCargo"); - info.FumigatedBulkCargo = (byte) ((fumigatedBulkCargo ?? false) ? 1 : 0); + info.FumigatedBulkCargo = (byte)((fumigatedBulkCargo ?? false) ? 1 : 0); return true; } - #endregion + #endregion INFO #region STAT private static bool ScanSTAT(Message statMessage, MessageCore messageCore, List messages, ExcelReader reader) { - if(statMessage.Elements.Count == 0) + if (statMessage.Elements.Count == 0) { STAT newSTAT = new STAT(); newSTAT.MessageHeader = statMessage; @@ -981,11 +979,11 @@ namespace ENI2.Excel STAT stat = statMessage.Elements[0] as STAT; ScanMessage(stat, reader); - foreach(Message preMessage in messages) + foreach (Message preMessage in messages) { - if(preMessage.MessageNotificationClass == Message.NotificationClass.PRE72H) + if (preMessage.MessageNotificationClass == Message.NotificationClass.PRE72H) { - if(preMessage.Elements.Count > 0) + if (preMessage.Elements.Count > 0) { PRE72H pre72h = preMessage.Elements[0] as PRE72H; pre72h.Tanker = stat.IsTanker; @@ -1007,14 +1005,15 @@ namespace ENI2.Excel if (stat.ISMCompanyId.StartsWith("imo", StringComparison.OrdinalIgnoreCase)) stat.ISMCompanyId = stat.ISMCompanyId.Substring(3); - if(stat.ISMCompanyId.Length < 7) { // zero - fill + 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 != null) { if (transportMode.Contains("maritime", StringComparison.OrdinalIgnoreCase)) stat.TransportMode = "1"; if (transportMode.Equals("1")) stat.TransportMode = transportMode; @@ -1029,12 +1028,12 @@ namespace ENI2.Excel return true; } - #endregion + #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(); @@ -1049,12 +1048,12 @@ namespace ENI2.Excel if (messageCore.IsTransit) { if (eta.HasValue) - noa_nod.ETAToKielCanal = eta; + noa_nod.ETAToKielCanal = eta; } else { if (eta.HasValue) - noa_nod.ETAToPortOfCall = eta; + noa_nod.ETAToPortOfCall = eta; for (int i = 1; i <= noa_nod.NumberOfExcelRows; i++) { @@ -1065,7 +1064,6 @@ namespace ENI2.Excel if (!callPurposeCode.IsNullOrEmpty()) { - if (!(noa_nod.GetSublistElementWithIdentifier(i.ToString()) is CallPurpose callPurpose)) { callPurpose = new CallPurpose(); @@ -1074,7 +1072,7 @@ namespace ENI2.Excel noa_nod.CallPurposes.Add(callPurpose); } callPurpose.CallPurposeCode = ((int?)reader.ReadNumber(callPurposeCodeKey)) ?? 0; - callPurpose.CallPurposeDescription = callPurposeDescription; + callPurpose.CallPurposeDescription = callPurposeDescription; } } } @@ -1099,19 +1097,19 @@ namespace ENI2.Excel string nextPort = reader.ReadText("NOA_NOD.NextPort")?.Trim().ToUpper(); if (!nextPort.IsNullOrEmpty() && (nextPort.Length > 5)) - nextPort = nextPort.Substring(0, 5); //trunc + nextPort = nextPort.Substring(0, 5); //trunc noa_nod.NextPort = nextPort; - if(messageCore.IsTransit) + if (messageCore.IsTransit) { - noa_nod.ETDFromKielCanal = reader.ReadDateTime("NOA_NOD.ETDDateFromPortOfCall", "NOA_NOD.ETDTimeFromPortOfCall"); + 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.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 @@ -1120,13 +1118,13 @@ namespace ENI2.Excel return true; } - #endregion + #endregion NOA_NOD #region AGNT private static bool ScanAGNT(Message agntMessage, ExcelReader reader) - { - if(agntMessage.Elements.Count == 0) + { + if (agntMessage.Elements.Count == 0) { AGNT newAgnt = new AGNT(); newAgnt.MessageHeader = agntMessage; @@ -1141,7 +1139,7 @@ namespace ENI2.Excel return true; } - #endregion + #endregion AGNT #region WAS @@ -1157,7 +1155,7 @@ namespace ENI2.Excel 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) @@ -1182,12 +1180,12 @@ namespace ENI2.Excel { //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 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); + string amountGen = string.Format("WAS.WasteAmountGeneratedTillNextPort_MTQ_{0}", i); if (!(was.GetSublistElementWithIdentifier(i.ToString()) is Waste waste)) { @@ -1197,9 +1195,9 @@ namespace ENI2.Excel was.Waste.Add(waste); } - waste.WasteType = (int?) reader.ReadNumber(wasteCode); + waste.WasteType = (int?)reader.ReadNumber(wasteCode); - // Waste description Spezialfälle für DK + // Waste description Spezialfälle für DK waste.WasteDescription = reader.ReadText(wasteDescription); if (waste.WasteDescription.IsNullOrEmpty()) { @@ -1226,7 +1224,7 @@ namespace ENI2.Excel } // RM am 24.1.18, ich hoffe das stimmt so wie sie meint.. - if((reader.Mode == ExcelReader.CountryMode.DK) && (i==9)) + 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; @@ -1248,9 +1246,9 @@ namespace ENI2.Excel 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 - + + waste.WasteDisposalPort = reader.ReadSSNLocode(wastePort); // aka RemainingWasteDisposalPort + if (waste.WasteDisposalPort.IsNullOrEmpty()) { waste.WasteDisposalPort = "ZZUKN"; @@ -1267,7 +1265,8 @@ namespace ENI2.Excel was.AddMissingWaste(); return true; } - #endregion + + #endregion WAS #region WAS_RCPT @@ -1302,7 +1301,7 @@ namespace ENI2.Excel wasr.PortReceptionFacilityName = reader.ReadText(wasrcpt_portreceptFacilityName); wasr.PortReceptionFacilityProviderName = reader.ReadText(wasrcpt_portreceptFacilityProviderName); string treatmentFacility = reader.ReadText(wasrcpt_treatmentFacility); - if(!treatmentFacility.IsNullOrEmpty()) + if (!treatmentFacility.IsNullOrEmpty()) { TreatmentFacilityProvider tfp = new TreatmentFacilityProvider(); tfp.WAS_RCPT = wasr; @@ -1327,7 +1326,7 @@ namespace ENI2.Excel 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.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")) @@ -1337,7 +1336,7 @@ namespace ENI2.Excel if (!wr.AmountWasteReceived_MTQ.HasValue) wr.AmountWasteReceived_MTQ = 0; // Default ist 0, nicht nix ;-) } - // only add message when an identification number was given + // only add message when an identification number was given if (wasr.IdentificationNumber.IsNullOrEmpty()) was_rcptMessage.Elements.Remove(wasr); } @@ -1345,13 +1344,13 @@ namespace ENI2.Excel return true; } - #endregion + #endregion WAS_RCPT #region MDH private static bool ScanMDH(Message mdhMessage, List messages, MessageCore messageCore, ExcelReader reader) - { - if(mdhMessage.Elements.Count == 0) + { + if (mdhMessage.Elements.Count == 0) { MDH newMDH = new MDH(); newMDH.MessageHeader = mdhMessage; @@ -1365,12 +1364,11 @@ namespace ENI2.Excel 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 @@ -1402,7 +1400,6 @@ namespace ENI2.Excel } else // "normal mode", aus den Zellen lesen { - // POC last 30 days for (int i = 0; i < mdh.NumberOfExcelRows; i++) { @@ -1422,7 +1419,7 @@ namespace ENI2.Excel } string pName = reader.ReadText(portName); - string pCountry = reader.ReadText(portCountry); + string pCountry = reader.ReadText(portCountry); poc30d.PortOfCallLast30DaysDateOfDeparture = reader.ReadDate(depDate); poc30d.PortOfCallLast30DaysLocode = reader.ReadLoCode(locode); @@ -1434,12 +1431,12 @@ namespace ENI2.Excel 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)) @@ -1450,9 +1447,9 @@ namespace ENI2.Excel poc30d.CrewJoinedShip.Add(poc30dCrew); } - poc30dCrew.PortOfCallLast30DaysCrewJoinedShipName = crew[j]; - } - } + poc30dCrew.PortOfCallLast30DaysCrewJoinedShipName = crew[j]; + } + } // Leer/def. Zeilen entfernen if (!poc30d.PortOfCallLast30DaysDateOfDeparture.HasValue && (poc30d.PortOfCallLast30DaysLocode == null)) @@ -1460,7 +1457,7 @@ namespace ENI2.Excel } } - #endregion + #endregion PoC last 30 days #region SanitaryMeasures @@ -1473,7 +1470,7 @@ namespace ENI2.Excel string smDate = string.Format("MDH.SanitaryMeasuresDate_{0}", i); SanitaryMeasuresDetail smd = mdh.GetSanitaryMeasuresDetailWithIdentifier(i.ToString()); - if(smd == null) + if (smd == null) { smd = new SanitaryMeasuresDetail(); smd.Identifier = i.ToString(); @@ -1481,8 +1478,8 @@ namespace ENI2.Excel smd.MDH = mdh; } - smd.SanitaryMeasuresType = reader.ReadText(smType); - smd.SanitaryMeasuresLocation = reader.ReadText(smLocation); + 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()) @@ -1490,7 +1487,7 @@ namespace ENI2.Excel } } - #endregion + #endregion SanitaryMeasures #region InfectedArea @@ -1509,7 +1506,7 @@ namespace ENI2.Excel ia.MDH = mdh; } - ia.InfectedAreaPort = reader.ReadText(iaPort); + ia.InfectedAreaPort = reader.ReadText(iaPort); ia.InfectedAreaDate = reader.ReadDate(iaDate); // dont save completely empty structs if (!ia.InfectedAreaDate.HasValue && ia.InfectedAreaPort.IsNullOrEmpty()) @@ -1517,11 +1514,11 @@ namespace ENI2.Excel } } - #endregion + #endregion InfectedArea #region StowawaysJoiningLocation - if(mdh.StowawaysDetected ?? false) + if (mdh.StowawaysDetected ?? false) { for (int i = 1; i <= 3; i++) { @@ -1537,16 +1534,15 @@ namespace ENI2.Excel sjl.StowawayJoiningLocation = reader.ReadText(sjlLookup); if (sjl.StowawayJoiningLocation.IsNullOrEmpty()) - { + { mdh.StowawaysJoiningLocations.Remove(sjl); - } + } } } - #endregion - + #endregion StowawaysJoiningLocation } - catch(Exception ex) + catch (Exception ex) { _log.ErrorFormat("Crash during reading of MDH message: {0}", ex); return false; @@ -1556,12 +1552,12 @@ namespace ENI2.Excel return true; } - #endregion + #endregion MDH #region SEC private static bool ScanSEC(Message secMessage, ExcelReader reader) - { + { if (secMessage.Elements.Count == 0) { SEC newSEC = new SEC(); @@ -1569,13 +1565,13 @@ namespace ENI2.Excel secMessage.Elements.Add(newSEC); } - SEC sec = secMessage.Elements[0] as SEC; + 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 != null) { if (isscType.Equals("full", StringComparison.OrdinalIgnoreCase) || isscType.Equals("1")) sec.ISSCType = 0; @@ -1585,23 +1581,23 @@ namespace ENI2.Excel 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; - } + if (shipsecLevel.Contains('3')) sec.CurrentShipSecurityLevel = 3; + } string isscIssuerType = reader.ReadText("SEC.ISSCIssuerType"); - if(isscIssuerType != null) + 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"); - + + sec.GeneralDescriptionOfCargo = reader.ReadGeneralDescriptionOfCargo("SEC.GeneralDescriptionOfCargo"); + bool? secKielArrival = reader.ReadBoolean("SEC.KielCanalPassagePlanned_Arrival"); bool? secKielDeparture = reader.ReadBoolean("SEC.KielCanalPassagePlanned_Departure"); @@ -1629,7 +1625,7 @@ namespace ENI2.Excel 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 portGISISCode = string.Format("SEC.PortFacilityGISISCode_{0}", i); string portSecMatters = string.Format("SEC.PortFacilitySecurityMattersToReport_{0}", i); if (!(sec.GetPortFacilityWithIdentifier(i.ToString()) is LastTenPortFacilitiesCalled l10fc)) @@ -1647,28 +1643,27 @@ namespace ENI2.Excel l10fc.PortFacilityDateOfDeparture = reader.ReadDate(portDateOfDeparture); string sLevel = reader.ReadText(portShipSecLevel); - if(!sLevel.IsNullOrEmpty()) - { + if (!sLevel.IsNullOrEmpty()) + { if (sLevel.Contains('1')) l10fc.PortFacilityShipSecurityLevel = 1; if (sLevel.Contains('2')) l10fc.PortFacilityShipSecurityLevel = 2; - if (sLevel.Contains('3')) l10fc.PortFacilityShipSecurityLevel = 3; + 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) + if (l10fc.PortFacilityGISISCode?.Length < 4) { while (l10fc.PortFacilityGISISCode.Length < 4) l10fc.PortFacilityGISISCode = "0" + l10fc.PortFacilityGISISCode; - } + } - l10fc.PortFacilitySecurityMattersToReport = reader.ReadText(portSecMatters); + 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 @@ -1697,7 +1692,7 @@ namespace ENI2.Excel { sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Remove(s2sActivity); continue; - } + } s2sActivity.ShipToShipActivityLocationLoCode = reader.ReadLoCode(s2sLocode); s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = (int?)reader.ReadNumber(s2sLatitude); @@ -1709,20 +1704,20 @@ namespace ENI2.Excel s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = null; s2sActivity.ShipToShipActivityDateFrom = reader.ReadDate(s2sFromDate); s2sActivity.ShipToShipActivityDateTo = reader.ReadDate(s2sToDate); - s2sActivity.ShipToShipActivityTypeCode = (int?) reader.ReadNumber(s2sActivityString); + 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); + s2sActivity.ShipToShipActivitySecurityMattersToReport = reader.ReadText(s2sSec); } return true; } - #endregion + #endregion SEC #region BKRA - private static bool ScanBKRA(Message bkraMessage,ExcelReader reader) - { + private static bool ScanBKRA(Message bkraMessage, ExcelReader reader) + { bkraMessage.DeleteElements(); for (int i = 1; i <= bkraMessage.NumberOfExcelRows; i++) { @@ -1747,12 +1742,12 @@ namespace ENI2.Excel return true; } - #endregion + #endregion BKRA #region BKRD private static bool ScanBKRD(Message bkrdMessage, ExcelReader reader) - { + { bkrdMessage.DeleteElements(); for (int i = 1; i <= bkrdMessage.NumberOfExcelRows; i++) { @@ -1767,21 +1762,21 @@ namespace ENI2.Excel } bkrd.BunkerFuelQuantity_TNE = reader.ReadNumber(lnQuantity); - bkrd.BunkerFuelType = reader.ReadText(lnType); + bkrd.BunkerFuelType = reader.ReadText(lnType); // dont save empty element if (bkrd.IsNew && !bkrd.BunkerFuelQuantity_TNE.HasValue && bkrd.BunkerFuelType.IsNullOrEmpty()) - bkrdMessage.Elements.Remove(bkrd); + bkrdMessage.Elements.Remove(bkrd); } return true; } - #endregion + #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++) @@ -1820,27 +1815,26 @@ namespace ENI2.Excel } towa.TowageOnArrivalName = towageName; - - towa.TowageOnArrivalFlag = reader.ReadNationality(tFlag); - towa.TowageOnArrivalPurposeOfCall = reader.ReadText(tPoC); + + 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.TowageOnArrivalGrossTonnage = (int?)reader.ReadNumber(tGT); towa.TowageOnArrivalLengthOverall_MTR = reader.ReadNumber(tLen); towa.TowageOnArrivalBeam_MTR = reader.ReadNumber(tBeam); - towa.TowageOnArrivalOperatorCompanyName = reader.ReadText(tOp); + towa.TowageOnArrivalOperatorCompanyName = reader.ReadText(tOp); } return true; } - #endregion + #endregion TOWA #region TOWD - private static bool ScanTOWD(Message towdMessage,ExcelReader reader) - { - + 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++) @@ -1892,7 +1886,7 @@ namespace ENI2.Excel return true; } - #endregion + #endregion TOWD #region PRE72H @@ -1909,18 +1903,18 @@ namespace ENI2.Excel // 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"); + pre72h.PlannedWorks = reader.ReadText("PRE72H.PlannedWorks"); if (pre72h.PlannedWorks.IsNullOrEmpty()) pre72h.PlannedWorks = "n"; return true; } - #endregion + #endregion PRE72H #region SERV private static bool ScanSERV(Message servMessage, ExcelReader reader) - { - if(servMessage.Elements.Count == 0) + { + if (servMessage.Elements.Count == 0) { SERV newSERV = new SERV(); newSERV.MessageHeader = servMessage; @@ -1929,21 +1923,21 @@ namespace ENI2.Excel } SERV serv = servMessage.Elements[0] as SERV; ScanMessage(serv, reader); - if (serv.ServiceBeneficiary.IsNullOrEmpty() && serv.ServiceInvoiceRecipient.IsNullOrEmpty()) + if (serv.ServiceBeneficiary.IsNullOrEmpty() && serv.ServiceInvoiceRecipient.IsNullOrEmpty()) return false; - + return true; } - #endregion + #endregion SERV #region STO private static bool ScanSTO(Message stoMessage, ExcelReader reader) - { + { stoMessage.DeleteElements(); - for(int i=0;i 20)) - { + { ladg.CargoCodeNST = null; } - } + } else { - ladg.CargoCodeNST = null; + ladg.CargoCodeNST = null; } - } + } } ladg.CargoLACode = reader.ReadCargoLACode(lnLACode); - ladg.CargoCodeNST_3 = reader.ReadText(lnZusatz); + 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.CargoCodeNST_3 = ladg.CargoCodeNST_3.Substring(0, 8); } } - ladg.CargoNumberOfItems = (int?) reader.ReadNumber(lnCNOI); + ladg.CargoNumberOfItems = (int?)reader.ReadNumber(lnCNOI); ladg.CargoGrossQuantity_TNE = reader.ReadNumber(lnCGQ); - ladg.PortOfLoading = reader.ReadLoCode(lnLoad); - ladg.PortOfDischarge = reader.ReadLoCode(lnDis); + ladg.PortOfLoading = reader.ReadLoCode(lnLoad); + ladg.PortOfDischarge = reader.ReadLoCode(lnDis); // dont save empty element if (ladg.IsNew && !ladg.CargoHandlingType.HasValue) @@ -2060,69 +2054,116 @@ namespace ENI2.Excel return true; } - #endregion + #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) - - bool? notificationSchengen = reader.ReadBoolean("CREW.NotificationSchengen"); - bool? notificationPax = reader.ReadBoolean("CREW.NotificationPAX"); - - for (int i = 0; i < 5000; i++) + if (reader.HasWorksheetNamed(sheetTitle)) { + bool? notificationSchengen = reader.ReadBoolean("CREW.NotificationSchengen"); + bool? notificationPax = reader.ReadBoolean("CREW.NotificationPAX"); - 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)) + for (int i = 0; i < 5000; i++) { - crew = new CREW(); - crew.Identifier = (i + 1).ToString(); - crew.MessageHeader = crewMessage; - crewMessage.Elements.Add(crew); + 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)); + 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; - 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; + 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.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)); - 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); + 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; - Util.UIHelper.SetBusyState(); // dialog might reset busy state + 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.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; @@ -2133,125 +2174,218 @@ namespace ENI2.Excel crewdMessage.DeleteElements(); string sheetTitle = "7. CREW - Departure"; // CREW DEPARTURE - - bool? notificationSchengen = reader.ReadBoolean("CREWD.NotificationSchengen"); - bool? notificationPax = reader.ReadBoolean("CREWD.NotificationPAX"); - - for (int i = 0; i < 5000; i++) + if (reader.HasWorksheetNamed(sheetTitle)) { + bool? notificationSchengen = reader.ReadBoolean("CREWD.NotificationSchengen"); + bool? notificationPax = reader.ReadBoolean("CREWD.NotificationPAX"); - string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18)); - if (lastName.IsNullOrEmpty()) break; - - if (!(crewdMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREWD crewd)) + for (int i = 0; i < 5000; i++) { - crewd = new CREWD(); - crewd.Identifier = (i + 1).ToString(); - crewd.MessageHeader = crewdMessage; - crewdMessage.Elements.Add(crewd); + 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)); + 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)); + if (!crewd.CrewMemberIdentityDocumentExpiryDate.HasValue) + crewd.CrewMemberIdentityDocumentExpiryDate = new DateTime(2100, 12, 31); + + crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142)); } - - 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)); - 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)); - if (!crewd.CrewMemberIdentityDocumentExpiryDate.HasValue) - crewd.CrewMemberIdentityDocumentExpiryDate = new DateTime(2100, 12, 31); - - crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142)); } + 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.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 13)); + crewd.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 13)); + } + } + else + { + return false; // nothing found + } + } + return true; } - #endregion + #endregion CREW #region PAS private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool isOldVersion) { - List newPasList = new List(); string sheetTitle = "8. PAX - Arrival"; - bool? notificationSchengen = reader.ReadBoolean("PAS.NotificationSchengen"); - bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX"); + if (reader.HasWorksheetNamed(sheetTitle)) + { + bool? notificationSchengen = reader.ReadBoolean("PAS.NotificationSchengen"); + bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX"); - for (int i = 0; i < 5000; i++) - { + 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 - 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 - - DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17)); - PAS pas = new PAS(); - pas.Identifier = (i + 1).ToString(); - pas.MessageHeader = pasMessage; - newPasList.Add(pas); + 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.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 == null) return true; + 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 == null) return true; - 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.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 = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)), out canceled); - if (canceled) return true; - pas.PassengerDateOfBirth = dateOfBirth; + pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 17)); - 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)); - if(!pas.PassengerIdentityDocumentExpiryDate.HasValue) - pas.PassengerIdentityDocumentExpiryDate = new DateTime(2100, 12, 31); + pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 17)); + pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)), out canceled); + if (canceled) return true; + DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17)); + pas.PassengerDateOfBirth = dateOfBirth; - 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)); + 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)); - Util.UIHelper.SetBusyState(); // dialog might reset busy state + pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("P{0}", i + 17)); + if (!pas.PassengerIdentityDocumentExpiryDate.HasValue) + pas.PassengerIdentityDocumentExpiryDate = 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.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(); @@ -2261,7 +2395,7 @@ namespace ENI2.Excel return true; } - #endregion + #endregion PAS #region PASD @@ -2311,7 +2445,7 @@ namespace ENI2.Excel 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); @@ -2332,7 +2466,7 @@ namespace ENI2.Excel return true; } - #endregion + #endregion PASD #region ScanMessage (generic) @@ -2348,14 +2482,14 @@ namespace ENI2.Excel { object propValue = property.GetValue(dbEntity, null); string value = (propValue == null) ? string.Empty : propValue.ToString(); - LookupNameAttribute lookupNameAttribute = Attribute.GetCustomAttribute(property, typeof(LookupNameAttribute)) as LookupNameAttribute; + 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); + property.SetValue(dbEntity, sheetValue); } } else if (property.PropertyType == typeof(double?)) @@ -2363,7 +2497,7 @@ namespace ENI2.Excel double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); if (sheetValue != null) { - property.SetValue(dbEntity, sheetValue); + property.SetValue(dbEntity, sheetValue); } } else if (property.PropertyType == typeof(string)) @@ -2371,7 +2505,7 @@ namespace ENI2.Excel string sheetValue = reader.ReadText(lookupNameAttribute.LookupName); if (sheetValue != null) { - property.SetValue(dbEntity, sheetValue); + property.SetValue(dbEntity, sheetValue); } } else if (property.PropertyType == typeof(int?)) @@ -2379,7 +2513,7 @@ namespace ENI2.Excel double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); if (sheetValue.HasValue) { - property.SetValue(dbEntity, (int)sheetValue.Value); + property.SetValue(dbEntity, (int)sheetValue.Value); } } else if (property.PropertyType == typeof(byte?)) @@ -2387,27 +2521,26 @@ namespace ENI2.Excel double? sheetValue = reader.ReadNumber(lookupNameAttribute.LookupName); if (sheetValue.HasValue) { - property.SetValue(dbEntity, (byte)sheetValue.Value); + 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); + if (sheetValue.HasValue) + { + property.SetValue(dbEntity, sheetValue); } } else { _log.DebugFormat("unhandled property type: {0}", property.PropertyType); } - } + } - } - - #endregion + #endregion ScanMessage (generic) #region LookupMessageCore @@ -2418,7 +2551,7 @@ namespace ENI2.Excel /// private static MessageCore LookupCoreById(ExcelReader reader) { - MessageCore result = null; + MessageCore result = null; string visitTransitId = reader.ReadTextNoWhitespace("ID"); if (visitTransitId != null) @@ -2435,15 +2568,17 @@ namespace ENI2.Excel return result; } - #endregion + #endregion LookupMessageCore + + #region GetMessageWithType private static Message GetMessageWithType(List messages, MessageCore core, Message.NotificationClass type) - { - foreach(Message message in messages) + { + foreach (Message message in messages) if (message.MessageNotificationClass == type) return message; - + Message newMessage = DBManager.Instance.GetMessage(core, type); if (newMessage == null) { @@ -2456,7 +2591,7 @@ namespace ENI2.Excel return newMessage; } - #endregion + #endregion GetMessageWithType #region "Semi-Manual" import functions (may open interactive dialog) @@ -2485,14 +2620,14 @@ namespace ENI2.Excel _genderImportDict[gender] = fid.SelectedValue; result = byte.Parse(_genderImportDict[gender]); } - } + } else { canceled = true; } } - } - if(!result.HasValue) + } + if (!result.HasValue) { result = 0; // not known } @@ -2504,7 +2639,7 @@ namespace ENI2.Excel { byte? result = DakosyUtil.ParseDocumentType(documentType); canceled = false; - + if (!result.HasValue) { if (documentType.IsNullOrEmpty()) @@ -2552,15 +2687,15 @@ namespace ENI2.Excel { result = "XX"; } - else if(CREW.NationalityDict.ContainsKey(nationality.ToUpper())) // is it already a key + else if (CREW.NationalityDict.ContainsKey(nationality.ToUpper())) // is it already a key { result = nationality.ToUpper(); } - else if(CREW.NationalityDict.ContainsValue(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(_countryImportDict.ContainsKey(nationality)) + else if (_countryImportDict.ContainsKey(nationality)) { result = _countryImportDict[nationality]; } @@ -2570,14 +2705,14 @@ namespace ENI2.Excel fid.Value = nationality; fid.ValueType = "Nationality"; fid.SelectionValues = CREW.NationalityDict; - if(fid.ShowDialog() ?? false) + if (fid.ShowDialog() ?? false) { - if(!fid.SelectedValue.IsNullOrEmpty()) + if (!fid.SelectedValue.IsNullOrEmpty()) { _countryImportDict[nationality] = fid.SelectedValue; - result = fid.SelectedValue.Substring(0,2); // attention manual entry + result = fid.SelectedValue.Substring(0, 2); // attention manual entry } - } + } else { canceled = true; @@ -2600,12 +2735,12 @@ namespace ENI2.Excel 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 + // reverse search: if this is a name lookup port code List possibleLocodes = LocodeDB.AllLocodesForCityName(val); - - if(possibleLocodes.Count > 1) + + if (possibleLocodes.Count > 1) { if (!_locodeImportDict.ContainsKey(val)) { @@ -2619,16 +2754,16 @@ namespace ENI2.Excel if (fid.ShowDialog() ?? false) { _locodeImportDict[val] = fid.SelectedValue; - } + } else { canceled = true; } } - if(_locodeImportDict.ContainsKey(val)) + if (_locodeImportDict.ContainsKey(val)) result = _locodeImportDict[val]; } - else if(possibleLocodes.Count == 1) + else if (possibleLocodes.Count == 1) { result = possibleLocodes[0]; } @@ -2653,6 +2788,6 @@ namespace ENI2.Excel return result; } - #endregion + #endregion "Semi-Manual" import functions (may open interactive dialog) } -} +} \ No newline at end of file diff --git a/ENI2/MainWindow.xaml.cs b/ENI2/MainWindow.xaml.cs index 57d88aec..745298dc 100644 --- a/ENI2/MainWindow.xaml.cs +++ b/ENI2/MainWindow.xaml.cs @@ -212,6 +212,7 @@ namespace ENI2 { if(drc.HasCriticalInfoMissing(out string missingClass)) { + _log.WarnFormat("set close warning because at least {0} is missing from BRE/BRV arrival", missingClass); if (MessageBox.Show(string.Format(Properties.Resources.textSpecialCaseBREBRV, missingClass), Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No) e.Cancel = true; diff --git a/ENI2/Properties/Resources.Designer.cs b/ENI2/Properties/Resources.Designer.cs index 58978e29..8687c93c 100644 --- a/ENI2/Properties/Resources.Designer.cs +++ b/ENI2/Properties/Resources.Designer.cs @@ -4552,7 +4552,7 @@ namespace ENI2.Properties { } /// - /// Looks up a localized string similar to One or more important classes haven't been sent for DEBRE/DEBRV: {0} Close anyway?. + /// Looks up a localized string similar to At least one of NOA_NOD, AGNT, INFO, SEC, TIEFA hasn't been sent for DEBRE/DEBRV: ({0}) Close anyway?. /// public static string textSpecialCaseBREBRV { get { diff --git a/ENI2/Properties/Resources.resx b/ENI2/Properties/Resources.resx index ddd43f54..eae8c582 100644 --- a/ENI2/Properties/Resources.resx +++ b/ENI2/Properties/Resources.resx @@ -1859,6 +1859,6 @@ Search NST2007 list - One or more important classes haven't been sent for DEBRE/DEBRV: {0} Close anyway? + At least one of NOA_NOD, AGNT, INFO, SEC, TIEFA hasn't been sent for DEBRE/DEBRV: ({0}) Close anyway? \ No newline at end of file