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:
parent
882861a328
commit
78a72caffc
@ -46,7 +46,7 @@
|
||||
<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" />
|
||||
<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"/>
|
||||
<Label Grid.Row="3" Grid.Column="5" Content="kg" />
|
||||
<TextBox Grid.Row="4" Grid.Column="1" Name="textBoxStowagePosition" MaxLength="24" Margin="2" VerticalContentAlignment="Center" />
|
||||
|
||||
@ -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<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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"));
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user