fixed excel import

This commit is contained in:
Daniel Schick 2023-11-09 11:54:11 +01:00
parent 5e85294375
commit e8b9ed80dc
2 changed files with 62 additions and 56 deletions

View File

@ -726,6 +726,7 @@ namespace ENI2.Excel
pas = new PASD(); pas = new PASD();
pas.Identifier = (i + 1).ToString(); pas.Identifier = (i + 1).ToString();
pas.MessageHeader = pasdMessage; pas.MessageHeader = pasdMessage;
pas.IsDeparture = true;
pasdMessage.Elements.Add(pas); pasdMessage.Elements.Add(pas);
} }
@ -1156,6 +1157,7 @@ namespace ENI2.Excel
crew = new CREWD(); crew = new CREWD();
crew.Identifier = (i + 1).ToString(); crew.Identifier = (i + 1).ToString();
crew.MessageHeader = crewMessage; crew.MessageHeader = crewMessage;
crew.IsDeparture = true;
crewMessage.Elements.Add(crew); crewMessage.Elements.Add(crew);
} }

View File

@ -2115,8 +2115,7 @@ namespace ENI2.Excel
crew.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled); crew.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled);
if (canceled) return true; 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));
crew.CrewMemberCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)); crew.CrewMemberCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out _);
if ((crew.CrewMemberCountryOfBirth != null) && (crew.CrewMemberCountryOfBirth.Length > 2)) crew.CrewMemberCountryOfBirth = null;
crew.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{0}", i + 18)); 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); crewd.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled);
if (canceled) return true; 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));
crewd.CrewMemberCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)); crewd.CrewMemberCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out _);
if ((crewd.CrewMemberCountryOfBirth != null) && (crewd.CrewMemberCountryOfBirth.Length > 2)) crewd.CrewMemberCountryOfBirth = null;
crewd.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{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); crewd.CrewMemberIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 18)), out canceled);
if (canceled) return true; if (canceled) return true;
@ -2304,7 +2301,7 @@ namespace ENI2.Excel
#region PAS #region PAS
private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool isOldVersion) private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool _)
{ {
List<PAS> newPasList = new List<PAS>(); List<PAS> newPasList = new List<PAS>();
@ -2348,8 +2345,7 @@ namespace ENI2.Excel
pas.PassengerInTransit = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", i + 17)); 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));
pas.PassengerCountryOfBirth = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)); pas.PassengerCountryOfBirth = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 17)), out _);
if ((pas.PassengerCountryOfBirth != null) && (pas.PassengerCountryOfBirth.Length > 2)) pas.PassengerCountryOfBirth = null;
if (canceled) return true; if (canceled) return true;
DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17)); 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) private static bool ScanPASD(Message pasMessage, ExcelReader reader)
{ {
pasMessage.DeleteElements(); List<PAS> newPasList = new List<PAS>();
bool? notificationSchengen = reader.ReadBoolean("PASD.NotificationSchengen"); string sheetTitle = "9. PAX - Departure";
bool? notificationPax = reader.ReadBoolean("PASD.NotificationPAX");
for (int i = 0; i < pasMessage.NumberOfExcelRows; i++) if (reader.HasWorksheetNamed(sheetTitle))
{ {
string pasLastName = string.Format("PASD.PassengerLastName_{0}", i + 1); bool? notificationSchengen = reader.ReadBoolean("PAS.NotificationSchengen");
string pasFirstName = string.Format("PASD.PassengerFirstName_{0}", i + 1); bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX");
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);
string lastName = reader.ReadText(pasLastName); for (int i = 0; i < 5000; i++)
if (!lastName.IsNullOrEmpty())
{ {
if (!(pasMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is PASD pas)) string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 18));
{ string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18));
pas = new PASD(); if (lastName.IsNullOrEmpty() && firstName.IsNullOrEmpty()) break; // finish after reading last row
pas.IsDeparture = true;
pas.Identifier = (i + 1).ToString();
pas.MessageHeader = pasMessage;
pasMessage.Elements.Add(pas);
}
PASD pas = new PASD();
pas.Identifier = (i + 1).ToString();
pas.MessageHeader = pasMessage;
pas.IsDeparture = true; pas.IsDeparture = true;
newPasList.Add(pas);
pas.NotificationSchengen = notificationSchengen; pas.NotificationSchengen = notificationSchengen;
pas.NotificationPAX = notificationPax; pas.NotificationPAX = notificationPax;
pas.PassengerLastName = lastName; pas.PassengerLastName = lastName;
pas.PassengerFirstName = reader.ReadText(pasFirstName); pas.PassengerFirstName = firstName;
pas.PassengerGender = reader.ReadGender(pasGender);
pas.PassengerNationality = reader.ReadNationality(pasNationality);
pas.PassengerPortOfEmbarkation = reader.ReadTextNoWhitespace(pasEmbarkation); pas.PassengerNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)), out bool canceled);
pas.PassengerPortOfDisembarkation = reader.ReadTextNoWhitespace(pasDebarkation); if (canceled) return true;
pas.PassengerInTransit = reader.ReadBoolean(pasTransit); pas.PassengerIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18)), out canceled);
pas.PassengerPlaceOfBirth = reader.ReadText(pasPlaceOfBirth); if (canceled) return true;
pas.PassengerDateOfBirth = reader.ReadBirthDate(pasDateOfBirth); if (pas.PassengerIdentityDocumentIssuingState.IsNullOrEmpty())
pas.PassengerIdentityDocumentType = reader.ReadIdentityDocumentType(pasIdentDocType); pas.PassengerIdentityDocumentIssuingState = "XX";
pas.PassengerIdentityDocumentId = reader.ReadText(pasIdentDocId);
pas.PassengerVisaNumber = reader.ReadText(pasVisaNo); pas.PassengerGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18)), out canceled);
pas.PassengerIdentityDocumentIssuingState = reader.ReadNationality(pasIssuing); if (canceled) return true;
pas.PassengerIdentityDocumentExpiryDate = reader.ReadDate(pasExpiryDate) ?? (DateTime?)new DateTime(2100, 12, 31); pas.PassengerPortOfEmbarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18)), out canceled);
pas.PassengerCountryOfBirth = reader.ReadNationality(pasCountryOfBirth); if (canceled) return true;
pas.EmergencyCare = reader.ReadText(pasEmergencyCare); pas.PassengerPortOfDisembarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)), out canceled);
pas.EmergencyContactNumber = reader.ReadText(pasEmergencyContact); 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; return true;
} }