StrataFrame Forum

Required Field Checks

http://forum.strataframe.net/Topic2029.aspx

By Joe Paquette - 7/31/2006

According to the help docs:

Required Field Validation

The required fields will be automatically checked during the CheckRulesOnCurrentRow event for each unique row in the business object.  StrataFrame supports the following data types when checking for a required field:

Character - When validating the rules for character data, the string length must be greater than zero.

Numeric - When validating the rules for numeric data, the value must be greater than zero.

Boolean - When validating the rules for Boolean data, the value must be True (or 1).

DateTime - When validating the rules for dates, the date must be greater than or equal to 01/01/1800.

 

The documentation does not match the code.  The code performs the following checks:

Character – For SqlDbType.Text, the string length must be greater than zero.  SqlDbType.Char and SqlDbType.Varchar are not evaluated here.

Numeric – For SqlDbType.BigInt, SqlDbType.Int, SqlDbType.SmallInt, SqlDbType.TinyInt, the value must be greater than zero.  Other non-integer numeric types are not evaluated here.

Boolean - When validating the rules for Boolean data, the value must be True (or 1).

DateTime - When validating the rules for dates, the date must be greater than or equal to 01/01/1800.

All Other Datatypes – The validation checks for NULL values.

 

Recommend BusinessLayer.CheckRequiredFields() method be modified to perform null checks on all datatypes and also check for 0-length strings for all database string datatypes (char, varchar, and text).  Drop the specific processing for Boolean, Numeric, and DateTime.  A Boolean value of FALSE should not be used to indicate an “empty” field.  The existing Boolean required field check implies the TRUE would be the only acceptable value, and this does not make sense.  Custom field validations should be used to handle all non-null Numeric and DataTime field checks.  Since zero (0) and negative numbers are valid numeric values, “> 0” should not be used for a required fields check representing “empty”.  The DataTime required field check is similar.  If a particular implementation uses a specific datatime value (such as 01/01/1800) as a null/invalid field value, that check should be implemented as a custom validation check.

By StrataFrame Team - 8/1/2006

When the required fields are added through the type editor, the required field checked the .NET data type of the field, and since all character fields are System.String, the required field is added with an SqlDbType of Text.  So, that's why none of the other character types are added, because they will not show up in the required fields through the type editor.  As for the integer types (bigint, tinyint, smallint, etc.) the type editor will create all of them with a data type of SqlDbType.Int. 

So, the only change that really needs to be made is to test the separate values for DBNull.Value before the other tests.  Any of the other logic can simply be handled by not choosing the field as a required field (just leave it unchecked) and implementing custom logic for the field.