Automatic Data Validation: Difference between revisions

From OpenPetra Wiki
Jump to navigation Jump to search
No edit summary
Line 14: Line 14:
*** these are calls to auto-generated data validation methods which are found in Shared DLL's
*** these are calls to auto-generated data validation methods which are found in Shared DLL's


'''All that generated code is solely for the ''automatic'' data validation of Controls ''which are bound to certain DataColumns of OpenPetra DB Tables'''''.
'''Scope:'''
 
* Generated code in Shared DLL's and in Server DLL's is for the automatic data validation of all DataColumns of all OpenPetra DB Tables (as specified in petra.xml).
* Generated code in Client DLL's is solely for the automatic data validation of Controls ''which are bound to DataColumns of OpenPetra DB Tables that are found on the individual Forms/UserControls''.


==Scope==
==Scope==

Revision as of 13:27, 15 Haziran 2012

Introduction

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

The ORM Generator for Cacheable DataTables creates program code...

  • in Shared DLL's
    • auto-generated data validation methods (get placed in separate *-generated.cs-files [e.g. 'Common.Validation-generated.cs']).
  • in Server DLL's
    • in the generated C# files for Cacheable DataTables
      • these are calls to auto-generated data validation methods which are found in Shared DLL's

The WinForms Generator automatically creates program code...

  • in Client DLL's
    • in the generated C# files of Forms/UserControls
      • these are calls to auto-generated data validation methods which are found in Shared DLL's

Scope:

  • Generated code in Shared DLL's and in Server DLL's is for the automatic data validation of all DataColumns of all OpenPetra DB Tables (as specified in petra.xml).
  • Generated code in Client DLL's is solely for the automatic data validation of Controls which are bound to DataColumns of OpenPetra DB Tables that are found on the individual Forms/UserControls.

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 are 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 and the automatically generated code in the C# files for Cacheable DataTables on the server side call automatically generated data validation Methods in the shared DLL's.

That called Method performs the actual Data Validation:

  • If a Data Validation Error or Warning is identified, a TVerificationResult object is created for it
    • 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/Warning 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 in the 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

Calls to automatic data validation code contained in Shared DLL's are automatically be placed in all the appropriate places of a generated C# file of all Cacheable DataTables.

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 the Class that contains Cacheable DataTables). 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).