From 3c6201bad739c03fa37748a20d6da883020f475c Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 9 Sep 2022 11:51:27 +0200 Subject: [PATCH] Test version for assisted import of CREW table (even if larger) --- ENI2/ENI2.csproj | 4 +- ENI2/EditControls/EditCREWDialog.xaml | 2 +- ENI2/EditControls/EditCREWDialog.xaml.cs | 19 ++- ENI2/EditControls/EditPasDialog.xaml | 2 +- ENI2/EditControls/EditPasDialog.xaml.cs | 15 +-- ENI2/EditControls/FixImportDialog.xaml | 2 +- ENI2/EditControls/FixImportDialog.xaml.cs | 11 +- ENI2/Excel/DakosyUtil.cs | 4 +- ENI2/Excel/ExcelUtil.cs | 134 +++++++++++++++++----- ENI2/Util/GlobalStructures.cs | 26 ++--- 10 files changed, 142 insertions(+), 77 deletions(-) diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index ce64ebd0..ed92aaf3 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -36,8 +36,8 @@ 5.4.0.0 true publish.html - 0 - 7.5.0.0 + 2 + 7.5.0.%2a false true true diff --git a/ENI2/EditControls/EditCREWDialog.xaml b/ENI2/EditControls/EditCREWDialog.xaml index ac19e4e7..947cd57b 100644 --- a/ENI2/EditControls/EditCREWDialog.xaml +++ b/ENI2/EditControls/EditCREWDialog.xaml @@ -52,7 +52,7 @@ - + diff --git a/ENI2/EditControls/EditCREWDialog.xaml.cs b/ENI2/EditControls/EditCREWDialog.xaml.cs index 2078b5d4..c9fcae97 100644 --- a/ENI2/EditControls/EditCREWDialog.xaml.cs +++ b/ENI2/EditControls/EditCREWDialog.xaml.cs @@ -31,18 +31,13 @@ namespace ENI2.EditControls this.textBoxLastName.Text = this.CREW.CrewMemberLastName; this.textBoxFirstName.Text = this.CREW.CrewMemberFirstName; this.comboBoxGender.ItemsSource = GlobalStructures.GenderDict; - //this.comboBoxGender.KeyUp += ComboBox_KeyUp; - this.comboBoxGender.SelectedIndex = this.CREW.CrewMemberGender ?? -1; - if (this.CREW.CrewMemberGender == 9) - this.comboBoxGender.SelectedIndex = 3; + this.comboBoxGender.SelectedValue = (this.CREW.CrewMemberGender == null) ? null : this.CREW.CrewMemberGender.ToString(); this.textBoxPlaceOfBirth.Text = this.CREW.CrewMemberPlaceOfBirth; this.comboBoxNationality.ItemsSource = bsmd.database.CREW.NationalityDict; - //this.comboBoxNationality.KeyUp += ComboBox_KeyUp; this.comboBoxNationality.SelectedValue = this.CREW.CrewMemberNationality; this.datePickerDateOfBirth.SelectedDate = this.CREW.CrewMemberDateOfBirth; - this.comboBoxIdDocType.ItemsSource = GlobalStructures.IDDocTypeList; - //this.comboBoxIdDocType.KeyUp += ComboBox_KeyUp; - this.comboBoxIdDocType.SelectedIndex = this.CREW.CrewMemberIdentityDocumentType ?? -1; + this.comboBoxIdDocType.ItemsSource = GlobalStructures.IDDocTypeDict; + this.comboBoxIdDocType.SelectedValue = (this.CREW.CrewMemberIdentityDocumentType == null) ? null : this.CREW.CrewMemberIdentityDocumentType.ToString(); this.textBoxIdDocNumber.Text = this.CREW.CrewMemberIdentityDocumentId; this.textBoxVisaNumber.Text = this.CREW.CrewMemberVisaNumber; this.comboBoxIssuingState.ItemsSource = bsmd.database.CREW.NationalityDict; @@ -62,14 +57,14 @@ namespace ENI2.EditControls this.CREW.CrewMemberDuty = this.textBoxDuty.Text.Trim(); this.CREW.CrewMemberLastName = this.textBoxLastName.Text.Trim(); this.CREW.CrewMemberFirstName = this.textBoxFirstName.Text.Trim(); - this.CREW.CrewMemberGender = (this.comboBoxGender.SelectedIndex == -1) ? null : (byte?) this.comboBoxGender.SelectedValue; + this.CREW.CrewMemberGender = (this.comboBoxGender.SelectedIndex == -1) ? null : (byte?) byte.Parse((string) this.comboBoxGender.SelectedValue); this.CREW.CrewMemberPlaceOfBirth = this.textBoxPlaceOfBirth.Text.Trim(); - this.CREW.CrewMemberNationality = (this.comboBoxNationality.SelectedValue == null) ? "" : (string)this.comboBoxNationality.SelectedValue; + this.CREW.CrewMemberNationality = (this.comboBoxNationality.SelectedValue == null) ? "" : (string) this.comboBoxNationality.SelectedValue; this.CREW.CrewMemberDateOfBirth = this.datePickerDateOfBirth.SelectedDate; - this.CREW.CrewMemberIdentityDocumentType = (this.comboBoxIdDocType.SelectedIndex == -1) ? null : (byte?)this.comboBoxIdDocType.SelectedIndex; + this.CREW.CrewMemberIdentityDocumentType = (this.comboBoxIdDocType.SelectedIndex == -1) ? null : (byte?) byte.Parse((string)this.comboBoxIdDocType.SelectedValue); this.CREW.CrewMemberIdentityDocumentId = this.textBoxIdDocNumber.Text.Trim(); this.CREW.CrewMemberVisaNumber = this.textBoxVisaNumber.Text.Trim(); - this.CREW.CrewMemberIdentityDocumentIssuingState = (this.comboBoxIssuingState.SelectedValue == null) ? "" : (string)this.comboBoxIssuingState.SelectedValue; + this.CREW.CrewMemberIdentityDocumentIssuingState = (this.comboBoxIssuingState.SelectedValue == null) ? "" : (string) this.comboBoxIssuingState.SelectedValue; this.CREW.CrewMemberIdentityDocumentExpiryDate = this.datePickerExpiryDate.SelectedDate; // this.CREW.CrewMemberCountryOfBirth = (this.comboBoxCountryOfBirth.SelectedValue == null) ? "" : (string)this.comboBoxCountryOfBirth.SelectedValue; // this.CREW.Effects = this.textBoxEffects.Text.Trim(); diff --git a/ENI2/EditControls/EditPasDialog.xaml b/ENI2/EditControls/EditPasDialog.xaml index 8d924fcf..cdfa55a4 100644 --- a/ENI2/EditControls/EditPasDialog.xaml +++ b/ENI2/EditControls/EditPasDialog.xaml @@ -56,7 +56,7 @@ - + diff --git a/ENI2/EditControls/EditPasDialog.xaml.cs b/ENI2/EditControls/EditPasDialog.xaml.cs index f26e51bb..fee66aac 100644 --- a/ENI2/EditControls/EditPasDialog.xaml.cs +++ b/ENI2/EditControls/EditPasDialog.xaml.cs @@ -30,18 +30,13 @@ namespace ENI2.EditControls this.textBoxLastName.Text = this.PAS.PassengerLastName; this.textBoxFirstName.Text = this.PAS.PassengerFirstName; this.comboBoxGender.ItemsSource = GlobalStructures.GenderDict; - //this.comboBoxGender.KeyUp += ComboBox_KeyUp; - this.comboBoxGender.SelectedIndex = this.PAS.PassengerGender ?? -1; - if (this.PAS.PassengerGender == 9) - this.comboBoxGender.SelectedIndex = 3; + this.comboBoxGender.SelectedValue = this.PAS.PassengerGender ?? -1; this.textBoxPlaceOfBirth.Text = this.PAS.PassengerPlaceOfBirth; this.comboBoxNationality.ItemsSource = bsmd.database.CREW.NationalityDict; - //this.comboBoxNationality.KeyUp += ComboBox_KeyUp; this.comboBoxNationality.SelectedValue = this.PAS.PassengerNationality; this.datePickerDateOfBirth.SelectedDate = this.PAS.PassengerDateOfBirth; - this.comboBoxIdDocType.ItemsSource = GlobalStructures.IDDocTypeList; - //this.comboBoxIdDocType.KeyUp += ComboBox_KeyUp; - this.comboBoxIdDocType.SelectedIndex = this.PAS.PassengerIdentityDocumentType ?? -1; + this.comboBoxIdDocType.ItemsSource = GlobalStructures.IDDocTypeDict; + this.comboBoxIdDocType.SelectedValue = this.PAS.PassengerIdentityDocumentType ?? null; this.textBoxIdDocNumber.Text = this.PAS.PassengerIdentityDocumentId; this.textBoxVisaNumber.Text = this.PAS.PassengerVisaNumber; this.locodePortOfEmbarkation.LocodeValue = this.PAS.PassengerPortOfEmbarkation; @@ -66,11 +61,11 @@ namespace ENI2.EditControls // copy back this.PAS.PassengerLastName = this.textBoxLastName.Text.Trim(); this.PAS.PassengerFirstName = this.textBoxFirstName.Text.Trim(); - this.PAS.PassengerGender = (this.comboBoxGender.SelectedIndex == -1) ? null : (byte?)this.comboBoxGender.SelectedValue; + this.PAS.PassengerGender = (this.comboBoxGender.SelectedIndex == -1) ? null : (byte?)byte.Parse((string)this.comboBoxGender.SelectedValue); this.PAS.PassengerPlaceOfBirth = this.textBoxPlaceOfBirth.Text.Trim(); this.PAS.PassengerNationality = (this.comboBoxNationality.SelectedValue == null) ? "" : (string)this.comboBoxNationality.SelectedValue; this.PAS.PassengerDateOfBirth = this.datePickerDateOfBirth.SelectedDate; - this.PAS.PassengerIdentityDocumentType = (this.comboBoxIdDocType.SelectedIndex == -1) ? null : (byte?)this.comboBoxIdDocType.SelectedIndex; + this.PAS.PassengerIdentityDocumentType = (this.comboBoxIdDocType.SelectedIndex == -1) ? null : (byte?) byte.Parse((string)this.comboBoxIdDocType.SelectedValue); this.PAS.PassengerIdentityDocumentId = this.textBoxIdDocNumber.Text.Trim(); this.PAS.PassengerVisaNumber = this.textBoxVisaNumber.Text.Trim(); this.PAS.PassengerPortOfEmbarkation = this.locodePortOfEmbarkation.LocodeValue; diff --git a/ENI2/EditControls/FixImportDialog.xaml b/ENI2/EditControls/FixImportDialog.xaml index 8804c161..a800d12e 100644 --- a/ENI2/EditControls/FixImportDialog.xaml +++ b/ENI2/EditControls/FixImportDialog.xaml @@ -7,7 +7,7 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:local="clr-namespace:ENI2.EditControls" mc:Ignorable="d" - Title="Fix imported value" Height="200" Width="500"> + Title="Fix imported value" Height="200" Width="500" WindowStyle="SingleBorderWindow" Background="AliceBlue" Loaded="EditWindowBase_Loaded"> diff --git a/ENI2/EditControls/FixImportDialog.xaml.cs b/ENI2/EditControls/FixImportDialog.xaml.cs index 95e6a629..132eadaf 100644 --- a/ENI2/EditControls/FixImportDialog.xaml.cs +++ b/ENI2/EditControls/FixImportDialog.xaml.cs @@ -27,8 +27,7 @@ namespace ENI2.EditControls { public FixImportDialog() { - InitializeComponent(); - this.comboBoxValues.ItemsSource = this.SelectionValues; + InitializeComponent(); } public string SelectedValue @@ -47,11 +46,15 @@ namespace ENI2.EditControls public string ValueType { - get { return this.textBlockValue.Text; } - set { this.textBlockValue.Text = value; } + get { return this.textBlockType.Text; } + set { this.textBlockType.Text = value; } } public Dictionary SelectionValues { get; set; } + private void EditWindowBase_Loaded(object sender, RoutedEventArgs e) + { + this.comboBoxValues.ItemsSource = this.SelectionValues; + } } } diff --git a/ENI2/Excel/DakosyUtil.cs b/ENI2/Excel/DakosyUtil.cs index d279d493..c8ad5d64 100644 --- a/ENI2/Excel/DakosyUtil.cs +++ b/ENI2/Excel/DakosyUtil.cs @@ -1240,8 +1240,8 @@ namespace ENI2.Excel { if (gender.Equals("male", StringComparison.OrdinalIgnoreCase) || gender.Equals("m", StringComparison.OrdinalIgnoreCase)) result = 1; if (gender.Equals("female", StringComparison.OrdinalIgnoreCase) || gender.Equals("f", StringComparison.OrdinalIgnoreCase)) result = 2; - if (gender.Equals("not_applicable", StringComparison.OrdinalIgnoreCase) || gender.Equals("n", StringComparison.OrdinalIgnoreCase)) result = 9; - if (gender.Equals("not_known", StringComparison.OrdinalIgnoreCase)) result = 0; + if (gender.Equals("not_applicable", StringComparison.OrdinalIgnoreCase) || gender.Equals("not applicable", StringComparison.OrdinalIgnoreCase) || gender.Equals("n", StringComparison.OrdinalIgnoreCase)) result = 9; + if (gender.Equals("not_known", StringComparison.OrdinalIgnoreCase) || gender.Equals("not known", StringComparison.OrdinalIgnoreCase)) result = 0; if (gender.Equals("other", StringComparison.OrdinalIgnoreCase) || gender.Equals("d", StringComparison.OrdinalIgnoreCase) || gender.Equals("diverse", StringComparison.OrdinalIgnoreCase)) result = 9; } return result; diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index 640ddd90..1ee4d0e9 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -2065,7 +2065,7 @@ namespace ENI2.Excel // 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"); + bool? notificationPax = reader.ReadBoolean("CREW.NotificationPAX"); for (int i = 0; i < 1000; i++) { @@ -2086,45 +2086,20 @@ namespace ENI2.Excel crew.CrewMemberLastName = lastName; crew.CrewMemberFirstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18)); - string gender = reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18)); - crew.CrewMemberGender = DakosyUtil.ParseGender(gender); - - if(!gender.IsNullOrEmpty() && !crew.CrewMemberGender.HasValue) - { - // special treatment / callback - if (_genderImportDict.ContainsKey(gender)) - { - crew.CrewMemberGender = DakosyUtil.ParseGender(_genderImportDict[gender]); // we have mapped this before - } - else - { - FixImportDialog fid = new FixImportDialog(); - fid.Value = gender; - fid.ValueType = "Gender"; - fid.SelectionValues = CREW.NationalityDict; - if(fid.ShowDialog() ?? false) - { - if(!fid.SelectedValue.IsNullOrEmpty()) - { - _genderImportDict[gender] = fid.SelectedValue; - crew.CrewMemberGender = DakosyUtil.ParseGender(_genderImportDict[gender]); - } - } - } - } + crew.CrewMemberGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18))); crew.CrewMemberDuty = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 18)); - crew.CrewMemberNationality = reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 18)); + crew.CrewMemberNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("G{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.CrewMemberDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("J{0}", i + 18)); - string idDocType = reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 18)); - crew.CrewMemberIdentityDocumentType = DakosyUtil.ParseDocumentType(idDocType); + + crew.CrewMemberIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("K{0}", i + 18))); crew.CrewMemberIdentityDocumentId = reader.ReadCellAsText(sheetTitle, string.Format("L{0}", i + 18)); crew.CrewMemberVisaNumber = reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 18)); - crew.CrewMemberIdentityDocumentIssuingState = reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 18)); + crew.CrewMemberIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("M{0}", i + 18))); if (crew.CrewMemberIdentityDocumentIssuingState.IsNullOrEmpty() && isOldVersion) crew.CrewMemberIdentityDocumentIssuingState = "XX"; crew.CrewMemberIdentityDocumentExpiryDate = reader.ReadCellAsDateTime(sheetTitle, string.Format("N{0}", i + 18)); @@ -2463,5 +2438,102 @@ namespace ENI2.Excel #endregion + #region "Semi-Manual" import functions (may open interactive dialog) + + public static byte? ReadGender(string gender) + { + byte? result = DakosyUtil.ParseGender(gender); + + if (!gender.IsNullOrEmpty() && !result.HasValue) + { + // special treatment / callback + if (_genderImportDict.ContainsKey(gender)) + { + result = byte.Parse(_genderImportDict[gender]); // we have mapped this before + } + else + { + FixImportDialog fid = new FixImportDialog(); + fid.Value = gender; + fid.ValueType = "Gender"; + fid.SelectionValues = Util.GlobalStructures.GenderDict; + if (fid.ShowDialog() ?? false) + { + if (!fid.SelectedValue.IsNullOrEmpty()) + { + _genderImportDict[gender] = fid.SelectedValue; + result = byte.Parse(_genderImportDict[gender]); + } + } + } + } + + return result; + } + + public static byte? ReadDocumentType(string documentType) + { + byte? result = DakosyUtil.ParseDocumentType(documentType); + + if (!documentType.IsNullOrEmpty() && !result.HasValue) + { + // special treatment / callback + if (_documentTypeImportDict.ContainsKey(documentType)) + { + result = byte.Parse(_documentTypeImportDict[documentType]); // we have mapped this before + } + else + { + FixImportDialog fid = new FixImportDialog(); + fid.Value = documentType; + fid.ValueType = "Document type"; + fid.SelectionValues = Util.GlobalStructures.IDDocTypeDict; + if (fid.ShowDialog() ?? false) + { + if (!fid.SelectedValue.IsNullOrEmpty()) + { + _genderImportDict[documentType] = fid.SelectedValue; + result = byte.Parse(_genderImportDict[documentType]); + } + } + } + } + + return result; + } + + public static string ReadNationality(string nationality) + { + string result = null; + + if(CREW.NationalityDict.ContainsKey(nationality)) + { + result = nationality; + } + else if(_countryImportDict.ContainsKey(nationality)) + { + result = _countryImportDict[nationality]; + } + else // we cannot find whatever this is.. + { + FixImportDialog fid = new FixImportDialog(); + fid.Value = nationality; + fid.ValueType = "Nationality"; + fid.SelectionValues = CREW.NationalityDict; + if(fid.ShowDialog() ?? false) + { + if(!fid.SelectedValue.IsNullOrEmpty()) + { + _countryImportDict[nationality] = fid.SelectedValue; + result = fid.SelectedValue; + } + } + } + + return result; + } + + #endregion + } } diff --git a/ENI2/Util/GlobalStructures.cs b/ENI2/Util/GlobalStructures.cs index b530f643..589c1754 100644 --- a/ENI2/Util/GlobalStructures.cs +++ b/ENI2/Util/GlobalStructures.cs @@ -12,24 +12,24 @@ using ENI2.Locode; namespace ENI2.Util { static class GlobalStructures - { + { - public static Dictionary GenderDict = new Dictionary + public static Dictionary GenderDict = new Dictionary { - { 0, Properties.Resources.textNotKnown }, - { 1, Properties.Resources.textMale }, - { 2, Properties.Resources.textFemale }, - { 9, Properties.Resources.textNotApplicable } + { "0", Properties.Resources.textNotKnown }, + { "1", Properties.Resources.textMale }, + { "2", Properties.Resources.textFemale }, + { "9", Properties.Resources.textNotApplicable } }; - public static string[] IDDocTypeList = + public static Dictionary IDDocTypeDict = new Dictionary { - Properties.Resources.textIdentityCard, - Properties.Resources.textPassport, - Properties.Resources.textMusterBook, - Properties.Resources.textPhotoId, - Properties.Resources.textResidencePermit, - Properties.Resources.textOtherLegalIdentityDocument + { "0", Properties.Resources.textIdentityCard }, + { "1", Properties.Resources.textPassport }, + { "2", Properties.Resources.textMusterBook }, + { "3", Properties.Resources.textPhotoId }, + { "4", Properties.Resources.textResidencePermit }, + { "5", Properties.Resources.textOtherLegalIdentityDocument } }; public static byte[] ShipSecurityLevels = { 1, 2, 3 };