diff --git a/ENI2/EditControls/EditIMSBCDialog.xaml b/ENI2/EditControls/EditIMSBCDialog.xaml
index e40e216c..0964c8f9 100644
--- a/ENI2/EditControls/EditIMSBCDialog.xaml
+++ b/ENI2/EditControls/EditIMSBCDialog.xaml
@@ -46,7 +46,7 @@
-
+
diff --git a/bsmd.database/IGCPosition.cs b/bsmd.database/IGCPosition.cs
index fab5e108..b0b5a354 100644
--- a/bsmd.database/IGCPosition.cs
+++ b/bsmd.database/IGCPosition.cs
@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
+using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace bsmd.database
@@ -27,6 +28,13 @@ namespace bsmd.database
this.tablename = "[dbo].[IGCPosition]";
}
+ #region static regex
+
+ private static readonly Regex unNumberRegex = new Regex("^[0-9]{4}$");
+ private static readonly Regex imoClassRegex = new Regex(@"^[1-9]{1}(\.[1-9]{1})?$");
+
+ #endregion
+
#region Properties
[JsonIgnore]
@@ -189,6 +197,20 @@ namespace bsmd.database
#endregion
+ #region Validation
+
+ public override void Validate(List errors, List violations)
+ {
+
+ if (!this.UNNumber.IsNullOrEmpty() && !unNumberRegex.IsMatch(this.UNNumber))
+ violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "UNNumber", this.UNNumber, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
+
+ if (!this.IMOClass.IsNullOrEmpty() && !imoClassRegex.IsMatch(this.IMOClass))
+ violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "IMOClass", this.IMOClass, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
+
+ }
+
+ #endregion
}
}
diff --git a/bsmd.database/IMDGPosition.cs b/bsmd.database/IMDGPosition.cs
index 2243f0b7..fbe1836e 100644
--- a/bsmd.database/IMDGPosition.cs
+++ b/bsmd.database/IMDGPosition.cs
@@ -28,6 +28,13 @@ namespace bsmd.database
this.tablename = "[dbo].[IMDGPosition]";
}
+ #region static Regex
+
+ private static Regex imoClassRegex = new Regex(@"^[1-9]{1}(\.[1-9]{1}([A-Z]{1})?)?$");
+ private static Regex unNumberRegex = new Regex(@"^[0 - 9]{4}$");
+
+ #endregion
+
#region Properties
[JsonIgnore]
@@ -507,13 +514,16 @@ namespace bsmd.database
if(!this.IMOClass.IsNullOrEmpty())
{
- const string pattern = @"^[1-9]{1}(\.[1-9]{1}([A-Z]{1})?)?$";
- Regex regex = new Regex(pattern);
-
- if (!regex.IsMatch(this.IMOClass))
+ if (!imoClassRegex.IsMatch(this.IMOClass))
errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "IMOClass", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
}
+ if(!this.UNNumber.IsNullOrEmpty())
+ {
+ if(!unNumberRegex.IsMatch(this.UNNumber))
+ errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "UNNumber", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
+ }
+
if (!this.StowagePosition.IsNullOrEmpty() && (!this.Bay.IsNullOrEmpty() || !this.Row.IsNullOrEmpty() || !this.Tier.IsNullOrEmpty()))
{
errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "StowagePosition AND Bay/Row/Tier SET", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
diff --git a/bsmd.database/IMSBCPosition.cs b/bsmd.database/IMSBCPosition.cs
index 9c0ed9d0..5b5098eb 100644
--- a/bsmd.database/IMSBCPosition.cs
+++ b/bsmd.database/IMSBCPosition.cs
@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
+using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace bsmd.database
@@ -22,6 +23,8 @@ namespace bsmd.database
public class IMSBCPosition : DatabaseEntity, ISublistElement
{
+ #region static defs
+
public static string[] hazardClass =
{
"A",
@@ -29,6 +32,11 @@ namespace bsmd.database
"A and B"
};
+ private static readonly Regex unNumberRegex = new Regex("^[0-9]{4}$");
+ private static readonly Regex imoClassRegex = new Regex(@"^[1-9]{1}(\.[1-9]{1})?$");
+
+ #endregion
+
public IMSBCPosition()
{
this.tablename = "[dbo].[IMSBCPosition]";
@@ -230,14 +238,13 @@ namespace bsmd.database
{
if(!MHB ?? false)
{
- if(this.UNNumber.IsNullOrEmpty() || this.IMOClass.IsNullOrEmpty())
- violations.Add(RuleEngine.CreateViolation(ValidationCode.V803, null, null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
- }
- if(MHB ?? false)
- {
- if(!this.UNNumber.IsNullOrEmpty() || !this.IMOClass.IsNullOrEmpty())
- violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "UNNumber/IMOClass not empty", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
+ if(this.UNNumber.IsNullOrEmpty() || !unNumberRegex.IsMatch(this.UNNumber))
+ violations.Add(RuleEngine.CreateViolation(ValidationCode.V803, "UNNumber", this.UNNumber, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
+
+ if (this.IMOClass.IsNullOrEmpty() || !imoClassRegex.IsMatch(this.IMOClass))
+ violations.Add(RuleEngine.CreateViolation(ValidationCode.V803, "IMOClass", this.IMOClass, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
}
+
if (!this.IMOHazardClass.HasValue)
{