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>
<Setter Property="Background" Value="Yellow" />
</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>
</DataGrid.RowStyle>

View File

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

View File

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

View File

@ -208,7 +208,7 @@ namespace bsmd.database
if(((value.Length >= 90) && isStandardML) || ((mla.MaxLength == value.Length) && (value.Length > 20) && !isStandardML))
{
// 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)
{
// 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)
{
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;
case ValidationCode.LOCODE:
{
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));
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
}
else if (_locodeChecker != null)
{
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;
case ValidationCode.LOCODE_NOPORT:
{
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(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;
case ValidationCode.LOCODE_SSN:
{
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(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;
case ValidationCode.LOCODE_GER:
{
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;
case ValidationCode.INT_GT_ZERO:
{
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;
case ValidationCode.DOUBLE_GT_ZERO:
{
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;
case ValidationCode.GISIS:
{
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;
case ValidationCode.FLAG_CODE:
{
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;
case ValidationCode.OPTIONAL_FLAG_CODE:
@ -298,14 +298,14 @@ namespace bsmd.database
if(!value.IsNullOrEmpty())
{
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;
case ValidationCode.TWO_DIGIT:
{
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;
case ValidationCode.STRING_EXACT_LEN:
@ -313,54 +313,54 @@ namespace bsmd.database
if (!value.IsNullOrEmpty())
{
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;
case ValidationCode.STRING_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;
case ValidationCode.STRING_IMOCLASS:
{
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;
case ValidationCode.STRING_UNNUMBER:
{
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;
case ValidationCode.DRAUGHT_IMPLAUSIBLE:
{
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
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;
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 ((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;
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 (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;
@ -368,11 +368,11 @@ namespace bsmd.database
{
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!
{
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;
}
@ -380,25 +380,25 @@ namespace bsmd.database
{
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;
}
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));
errors.Add(RuleEngine.CreateError(validationCode, property.Name, value, entity.Title, identifier, entity.Title));
break;
case ValidationCode.FRZ:
{
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;
}
case ValidationCode.MMSI:
{
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;
}
case ValidationCode.INVALID_NUMBER_CHARS:
@ -409,7 +409,7 @@ namespace bsmd.database
{
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;
}
}
@ -505,20 +505,20 @@ namespace bsmd.database
#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 = "")
{
MessageError error = new MessageError();
if (identifier.IsNullOrEmpty())
error.FullName = string.Format("{0}.{1}", entityName, p);
error.FullName = string.Format("{0}.{1}", entityName, property);
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.Identifier = identifier;
error.PropertyName = p;
error.PropertyName = property;
var match = Regex.Match(notificationClass, @"\[*\]\.\[(.*)\]");
if (match.Success)
@ -528,11 +528,11 @@ namespace bsmd.database
if (errorTextList.ContainsKey((int)validationCode))
{
error.ErrorText = string.Format(errorTextList[(int)validationCode], p, value);
error.ErrorText = string.Format(errorTextList[(int)validationCode], property, value);
}
else
{
error.ErrorText = p;
error.ErrorText = property;
if (value != null)
error.ErrorText += " - " + value;
}