Saturday, 6 May 2017

Four Levels of Data validation on PowerBuilder Datawindows

Powerbuilder validates a data item before it can be moved from the edit control to the underlying dataitem. Validation begins automatically when the data is changed and the user presses the enter key or tabs to another field in the datawindow control thus changes the focus. Validation can also be forced using on AcceptText() function.

During the time the data is being validated the contents of the editcontrol and values of the item may be different. The data is moved from the editcontrol to the underlying item only when it passes all four levels of validation. These four levels of validation are:
  • Did the user change any data?
  • Whether the user-entered data (in edit control) and the underlying data item are of the same data type
  • Validation rules specified for columns through the datawindow object painter
  • Advanced validation done through the itemchanged event
I Level - Did the user change any data?
In this level, the datawindow control tests the contents of the edit control to see if it is different from the data in the item in the datawindow control. When the user simply tabs to a different field, the datawindow control knows that nothing has changed, stops further validation, and allows the user to move to a different field. If the values has changed, the validation continues on to the next level.

II Level - Data type check
PB checks the datatype of the edit control matches the datatype of the underlying item in the datawindow control. If they are the same validation continues to the next level. If the validation fails the user receives a standard message informing that the entry did not pass the validation rules and the cursor is returned to the edit control. You can also write a custom error message. Gettext() functions retrieves the contents of the edit control. Getltemxxx() retrieves the contents of the item in the edit control. You must use one of the following Getitem function that corresponds to the underlying data type.
GetltemString()
GetltemNumber()
GetltemDate()
GetltemTime()
GetltemDateTime()

But remember the data type of editcontrol is always string and the GetText function always returns a string.

III Level - Validation rules
You can define validation rules for a column when you create a datawindow object.

IV - Level - ItemChanged Event
The itemchanged event is the fourth and final level of validation. You can use this for integrity checking and cross table validations
Thanks,
Pushparaj

No comments: