There's more...

We should add number sequence handling logic to the ConVMSVehicleTable form.

We don't need a form handler class in this case; we can add the methods directly to the ConVMSVehicleTable form. Declare the NumberSeqFormHandler class global to the form and write the initialize method also at the form level. Call the method after the super() call in init. In each data source method we changed in this recipe, just call numberSeqFormHandler(element, ConVMSVehicleTable_DS).<method> directly.

The CustTable form is a good example of this.

You can also create a type class for this. This isn't usually required for Main tables as the business logic on these tables is not as complicated.

Feel free to challenge yourself on this. To save time, we can copy the ConVMSVehicleServiceTableType class and refactor it to our purposes. The following steps cover how to add number sequence handling logic to the form. In this case, they are summarized, as the tasks are very similar to the recipes we have already covered. To do this, follow these steps:

  1. Open the code for the ConVMSParameters table.
  2. Copy and paste the NumRefServiceId method, changing it so that it reads as follows:
public static NumberSequenceReference NumRefVehicleId()
{
return NumberSeqReference::findReference(extendedTypeNum(
ConVMSVehicleId));
}
  1. Save and close the editor.
  2. Create a new class named ConVMSVehicleTableType.
  3. Copy the contents of ConVMSVehicleServiceTableType (everything inside the outermost braces) and paste it into our new class.
  1. Now for a series of find and replace. Double-click on ConVMSVehicleServiceTable so that it's highlighted and press Ctrl + H. Enter ConVMSVehicleTable in the second textbox and ensure Match case is selected it should look as follows:

  1. The two icons to the right of the second textbox are Replace next and Replace all. In our case, replacing all occurrences is fine, and you can do this by pressing Alt + A.
  2. Do the same to replace serviceTable with vehicleTable, ensuring that case-sensitivity is selected.
  3. Then, replace all occurrences of Service with Vehicle, following by service with vehicle.
It is always prudent to look at the code to check that it will only affect the code that you want it to. The code editor will highlight the changes in yellow.
  1. Edit the remaining methods so that the validate methods all just return true and remove the code from the modifeidField method. The only methods with code should be the number sequence methods, the Construct method, and the ParmConVMSVehicleTable method.
  2. Just like we did for ConVMSVehicleServiceTable, create the Type method and override the insert, delete, update, validateField, validateWrite, validateDeleteand modifiedField methods to be able to call the methods on the ParmConVMSVehicleTableType class. You can copy and paste these methods if desired and rename them as required. Remove the four CanEdit methods as they are not required in this class:
We have already modified the validateField method, so this should be migrated to the type class.
  1. Finally, modify the ConVMSVehicleTable form as we did the ConVMSVehicleServiceTable form in order to hook up the number sequence. The only difference is the Create method since we don't have a create form. We just need to call the formMethodDataSourceCreate method and place the following code after the super() call on the overridden create data source method:
if (!vehicleTableType)
{
vehicleTableType = ConVMSVehicleTable.type();
}
vehicleTableType.formMethodDataSourceCreate( element, this);

The remaining methods are simple refactored copies from the ConVMSVehicleServiceTable form. In order to test this, a number sequence should be created and associated with Vehicle Service Id. It should honor all the settings on the number sequence.

Take care when refactoring. The order of find and replace is important and it will only affect the code we want to and that the casing is respected.