Instructions for the Implementation of Data Validation: Difference between revisions
Line 15: | Line 15: | ||
'''Examples''' | '''Examples''' | ||
* <code>dtpDetailMailingDate: {Label=Mailing Date, Validation=True}</code> (found in \csharp\Petra\Client\MPartner\Gui\Setup\MailingSetup.yaml) | * <code>dtpDetailMailingDate: {Label=Mailing Date, ''Validation=True''}</code> (found in \csharp\Petra\Client\MPartner\Gui\Setup\MailingSetup.yaml) | ||
Once the YAML file gets (re-)generated with the WinForms Generator (using the <code>nant | Once the YAML file gets (re-)generated with the WinForms Generator (using the <code>nant generateWinforms</code> command), support for Data Validation will be added to the auto-generated C# code file of the Form/UserControl if the 'Validation' property has been set to 'true' for at least one Control. (If automatically generated Data Validation code for Controls is present in the auto-generated C# code file of the Form/UserControl, support for Data Validation will be added/will have been added to that file even if no manual Data Validation is specified.) | ||
=====Multiple Controls involved in a single Data Validation===== | =====Multiple Controls involved in a single Data Validation===== | ||
'''TODO''' | '''TODO''' | ||
====*.ManualCode.cs File==== | ====*.ManualCode.cs File==== |
Revision as of 15:20, 18 Mayıs 2012
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!!!
Overview
In OpenPetra, different aspects of Data Validation need to be implemented in several places to make the whole 'Data Validation Framework' work - on Client Side and Server Side.
The sections below detail what needs to be done and in which places to make Data Validation work. Following the way that is presented in those sections will help you in creating Data Validation and should help the whole development team to code Data Validation in a common and standardised way.
Client Side
YAML File of a Form or UserControl
- For every Control to which manual Data Validation should be added, the Attribute Validation=true needs to be added.
- The 'Validation' Attribute is not available for Controls that group other controls, such as GroupBoxes, Panels, TabPages, UserControls, etc. - It is available only for individual Controls.
Examples
dtpDetailMailingDate: {Label=Mailing Date, Validation=True}
(found in \csharp\Petra\Client\MPartner\Gui\Setup\MailingSetup.yaml)
Once the YAML file gets (re-)generated with the WinForms Generator (using the nant generateWinforms
command), support for Data Validation will be added to the auto-generated C# code file of the Form/UserControl if the 'Validation' property has been set to 'true' for at least one Control. (If automatically generated Data Validation code for Controls is present in the auto-generated C# code file of the Form/UserControl, support for Data Validation will be added/will have been added to that file even if no manual Data Validation is specified.)
Multiple Controls involved in a single Data Validation
TODO
*.ManualCode.cs File
In order for the manual Data Validation to be doing something useful, the following Method needs to be present in the *.ManualCode.cs file of the Form/UserControl:
private void ValidateDataDetailsManual(RowType ARow)
(where RowType is the Type of the Typed DataRow that is to be validated in this screen, e.g. 'PMailingRow' for a screen that edits 'p_mailing' DB Table records)
After adding this Method, nant generateWinForms
needs to be run for the corresponding YAML file. This ensures that this Method is called from the generated code of the Form/UserControl and that through that the manual Data Validation code will be run in all circumstances where it needs to be run.
The content of the Method follows a standard pattern:
- The content of the first line is always
TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;
- A single empty line follows.
- A single call to a Method that is to be defined in a Shared DLL follows. That Method performs the actual Data Validation.
NOTE: Although the called Method could reside in a client-side DLL, doing so will make it impossible to perform the Data Validation from the server side! Since we want Data Validation to work both on client and on server side, the Method that contains the Data Validation code needs to be placed in shared DLL's!
Sample code: (found in file \csharp\ICT\Petra\Client\MPartner\Gui\Setup\MailingSetup.ManualCode.cs)
private void ValidateDataDetailsManual(PMailingRow ARow) { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TSharedPartnerValidation_Partner.ValidateMailingSetup(this, ARow, ref VerificationResultCollection, FPetraUtilsObject.ValidationControlsDict); }
For information about the called Method that is to be defined in a Shared DLL and which performs the actual Data Validation please see the section Shared Libraries.
For Information Only: Generated Form File
TODO
The Data Validation Method
The Method ValidateDataDetailsManual
situated in the *.ManualCode.cs file of the Form/UserContro needs to call a Method in a shared DLL.
That 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.
NOTE: Although this Method could reside in a client-side DLL, doing so will make it impossible to perform the Data Validation from the server side! Since we want Data Validation to work both on client and on server side, the Method that contains the Data Validation code needs to be placed in shared DLL's!
Typical Method signature:
public static void ValidateMailingSetup(object AContext, PMailingRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
The Method needs to have a ref VerificationResultCollection
Argument, among other Arguments. By modifying that Collection, this Method can add or remove specific TVerificationResult objects to/from the Form's Collection of TVerificationResult objects (which is always held in the FPetraUtilsObject.VerificationResultCollection object).
(The Method can optionally inspect that Collection for other TVerificationResult objects and evaluate those [that is needed only for complex data validation scenarios, though]. As the Collection will hold all TVerificationResult objects of the Form, TVerificationResult objects from other parts of the screen [namely those created by another UserControl, perhaps situated even on a different TabPage of the same Form] can be inspected!)
The content of the Method follows a standard pattern:
- There is a Variable declaration section. This is 'boiler plate' code.
- 1..n 'Data Validation Code Blocks' follow.
Each 'Data Validation Code Block' follows a standard pattern:
- The DataColumn that is to be validated is stored in the ValidationColumn Variable
- A check is done whether that DataColumn should be validated at the current execution of the Method. This is done with a single line of 'boiler plate' code.
- If so,
- the actual data validation code is run,
- the addition/removal of the corresponding TVerificationResult is handled. Again, this is done with a single line of 'boiler plate' code.
The check whether the DataColumn should be validated seems strange, but that makes it possible to check for a different set of DataColumns, depending if the Method got called from the client-side or the server-side of OpenPetra.
Sample code: (found in \csharp\ICT\Petra\Shared\lib\MPartner\validation\Partner.Validation.cs)
// 'MailingDate' must not be empty ValidationColumn = ARow.Table.Columns[PMailingTable.ColumnMailingDateId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { // actual Data Validation code goes here // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); }
Data Validation Code for a single Data Validation Code Block
TODO
Utilising Special Functionality
Accessing a Cacheable DataTable
- Use Ict.Petra.Shared.TSharedDataCache
TODO
Accessing Server-side Functionality that is exposed to the Client
Example: Calling the TServerLookup.TMPartner.VerifyPartner Method
- PetraClientMain.cs, InitialiseClasses: TSharedPartnerValidationHelper.VerifyPartnerDelegate = @TServerLookup.TMPartner.VerifyPartner;
- Ict.Petra.Shared.MPartner.Validation.TSharedPartnerValidationHelper
- public static TVerifyPartner VerifyPartnerDelegate
- public static bool VerifyPartner
TODO
TODO
Server Side
TODO