Tuto WEBDEV 25
Part 3: Intranet site with data 127 Let’s study this code: • If the product identifier is set to -1, it means that we are adding a product. In this case, HReset is run. This function initializes the item variables in the "Product" data file with the default values to manage a new record. • If the product identifier has a value different from -1, we retrieve the code used to open the form in modification. 6. Close the code window. ▶ The "Validate" Button control must also support the addition of the record. 1. Select the "Validate" Button control in "PAGE_Product_form". 2. Display the WLanguage events associated with the control (F2). 3. The code in the event "Click (browser)" must not change: the checks to perform are always the same. Only the server code must be modified. 4. In the "Click (Server)" event, replace the existing code with the following code: PageToFile() IF gsImagePath <> "" THEN Product.Visual = fLoadBuffer(gsImagePath) END IF Product..NewRecord THEN HAdd(Product) ELSE HModify(Product) END PageDisplay(PAGE_List_of_products) Let’s study this code: • ..NewRecord is used to find out whether the current record must be created. • If HReset has been called previously, the property returns True (new product) and the record must be created by HAdd . • Otherwise, the current record already exists and it must be modified by HModify . • HAdd adds the record into the data file. This function takes the values in memory and writes the content of file items into the data file itself. The indexes are immediately and automatically updated. In this case, it is the "Product" data file that is updated. Remark The test code of new record can be replaced by HSave . This function is used to check whether the record is already found in the data file, and it allows you to add it or to modify it. The WLanguage code becomes: PageToFile() IF gsImagePath <> "" THEN Product.Visual = fLoadBuffer(gsImagePath) END HSave(Product) PageDisplay(PAGE_List_of_products)
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==