diff --git a/ENI2/Excel/DakosyUtil.cs b/ENI2/Excel/DakosyUtil.cs index df31cffb..f3f6b81f 100644 --- a/ENI2/Excel/DakosyUtil.cs +++ b/ENI2/Excel/DakosyUtil.cs @@ -726,6 +726,7 @@ namespace ENI2.Excel pas = new PASD(); pas.Identifier = (i + 1).ToString(); pas.MessageHeader = pasdMessage; + pas.IsDeparture = true; pasdMessage.Elements.Add(pas); } @@ -1156,6 +1157,7 @@ namespace ENI2.Excel crew = new CREWD(); crew.Identifier = (i + 1).ToString(); crew.MessageHeader = crewMessage; + crew.IsDeparture = true; crewMessage.Elements.Add(crew); } diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index 9c5ba894..337452a9 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -2115,8 +2115,7 @@ namespace ENI2.Excel crew.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled); if (canceled) return true; crew.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 18)); - crew.CrewMemberCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)); - if ((crew.CrewMemberCountryOfBirth != null) && (crew.CrewMemberCountryOfBirth.Length > 2)) crew.CrewMemberCountryOfBirth = null; + crew.CrewMemberCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out _); crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{0}", i + 18)); @@ -2228,11 +2227,9 @@ namespace ENI2.Excel crewd.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled); if (canceled) return true; crewd.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 18)); - crewd.CrewMemberCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)); - if ((crewd.CrewMemberCountryOfBirth != null) && (crewd.CrewMemberCountryOfBirth.Length > 2)) crewd.CrewMemberCountryOfBirth = null; + crewd.CrewMemberCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out _); 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; @@ -2304,7 +2301,7 @@ namespace ENI2.Excel #region PAS - private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool isOldVersion) + private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool _) { List newPasList = new List(); @@ -2348,8 +2345,7 @@ namespace ENI2.Excel pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 17)); pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 17)); - pas.PassengerCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)); - if ((pas.PassengerCountryOfBirth != null) && (pas.PassengerCountryOfBirth.Length > 2)) pas.PassengerCountryOfBirth = null; + pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)), out _); if (canceled) return true; DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17)); @@ -2435,66 +2431,74 @@ namespace ENI2.Excel private static bool ScanPASD(Message pasMessage, ExcelReader reader) { - pasMessage.DeleteElements(); + List newPasList = new List(); - bool? notificationSchengen = reader.ReadBoolean("PASD.NotificationSchengen"); - bool? notificationPax = reader.ReadBoolean("PASD.NotificationPAX"); + string sheetTitle = "9. PAX - Departure"; - for (int i = 0; i < pasMessage.NumberOfExcelRows; i++) + if (reader.HasWorksheetNamed(sheetTitle)) { - string pasLastName = string.Format("PASD.PassengerLastName_{0}", i + 1); - string pasFirstName = string.Format("PASD.PassengerFirstName_{0}", i + 1); - string pasGender = string.Format("PASD.PassengerGender_{0}", i + 1); - string pasNationality = string.Format("PASD.PassengerNationality_{0}", i + 1); - string pasEmbarkation = string.Format("PASD.PassengerPortOfEmbarkation_{0}", i + 1); - string pasDebarkation = string.Format("PASD.PassengerPortOfDisembarkation_{0}", i + 1); - string pasTransit = string.Format("PASD.PassengerInTransit_{0}", i + 1); - string pasPlaceOfBirth = string.Format("PASD.PassengerPlaceOfBirth_{0}", i + 1); - string pasDateOfBirth = string.Format("PASD.PassengerDateOfBirth_{0}", i + 1); - string pasIdentDocType = string.Format("PASD.PassengerIdentityDocumentType_{0}", i + 1); - string pasIdentDocId = string.Format("PASD.PassengerIdentityDocumentId_{0}", i + 1); - string pasVisaNo = string.Format("PASD.PassengerVisaNumber_{0}", i + 1); - string pasIssuing = string.Format("PASD.PassengerIdentityDocumentIssuingState_{0}", i + 1); - string pasExpiryDate = string.Format("PASD.PassengerIdentityDocumentExpiryDate_{0}", i + 1); - string pasCountryOfBirth = string.Format("PASD.CountryOfBirth_{0}", i + 1); - string pasEmergencyCare = string.Format("PASD.EmergencyCare_{0}", i + 1); - string pasEmergencyContact = string.Format("PASD.EmergencyContactNumber_{0}", i + 1); + bool? notificationSchengen = reader.ReadBoolean("PAS.NotificationSchengen"); + bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX"); - string lastName = reader.ReadText(pasLastName); - if (!lastName.IsNullOrEmpty()) + for (int i = 0; i < 5000; i++) { - if (!(pasMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is PASD pas)) - { - pas = new PASD(); - pas.IsDeparture = true; - pas.Identifier = (i + 1).ToString(); - pas.MessageHeader = pasMessage; - pasMessage.Elements.Add(pas); - } + 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; // finish after reading last row + PASD pas = new PASD(); + pas.Identifier = (i + 1).ToString(); + pas.MessageHeader = pasMessage; pas.IsDeparture = true; + newPasList.Add(pas); + pas.NotificationSchengen = notificationSchengen; pas.NotificationPAX = notificationPax; pas.PassengerLastName = lastName; - pas.PassengerFirstName = reader.ReadText(pasFirstName); - pas.PassengerGender = reader.ReadGender(pasGender); - pas.PassengerNationality = reader.ReadNationality(pasNationality); + pas.PassengerFirstName = firstName; - pas.PassengerPortOfEmbarkation = reader.ReadTextNoWhitespace(pasEmbarkation); - pas.PassengerPortOfDisembarkation = reader.ReadTextNoWhitespace(pasDebarkation); - pas.PassengerInTransit = reader.ReadBoolean(pasTransit); - pas.PassengerPlaceOfBirth = reader.ReadText(pasPlaceOfBirth); - pas.PassengerDateOfBirth = reader.ReadBirthDate(pasDateOfBirth); - pas.PassengerIdentityDocumentType = reader.ReadIdentityDocumentType(pasIdentDocType); - pas.PassengerIdentityDocumentId = reader.ReadText(pasIdentDocId); - pas.PassengerVisaNumber = reader.ReadText(pasVisaNo); - pas.PassengerIdentityDocumentIssuingState = reader.ReadNationality(pasIssuing); - pas.PassengerIdentityDocumentExpiryDate = reader.ReadDate(pasExpiryDate) ?? (DateTime?)new DateTime(2100, 12, 31); - pas.PassengerCountryOfBirth = reader.ReadNationality(pasCountryOfBirth); - pas.EmergencyCare = reader.ReadText(pasEmergencyCare); - pas.EmergencyContactNumber = reader.ReadText(pasEmergencyContact); + pas.PassengerNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out bool canceled); + if (canceled) return true; + pas.PassengerIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18)), out canceled); + if (canceled) return true; + if (pas.PassengerIdentityDocumentIssuingState.IsNullOrEmpty()) + pas.PassengerIdentityDocumentIssuingState = "XX"; + + pas.PassengerGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18)), out canceled); + if (canceled) return true; + pas.PassengerPortOfEmbarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18)), out canceled); + if (canceled) return true; + pas.PassengerPortOfDisembarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled); + if (canceled) return true; + + pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 18)); + + pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 18)); + pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 18)), out _); + + if (canceled) return true; + DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 18)); + pas.PassengerDateOfBirth = dateOfBirth; + + pas.PassengerIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 18)), out canceled); + if (canceled) return true; + pas.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 18)); + + pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("P{0}", i + 18)) ?? (DateTime?)new DateTime(2100, 12, 31); + + pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("Q{0}", i + 18)); + pas.EmergencyCare = reader.ReadCellAsText(sheetTitle, string.Format("R{0}", i + 18)); + pas.EmergencyContactNumber = reader.ReadCellAsText(sheetTitle, string.Format("S{0}", i + 18)); + + Util.UIHelper.SetBusyState(); // dialog might reset busy state } - } + } + + DBManager.Instance.DeleteAllPASForMessage(pasMessage.Id); + pasMessage.Elements.Clear(); + foreach (PASD pas in newPasList) + pasMessage.Elements.Add(pas); + return true; }