Input Validation
 
The simple validation is managed in the tables:
XConfigValidationFieldContent and XConfigValidationMandatoryFields.
 
Depending on the field type the following validations can be configured in the XConfigValidationFieldContent table:
  • Input type (text, integer, date)
  • Range of the entered values (minimum and maximum of text length, dates or numbers).
  • For text field a regular expression check can be performed (e.g. only digits: ^\d*$ and for two digits - two digits: ^\d\d-\d\d$) 
The field ValidationType is used to configure how strong the validation is. So there is a possibility that the user is warned that the input doesn't match the validation critiria but despite that it can be saved. This is achieved by setting the ValidationType to Yellow. Red means that the validation critiria must be met.
 

In the XConfigValidationMandatoryFields table mandatory fields are configured. In addition fields can be configured as unique or unique in combination. The following fields can be set to true or false, or just kept empty.
  • IsMandatory 
  • IsUnique
  • IsUniqueInCombination: For this case at least two fields of the same entity must be set up as unique in combination.  
To mark the fields with validation errors in the following code must be added to each  field:

<TextBox Grid.Column="1" Margin="5,108,5,0" Name="FiAccountNameEn" Height="23" Text="{Binding FiAccountNameEn, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" ... />

 
In addition to the standard validation feature also context dependent validation can be added in code. The following code is used in the FiTransaction module to validate that the credit sum equals the debit sum. It is placed in the Business Entity class FiTransactionHeader.

public override P2Validator Validator
{
 get
 {
  if (_validator == null)
  {
   _validator =
new P2Validator(Properties.Settings.Default.ModuleName,
  
this.EntityName, "FiTransactionHeaderID", this);
  
_validator.CompareValidators.Add(new P2ValidationItemCompare()
   {PropertyName1 = "CreditTransactionSum",
   
PropertyName2 = "DebitTransactionSum",
    ClassName = "FiTransactionHeader",
   
Operation = P2ValidationItemCompare.Operations.Equal,
   
ValidationType =
P2ValidationStatus.red});
  };
 return _validator;
 }
}