Validierung für IMOClass / UNnumber per Regex eingebaut.

Die maximale Zeichenlänge kann allerdings nicht stimmen, die im Excel mit 10 angegeben ist.
This commit is contained in:
Daniel Schick 2023-04-02 11:42:41 +02:00
parent 882861a328
commit 78a72caffc
4 changed files with 51 additions and 12 deletions

View File

@ -46,7 +46,7 @@
<TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Name="textBoxBulkCargoShippingName" MaxLength="255" Margin="2" /> <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Name="textBoxBulkCargoShippingName" MaxLength="255" Margin="2" />
<CheckBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="2" Name="checkBoxMaterialHazardous" /> <CheckBox Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="2" Name="checkBoxMaterialHazardous" />
<TextBox Grid.Row="2" Grid.Column="4" Name="textBoxUNNumber" MaxLength="4" Margin="2" VerticalContentAlignment="Center" /> <TextBox Grid.Row="2" Grid.Column="4" Name="textBoxUNNumber" MaxLength="4" Margin="2" VerticalContentAlignment="Center" />
<TextBox Grid.Row="3" Grid.Column="1" Name="textBoxIMOClass" MaxLength="4" Margin="2" VerticalContentAlignment="Center" /> <TextBox Grid.Row="3" Grid.Column="1" Name="textBoxIMOClass" MaxLength="3" Margin="2" VerticalContentAlignment="Center" />
<xctk:DoubleUpDown Name="doubleUpDownQuantity" Grid.Row="3" Grid.Column="4" Margin="2" FormatString="N3" ShowButtonSpinner="False" TextAlignment="Left"/> <xctk:DoubleUpDown Name="doubleUpDownQuantity" Grid.Row="3" Grid.Column="4" Margin="2" FormatString="N3" ShowButtonSpinner="False" TextAlignment="Left"/>
<Label Grid.Row="3" Grid.Column="5" Content="kg" /> <Label Grid.Row="3" Grid.Column="5" Content="kg" />
<TextBox Grid.Row="4" Grid.Column="1" Name="textBoxStowagePosition" MaxLength="24" Margin="2" VerticalContentAlignment="Center" /> <TextBox Grid.Row="4" Grid.Column="1" Name="textBoxStowagePosition" MaxLength="24" Margin="2" VerticalContentAlignment="Center" />

View File

@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Text.RegularExpressions;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace bsmd.database namespace bsmd.database
@ -27,6 +28,13 @@ namespace bsmd.database
this.tablename = "[dbo].[IGCPosition]"; 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 #region Properties
[JsonIgnore] [JsonIgnore]
@ -189,6 +197,20 @@ namespace bsmd.database
#endregion #endregion
#region Validation
public override void Validate(List<MessageError> errors, List<MessageViolation> 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
} }
} }

View File

@ -28,6 +28,13 @@ namespace bsmd.database
this.tablename = "[dbo].[IMDGPosition]"; 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 #region Properties
[JsonIgnore] [JsonIgnore]
@ -507,13 +514,16 @@ namespace bsmd.database
if(!this.IMOClass.IsNullOrEmpty()) if(!this.IMOClass.IsNullOrEmpty())
{ {
const string pattern = @"^[1-9]{1}(\.[1-9]{1}([A-Z]{1})?)?$"; if (!imoClassRegex.IsMatch(this.IMOClass))
Regex regex = new Regex(pattern);
if (!regex.IsMatch(this.IMOClass))
errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "IMOClass", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA")); 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())) 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")); errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "StowagePosition AND Bay/Row/Tier SET", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));

View File

@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Text.RegularExpressions;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace bsmd.database namespace bsmd.database
@ -22,6 +23,8 @@ namespace bsmd.database
public class IMSBCPosition : DatabaseEntity, ISublistElement public class IMSBCPosition : DatabaseEntity, ISublistElement
{ {
#region static defs
public static string[] hazardClass = public static string[] hazardClass =
{ {
"A", "A",
@ -29,6 +32,11 @@ namespace bsmd.database
"A and B" "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() public IMSBCPosition()
{ {
this.tablename = "[dbo].[IMSBCPosition]"; this.tablename = "[dbo].[IMSBCPosition]";
@ -230,14 +238,13 @@ namespace bsmd.database
{ {
if(!MHB ?? false) if(!MHB ?? false)
{ {
if(this.UNNumber.IsNullOrEmpty() || this.IMOClass.IsNullOrEmpty()) if(this.UNNumber.IsNullOrEmpty() || !unNumberRegex.IsMatch(this.UNNumber))
violations.Add(RuleEngine.CreateViolation(ValidationCode.V803, null, null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA")); violations.Add(RuleEngine.CreateViolation(ValidationCode.V803, "UNNumber", this.UNNumber, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
}
if(MHB ?? false) 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.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.IMOHazardClass.HasValue) if (!this.IMOHazardClass.HasValue)
{ {