a

Form Master / Detail (Update)

In this example a complete master / detail application is developed. To build this application two forms are created. The first (Master) is based on the orders table and second (Detail) is based on the orders_details.

Creating the Master form

1. Create a new Simple form application based on the table orders.

2. In the application menu click in Select Fields.

   

3. Remove the fields: ShipVia, ShipRegion e ShipPostalCode

4. In the application menu click in Blocks from the Layout folder.

   

5. Change the block name and label to General Info

6. Click in Create New Block.

7. Enter the values for the attributes Name, Label and Ship Info

   

8. Click in Create New Block again.

9. Enter the values for the attributes Name, Label and Order Details.

10. Edit the created blocks properties according to the image below:

   

11. In the application menu click in Select Fields to organize the field according to the table below:

Block Field
General Info OrderID
CustomerID
EmplyeeID
OrderDate
RequiredDate
PriceOrder
Ship Info ShippedDate
ShipAdress
Freight
ShipCity
ShipState
ShipCountry
Order Details  

 

Creating the detail form

12. Create a new grid application of type Editable grid view based on the table order_details

   

13.In the application menu click in Select Fields.

   

14. Remove the fields OrderDetailsID and OrderID.

   

15. In the application menu click in ProductID in the Field folder.

16. Change Data Type to Select.

17. Access the Edition Lookup tab for the field ProductID.

   

18. Enter the following instructions for the SQL Select Statement :

SELECT ProductID, ProductName
FROM products
ORDER BY ProductID

19. Change the attribute Allow negative value to Yes.

20. Select the New Field option on the Field menu.

   

21. Enter 1 to field quantity and e Click in Next.

22. Select Decimal for the property Type and enter Total for Name and Label . Click in Create.

   

Creating methods for form details

23. In the application menu select the folder Programming->Methods PHP .

   

24. Create a new method called calculate_total

25. Enter the following source code to the calculate_total method:

   

26. Create a new method called check_stock

27. Enter the following source code to the check_stock method:

   

28. Create a new method called update_master

29. Enter the following source code to the update_master method:

   

Creating events Ajax for the detail form

30. In the application menu select the folder Ajax Events.

   

31. Click in New Ajax Event.

32. Select the field Discount for the attribute Select the field to create an event and select onChange for the attribute Select event for Ajax processing. Click in Create Event to finish.

   

33. In the event editor call the method calculate_total.

   

34. Create a new Ajax event for the field ProductID.

35. Enter the following source code for the onChange event :

   

36. Create a new Ajax event for the field Quantity.

37. Enter the following source code for the onChange event:

   

38. Create a new onChange Ajax event for the field UnitPrice.

39. In the event editor call the method calculate_total.

   

Calling the methods from the form created events

40. In the application menu select the Events folder (see image below). As was done for the field events, the methods are called on the form events. In the table below there is a list of methods that must be called at each event.

 

Event Method
onBeforeInsert check_stock();
onAfterInsert update_master();
onBeforeUpdate check_stock();
onAfterUpdate update_master();
onAfterDelete update_master();
onLoadRecord check_stock();

   

41. Generate the detail form source code by clicking in Generate Source in the ScriptCase toolbar.

   

Creating the link between the Master and Detail forms.

42. Return to the Master Form by clicking on the of applications tab

   

43.In the application menu click in New Detail from the Master/Detail Form folder.

   

44. Enter Details for Name and Label. Click in Create.

   

45. Select the detail form and Next.

   

46. Following the wizard directives link the OrderID fields from the the two forms. Click in Save.

   

Untitled Document

Rate this Tutorial
Bad Great
Leave your comments (optional).