In the example below, for readability, some RES-Reach tags may span several lines on your browser page. This is not allowed in a real template file.
|
File: order.nbt |
Comments |
|
< HTML > |
This is ordinary HTML |
|
< HEAD > |
|
|
< TITLE >Order Confirmation for Customer {Cust}, Purchase Order {PO}< /TITLE > |
It should be called with |
|
< /HEAD > |
3 parameters: Cust, PO, and Qty |
|
< BODY > |
Optional Item, PerUnit If Qty > 0 |
|
< IF VARIABLE="{ACTION}" OPERATOR="EQ" COMPARISON="MOD" > |
Optional: Action |
|
< DATA SQL="UPDATE DISTINCTROW CUSTOMER SET [NAME] = '{CName}', [ADDRESS] = '{CADDR}', [CREDITCARD] = '{CARD}' WHERE CUSTOMER='{Cust}';", DATABASE="{DB}", CONNECT="dBase III", MODE="SHARED" > |
If action= MOD (see below) then update customer information. Open CUSTOMER in SHARED mode. |
|
< /DATA > |
Close the table |
|
< /IF > |
|
|
< DATA SQL="SELECT * FROM [CUSTOMER] WHERE CUSTOMER='{Cust}';" DATABASE="{DB}" CONNECT="dBase III" MODE="READONLY" > |
Find the customer with this ID |
|
< IF VARIABLE="{TotalRows}" OPERATOR="EQ" COMPARISON="0" > |
If there is no such customer |
|
< /DATA > |
close this empty query, |
|
< DATA SQL="INSERT INTO CUSTOMER ([CUSTOMER]) VALUES ('{Cust}');", DATABASE="{DB}", CONNECT="dBase III", MODE="SHARED" > |
insert the customer record |
|
< /DATA > |
close the insert query |
< DATA SQL="SELECT * FROM [CUSTOMER] WHERE CUSTOMER='{Cust}';" DATABASE="{DB}" CONNECT="dBase III" MODE="READONLY" > |
execute the original query again |
|
< /IF > |
|
|
< H2 >Customer Information< /H2 > |
|
|
< RECORD > |
iterate through the one record |
|
< FORM ACTION={Call_NBT} > |
create a form |
|
< INPUT TYPE=hidden NAME="NBT" Value="Order" > |
it calls ORDER.NBT (this file again!) |
|
< INPUT TYPE=hidden NAME="Cust" Value="{Cust}" > |
with this customer ID |
|
< INPUT TYPE=hidden NAME="PO" Value="{PO}" > |
same PO # |
|
< INPUT TYPE=hidden NAME="ACTION" Value="MOD" > |
ACTION = "MOD" (see above) |
|
< INPUT TYPE=hidden NAME="Qty" Value="0" > |
don’t add to the order |
|
< PRE > |
|
|
NAME: < INPUT TYPE=text NAME="CNAME" Value="{[NAME]}" > |
Change the name? defaults to current |
|
ADDRESS: < INPUT TYPE=text NAME="CADDR" Value="{[ADDRESS]}" Size=60 > |
Change the address? |
|
Credit Card: < INPUT TYPE=text NAME="CARD" Value="{[CREDITCARD]}" > |
Change the credit card? |
|
< INPUT TYPE=submit VALUE="Update" > |
Press the button to call ORDER.NBT |
|
< /PRE > |
|
|
< /FORM > |
end of form |
|
< /RECORD > |
end of record |
|
< /DATA > |
end of query |
|
< HR > |
|
|
< IF VARIABLE="{Qty}" OPERATOR="NE" COMPARISON="0" > |
Adding to the order! |
|
< DATA SQL="INSERT INTO [ORDER] ( ITEM_ID, UNITS, CUSTOMER, PO, COST ) SELECT '{Item}' AS Expr1, '{Qty}' AS Expr2, '{Cust}' AS Expr3, '{PO}' AS Expr4, {Qty}*{PerUnit} AS Expr5;" DATABASE="{DB}" CONNECT="dBase III" MODE="EXCLUSIVE" > |
insert a record to the ORDER table, calculate the cost as Qty*PerUnit |
|
< IF VARIABLE="{ErrNo}" OPERATOR="EQ" COMPARISON="0" > |
Did it work? |
|
< H1 >Added {Qty} x {Item} To PO #{PO}< /H1 > |
tell the user |
|
< /IF > |
|
|
< /DATA > |
close the table |
|
< /IF > |
|
|
< DATA SQL="SELECT * FROM [ORDER] LEFT JOIN [PRODUCTS] ON ORDER.ITEM_ID=PRODUCTS.ITEM_ID WHERE CUSTOMER='{Cust}' AND PO='{PO}';" DATABASE="{DB}" CONNECT="dBase III" MODE="READONLY" ALIAS="Cur" > |
Get a current list of the items in this customer’s PO |
|
< RECORD > |
Iterate through the records |
|
< IF VARIABLE="{RecNo}" OPERATOR="EQ" COMPARISON="1" > |
For the first record, |
|
< TABLE BORDER > |
Start at table |
< CAPTION >< H3 >Your purchase order #{PO}:< /H3 >< /CAPTION > |
with a caption |
< TR >< TH >Item #< /TH >< TH >Description< /TH >< TH >Cost per unit< /TH >< TH >Quantity< /TH >< TH >Price< /TH >< /TR > |
and column headings |
|
< /IF > |
|
|
< TR >< TH >{RecNo}< /TH >< TH > |
sequence number |
|
< B >{[DESCRIPT]}< /B >< /TH >< TH > |
show the DESCRIPT database field, from the joined PRODUCTS table |
|
${[PER_UNIT]}< /TH >< TH > |
PER_UNIT cost field |
|
{[UNITS]}< /TH >< TH > |
UNITS field |
|
${[COST]}< /TH >< /TR > |
recorded cost this item |
|
< /RECORD > |
|
|
< DATA SQL="SELECT SUM([COST]) AS Expr1 FROM [ORDER] LEFT JOIN [PRODUCTS] ON ORDER.ITEM_ID=PRODUCTS.ITEM_ID WHERE CUSTOMER='{Cust}' AND PO='{PO}';" DATABASE="{DB}" CONNECT="dBase III" MODE="READONLY" > |
Now, add up the cost fields. Notice the other one (same table) is not yet closed. |
|
< RECORD > |
This aggregate query has 1 record and 1 field. Iterate through it. |
|
< TR >< TH >< /TH >< TH > |
Another row in the HTML table. |
|
< B >Total for this order< /B >< /TH >< TH > |
Some Browsers don’t like empty cells... |
|
< /TH >< TH > |
|
|
< /TH >< TH > |
|
|
${[Expr1]}< /TH >< /TR > |
Calculated expression from the query |
|
< /RECORD > |
|
|
< /DATA > |
Close the query and table. |
|
< IF VARIABLE="{TotalRows}" OPERATOR="NE" COMPARISON="0" > |
This TotalRows refers to outside query on the database table. |
|
< /TABLE > |
end the HTML table. |
|
< /IF > |
if it was started |
|
< /DATA > |
Close the outside query and tables. |
|
< FORM ACTION={Call_NBT} > |
another form |
|
< INPUT TYPE=hidden NAME="NBT" Value="catalog" > |
look at the catalog again? |
|
< INPUT TYPE=hidden NAME="Cust" Value="{Cust}" > |
Same customer |
|
< INPUT TYPE=hidden NAME="PO" Value="{PO}" > |
Same PO. |
|
< INPUT TYPE=submit VALUE="View Catalog" > |
Press the button? |
|
< /FORM > |
|
|
< FORM ACTION={Call_NBT} > |
another option again |
|
< INPUT TYPE=hidden NAME="NBT" Value="Enterpo" > |
Return to the customer/PO screen |
|
< INPUT TYPE=hidden NAME="Cust" Value="{Cust}" > |
Same customer |
|
< INPUT TYPE=hidden NAME="PO" Value="{PO}" > |
Same default PO |
|
< INPUT TYPE=submit VALUE="Other PO" > |
Presumably to change it. |
|
< /FORM > |
|
|
< HR > |
more ordinary HTML |
|
< I >Thank you for using our on-line catalog. For other services, visit our |
|
|
< A HREF="home.htm" >home page< /A >< /I > |
|
|
< /BODY > |
|
|
< /HTML > |