Automatic Data Validation

From OpenPetra Wiki
Jump to navigation Jump to search

DOCUMENTATION IS WORK IN PROGRESS

This wiki page is under construction. Information contained on it should not be relied on until this message is no longer present!!!

Introduction

The term 'Automatic Data Validation' relates to Data Validation code that is automatically generated by the OpenPetra WinForms Generator.

The WinForms Generator automatically creates program code...

  • in Client DLL's (in the generated C# files of Forms/UserControls),
  • in Shared DLL's and
  • in Server DLL's

...for the automatic data validation of Controls which are bound to certain DataColumns of OpenPetra DB Tables.

Scope

Automatic Data Validation code is generated only for DB Tables that are specified in the petra.xml file!

DataColumns in the petra.xml file for which automatic data validation code is generated:

  • DataColumns which are part of a Primary Key or are part of a Unique Key
    • Data Validation code enforces that NULL must never be assigned to those DataColumns.
  • DataColumns with a NOT NULL restriction (applies to any DataColumn that isn't part of a Primary Key or Unique Key)
    • Data Validation code enforces that NULL must never be assigned to such a DataColumn.
  • DataColumns of varchar/string Type
    • Data Validation code enforces that the length of the String is not exceeded.
  • DataColumns of a numeric Type
    • Data Validation code enforces that the numeric range of the Type (e.g. Int16, Int32, Decimal) and it's precision (if applicable) is not exceeded.

Multiple automatic data validations may be generated for a single DataColumn to enforce multiple rules! Example: Automatic data validation code that will be created for a varchar/string column which is part of a Unique Key: 1) code for a NOT NULL check, 2) code for a string length check.


Placement of Automatic Data Validation Code

Client DLL's

Calls to automatic data validation code contained in Shared DLL's will automatically be placed in all the appropriate places of a generated C# file of a Form/UserControl. The only requirement for this to happen is that the YAML file that specifies the Form/UserControl contains data bound Controls. Validation=true does not need to be set on Controls for that to happen - this must only be done to indicate to the WinForms Generator that manual data validation code needs to be called for a DataColumn that is bound to that Control!

Calls to the automatic data validation code always precede calls to the manual data validation code (if manual data validation code is present at all in a Form/UserControl). This allows manual data validation code to modify the TVerificationResult objects that the automatic data validation code may create, should that be necessary (e.g. to modify the standard texts that are presented to the user for).


Shared DLL's

The automatically generated code in the *.ManualCode.cs file of the Form/UserControl that calls the automatic data validation calls a Method in a shared DLL to do this.

That called Method performs the actual Data Validation:

  • If a Data Validation occurs, a TVerificationResult object is created
    • the TVerificationResult object gets appended to a Collection that is held in the Form where the Data Validation is run.
  • Once a Data Validation error got rectified by the user, the corresponding TVerificationResult object is removed from the Collection.

More details about the code in Shared DLL's can be found here. - Though that section relates to manually written code, the same applies for the automatically generated code, with the exception of the Method names, which are ValidateData / ValidateDataDetails instead of ValidateDataManual / ValidateDataDetailsManual, respectively.

Regarding the placement of the automatically data validation code in the various C# files and Shared DLL's please refer to this section, which again relates to manually written code, but the same applies for the automatically generated code.

Server DLL's

TODO