UltraLite ActiveX User's Guide
Tutorial: An UltraLite Application for Pocket IE
Lesson 5: Write the JScript sample code
The following procedures implement data manipulation and navigation.
To scroll through the list of orders
Tap Back or Next.
One of the following functions runs:
function MoveBack() { var cs = top.CS; var posn = cs.GetBookmark(); if ( MoveOrder( -1 ) ) { cs.SetBookmark(posn - 1); UpdateForm(); } } function MoveNext() { var cs = top.CS; var posn = cs.GetBookmark(); if ( MoveOrder(1) ) { cs.SetBookmark(posn + 1); UpdateForm(); } }
To add an order to the database
Tap Add.
The following script runs, replacing main.htm with add.htm in the frame.
function addNewOrder() { document.location.replace("add.htm"); }
Fill in the form with the desired values. Click OK.
The following script runs:
For more information about inserting rows, see Inserting, updating, and deleting rows.
function addCustomer() { var custName = window.prompt("Enter new customer name: ", ""); if ( custName == "" ) return; var conn = top.Connection; var custlist = conn.GetTable( "ULCustomer" ) custlist.Open("ULCustomerName"); custlist.FindBegin(); custlist.Columns("cust_name").value = custName; if ( custlist.FindFirst() ) { // already present. Done. custlist.Close(); return; } var custid = NextCustomerID(); if ( custid == -1 ) { alert("No more customer IDs, cannot add. Replenish ULCustomerIDPool"); custlist.Close(); return; } custlist.InsertBegin(); custlist.Columns("cust_id").value = custid; custlist.Columns("cust_name").Value = custName; custlist.Insert(); custlist.Close(); conn.Commit(); // Only way to show new customer is to reload this form! document.location.reload(); }
To approve or deny an order
Click Approve or Deny.
One of the following scripts runs, loading approve.htm or deny.htm in the frame.
function ApproveOrder() { var cs = top.CS; document.location.replace("approve.htm"); } function DenyOrder() { document.location.replace("deny.htm"); }
Enter a note and click OK.
If you are approving an order, the following code runs. If you are denying an order, the code is the same but the status is instead set to Denied.
For more information about updating rows, see Inserting, updating, and deleting rows.
function OK_Approve() { var cs = top.CS; var conn = top.Connection; var notes = txt_Notes.value; var order = conn.GetTable("ULOrder"); order.Open(); order.FindBegin(); order.Columns("order_id").value = cs.GetOrderID(); if ( order.FindFirst() ) { order.UpdateBegin(); order.Columns("status").value = "Approved"; order.Columns("notes").value = notes; order.Update(); if (conn.LastErrorCode != 0 ) { alert("Failed: " + conn.LastErrorDescription ); } conn.Commit(); } else { alert("Cannot find order " + cs.GetOrderID() ); } order.Close(); document.location.replace("main.htm"); }