home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * *
- * CustOrd.jfm -- Customer Order Sample Form *
- * *
- * CustOrd.jfm is a stand-alone sample form that demonstrates several things. *
- * It uses two Query objects and relates the tables using the rowset *
- * properties. It uses client side events to control the calling of the *
- * server. The client side events submit the form which causes it to be re- *
- * rendered on the server. *
- * *
- * Note: When using the form in some older browsers, you must leave the *
- * Select control for the onChange event to fire. To view another *
- * customer or order simply select one in the Select control and click *
- * on the background area. Beta 5 of Netscape Navigator 3.0 does not *
- * have this problem. *
- * *
- * Updated 11/13/96 by IntraBuilder Samples Group *
- * $Revision: 1.12 $ *
- * *
- * Copyright (c) 1996, Borland International, Inc. All rights reserved. *
- * *
- \****************************************************************************/
- #include "intra.h"
- // {End Header} Do not remove this comment//
- // Generated on 11/13/96
- //
- var f = new custordForm();
- f.open();
- class custordForm extends Form {
- with (this) {
- onServerSubmit = class::form_onServerSubmit;
- onServerLoad = class::form_onServerLoad;
- height = 14.6667;
- left = 0;
- top = 0;
- width = 76;
- title = "Customer Orders";
- }
-
-
- with (this.query1 = new Query()){
- left = 60;
- top = 0;
- sql = 'select * from "customer.dbf"';
-
- active = true;
- }
-
-
- with (this.query1.rowset) {
-
- autoEdit = false;
- }
-
-
- with (this.query2 = new Query()){
- left = 64;
- top = 0;
- sql = 'select * from "orders.dbf"';
-
- active = true;
- }
-
-
- with (this.query2.rowset) {
-
- autoEdit = false;
- indexName = "CUSTOMER_N";
- masterRowset = parent.parent.query1.rowset;
- masterFields = "customer_n";
- }
-
-
- with (this.rule1 = new Rule(this)){
- top = 9.5;
- size = 2;
- right = 70;
- }
-
-
- with (this.rule2 = new Rule(this)){
- top = 1.5;
- size = 2;
- right = 70;
- }
-
-
- with (this.rule3 = new Rule(this)){
- top = 17.5;
- size = 2;
- right = 70;
- }
-
-
- with (this.Street = new Text(this)){
- top = 5;
- width = 28;
- dataLink = parent.query1.rowset.fields["STREET"];
- }
-
-
- with (this.City = new Text(this)){
- top = 6;
- width = 12;
- dataLink = parent.query1.rowset.fields["CITY"];
- }
-
-
- with (this.State_prov = new Text(this)){
- left = 14;
- top = 6;
- width = 4;
- dataLink = parent.query1.rowset.fields["STATE_PROV"];
- }
-
-
- with (this.Zip_postal = new Text(this)){
- left = 22;
- top = 6;
- width = 6;
- dataLink = parent.query1.rowset.fields["ZIP_POSTAL"];
- }
-
-
- with (this.Country = new Text(this)){
- top = 7;
- width = 18;
- dataLink = parent.query1.rowset.fields["COUNTRY"];
- }
-
-
- with (this.Phone = new Text(this)){
- top = 8;
- width = 18;
- dataLink = parent.query1.rowset.fields["PHONE"];
- }
-
-
- with (this.First_cont = new Text(this)){
- left = 50;
- top = 6;
- width = 12;
- dataLink = parent.query1.rowset.fields["FIRST_CONT"];
- }
-
-
- with (this.Ytd_sales = new Text(this)){
- left = 50;
- top = 7;
- width = 12;
- dataLink = parent.query1.rowset.fields["YTD_SALES"];
- }
-
-
- with (this.HTML1 = new HTML(this)){
- height = 1;
- left = 32;
- top = 6;
- width = 12;
- color = "black";
- alignVertical = 1;
- text = "First Contact";
- }
-
-
- with (this.HTML2 = new HTML(this)){
- height = 1;
- left = 32;
- top = 7;
- width = 12;
- color = "black";
- alignVertical = 1;
- text = "Year to Date";
- }
-
-
- with (this.HTML3 = new HTML(this)){
- height = 1;
- top = 13;
- width = 14;
- color = "black";
- alignVertical = 1;
- text = "Sale Date";
- }
-
-
- with (this.Sale_date = new Text(this)){
- left = 14;
- top = 13;
- width = 8;
- dataLink = parent.query2.rowset.fields["SALE_DATE"];
- }
-
-
- with (this.HTML4 = new HTML(this)){
- height = 1;
- top = 14;
- width = 14;
- color = "black";
- alignVertical = 1;
- text = "Ship Date";
- }
-
-
- with (this.Ship_date = new Text(this)){
- left = 14;
- top = 14;
- width = 8;
- dataLink = parent.query2.rowset.fields["SHIP_DATE"];
- }
-
-
- with (this.HTML5 = new HTML(this)){
- height = 1;
- top = 15;
- width = 14;
- color = "black";
- alignVertical = 1;
- text = "Ship Via";
- }
-
-
- with (this.Ship_via = new Text(this)){
- left = 14;
- top = 15;
- width = 8;
- dataLink = parent.query2.rowset.fields["SHIP_VIA"];
- }
-
-
- with (this.HTML6 = new HTML(this)){
- height = 1;
- left = 30;
- top = 14;
- width = 18;
- color = "black";
- alignVertical = 1;
- text = "Amount Paid";
- }
-
-
- with (this.Amt_paid = new Text(this)){
- left = 48;
- top = 14;
- width = 10;
- dataLink = parent.query2.rowset.fields["AMT_PAID"];
- }
-
-
- with (this.HTML7 = new HTML(this)){
- height = 1;
- top = 16;
- width = 14;
- color = "black";
- alignVertical = 1;
- text = "Terms";
- }
-
-
- with (this.Terms = new Text(this)){
- left = 14;
- top = 16;
- width = 8;
- dataLink = parent.query2.rowset.fields["TERMS"];
- }
-
-
- with (this.HTML8 = new HTML(this)){
- height = 1;
- left = 30;
- top = 13;
- width = 18;
- color = "black";
- alignVertical = 1;
- text = "Payment Method";
- }
-
-
- with (this.Pay_method = new Text(this)){
- left = 48;
- top = 13;
- width = 10;
- dataLink = parent.query2.rowset.fields["PAY_METHOD"];
- }
-
-
- with (this.HTML9 = new HTML(this)){
- height = 1;
- left = 30;
- top = 15;
- width = 18;
- color = "black";
- alignVertical = 1;
- text = "Total";
- }
-
-
- with (this.Total = new Text(this)){
- left = 48;
- top = 15;
- width = 10;
- dataLink = parent.query2.rowset.fields["TOTAL"];
- }
-
-
- with (this.customerSelect = new Select(this)){
- onChange = class::customerSelect_onChange;
- top = 4;
- width = 30;
- }
-
-
- with (this.orderSelect = new Select(this)){
- onChange = class::orderSelect_onChange;
- left = 14;
- top = 12;
- width = 16;
- }
-
-
- with (this.HTML10 = new HTML(this)){
- height = 1;
- top = 12;
- width = 14;
- color = "black";
- alignVertical = 1;
- text = "Order Number";
- }
-
-
- with (this.HTML11 = new HTML(this)){
- height = 1.5;
- width = 70;
- color = "black";
- text = "<H1>Customer Orders</H1>";
- }
-
-
- with (this.HTML12 = new HTML(this)){
- height = 1;
- top = 10;
- width = 70;
- color = "black";
- text = "<H2>Orders for this customer</H2>";
- }
-
-
- with (this.HTML13 = new HTML(this)){
- height = 1;
- top = 2;
- width = 70;
- color = "black";
- text = "<H2>Customer Profile</H2>";
- }
-
-
- with (this.HTML14 = new HTML(this)){
- height = 1;
- top = 18;
- width = 70;
- color = "black";
- text = {||"<ADDRESS>Generated by IntraBuilder on " + new Date() + "</ADDRESS>"};
- }
-
-
- with (this.whatChanged = new Hidden(this)){
- left = 68;
- value = 0;
- }
-
-
- with (this.customerButton = new Button(this)){
- onServerClick = class::customerButton_onServerClick;
- left = 32;
- top = 8;
- width = 16;
- text = "Edit Customer";
- }
-
-
- with (this.orderButton = new Button(this)){
- onServerClick = class::orderButton_onServerClick;
- left = 30;
- top = 16;
- width = 16;
- text = "Edit Orders";
- }
-
-
- with (this.saveCustomer = new Hidden(this)){
- left = 50;
- top = 8;
- value = 0;
- }
-
-
- with (this.saveOrder = new Hidden(this)){
- left = 48;
- top = 16;
- value = 0;
- }
-
- this.rowset = this.query1.rowset;
-
- function form_onServerLoad()
- {
- var name;
- // fill customer array
- this.custArray = new Array();
- while (!this.query1.rowset.endOfSet) {
- name = new StringEx(this.query1.rowset.fields["name"].value);
- name = name.rightTrim();
- this.custArray.add(name);
- this.query1.rowset.next();
- }
- this.query1.rowset.first();
- // assign options and value
- this.custArray.sort();
- this.customerSelect.options="array this.custArray";
- this.customerSelect.value = this.custArray[0];
- // set new customer flag and call onServerSubmit
- this.whatChanged.value = 1;
- class::form_onServerSubmit();
- }
-
- function submit()
- {
- this.form_onServerSubmit();
- }
-
- function customerButton_onServerClick()
- {
- if (this.text == 'Save Customer') {
- this.form.query1.rowset.save();
- this.text = 'Edit Customer';
- }
- else {
- this.form.query1.rowset.beginEdit();
- this.text = 'Save Customer';
- }
- }
-
- function orderButton_onServerClick()
- {
- if (this.text == 'Save Order') {
- this.form.query2.rowset.save();
- this.text = 'Edit Order';
- }
- else {
- this.form.query2.rowset.beginEdit();
- this.text = 'Save Order';
- }
- }
-
- function form_onServerSubmit(notForm, formRef)
- {
- var frm = notForm ? formRef : this;
- var change = parseInt(frm.whatChanged.value);
- switch (change) {
- case 1: // customer has changed
- if (frm.query2.rowset.state == STATE_EDIT) {
- frm.query2.rowset.abandon();
- frm.orderButton.text = 'Edit Order';
- }
- if (frm.query1.rowset.state == STATE_EDIT) {
- frm.query1.rowset.abandon();
- frm.customerButton.text = 'Edit Customer';
- }
- var x=frm.query1.rowset.applyLocate("Name='" + escapeChar(frm.customerSelect.value,"'") + "'");
- //
- // fill order array
- //
- frm.orderArray = new Array();
- frm.query2.rowset.first();
- while (!frm.query2.rowset.endOfSet) {
- frm.orderArray.add(frm.query2.rowset.fields["Order_no"].value);
- frm.query2.rowset.next();
- }
- frm.query2.rowset.first();
- // assign options and value
- frm.orderSelect.options="array frm.orderArray";
- if (frm.orderArray.length > 0)
- frm.orderSelect.value = frm.orderArray[0];
- break;
- case 2:
- if (frm.query2.rowset.state == STATE_EDIT) {
- frm.query2.rowset.abandon();
- frm.orderButton.text = 'Edit Order';
- }
- frm.query2.rowset.applyLocate("Order_no='" + frm.orderSelect.value + "'");
- break;
- }
- frm.whatChanged.value = 0;
- }
-
- function customerSelect_onChange()
- {
- this.form.whatChanged.value = 1; // 1 for customer select
- this.form.submit();
- }
-
- function orderSelect_onChange()
- {
- this.form.whatChanged.value = 2; // 2 for order select
- this.form.submit();
- }
-
- }
- function escapeChar(str,chr)
- {
- var offset = last = 0;
- var returnVal = "";
- while(str.indexOf(chr,last) >= 0) {
- offset = str.indexOf(chr,last);
- returnVal += str.substring(last, offset) + "\\" + chr;
- last = offset+1;
- }
- returnVal += str.substring(last,str.length);
- return returnVal;
- }
-