diff --git a/ENI-2/ENI2/ENI2/App.xaml.cs b/ENI-2/ENI2/ENI2/App.xaml.cs index d47cc03c..c9289697 100644 --- a/ENI-2/ENI2/ENI2/App.xaml.cs +++ b/ENI-2/ENI2/ENI2/App.xaml.cs @@ -81,6 +81,7 @@ namespace ENI2 // Preload validation fields List vFields = bsmd.database.ValidationRule.ValidationFields; RuleEngine.RegisterLocodeChecker(Util.GlobalStructures.IsValidLocode); + RuleEngine.RegisterPortAreaChecker(LocalizedLookup.PortAreaExists); // Connect to locking service (if enabled) try diff --git a/ENI-2/ENI2/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs b/ENI-2/ENI2/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs index 271b1613..eb92f5e0 100644 --- a/ENI-2/ENI2/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/DetailViewControls/BorderPoliceDetailControl.xaml.cs @@ -425,7 +425,7 @@ namespace ENI2.DetailViewControls if (!reader.IsDBNull(0)) crew.CrewMemberLastName = reader.GetString(0); if (!reader.IsDBNull(1)) crew.CrewMemberFirstName = reader.GetString(1); if (!reader.IsDBNull(2)) crew.CrewMemberGender = GlobalStructures.ParseGender(reader.GetString(2)); - if (!reader.IsDBNull(3)) crew.CrewMemberNationality = reader.GetString(3).Substring(0, 2); + if (!reader.IsDBNull(3)) crew.CrewMemberNationality = reader.GetString(3).Substring(0, 2).ToUpper(); if (!reader.IsDBNull(4)) crew.CrewMemberDuty = reader.GetString(4); if (!reader.IsDBNull(5)) crew.CrewMemberPlaceOfBirth = reader.GetString(5); if (!reader.IsDBNull(6)) @@ -498,7 +498,7 @@ namespace ENI2.DetailViewControls if (!reader.IsDBNull(0)) pas.PassengerLastName = reader.GetString(0); if (!reader.IsDBNull(1)) pas.PassengerFirstName = reader.GetString(1); if (!reader.IsDBNull(2)) pas.PassengerGender = GlobalStructures.ParseGender(reader.GetString(2)); - if (!reader.IsDBNull(3)) pas.PassengerNationality = reader.GetString(3).Substring(0, 2); + if (!reader.IsDBNull(3)) pas.PassengerNationality = reader.GetString(3).Substring(0, 2).ToUpper(); if (!reader.IsDBNull(4)) pas.PassengerPortOfEmbarkation = reader.GetString(4); if (LocodeDB.PortNameFromLocode(pas.PassengerPortOfEmbarkation) == null) pas.PassengerPortOfEmbarkation = null; diff --git a/ENI-2/ENI2/ENI2/ENI2.csproj b/ENI-2/ENI2/ENI2/ENI2.csproj index f5c75fb4..5f1fb549 100644 --- a/ENI-2/ENI2/ENI2/ENI2.csproj +++ b/ENI-2/ENI2/ENI2/ENI2.csproj @@ -35,7 +35,7 @@ 3.5.1.0 true publish.html - 0 + 1 3.9.10.%2a false true diff --git a/ENI-2/ENI2/ENI2/LocalizedLookup.cs b/ENI-2/ENI2/ENI2/LocalizedLookup.cs index bf031024..69313934 100644 --- a/ENI-2/ENI2/ENI2/LocalizedLookup.cs +++ b/ENI-2/ENI2/ENI2/LocalizedLookup.cs @@ -62,6 +62,14 @@ namespace ENI2 return result; } + public static bool PortAreaExists(string locode, string portArea) + { + string query = string.Format("SELECT COUNT(*) FROM INFO_PortArea WHERE Locode = '{0}' AND Code = '{1}'", locode, portArea); + SQLiteCommand cmd = new SQLiteCommand(query, _con); + long numResults = (long) cmd.ExecuteScalar(); + return (numResults > 0); + } + public static Dictionary getNationalities() { Dictionary result = new Dictionary(); diff --git a/ENI-2/ENI2/ENI2/Util/GlobalStructures.cs b/ENI-2/ENI2/ENI2/Util/GlobalStructures.cs index 04581efb..2ec9438e 100644 --- a/ENI-2/ENI2/ENI2/Util/GlobalStructures.cs +++ b/ENI-2/ENI2/ENI2/Util/GlobalStructures.cs @@ -210,6 +210,6 @@ namespace ENI2.Util return !LocodeDB.PortNameFromLocode(locode).IsNullOrEmpty(); } } - + } } diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 00e0a699..ae7317bb 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs b/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs index b5910c2c..959f44e1 100644 --- a/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs +++ b/nsw/Source/bsmd.ExcelReadService/ExcelReader.cs @@ -309,7 +309,10 @@ namespace bsmd.ExcelReadService } if (val.Length == 2) + { this.Conf.ConfirmText(lookup, val, ReadState.OK); + val = val.ToUpper(); + } } return val; } diff --git a/nsw/Source/bsmd.database/INFO.cs b/nsw/Source/bsmd.database/INFO.cs index 74c69b62..694e2de7 100644 --- a/nsw/Source/bsmd.database/INFO.cs +++ b/nsw/Source/bsmd.database/INFO.cs @@ -190,7 +190,25 @@ namespace bsmd.database return result; } - #endregion + #endregion + + #region Validation + + public override void Validate(List errors, List violations) + { + if ((PortArea.Length >= 2) && (PortArea.Length <= 4)) + { + if ((RuleEngine.PortAreaChecker != null) && (this.MessageCore != null)) + if (!RuleEngine.PortAreaChecker(this.MessageCore.PoC, this.PortArea)) + errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "PortArea", this.PortArea, "INFO", "", this.Tablename)); + } + else + { + errors.Add(RuleEngine.CreateError(ValidationCode.PORTAREA, "PortArea", this.PortArea, "INFO", "", this.Tablename)); + } + } + + #endregion } } \ No newline at end of file diff --git a/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs b/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs index 4ff08700..9b46e39a 100644 --- a/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs +++ b/nsw/Source/bsmd.database/LastTenPortFacilitiesCalled.cs @@ -72,7 +72,7 @@ namespace bsmd.database //[Validation(ValidationCode.LOCODE)] //[ENI2Validation] [MaxLength(5)] - public string PortFacilityGISICodeLocode { get; set; } + public string PortFacilityGISISCodeLocode { get; set; } public string Identifier { get; set; } @@ -96,7 +96,7 @@ namespace bsmd.database scmd.Parameters.AddWithNullableValue("@P7", this.PortFacilityShipSecurityLevel); scmd.Parameters.AddWithNullableValue("@P8", this.PortFacilitySecurityMattersToReport); scmd.Parameters.AddWithNullableValue("@P9", this.PortFacilityGISISCode); - scmd.Parameters.AddWithNullableValue("@P10", this.PortFacilityGISICodeLocode); + scmd.Parameters.AddWithNullableValue("@P10", this.PortFacilityGISISCodeLocode); scmd.Parameters.AddWithNullableValue("@P11", this.Identifier); if (this.IsNew) @@ -105,7 +105,7 @@ namespace bsmd.database scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, SEC_Id, PortFacilityPortName, PortFacilityPortCountry, " + "PortFacilityPortLoCode, PortFacilityDateOfArrival, PortFacilityDateOfDeparture, PortFacilityShipSecurityLevel, " + - "PortFacilitySecurityMattersToReport, PortFacilityGISISCode, PortFacilityGISICodeLoCode, Identifier) VALUES " + + "PortFacilitySecurityMattersToReport, PortFacilityGISISCode, PortFacilityGISISCodeLoCode, Identifier) VALUES " + "( @ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11)", this.Tablename); } else @@ -114,7 +114,7 @@ namespace bsmd.database scmd.CommandText = string.Format("UPDATE {0} SET PortFacilityPortName = @P2, PortFacilityPortCountry = @P3, " + "PortFacilityPortLoCode = @P4, PortFacilityDateOfArrival = @P5, PortFacilityDateOfDeparture = @P6," + "PortFacilityShipSecurityLevel = @P7, PortFacilitySecurityMattersToReport = @P8, PortFacilityGISISCode = @P9, " + - "PortFacilityGISICodeLoCode = @P10, Identifier = @P11 WHERE Id = @ID", this.Tablename); + "PortFacilityGISISCodeLoCode = @P10, Identifier = @P11 WHERE Id = @ID", this.Tablename); } } @@ -122,7 +122,7 @@ namespace bsmd.database { string query = string.Format("SELECT Id, PortFacilityPortName, PortFacilityPortCountry, PortFacilityPortLoCode, " + "PortFacilityDateOfArrival, PortFacilityDateOfDeparture, PortFacilityShipSecurityLevel, PortFacilitySecurityMattersToReport, " + - "PortFacilityGISISCode, PortFacilityGISICodeLoCode, Identifier FROM {0} ", this.Tablename); + "PortFacilityGISISCode, PortFacilityGISISCodeLoCode, Identifier FROM {0} ", this.Tablename); switch (filter) { @@ -158,7 +158,7 @@ namespace bsmd.database if (!reader.IsDBNull(6)) ltpfc.PortFacilityShipSecurityLevel = reader.GetByte(6); if (!reader.IsDBNull(7)) ltpfc.PortFacilitySecurityMattersToReport = reader.GetString(7); if (!reader.IsDBNull(8)) ltpfc.PortFacilityGISISCode = reader.GetString(8); - if (!reader.IsDBNull(9)) ltpfc.PortFacilityGISICodeLocode = reader.GetString(9); + if (!reader.IsDBNull(9)) ltpfc.PortFacilityGISISCodeLocode = reader.GetString(9); if (!reader.IsDBNull(10)) ltpfc.Identifier = reader.GetString(10); result.Add(ltpfc); } diff --git a/nsw/Source/bsmd.database/RuleEngine.cs b/nsw/Source/bsmd.database/RuleEngine.cs index 703229d9..f1a51966 100644 --- a/nsw/Source/bsmd.database/RuleEngine.cs +++ b/nsw/Source/bsmd.database/RuleEngine.cs @@ -91,7 +91,8 @@ namespace bsmd.database "DEWIS", "DE003", "DEWOL", - "DEWYK" + "DEWYK", + "DEMAG" }; #endregion @@ -104,11 +105,13 @@ namespace bsmd.database }; public delegate bool LocodeValidHandler(string locode, LocodeMode mode); + public delegate bool PortAreaValidHandler(string locode, string portArea); private static ILog log = LogManager.GetLogger(typeof(RuleEngine)); private static Dictionary errorTextList = null; private static Dictionary violationTextList = null; private static LocodeValidHandler _locodeChecker = null; + private static PortAreaValidHandler _portAreaChecker = null; private Dictionary> errorDict = new Dictionary>(); private Dictionary> violationDict = new Dictionary>(); @@ -124,9 +127,12 @@ namespace bsmd.database public Dictionary> ErrorDict { get { return this.errorDict; } } public Dictionary> ViolationDict { get { return this.violationDict; } } + public static PortAreaValidHandler PortAreaChecker { get { return _portAreaChecker; } } + #region public static property validation public static void RegisterLocodeChecker(LocodeValidHandler handler) { _locodeChecker = handler; } + public static void RegisterPortAreaChecker(PortAreaValidHandler handler) { _portAreaChecker = handler; } /// /// Test function checks decorated properties on an entity for errors (only errors, violations cannot @@ -348,13 +354,7 @@ namespace bsmd.database case ValidationCode.NOT_NULL_MAX_LEN: if ((value.Length > maxlen) || (value.Length == 0)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); - break; - case ValidationCode.PORTAREA: - { - if ((value.Length < 2) || (value.Length > 4)) - errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); - break; - } + break; case ValidationCode.FRZ: { Regex rgx = new Regex(@"^[A-Z, a-z,0-9]{4,7}$"); diff --git a/nsw/Source/misc/db.sqlite b/nsw/Source/misc/db.sqlite index 4c7511d1..968ec258 100644 Binary files a/nsw/Source/misc/db.sqlite and b/nsw/Source/misc/db.sqlite differ