diff --git a/ENI2/Controls/EditWindowBase.cs b/ENI2/Controls/EditWindowBase.cs index 38fe3b4c..a10d77d8 100644 --- a/ENI2/Controls/EditWindowBase.cs +++ b/ENI2/Controls/EditWindowBase.cs @@ -56,6 +56,12 @@ namespace ENI2.Controls set { var addButton = (Button)Template.FindName("buttonAdd", this); addButton.Visibility = value ? Visibility.Visible : Visibility.Hidden; } } + public bool OkVisible + { + get { var okButton = (Button)Template.FindName("buttonOK", this); return okButton.Visibility == Visibility.Visible; } + set { var okButton = (Button)Template.FindName("buttonOK", this); okButton.Visibility = value ? Visibility.Visible : Visibility.Hidden; } + } + private void Window_Closing(object sender, CancelEventArgs e) { if (this.shouldCancel) e.Cancel = true; diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index 698137b0..5868211b 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -36,7 +36,7 @@ 5.4.0.0 true publish.html - 7 + 9 7.5.0.%2a false true diff --git a/ENI2/EditControls/NewDGItemDialog.xaml.cs b/ENI2/EditControls/NewDGItemDialog.xaml.cs index 848450f6..09ab828c 100644 --- a/ENI2/EditControls/NewDGItemDialog.xaml.cs +++ b/ENI2/EditControls/NewDGItemDialog.xaml.cs @@ -40,6 +40,7 @@ namespace ENI2.EditControls this.listBoxDescription.ItemsSource = _data; this.comboBoxType.ItemsSource = Enum.GetValues(typeof(HAZPosTemplate.SublistType)); this.AddVisible = true; + this.OkVisible = false; } private void comboBoxType_SelectionChanged(object sender, SelectionChangedEventArgs e) diff --git a/ENI2/Excel/ExcelUtil.cs b/ENI2/Excel/ExcelUtil.cs index bbf39065..fdd74c3c 100644 --- a/ENI2/Excel/ExcelUtil.cs +++ b/ENI2/Excel/ExcelUtil.cs @@ -2087,20 +2087,23 @@ namespace ENI2.Excel crew.CrewMemberLastName = lastName; crew.CrewMemberFirstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 18)); - crew.CrewMemberGender = ReadGender(reader.ReadCellAsText(sheetTitle, string.Format("E{0}", i + 18))); + 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))); + 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))); + 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))); + 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)); @@ -2141,20 +2144,24 @@ namespace ENI2.Excel 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))); + 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))); + 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))); + 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))); + 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)); @@ -2172,45 +2179,54 @@ namespace ENI2.Excel private static bool ScanPAS(Message pasMessage, ExcelReader reader, bool isOldVersion) { - pasMessage.DeleteElements(); + + List newPasList = new List(); + string sheetTitle = "8. PAX - Arrival"; bool? notificationSchengen = reader.ReadBoolean("PAS.NotificationSchengen"); - bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX"); + bool? notificationPax = reader.ReadBoolean("PAS.NotificationPAX"); for (int i = 0; i < 5000; i++) - { + { string lastName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", i + 17)); - if (lastName.IsNullOrEmpty()) break; + if (lastName.IsNullOrEmpty()) break; // finish after reading last row + string firstName = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 17)); + DateTime? dateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{0}", i + 17)); - if (!(pasMessage.GetSublistElementWithIdentifier((i + 1).ToString()) is PAS pas)) - { - pas = new PAS(); - pas.Identifier = (i + 1).ToString(); - pas.MessageHeader = pasMessage; - pasMessage.Elements.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 = reader.ReadCellAsText(sheetTitle, string.Format("D{0}", i + 17)); + pas.PassengerFirstName = firstName; - pas.PassengerNationality = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("I{0}", i + 17))); - pas.PassengerIdentityDocumentIssuingState = ReadNationality(reader.ReadCellAsText(sheetTitle, string.Format("O{0}", i + 17))); + 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))); - pas.PassengerPortOfEmbarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("F{0}", i + 17))); - pas.PassengerPortOfDisembarkation = ReadLocode(reader.ReadCellAsText(sheetTitle, string.Format("G{0}", i + 17))); + 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))); - pas.PassengerDateOfBirth = reader.ReadCellAsDateTime(sheetTitle, string.Format("L{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.PassengerIdentityDocumentType = ReadDocumentType(reader.ReadCellAsText(sheetTitle, string.Format("M{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)); @@ -2219,9 +2235,15 @@ namespace ENI2.Excel 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.EmergencyContactNumber = reader.ReadCellAsText(sheetTitle, string.Format("S{0}", i + 17)); + } + DBManager.Instance.DeleteAllPASForMessage(pasMessage.Id); + pasMessage.Elements.Clear(); + foreach (PAS pas in newPasList) + pasMessage.Elements.Add(pas); + return true; } @@ -2424,9 +2446,10 @@ namespace ENI2.Excel #region "Semi-Manual" import functions (may open interactive dialog) - public static byte? ReadGender(string gender) + public static byte? ReadGender(string gender, out bool canceled) { byte? result = DakosyUtil.ParseGender(gender); + canceled = false; if (!gender.IsNullOrEmpty() && !result.HasValue) { @@ -2448,6 +2471,10 @@ namespace ENI2.Excel _genderImportDict[gender] = fid.SelectedValue; result = byte.Parse(_genderImportDict[gender]); } + } + else + { + canceled = true; } } } @@ -2455,9 +2482,10 @@ namespace ENI2.Excel return result; } - public static byte? ReadDocumentType(string documentType) + public static byte? ReadDocumentType(string documentType, out bool canceled) { byte? result = DakosyUtil.ParseDocumentType(documentType); + canceled = false; if (!documentType.IsNullOrEmpty() && !result.HasValue) { @@ -2479,6 +2507,10 @@ namespace ENI2.Excel _genderImportDict[documentType] = fid.SelectedValue; result = byte.Parse(_genderImportDict[documentType]); } + } + else + { + canceled = true; } } } @@ -2490,9 +2522,10 @@ namespace ENI2.Excel return result; } - public static string ReadNationality(string nationality) + public static string ReadNationality(string nationality, out bool canceled) { string result = null; + canceled = false; nationality = nationality.Trim(); if (nationality.IsNullOrEmpty()) { @@ -2523,15 +2556,20 @@ namespace ENI2.Excel _countryImportDict[nationality] = fid.SelectedValue; result = fid.SelectedValue.Substring(0,2); // attention manual entry } + } + else + { + canceled = true; } } return result; } - public static string ReadLocode(string val) + public static string ReadLocode(string val, out bool canceled) { string result = null; + canceled = false; val = val.ToUpper(); @@ -2560,6 +2598,10 @@ namespace ENI2.Excel if (fid.ShowDialog() ?? false) { _locodeImportDict[val] = fid.SelectedValue; + } + else + { + canceled = true; } } if(_locodeImportDict.ContainsKey(val)) diff --git a/bsmd.database/CREW.cs b/bsmd.database/CREW.cs index e9ca5665..93791588 100644 --- a/bsmd.database/CREW.cs +++ b/bsmd.database/CREW.cs @@ -272,6 +272,37 @@ namespace bsmd.database #endregion + #region Validation + + public override void Validate(List errors, List violations) + { + if (this.CrewMemberIdentityDocumentType.HasValue) + { + if (this.CrewMemberIdentityDocumentType.Value == 5) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Doc. type set to OTHER_LEGAL_IDENTITY_DOCUMENT", null, this.Title, this.Identifier, this.Tablename)); + } + + if (this.CrewMemberIdentityDocumentIssuingState != null) + { + if (this.CrewMemberIdentityDocumentIssuingState.Equals("XX")) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Id. doc issuing state set to XX", null, this.Title, this.Identifier, this.Tablename)); + } + + if (this.CrewMemberNationality != null) + { + if (this.CrewMemberNationality.Equals("XX")) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Nationality set to XX", null, this.Title, this.Identifier, this.Tablename)); + } + + if (this.CrewMemberIdentityDocumentExpiryDate.HasValue) + { + if (this.CrewMemberIdentityDocumentExpiryDate.Equals(new DateTime(2100, 12, 31))) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Id doc expiry date set to 31/12/2100", null, this.Title, this.Identifier, this.Tablename)); + } + } + + #endregion + #region IBulkSaver implementation public DataTable PrepareBulkInsert(List databaseEntities) diff --git a/bsmd.database/DBManager.cs b/bsmd.database/DBManager.cs index a37ceff9..6ca7c36f 100644 --- a/bsmd.database/DBManager.cs +++ b/bsmd.database/DBManager.cs @@ -729,6 +729,18 @@ namespace bsmd.database return result; } + public void DeleteAllPASForMessage(Guid? id) + { + if (!id.HasValue) return; + using (SqlCommand cmd = new SqlCommand()) + { + cmd.CommandText = "DELETE FROM PAS WHERE MessageHeaderId = @MESSAGEHEADERID"; + cmd.Parameters.AddWithValue("@MESSAGEHEADERID", id); + int numDel = this.PerformNonQuery(cmd); + _log.InfoFormat("Deleted all elements ({0}) from PAS message", numDel); + } + } + #endregion #region internal/private funcs @@ -1611,7 +1623,7 @@ namespace bsmd.database bulkCopy.WriteToServer(table); } } - } + } #endregion diff --git a/bsmd.database/PAS.cs b/bsmd.database/PAS.cs index 57062f31..f145c1b3 100644 --- a/bsmd.database/PAS.cs +++ b/bsmd.database/PAS.cs @@ -17,11 +17,15 @@ namespace bsmd.database public class PAS : DatabaseEntity, ISublistElement, IBulkSaver { + #region Construction + public PAS() { this.tablename = "[dbo].[PAS]"; } + #endregion + #region Properties [ShowReport] @@ -320,15 +324,38 @@ namespace bsmd.database if (this.PassengerPortOfDisembarkation != null) { if (this.PassengerPortOfDisembarkation.Equals("ZZUKN")) - violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "PassengerPortOfDisembarkation", null, this.Title, this.Identifier, this.Tablename)); + violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "Port of disembarkation set to ZZUKN", null, this.Title, this.Identifier, this.Tablename)); } if (this.PassengerPortOfEmbarkation != null) { if (this.PassengerPortOfEmbarkation.Equals("ZZUKN")) - violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "PassengerPortOfEmbarkation", null, this.Title, this.Identifier, this.Tablename)); + violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, "Port of embarkation set to ZZUKN", null, this.Title, this.Identifier, this.Tablename)); + } + + if(this.PassengerIdentityDocumentType.HasValue) + { + if(this.PassengerIdentityDocumentType.Value == 5) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Doc. type set to OTHER_LEGAL_IDENTITY_DOCUMENT", null, this.Title, this.Identifier, this.Tablename)); + } + + if(this.PassengerNationality != null) + { + if (this.PassengerNationality.Equals("XX")) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Nationality set to XX", null, this.Title, this.Identifier, this.Tablename)); + } + + if (this.PassengerIdentityDocumentIssuingState != null) + { + if (this.PassengerIdentityDocumentIssuingState.Equals("XX")) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Id. doc issuing state set to XX", null, this.Title, this.Identifier, this.Tablename)); + } + + if (this.PassengerIdentityDocumentExpiryDate.HasValue) + { + if(this.PassengerIdentityDocumentExpiryDate.Equals(new DateTime(2100, 12, 31))) + violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Id doc expiry date set to 31/12/2100", null, this.Title, this.Identifier, this.Tablename)); } - // */ } #endregion