Customer Update - democupd.bbx

This program is launched from the Customer Maintenance form. It reads the CGI input stream for form values and adds or updates the customer record accordingly.

0001 SETERR ERRTRAP
0010 REM "democupd.bbx - BASIC Web Utility demo customer update from entry form
0020 REM "Copyright 1996 by Allen Miglore. All rights reserved.
0030 REM "Permission to derive programs from this is hereby granted,
0040 REM "provided said programs utilize licensed copies of the BASIC Web Utility.
0100 REM ^100 - Open customer file
0110 LET CUSTCHAN=UNT;
OPEN (CUSTCHAN)"GENSMPL1"

For a new customer entry, the CGI value "cust_id" contains blanks, and the program jumps to the new customer entry label. An existing customer, selected from the customer list, will have a hidden value on the form that contains the ID, and the current record is read into CUST$.

0200 REM ^100 - Get current record
0210 EXTRACT RECORD(CUSTCHAN,KEY=CGI.CUST_ID$,DOM=NEW_CUSTOMER)CUST$

On an existing record, the contents of the form are updated into the contents of the CUST$ record using the utfrmin.wbb program. The record is then updated, and the program continues.

Concurrency issues are not addressed in the sample programs because the task that loaded the maintenance form cannot retain a lock on the record. There are several methods for managing records that cannot be locked during maintenance. One method is to store a CRC value as a hidden field on the form, calculated from the record used to generate the form. When the current record is loaded in the update program, the CRC values can be compared to determine if a change was made to the record after the form was displayed, and appropriate action can be taken.

0300 REM ^100 - Fill in form data
0310 CALL "utfrmin.wbb",CGI$,CUST$
0400 REM ^100 - Update record
0410 WRITE RECORD(CUSTCHAN)CUST$

When the customer is updated or added, a message is stored in MSG$, indicating success. The customer entry program is run, which builds a new form for the customer, showing their changes, and also displays the MSG$ value so the user can see that the last update was successful.

0500 CONTINUE:
REM ^100 - redisplay form to show updated data
0510 LET MSG$="Updated "+CVS(CUST.NAME$,3)+" ("+CUST.CUST_ID$+")."
0520 DIM CUST$:FATTR(CUST$)
0530 RUN "democent.bbx"

When the CGI value "cust_id" does not contain a valid customer number, a new customer is added. The CUST$ data template is filled in from the form CGI data by calling utfrmin.wbb. The customer ID is generated by adding 1 to the last key in the file and formatting a new 5-digit key. Once successful, the program continues.

0600 NEW_CUSTOMER:
REM ^100 - Get new customer ID by adding 1 to highest current ID
0610 CALL "utfrmin.wbb",CGI$,CUST$
0620 LET LASTKEY$=KEYL(CUSTCHAN,KNUM=0)
0630 LET CUST.CUST_ID$=STR(NUM(LASTKEY$)+1:FILL(LEN(CUST.CUST_ID$),"0"))
0640 WRITE RECORD(CUSTCHAN,DOM=NEW_CUSTOMER)CUST$
0650 GOTO CONTINUE

Although a normal exit from this program runs utcent.bbx, the error routine may need to exit this way.

1000 DONE:
REM ^1000 - Clean up and exit
1010 CALL "utexit.wbb",CGI$
1020 IF RETURN_TO_WATCH
THEN
RUN "utwatch.wbb"
1030 RELEASE
2000 ERRTRAP:
REM ^1000 - generic error trap
2010 CALL "uterr.wbb",ERR,TCB(5),PGM(-2)
2020 GOTO DONE