diff --git a/ENI2/Excel/ExcelReader.cs b/ENI2/Excel/ExcelReader.cs index 07aa71fc..b170c136 100644 --- a/ENI2/Excel/ExcelReader.cs +++ b/ENI2/Excel/ExcelReader.cs @@ -636,14 +636,20 @@ namespace ENI2.Excel } } - internal string ReadCellAsText(string sheetName, string range) + internal string ReadCellAsText(string sheetName, string range, int? maxLength = null) { try { Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName]; string result = workSheet.Range[range].Text.ToString(); if (!result.IsNullOrEmpty()) + { result = result.Trim().Clean(); + if(maxLength.HasValue && result.Length > maxLength.Value) + { + result = result.Substring(0, maxLength.Value); + } + } return result; } catch (Exception e) diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index a0fbcabb..2404453e 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -2091,8 +2091,8 @@ namespace ENI2.Excel for (int i = 0; i < 5000; i++) { - string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18)); - string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18)); + string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18), 100); + string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18), 100); if (lastName.IsNullOrEmpty() && firstName.IsNullOrEmpty()) break; if (!(crewMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREW crew)) @@ -2111,10 +2111,10 @@ namespace ENI2.Excel 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.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18), 100); 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.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 18), 100); crew.CrewMemberCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out _); crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{0}", i + 18)); @@ -2122,8 +2122,8 @@ namespace ENI2.Excel 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.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 18), 100); + crew.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18), 100); crew.CrewMemberIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 18)), out canceled); if (canceled) return true; if (crew.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty() && isOldVersion) @@ -2132,11 +2132,7 @@ namespace ENI2.Excel 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.NotificationSchengen = crew.HasSchengenDetails; + crew.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142), 256); Util.UIHelper.SetBusyState(); // dialog might reset busy state } @@ -2208,7 +2204,7 @@ namespace ENI2.Excel for (int i = 0; i < 5000; i++) { - string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18)); + string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18), 100); if (lastName.IsNullOrEmpty()) break; if (!(crewdMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is CREWD crewd)) @@ -2223,32 +2219,30 @@ namespace ENI2.Excel crewd.NotificationSchengen = true; crewd.NotificationPAX = notificationPax ?? false; crewd.CrewMemberLastName = lastName; - crewd.CrewMemberFirstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18)); + crewd.CrewMemberFirstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18), 100); 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.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18), 100); 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.CrewMemberPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("H{0}", i + 18), 100); 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; - crewd.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 18)); - crewd.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18)); + crewd.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 18), 100); + crewd.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18), 100); 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)) ?? (DateTime?)new DateTime(2100, 12, 31); - crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142)); - - // crewd.NotificationSchengen = crewd.HasSchengenDetails; + crewd.Effects = reader.ReadCellAsText("2. PORT", string.Format("C{0}", i + 142), 256); Util.UIHelper.SetBusyState(); // dialog might reset busy state } @@ -2321,8 +2315,8 @@ namespace ENI2.Excel 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)); + string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 17), 100); + string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 17), 100); if (lastName.IsNullOrEmpty() && firstName.IsNullOrEmpty()) break; // finish after reading last row PAS pas = new PAS(); @@ -2351,7 +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.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 17), 100); pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)), out _); if (canceled) return true; @@ -2360,13 +2354,13 @@ namespace ENI2.Excel 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.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 17), 100); pas.PassengerIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("P{0}", i + 17)) ?? (DateTime?)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)); + pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("Q{0}", i + 17), 100); + pas.EmergencyCare = reader.ReadCellAsText(sheetTitle, string.Format("R{0}", i + 17), 255); + pas.EmergencyContactNumber = reader.ReadCellAsText(sheetTitle, string.Format("S{0}", i + 17), 99); // pas.NotificationSchengen = pas.HasSchengenDetails; @@ -2458,8 +2452,8 @@ namespace ENI2.Excel for (int i = 0; i < 5000; i++) { - string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18)); - string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18)); + string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18), 100); + string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18), 100); if (lastName.IsNullOrEmpty() && firstName.IsNullOrEmpty()) break; // finish after reading last row PASD pas = new PASD(); @@ -2489,7 +2483,7 @@ namespace ENI2.Excel pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 18)); - pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 18)); + pas.PassengerPlaceOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", i + 18), 100); pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 18)), out _); if (canceled) return true; @@ -2498,13 +2492,13 @@ namespace ENI2.Excel 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.PassengerIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("N{0}", i + 18), 100); 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)); + pas.PassengerVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("Q{0}", i + 18), 100); + pas.EmergencyCare = reader.ReadCellAsText(sheetTitle, string.Format("R{0}", i + 18), 255); + pas.EmergencyContactNumber = reader.ReadCellAsText(sheetTitle, string.Format("S{0}", i + 18), 99); // pas.NotificationSchengen = pas.HasSchengenDetails;