Tuto WEBDEV 25

126 Part 3: Intranet site with data Adding a new product via the "Product form" page We just explained how to modify a product. Now, we want to be able to add a product. To do so, there is not need to re-create a new page: we will be using the "PAGE_Product_form" page that was created beforehand and adapt it to manage the addition. ▶ First of all, we are going to modify the opening mode of "PAGE_Product_form" page: 1. Position on the "Product form" page: click the "PAGE_Product_form" button found in the open documents bar. 2. Press F2 to display the different WLanguage events of the page. 3.  In the "Global declarations" event, we are going to give a default value to the parameter passed to the page. Indeed, when modifying the record, the parameter passed always corresponds to the identifier of product to modify. But when adding a record, the element identifier does not exist. To manage this case, we will be using the default value "-1". 4. Replace the following line of code in the "Global declarations" event: PROCEDURE MyPage(gnProductID is 8-byte int) by the code: PROCEDURE MyPage(gnProductID is 8-byte int = -1) 5. We must now manage the value "-1" (when adding a record). Replace the following code: HReadSeekFirst(Product,ProductID,gnProductID) IF HFound(Product) = False THEN // Display the list of products PageDisplay(PAGE_List_of_products) END FileToPage() by the code: IF gnProductID = -1 THEN HReset(Product) ELSE HReadSeekFirst(Product,ProductID,gnProductID) IF HFound(Product) = False THEN // Display the list of products PageDisplay(PAGE_List_of_products) END END FileToPage()

RkJQdWJsaXNoZXIy NDQ0OA==