How it works...

There are few new concepts here, and I'll start with the code structure at the end of the step list.

The most important part of this code is that we didn't write this.ServiceStatus <= ConWHSVehicleServiceStatus::Confirmed. This is an extensible enum, and we can't be sure of the numeric value that the symbols have.

The other part is that we have split what may seem to be a simple if statement in validateWrite into three methods. The reason is reusability. It is nicer to make a record read-only in the form than it is to throw an error when the user tries to save. So, we can use CanEdit to control whether the record is editable on the form, making all controls greyed out.

Check methods are written to simplify the validation methods where they are used, and also to make the checks reusable, ergo consistent. Check methods are expected to return a silent true if the check passes, or to display an error should the check fail. The error is sent to the user using the checkFailed method, which does not throw an exception.

The next is the InitFrom method. This is a very common technique and should always be used to initialize data from foreign tables. The odd thing is that we don't check that it exists first.

This is deliberate. Records in Operations initialize so that all the fields are empty, or zero (depending on the field's type). So, if the record is not found, the values that are initialized will be made to be empty, which is desirable. Also, modifiedField occurs after the field is validated. So, the method won't be triggered should the user enter and invalid vehicle ID. If the vehicle is not mandatory, we may find the vehicle ID is empty; however, again, this is fine.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.111.58