Customizing a Data Dictionary for the Inventory Parts Table
In this section, you will customize the cInventoryDataDictionary that was automatically created when you created the table. You will add some business rules and other settings to the Data Dictionary. The reason for each Data Dictionary setting you apply will be explained.
The exceptions are business rules already explained when you created the previous Data Dictionaries in the Customizing the Data Dictionaries book. Most explanations can be read on the Customizing a Data Dictionary for the Customer Table page, since this is the first Data Dictionary created.
Steps to Customize the Data Dictionary
-
In Table Explorer, expand the
Inventorytable to display its Columns, Indexes, Relationships, and Data Dictionaries. You will seecInventoryDataDictionarylisted. -
Double-click on the
cInventoryDataDictionaryclass. The class will now open in the Studio's Data Dictionary Designer. -
Select the
Item_Idcolumn and set theAuto Find EQ,Capslock, andProtect Value (Key)options in theData Entry Optiongroup toTrue. -
Select the
Vendor_Idcolumn and set theCapslockoption toTrue. -
Select the
Unit_Pricecolumn, then select theValidation Typeoption in theLookup/Validationgroup. -
Click on the
Prompt (...)button in theValidation Typeoption form. This will open theColumn Validationdialog. - Select the
Rangeradio button. Enter0in theRange Fromform and999999.99in theToform, then clickOk.
Back on the Columns tab page of the Data Dictionary Designer, you will see 0, 999999.99 filled in as the Validation Type. This disallows any negative entries or entries over $1 million.
-
For the
On_Handcolumn, create another range validation and enter-999999and999999inRange FromandTo, respectively. -
Select the
Unit_Pricecolumn and set theMask Typeoption in theAppearancegroup toMask_Currency_Window. -
Select the
Item_Idcolumn and set the following options in theAppearancegroup: Long Label:Inventory.Item IdShort Label:Item IdStatus Help:Inventory Item ID - user defined identification
Select the Description column and set the following options:
- Long Label: Inventory.Description
- Short Label: Description
- Status Help: Inventory Part Description
Select the Vendor_Id column and set the Status Help option to Vendor Number.
Select the Vendor_Part_Id column and set the Status Help option to Vendor ID name for this item.
Select the Unit_Price column and set the Status Help option to Retail unit price.
Select the On_Hand column and set the Status Help option to Units currently available.
-
Click on the
Structuretab page of the Data Dictionary Designer. -
For Key Foreign Field Options, verify that
Find RequiredandNo Putare checked. - For Indexed Foreign Field Options, only
No Putshould be checked. - For Default Foreign Field Options, only
Display Onlyshould be checked.
Business Rule #4 states that if an item appears on an order, you cannot delete the item from the Inventory Report. Restated in database terms: if a parent record has child records, do not delete the parent record. More specifically, if an item appears in the OrderDetail table, then it cannot be deleted from the Inventory table.
-
In the Properties window, set the
Cascade_Delete_Stateproperty toFalse.Business Rule #3 states that the quantity sold of an item cannot exceed the number that exists in inventory stock. We can restate this business rule in DataFlex database terms as "you cannot order an item if the value in
Inventory.On_Handwould be less than zero afterwards." -
In the Properties window, click on the
Eventstab.- Double-click on
Validate_Save. When you have completed this process, theValidate_Saveevent will be listed in the code editor (and the Studio has switched from the Data Dictionary Designer to the code editor).
- Double-click on
-
Modify the
Validate_Savemethod to look like the code below:Function Validate_Save Returns Integer Integer iRetVal Forward Get Validate_Save To iRetVal If iRetVal Function_Return iRetVal If (Inventory.On_Hand < 0) Begin Send UserError "Insufficient Inventory Stock" "" Function_Return 1 End End_FunctionThe code above for the function that implements this business rule simply augments the
Validate_Savemessage to return an error if the user tries to enter more of an item than is available. A save is only performed on a function return value of0, so returning1(or a non-zero value) means no save takes place.Notice that we did not try to accomplish this validation by using
set Field_Value_Range. The inventory quantity check can only be performed while the record is being saved and the record is locked.Validate_Saveis called right before the actual save. All required records are locked and all columns have been updated. The value in the column is the value that will be saved (i.e., any quantity adjustments have already taken place).All other validations occur during data entry or at the start of a save process before any locking has taken place.
Validate_Saveis special in that it occurs in a locked and fully updated state. These validations should be as quick as possible. Also note that theerrorcommand in this function will not be executed in a locked state. Before the error is reported, the transaction is canceled and rolled back as required. DataFlex does this for you automatically. -
Click the
Save Filetoolbar button (or pressCtrl + S) to save the Data Dictionary.