small error fixes and additions

This commit is contained in:
Daniel Schick 2023-11-09 07:19:47 +01:00
parent 1e0dbb8c8c
commit c3b839635b
4 changed files with 67 additions and 56 deletions

View File

@ -155,6 +155,13 @@
</MultiDataTrigger.Conditions> </MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Yellow" /> <Setter Property="Background" Value="Yellow" />
</MultiDataTrigger> </MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Elements, Converter={util:CutoffConverter}, ConverterParameter=0}" Value="True" />
<Condition Binding="{Binding Path=MessageNotificationClass}" Value="{x:Static data:Message+NotificationClass.PASD}" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Yellow" />
</MultiDataTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</DataGrid.RowStyle> </DataGrid.RowStyle>

View File

@ -273,6 +273,8 @@ namespace bsmd.database
return result; return result;
} }
public override string Title => "CREWA";
#endregion #endregion
#region Validation #region Validation

View File

@ -312,6 +312,8 @@ namespace bsmd.database
return result; return result;
} }
public override string Title => "PASA";
#endregion #endregion
#region Validation #region Validation

View File

@ -208,7 +208,7 @@ namespace bsmd.database
if(((value.Length >= 90) && isStandardML) || ((mla.MaxLength == value.Length) && (value.Length > 20) && !isStandardML)) if(((value.Length >= 90) && isStandardML) || ((mla.MaxLength == value.Length) && (value.Length > 20) && !isStandardML))
{ {
// put out a warning this might be truncated // put out a warning this might be truncated
violations.Add(RuleEngine.CreateViolation(ValidationCode.TRUNCATE, property.Name, value, entity.Title, identifier, entity.Tablename)); violations.Add(RuleEngine.CreateViolation(ValidationCode.TRUNCATE, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
@ -220,7 +220,7 @@ namespace bsmd.database
if (value.MaxLenNoWS() > mwla.MaxWordLength) if (value.MaxLenNoWS() > mwla.MaxWordLength)
{ {
// put out a warning this might be overflowing in the report // put out a warning this might be overflowing in the report
violations.Add(RuleEngine.CreateViolation(ValidationCode.WORDOVERFLOW, property.Name, value, entity.Title, identifier, entity.Tablename)); violations.Add(RuleEngine.CreateViolation(ValidationCode.WORDOVERFLOW, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
@ -229,68 +229,68 @@ namespace bsmd.database
switch (validationCode) switch (validationCode)
{ {
case ValidationCode.NOT_NULL: case ValidationCode.NOT_NULL:
if (value.Length == 0) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (value.Length == 0) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
break; break;
case ValidationCode.LOCODE: case ValidationCode.LOCODE:
{ {
Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$"); Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$");
if (!rgx.IsMatch(value)) if (!rgx.IsMatch(value))
{ {
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
else if (_locodeChecker != null) else if (_locodeChecker != null)
{ {
if (!_locodeChecker(value, LocodeMode.STANDARD)) if (!_locodeChecker(value, LocodeMode.STANDARD))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
break; break;
case ValidationCode.LOCODE_NOPORT: case ValidationCode.LOCODE_NOPORT:
{ {
Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$"); Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
if (_locodeChecker != null) if (_locodeChecker != null)
if (!_locodeChecker(value, LocodeMode.NO_PORT_FLAG)) if (!_locodeChecker(value, LocodeMode.NO_PORT_FLAG))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.LOCODE_SSN: case ValidationCode.LOCODE_SSN:
{ {
Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$"); Regex rgx = new Regex("^[A-Z]{2}[A-Z0-9]{3}$");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
if (_locodeChecker != null) if (_locodeChecker != null)
if (!_locodeChecker(value, LocodeMode.SSN)) if (!_locodeChecker(value, LocodeMode.SSN))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.LOCODE_GER: case ValidationCode.LOCODE_GER:
{ {
if(!RuleEngine.gerLocodeList.Contains(value)) if(!RuleEngine.gerLocodeList.Contains(value))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.INT_GT_ZERO: case ValidationCode.INT_GT_ZERO:
{ {
if (!Int32.TryParse(value, out int intVal) || intVal <= 0) if (!Int32.TryParse(value, out int intVal) || intVal <= 0)
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.DOUBLE_GT_ZERO: case ValidationCode.DOUBLE_GT_ZERO:
{ {
if (!Double.TryParse(value, out double dVal) || dVal <= 0) if (!Double.TryParse(value, out double dVal) || dVal <= 0)
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.GISIS: case ValidationCode.GISIS:
{ {
Regex rgx = new Regex("[0-9]{4}"); Regex rgx = new Regex("[0-9]{4}");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.FLAG_CODE: case ValidationCode.FLAG_CODE:
{ {
if(!RuleEngine.NationalityChecker(value)) if(!RuleEngine.NationalityChecker(value))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.OPTIONAL_FLAG_CODE: case ValidationCode.OPTIONAL_FLAG_CODE:
@ -298,14 +298,14 @@ namespace bsmd.database
if(!value.IsNullOrEmpty()) if(!value.IsNullOrEmpty())
{ {
if (!RuleEngine.NationalityChecker(value)) if (!RuleEngine.NationalityChecker(value))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
break; break;
case ValidationCode.TWO_DIGIT: case ValidationCode.TWO_DIGIT:
{ {
Regex rgx = new Regex("[0-9]{2}"); Regex rgx = new Regex("[0-9]{2}");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.STRING_EXACT_LEN: case ValidationCode.STRING_EXACT_LEN:
@ -313,54 +313,54 @@ namespace bsmd.database
if (!value.IsNullOrEmpty()) if (!value.IsNullOrEmpty())
{ {
if (value.Length != maxlen) if (value.Length != maxlen)
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
break; break;
case ValidationCode.STRING_MAXLEN: case ValidationCode.STRING_MAXLEN:
{ {
if (value.Length > maxlen) if (value.Length > maxlen)
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.STRING_IMOCLASS: case ValidationCode.STRING_IMOCLASS:
{ {
Regex rgx = new Regex(@"[1-9]{1}(\.[1-9]{1})?"); Regex rgx = new Regex(@"[1-9]{1}(\.[1-9]{1})?");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.STRING_UNNUMBER: case ValidationCode.STRING_UNNUMBER:
{ {
Regex rgx = new Regex("[0-9]{4}"); Regex rgx = new Regex("[0-9]{4}");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.DRAUGHT_IMPLAUSIBLE: case ValidationCode.DRAUGHT_IMPLAUSIBLE:
{ {
if (!Double.TryParse(value, out double dVal) || dVal <= 0) if (!Double.TryParse(value, out double dVal) || dVal <= 0)
errors.Add(RuleEngine.CreateError(ValidationCode.DOUBLE_GT_ZERO, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(ValidationCode.DOUBLE_GT_ZERO, property.Name, value, entity.Title, identifier, entity.Title));
else else
if ((dVal < 20) || (dVal > 150)) if ((dVal < 20) || (dVal > 150))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
case ValidationCode.TIME_IMPLAUSIBLE: case ValidationCode.TIME_IMPLAUSIBLE:
{ {
if (value.Length == 0) errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Tablename)); if (value.Length == 0) errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Title));
if (DateTime.TryParse(value, out DateTime aTime)) if (DateTime.TryParse(value, out DateTime aTime))
{ {
if ((aTime - DateTime.UtcNow).Minutes > 15) if ((aTime - DateTime.UtcNow).Minutes > 15)
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
break; break;
case ValidationCode.PAST_DATE: case ValidationCode.PAST_DATE:
{ {
if (value.Length == 0) violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Tablename)); if (value.Length == 0) violations.Add(RuleEngine.CreateViolation(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Title));
if (DateTime.TryParse(value, out DateTime aTime)) if (DateTime.TryParse(value, out DateTime aTime))
{ {
if (aTime < DateTime.UtcNow) if (aTime < DateTime.UtcNow)
violations.Add(RuleEngine.CreateViolation(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); violations.Add(RuleEngine.CreateViolation(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
} }
break; break;
@ -368,11 +368,11 @@ namespace bsmd.database
{ {
if(!value.IsNullOrEmpty() && (value.Contains(","))) if(!value.IsNullOrEmpty() && (value.Contains(",")))
{ {
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
} }
if(!value.IsNullOrEmpty() && !value.Trim().Any(char.IsDigit)) // falls "-" oder keine Zahl enthalten, Fehler! if(!value.IsNullOrEmpty() && !value.Trim().Any(char.IsDigit)) // falls "-" oder keine Zahl enthalten, Fehler!
{ {
errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
} }
@ -380,25 +380,25 @@ namespace bsmd.database
{ {
if((value.Length == 0) || (STAT.VesselTypeDict?.ContainsKey(value) == false)) if((value.Length == 0) || (STAT.VesselTypeDict?.ContainsKey(value) == false))
{ {
errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, property.Name, value, entity.Title, identifier, entity.Title));
} }
break; break;
} }
case ValidationCode.NOT_NULL_MAX_LEN: case ValidationCode.NOT_NULL_MAX_LEN:
if ((value.Length > maxlen) || (value.Length == 0)) if ((value.Length > maxlen) || (value.Length == 0))
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
break; break;
case ValidationCode.FRZ: case ValidationCode.FRZ:
{ {
Regex rgx = new Regex("^[A-Z,a-z,0-9]{4,7}$"); Regex rgx = new Regex("^[A-Z,a-z,0-9]{4,7}$");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
break; break;
} }
case ValidationCode.MMSI: case ValidationCode.MMSI:
{ {
Regex rgx = new Regex("^[0-9]{9}$"); Regex rgx = new Regex("^[0-9]{9}$");
if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); if (!rgx.IsMatch(value)) errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
break; break;
} }
case ValidationCode.INVALID_NUMBER_CHARS: case ValidationCode.INVALID_NUMBER_CHARS:
@ -409,7 +409,7 @@ namespace bsmd.database
{ {
if((elems[i].Length > 50) || (elems[i].IndexOfAny(invalidChars) >= 0)) if((elems[i].Length > 50) || (elems[i].IndexOfAny(invalidChars) >= 0))
{ {
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Tablename)); errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
break; break;
} }
} }
@ -505,20 +505,20 @@ namespace bsmd.database
#region private helper #region private helper
public static MessageError CreateError(ValidationCode validationCode, string p, string value, string entityName, public static MessageError CreateError(ValidationCode validationCode, string property, string value, string entityName,
string identifier = "", string notificationClass = "") string identifier = "", string notificationClass = "")
{ {
MessageError error = new MessageError(); MessageError error = new MessageError();
if (identifier.IsNullOrEmpty()) if (identifier.IsNullOrEmpty())
error.FullName = string.Format("{0}.{1}", entityName, p); error.FullName = string.Format("{0}.{1}", entityName, property);
else else
error.FullName = string.Format("{0}.{1}_{2}", entityName, p, identifier); error.FullName = string.Format("{0}.{1}_{2}", entityName, property, identifier);
error.ErrorCode = (int)validationCode; error.ErrorCode = (int)validationCode;
error.Identifier = identifier; error.Identifier = identifier;
error.PropertyName = p; error.PropertyName = property;
var match = Regex.Match(notificationClass, @"\[*\]\.\[(.*)\]"); var match = Regex.Match(notificationClass, @"\[*\]\.\[(.*)\]");
if (match.Success) if (match.Success)
@ -528,11 +528,11 @@ namespace bsmd.database
if (errorTextList.ContainsKey((int)validationCode)) if (errorTextList.ContainsKey((int)validationCode))
{ {
error.ErrorText = string.Format(errorTextList[(int)validationCode], p, value); error.ErrorText = string.Format(errorTextList[(int)validationCode], property, value);
} }
else else
{ {
error.ErrorText = p; error.ErrorText = property;
if (value != null) if (value != null)
error.ErrorText += " - " + value; error.ErrorText += " - " + value;
} }