home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / OrderEntryFrame.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  45.7 KB  |  1,028 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. //Title:        Cliffhanger Adventure Gear
  21. //Version:      
  22. //Copyright:    Copyright (c) 1997 Borland International, Inc.
  23. //Author:       Application Methods, Inc.
  24. //Description:  Cliffhanger Adventure Gear order entry system
  25.  
  26. package borland.reference.cliffhanger;
  27.  
  28. import java.util.*;
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import borland.jbcl.layout.*;
  32. import borland.jbcl.control.*;
  33. import borland.sql.dataset.*;
  34. import borland.jbcl.dataset.*;
  35. import borland.jbcl.util.*;
  36. import java.lang.Exception;
  37.  
  38. /**
  39.  * OrderEntryFrame is the Frame subclass that is used to view, insert, and
  40.  * update Order records.
  41.  * 
  42.  */
  43. public class OrderEntryFrame extends DecoratedFrame {
  44.   private static DataModule1 dm = DataModule1.getDataModule();
  45.  
  46.   private static OrderEntryFrame myOrderEntryFrame;
  47.   private QueryDataSet qdsOrder;
  48.   private QueryDataSet qdsOrderItem;
  49.   private QueryDataSet qdsPayMethod;
  50.   private QueryDataSet qdsShipMethod;
  51.   private QueryDataSet qdsStatus;
  52.   private QueryDataSet qdsCustomer;
  53.   private QueryDataSet qdsProduct;
  54.   BevelPanel pnlTop = new BevelPanel();
  55.   BevelPanel pnlNavigator = new BevelPanel();
  56.   BevelPanel pnlDate = new BevelPanel();
  57.   BevelPanel pnlOrder = new BevelPanel();
  58.   BevelPanel pnlBillTo = new BevelPanel();
  59.   BevelPanel pnlShipTo = new BevelPanel();
  60.   BevelPanel pnlMiddle = new BevelPanel();
  61.   BevelPanel pnlOrderInfo = new BevelPanel();
  62.   BevelPanel pnlOrderItems = new BevelPanel();
  63.   BevelPanel pnlBottom = new BevelPanel();
  64.   BevelPanel pnlButtons = new BevelPanel();
  65.   LabelControl txtID = new LabelControl();
  66.   FieldControl txtOrderTrackNum = new FieldControl();
  67.   FieldControl txtCustomerPONum = new FieldControl();
  68.   FieldControl txtOrderDate = new FieldControl();
  69.   FieldControl txtCustomerName = new FieldControl();
  70.   FieldControl txtCustomerID = new FieldControl();
  71.   FieldControl txtBillAddr1 = new FieldControl();
  72.   FieldControl txtBillAddr2 = new FieldControl();
  73.   FieldControl txtBillCity = new FieldControl();
  74.   FieldControl txtBillState = new FieldControl();
  75.   FieldControl txtBillPostalCode = new FieldControl();
  76.   FieldControl txtBillCountry = new FieldControl();
  77.   FieldControl txtShipName = new FieldControl();
  78.   FieldControl txtShipAddr1 = new FieldControl();
  79.   FieldControl txtShipAddr2 = new FieldControl();
  80.   FieldControl txtShipCity = new FieldControl();
  81.   FieldControl txtShipState = new FieldControl();
  82.   FieldControl txtShipPostalCode = new FieldControl();
  83.   FieldControl txtShipCountry = new FieldControl();
  84.   FieldControl txtCreditCardNum= new FieldControl();
  85.   ChoiceControl cboPayMethod = new ChoiceControl();
  86.   ChoiceControl cboShipMethod = new ChoiceControl();
  87.   ChoiceControl cboStatus = new ChoiceControl();
  88.   FieldControl txtShipDate = new FieldControl();
  89.   LabelControl lblID = new LabelControl();
  90.   LabelControl lblDate = new LabelControl();
  91.   LabelControl lblOrderTrackNum = new LabelControl();
  92.   LabelControl lblCustomerPONum = new LabelControl();
  93.   LabelControl lblShipDate = new LabelControl();
  94.   LabelControl lblBillTo = new LabelControl();
  95.   LabelControl lblShipTo = new LabelControl();
  96.   LabelControl lblCreditCardNum = new LabelControl();
  97.   LabelControl lblPayMethod = new LabelControl();
  98.   LabelControl lblShipMethod = new LabelControl();
  99.   LabelControl lblStatus = new LabelControl();
  100.   GridBagLayout gridBagLayout3 = new GridBagLayout();
  101.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  102.   GridBagLayout gridBagLayout5 = new GridBagLayout();
  103.   GridBagLayout gridBagLayout6 = new GridBagLayout();
  104.   BorderLayout borderLayout1 = new BorderLayout();
  105.   BorderLayout borderLayout2 = new BorderLayout();
  106.   BorderLayout borderLayout3 = new BorderLayout();
  107.   GridControl grdOrderItems = new GridControl();
  108.   ButtonControl btnSave = new ButtonControl();
  109.   ButtonControl btnCancel = new ButtonControl();
  110.   ButtonControl btnClose = new ButtonControl();
  111.   GridBagLayout gridBagLayout9 = new GridBagLayout();
  112.   GridBagLayout gridBagLayout4 = new GridBagLayout();
  113.   BevelPanel pnlTotals = new BevelPanel();
  114.   LabelControl lblSubTotal = new LabelControl();
  115.   LabelControl lblTax = new LabelControl();
  116.   LabelControl lblShipping = new LabelControl();
  117.   LabelControl lblAmtPaid = new LabelControl();
  118.   LabelControl lblAmtDue = new LabelControl();
  119.   FieldControl txtSubTotal = new FieldControl();
  120.   FieldControl txtTax = new FieldControl();
  121.   FieldControl txtTaxPercent = new FieldControl();
  122.   FieldControl txtShipping = new FieldControl();
  123.   FieldControl txtShipPercent = new FieldControl();
  124.   FieldControl txtAmtPaid = new FieldControl();
  125.   FieldControl txtAmtDue = new FieldControl();
  126.   NavigatorControl navigatorControl1 = new NavigatorControl();
  127.   StatusBar statusBarOrder = new StatusBar();
  128.   StatusBar statusBarOrderItem = new StatusBar();
  129.   ImageControl imgLogo = new ImageControl();
  130.   ButtonControl btnFindCustomer = new ButtonControl();
  131.   ButtonControl btnNewCustomer = new ButtonControl();
  132.   GridBagLayout gridBagLayout7 = new GridBagLayout();
  133.   BevelPanel pnlBillToButtons = new BevelPanel();
  134.   GridBagLayout gridBagLayout8 = new GridBagLayout();
  135.   GridBagLayout gridBagLayout10 = new GridBagLayout();
  136.   ButtonControl btnSaveShipTo = new ButtonControl();
  137.   BevelPanel pnlOrderItemStatus = new BevelPanel();
  138.   ButtonControl btnAddOrderItem = new ButtonControl();
  139.   ButtonControl btnRemoveOrderItem = new ButtonControl();
  140.   GridBagLayout gridBagLayout11 = new GridBagLayout();
  141.   BevelPanel pnlOrderItemButtons = new BevelPanel();
  142.   LabelControl lblOrderItemStatus = new LabelControl();
  143.   ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
  144.   GridBagLayout gridBagLayout12 = new GridBagLayout();
  145.   GridBagLayout gridBagLayout13 = new GridBagLayout();
  146.   GridLayout gridLayout1 = new GridLayout();
  147.  
  148.   /**
  149.    * The constructor is protected. Use the getOrderEntryFrame method to get an
  150.    * instance of this class.
  151.    */
  152.   protected OrderEntryFrame() {
  153.     try {
  154.       jbInit();    // initialize frame's controls (JBuilder designer)
  155.       initData();  // initialize default data-aware component values.
  156.     }
  157.     catch (Exception e) {
  158.       e.printStackTrace();
  159.     };
  160.   }
  161.  
  162.   /**
  163.    * Method generated and maintained by JBuilder designer to initialize
  164.    * control properties.
  165.    */
  166.   private void jbInit() throws Exception{
  167.     this.setSize(new Dimension(600, 600));
  168.     this.setTitle(res.getString("OEF_Orders"));
  169.     this.addWindowListener(new OrderEntryFrame_this_windowAdapter(this));
  170.     this.setExitOnClose(false);
  171.     pnlShipTo.setLayout(gridBagLayout6);
  172.     pnlOrder.setLayout(gridBagLayout5);
  173.     pnlBillTo.setLayout(gridBagLayout3);
  174.     pnlOrder.setBevelInner(BevelPanel.FLAT);
  175.     pnlOrder.setBevelOuter(BevelPanel.FLAT);
  176.     pnlBillTo.setMargins(new Insets(5, 0, 5, 0));
  177.     pnlShipTo.setMargins(new Insets(5, 0, 5, 0));
  178.     pnlMiddle.setBevelOuter(BevelPanel.FLAT);
  179.     pnlOrderInfo.setBevelInner(BevelPanel.FLAT);
  180.     pnlOrderInfo.setMargins(new Insets(0, 0, 4, 0));
  181.     pnlOrderItems.setBevelOuter(BevelPanel.LOWERED);
  182.     pnlBottom.setBevelInner(BevelPanel.FLAT);
  183.     pnlOrderInfo.setLayout(gridBagLayout4);
  184.     pnlBottom.setLayout(gridBagLayout10);
  185.     pnlOrderItems.setLayout(borderLayout3);
  186.     pnlMiddle.setLayout(borderLayout2);
  187.     pnlNavigator.setBevelInner(BevelPanel.FLAT);
  188.     pnlNavigator.setBevelOuter(BevelPanel.FLAT);
  189.     pnlNavigator.setMargins(new Insets(0, 4, 0, 0));
  190.     pnlDate.setBevelInner(BevelPanel.FLAT);
  191.     pnlDate.setBevelOuter(BevelPanel.FLAT);
  192.     pnlDate.setMargins(new Insets(4, 0, 4, 0));
  193.     pnlTop.setLayout(gridBagLayout2);
  194.     pnlDate.setLayout(gridLayout1);
  195.     pnlNavigator.setLayout(gridBagLayout8);
  196.     lblBillTo.setText(res.getString("OEF_Bill_To"));
  197.     lblShipTo.setText(res.getString("OEF_Ship_To"));
  198.     lblDate.setText(res.getString("OEF_Date"));
  199.     lblCreditCardNum.setText(res.getString("OEF_Credit_Card_No"));
  200.     lblPayMethod.setText(res.getString("OEF_Payment_Method"));
  201.     lblShipMethod.setText(res.getString("OEF_Ship_Via"));
  202.     lblStatus.setText(res.getString("OEF_Status"));
  203.     grdOrderItems.setDataSet(dm.getOrderItemDataSet());
  204.     pnlButtons.setBevelInner(BevelPanel.FLAT);
  205.     pnlButtons.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  206.     txtCustomerName.setAutoEdit(false);
  207.     txtCustomerName.setColumnName("CUSTOMERNAME");
  208.     txtCustomerName.setBackground(SystemColor.control);
  209.     txtCustomerName.setDataSet(dm.getOrderDataSet());
  210.     txtCustomerName.setEditInPlace(false);
  211.     txtCustomerName.setReadOnly(true);
  212.     txtCustomerID.setAutoEdit(false);
  213.     txtCustomerID.setColumnName("CUSTOMERID");
  214.     txtCustomerID.setBackground(SystemColor.control);
  215.     txtCustomerID.setDataSet(dm.getOrderDataSet());
  216.     txtCustomerID.setEditInPlace(false);
  217.     txtCustomerID.setReadOnly(true);
  218.     txtBillAddr1.setAutoEdit(false);
  219.     txtBillAddr1.setColumnName("BILLADDR1");
  220.     txtBillAddr1.setBackground(SystemColor.control);
  221.     txtBillAddr1.setDataSet(dm.getOrderDataSet());
  222.     txtBillAddr1.setEditInPlace(false);
  223.     txtBillAddr1.setReadOnly(true);
  224.     txtBillAddr2.setAutoEdit(false);
  225.     txtBillAddr2.setColumnName("BILLADDR2");
  226.     txtBillAddr2.setBackground(SystemColor.control);
  227.     txtBillAddr2.setDataSet(dm.getOrderDataSet());
  228.     txtBillAddr2.setEditInPlace(false);
  229.     txtBillAddr2.setReadOnly(true);
  230.     txtBillCity.setAutoEdit(false);
  231.     txtBillCity.setColumnName("BILLCITY");
  232.     txtBillCity.setBackground(SystemColor.control);
  233.     txtBillCity.setDataSet(dm.getOrderDataSet());
  234.     txtBillCity.setEditInPlace(false);
  235.     txtBillCity.setReadOnly(true);
  236.     txtBillState.setAutoEdit(false);
  237.     txtBillState.setColumnName("BILLSTATE");
  238.     txtBillState.setBackground(SystemColor.control);
  239.     txtBillState.setDataSet(dm.getOrderDataSet());
  240.     txtBillState.setEditInPlace(false);
  241.     txtBillState.setReadOnly(true);
  242.     txtBillPostalCode.setAutoEdit(false);
  243.     txtBillPostalCode.setColumnName("BILLPOSTALCODE");
  244.     txtBillPostalCode.setBackground(SystemColor.control);
  245.     txtBillPostalCode.setDataSet(dm.getOrderDataSet());
  246.     txtBillPostalCode.setEditInPlace(false);
  247.     txtBillPostalCode.setReadOnly(true);
  248.     txtBillCountry.setAutoEdit(false);
  249.     txtBillCountry.setColumnName("BILLCOUNTRY");
  250.     txtBillCountry.setBackground(SystemColor.control);
  251.     txtBillCountry.setDataSet(dm.getOrderDataSet());
  252.     txtBillCountry.setEditInPlace(false);
  253.     txtBillCountry.setReadOnly(true);
  254.     txtShipName.setColumnName("SHIPNAME");
  255.     txtShipName.setDataSet(dm.getOrderDataSet());
  256.     txtShipAddr1.setColumnName("SHIPADDR1");
  257.     txtShipAddr1.setDataSet(dm.getOrderDataSet());
  258.     txtShipAddr2.setColumnName("SHIPADDR2");
  259.     txtShipAddr2.setDataSet(dm.getOrderDataSet());
  260.     txtShipCity.setColumnName("SHIPCITY");
  261.     txtShipCity.setDataSet(dm.getOrderDataSet());
  262.     txtShipState.setColumnName("SHIPSTATE");
  263.     txtShipState.setDataSet(dm.getOrderDataSet());
  264.     txtShipPostalCode.setColumnName("SHIPPOSTALCODE");
  265.     txtShipPostalCode.setDataSet(dm.getOrderDataSet());
  266.     txtShipCountry.setColumnName("SHIPCOUNTRY");
  267.     txtShipCountry.setDataSet(dm.getOrderDataSet());
  268.     txtCreditCardNum.setColumnName("CREDITCARDNUM");
  269.     txtCreditCardNum.setDataSet(dm.getOrderDataSet());
  270.     cboPayMethod.setColumnName("PAYMETHOD");
  271.     cboPayMethod.setDataSet(dm.getOrderDataSet());
  272.     cboShipMethod.setColumnName("SHIPMETHOD");
  273.     cboShipMethod.setDataSet(dm.getOrderDataSet());
  274.     cboStatus.setColumnName("STATUS");
  275.     cboStatus.setDataSet(dm.getOrderDataSet());
  276.     txtShipDate.setColumnName("SHIPDATE");
  277.     txtShipDate.setDataSet(dm.getOrderDataSet());
  278.     cboPayMethod.addItemListener(new OrderEntryFrame_cboPayMethod_itemAdapter(this));
  279.     pnlButtons.setLayout(gridBagLayout9);
  280.     btnSave.setActionCommand("");
  281.     btnSave.setLabel(res.getString("OEF_Save"));
  282.     btnSave.addActionListener(new OrderEntryFrame_btnSave_actionAdapter(this));
  283.     btnCancel.setActionCommand("");
  284.     btnCancel.setLabel(res.getString("OEF_Cancel"));
  285.     btnCancel.addActionListener(new OrderEntryFrame_btnCancel_actionAdapter(this));
  286.     btnClose.setActionCommand("");
  287.     btnClose.setLabel(res.getString("OEF_Close"));
  288.     btnClose.addActionListener(new OrderEntryFrame_btnClose_actionAdapter(this));
  289.     pnlTotals.setBevelInner(BevelPanel.FLAT);
  290.     pnlTotals.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  291.     pnlTotals.setMargins(new Insets(4, 0, 4, 0));
  292.     pnlTotals.setLayout(gridBagLayout7);
  293.     lblSubTotal.setText(res.getString("OEF_SubTotal"));
  294.     lblTax.setText(res.getString("OEF_Tax"));
  295.     lblShipping.setText(res.getString("OEF_Shipping"));
  296.     lblAmtPaid.setText(res.getString("OEF_Paid"));
  297.     lblAmtDue.setText(res.getString("OEF_Due"));
  298.     txtSubTotal.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  299.     txtSubTotal.setColumnName("SUBTOTAL");
  300.     txtSubTotal.setDataSet(dm.getOrderItemDataSet());
  301.     txtTax.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  302.     txtTax.setColumnName("TAX");
  303.     txtTax.setDataSet(dm.getOrderItemDataSet());
  304.     txtTaxPercent.setText(String.valueOf(dm.TAXPERCENT));
  305.     txtTaxPercent.setBackground(SystemColor.control);
  306.     txtTaxPercent.setReadOnly(true);
  307.     txtTaxPercent.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  308.     txtShipping.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  309.     txtShipping.setColumnName("SHIPPING");
  310.     txtShipping.setDataSet(dm.getOrderItemDataSet());
  311.     txtShipPercent.setText(String.valueOf(dm.SHIPPERCENT));
  312.     txtShipPercent.setBackground(SystemColor.control);
  313.     txtShipPercent.setReadOnly(true);
  314.     txtShipPercent.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  315.     txtAmtPaid.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  316.     txtAmtPaid.setColumnName("AMTPAID");
  317.     txtAmtPaid.setDataSet(dm.getOrderDataSet());
  318.     txtAmtDue.setAlignment(borland.jbcl.util.Alignment.RIGHT | borland.jbcl.util.Alignment.MIDDLE);
  319.     txtAmtDue.setColumnName("AMTDUE");
  320.     txtAmtDue.setDataSet(dm.getOrderItemDataSet());
  321.     txtAmtDue.setFont(new Font("Dialog", 1, 12));
  322.     navigatorControl1.setDataSet(dm.getOrderDataSet());
  323.     lblID.setFont(new Font("Dialog", 1, 12));
  324.     lblID.setText(res.getString("OEF_Order_No"));
  325.     txtID.setColumnName("ID");
  326.     txtID.setBackground(SystemColor.control);
  327.     txtID.setDataSet(dm.getOrderDataSet());
  328.     txtID.setForeground(Color.red);
  329.     txtOrderTrackNum.setColumnName("ORDERTRACKNUM");
  330.     txtOrderTrackNum.setDataSet(dm.getOrderDataSet());
  331.     txtCustomerPONum.setColumnName("CUSTOMERPONUM");
  332.     txtCustomerPONum.setDataSet(dm.getOrderDataSet());
  333.     txtOrderDate.setColumnName("ORDERDATE");
  334.     txtOrderDate.setDataSet(dm.getOrderDataSet());
  335.     txtID.setReadOnly(true);
  336.     txtID.setFont(new Font("Dialog", 1, 14));
  337.     lblOrderTrackNum.setText(res.getString("OEF_OrderTrack_No"));
  338.     lblCustomerPONum.setText(res.getString("OEF_PO_No"));
  339.     pnlBillToButtons.setBevelInner(BevelPanel.FLAT);
  340.     pnlBillToButtons.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  341.     btnSaveShipTo.setLabel(res.getString("OEF_Save_as_Default"));
  342.     pnlOrderItemStatus.setBevelInner(BevelPanel.FLAT);
  343.     pnlOrderItemButtons.setLayout(gridBagLayout12);
  344.     pnlOrderItemStatus.setLayout(gridBagLayout11);
  345.     btnAddOrderItem.setForeground(Color.blue);
  346.     btnAddOrderItem.setLabel(res.getString("OEF_Add_Item"));
  347.     btnAddOrderItem.addActionListener(new OrderEntryFrame_btnAddOrderItem_actionAdapter(this));
  348.     btnRemoveOrderItem.setForeground(Color.red);
  349.     btnRemoveOrderItem.setLabel(res.getString("OEF_Remove_Item"));
  350.     statusBarOrder.setDataSet(dm.getOrderDataSet());
  351.     statusBarOrder.setBevelOuter(BevelPanel.LOWERED);
  352.     statusBarOrder.setFont(new Font("Dialog", 0, 10));
  353.     statusBarOrderItem.setBevelInner(BevelPanel.FLAT);
  354.     statusBarOrderItem.setDataSet(dm.getOrderItemDataSet());
  355.     statusBarOrderItem.setFont(new Font("Dialog", 0, 10));
  356.     pnlOrderItemButtons.setBevelInner(BevelPanel.FLAT);
  357.     lblOrderItemStatus.setFont(new Font("Dialog", 0, 10));
  358.     lblOrderItemStatus.setText(res.getString("OEF_Order_Item"));
  359.     gridLayout1.setRows(3);
  360.     gridLayout1.setColumns(2);
  361.     btnRemoveOrderItem.addActionListener(new OrderEntryFrame_btnRemoveOrderItem_actionAdapter(this));
  362.     btnSaveShipTo.addActionListener(new OrderEntryFrame_btnSaveShipTo_actionAdapter(this));
  363.     lblShipDate.setText(res.getString("OEF_Ship_Date"));
  364.     pnlBillToButtons.setLayout(gridBagLayout13);
  365.     btnFindCustomer.setLabel(res.getString("OEF_Find_"));
  366.     btnFindCustomer.addActionListener(new OrderEntryFrame_btnFindCustomer_actionAdapter(this));
  367.     btnNewCustomer.setActionCommand("");
  368.     btnNewCustomer.setLabel(res.getString("OEF_New_"));
  369.     btnNewCustomer.addActionListener(new OrderEntryFrame_btnNewCustomer_actionAdapter(this));
  370.     imgLogo.setBackground(SystemColor.control);
  371.     imgLogo.setAlignment(borland.jbcl.util.Alignment.CENTER | borland.jbcl.util.Alignment.MIDDLE);
  372.     imgLogo.setImageName(".\\Graphics\\Logo_sml.gif");
  373.     this.setLayout(borderLayout1);
  374.     this.add(pnlOrder, BorderLayout.NORTH);
  375.     pnlOrder.add(pnlBillTo, new GridBagConstraints2(0, 1, 1, 2, 100.0, 0.0
  376.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  377.     pnlBillTo.add(txtCustomerName, new GridBagConstraints2(0, 1, 2, 1, 1.0, 0.0
  378.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  379.     pnlBillTo.add(txtCustomerID, new GridBagConstraints2(2, 1, 1, 1, 1.0, 0.0
  380.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 8), 0, 0));
  381.     pnlBillTo.add(txtBillAddr1, new GridBagConstraints2(0, 2, 3, 1, 1.0, 0.0
  382.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  383.     pnlBillTo.add(txtBillAddr2, new GridBagConstraints2(0, 3, 3, 1, 1.0, 0.0
  384.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  385.     pnlBillTo.add(txtBillCity, new GridBagConstraints2(0, 4, 1, 1, 1.0, 0.0
  386.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  387.     pnlBillTo.add(txtBillState, new GridBagConstraints2(1, 4, 1, 2, 1.0, 0.0
  388.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0), 0, 0));
  389.     pnlBillTo.add(txtBillPostalCode, new GridBagConstraints2(2, 4, 1, 2, 1.0, 0.0
  390.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8), 0, 0));
  391.     pnlBillTo.add(txtBillCountry, new GridBagConstraints2(0, 5, 3, 1, 1.0, 0.0
  392.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  393.     pnlBillTo.add(lblBillTo, new GridBagConstraints2(0, 0, 1, 1, 1.0, 0.0
  394.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  395.     pnlBillTo.add(pnlBillToButtons, new GridBagConstraints2(1, 0, 2, 1, 0.0, 0.0
  396.             ,GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 8), 20, 0));
  397.     pnlBillToButtons.add(btnNewCustomer, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  398.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 50, 0));
  399.     pnlBillToButtons.add(btnFindCustomer, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
  400.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 0), 50, 0));
  401.     pnlOrder.add(pnlShipTo, new GridBagConstraints2(1, 1, 1, 2, 100.0, 0.0
  402.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  403.     pnlShipTo.add(txtShipName, new GridBagConstraints2(0, 1, 3, 1, 1.0, 0.0
  404.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  405.     pnlShipTo.add(txtShipAddr1, new GridBagConstraints2(0, 2, 3, 1, 1.0, 0.0
  406.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  407.     pnlShipTo.add(txtShipAddr2, new GridBagConstraints2(0, 3, 3, 1, 1.0, 0.0
  408.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  409.     pnlShipTo.add(txtShipCity, new GridBagConstraints2(0, 4, 1, 1, 1.0, 0.0
  410.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  411.     pnlShipTo.add(txtShipState, new GridBagConstraints2(1, 4, 1, 2, 1.0, 0.0
  412.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 0), 0, 0));
  413.     pnlShipTo.add(txtShipPostalCode, new GridBagConstraints2(2, 4, 1, 2, 1.0, 0.0
  414.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 8, 8), 0, 0));
  415.     pnlShipTo.add(txtShipCountry, new GridBagConstraints2(0, 5, 3, 1, 1.0, 0.0
  416.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  417.     pnlShipTo.add(lblShipTo, new GridBagConstraints2(0, 0, 2, 1, 100.0, 0.0
  418.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  419.     pnlShipTo.add(btnSaveShipTo, new GridBagConstraints2(2, 0, 1, 1, 0.0, 0.0
  420.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, -8, 0, 8), 0, 0));
  421.     pnlOrder.add(pnlTop, new GridBagConstraints2(0, 0, 2, 1, 100.0, 100.0
  422.             ,GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  423.     pnlTop.add(pnlNavigator, new GridBagConstraints2(0, 0, 1, 1, 100.0, 0.0
  424.             ,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
  425.     pnlNavigator.add(navigatorControl1, new GridBagConstraints2(0, 0, 2, 1, 100.0, 100.0
  426.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 40, 1));
  427.     pnlNavigator.add(lblID, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
  428.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0));
  429.     pnlNavigator.add(txtID, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0
  430.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  431.     pnlTop.add(pnlDate, new GridBagConstraints2(1, 0, 1, 3, 0.0, 0.0
  432.             ,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 14, 0));
  433.     pnlDate.add(lblDate, null);
  434.     pnlDate.add(txtOrderDate, null);
  435.     pnlDate.add(lblOrderTrackNum, null);
  436.     pnlDate.add(txtOrderTrackNum, null);
  437.     pnlDate.add(lblCustomerPONum, null);
  438.     pnlDate.add(txtCustomerPONum, null);
  439.     this.add(pnlMiddle, BorderLayout.CENTER);
  440.     pnlMiddle.add(pnlOrderInfo, BorderLayout.NORTH);
  441.     pnlOrderInfo.add(txtCreditCardNum, new GridBagConstraints2(2, 1, 1, 1, 1.0, 0.0
  442.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  443.     pnlOrderInfo.add(cboPayMethod, new GridBagConstraints2(1, 1, 1, 1, 1.0, 0.0
  444.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  445.     pnlOrderInfo.add(cboShipMethod, new GridBagConstraints2(4, 1, 1, 1, 1.0, 0.0
  446.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  447.     pnlOrderInfo.add(cboStatus, new GridBagConstraints2(5, 1, 1, 1, 1.0, 0.0
  448.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  449.     pnlOrderInfo.add(lblCreditCardNum, new GridBagConstraints2(2, 0, 1, 1, 0.0, 0.0
  450.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  451.     pnlOrderInfo.add(lblPayMethod, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
  452.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  453.     pnlOrderInfo.add(lblShipMethod, new GridBagConstraints2(4, 0, 1, 1, 0.0, 0.0
  454.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  455.     pnlOrderInfo.add(lblStatus, new GridBagConstraints2(5, 0, 1, 1, 0.0, 0.0
  456.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0));
  457.     pnlOrderInfo.add(txtShipDate, new GridBagConstraints2(6, 1, 2, 1, 0.0, 0.0
  458.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  459.     pnlOrderInfo.add(lblShipDate, new GridBagConstraints2(6, 0, 1, 1, 0.0, 0.0
  460.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 8), 0, 0));
  461.     pnlMiddle.add(pnlOrderItems, BorderLayout.CENTER);
  462.     pnlOrderItems.add(grdOrderItems, BorderLayout.CENTER);
  463.     pnlOrderItems.add(pnlOrderItemStatus, BorderLayout.SOUTH);
  464.     pnlOrderItemStatus.add(statusBarOrderItem, new GridBagConstraints2(1, 0, 1, 1, 1.0, 0.0
  465.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
  466.     pnlOrderItemStatus.add(pnlOrderItemButtons, new GridBagConstraints2(3, 0, 1, 1, 0.0, 0.0
  467.             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  468.     pnlOrderItemButtons.add(btnAddOrderItem, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  469.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 25, 0));
  470.     pnlOrderItemButtons.add(btnRemoveOrderItem, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
  471.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
  472.     pnlMiddle.add(pnlBottom, BorderLayout.SOUTH);
  473.     pnlBottom.add(pnlButtons, new GridBagConstraints2(3, 0, 1, 1, 1.0, 1.0
  474.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  475.     pnlButtons.add(btnSave, new GridBagConstraints2(0, 0, 1, 1, 100.0, 100.0
  476.             ,GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 40, 0));
  477.     pnlButtons.add(btnCancel, new GridBagConstraints2(0, 1, 1, 1, 100.0, 100.0
  478.             ,GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
  479.     pnlButtons.add(btnClose, new GridBagConstraints2(0, 2, 1, 1, 100.0, 100.0
  480.             ,GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
  481.     pnlBottom.add(pnlTotals, new GridBagConstraints2(1, 0, 2, 1, 1.0, 1.0
  482.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  483.     pnlTotals.add(lblSubTotal, new GridBagConstraints2(0, 0, 2, 1, 0.0, 0.0
  484.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  485.     pnlTotals.add(lblTax, new GridBagConstraints2(0, 1, 2, 1, 0.0, 0.0
  486.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  487.     pnlTotals.add(txtSubTotal, new GridBagConstraints2(4, 0, 2, 1, 1.0, 0.0
  488.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
  489.     pnlTotals.add(txtTax, new GridBagConstraints2(5, 1, 1, 1, 1.0, 0.0
  490.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  491.     pnlTotals.add(txtTaxPercent, new GridBagConstraints2(4, 1, 1, 1, 1.0, 0.0
  492.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
  493.     pnlTotals.add(txtShipping, new GridBagConstraints2(5, 2, 1, 1, 1.0, 0.0
  494.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  495.     pnlTotals.add(lblShipping, new GridBagConstraints2(0, 2, 2, 1, 0.0, 0.0
  496.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  497.     pnlTotals.add(txtAmtPaid, new GridBagConstraints2(4, 3, 2, 1, 1.0, 0.0
  498.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
  499.     pnlTotals.add(txtAmtDue, new GridBagConstraints2(4, 4, 2, 1, 1.0, 0.0
  500.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
  501.     pnlTotals.add(lblAmtPaid, new GridBagConstraints2(0, 3, 2, 1, 0.0, 0.0
  502.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  503.     pnlTotals.add(lblAmtDue, new GridBagConstraints2(0, 4, 2, 1, 0.0, 0.0
  504.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0));
  505.     pnlTotals.add(txtShipPercent, new GridBagConstraints2(4, 2, 1, 1, 1.0, 0.0
  506.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
  507.     pnlBottom.add(imgLogo, new GridBagConstraints2(0, 0, 1, 1, 1.0, 1.0
  508.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  509.     this.add(statusBarOrder, BorderLayout.SOUTH);
  510.     pnlOrderItemStatus.add(lblOrderItemStatus, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  511.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), -40, 0));
  512.   }
  513.  
  514.   /**
  515.    * We created this method to separate code to initialize database and
  516.    * data-aware controls, which otherwise would go in the jbInit() method.
  517.    * Note that by doing so, the properties set here are not visible to the
  518.    * property inspector. And setting any properties via the inspector will
  519.    * add code to jbInit() instead of here.
  520.    */
  521.   private void initData() throws Exception {
  522.     qdsOrder      = dm.getOrderDataSet();
  523.     qdsOrderItem  = dm.getOrderItemDataSet();
  524.     qdsPayMethod  = dm.getPayMethodDataSet();
  525.     qdsShipMethod = dm.getShipMethodDataSet();
  526.     qdsStatus     = dm.getStatusDataSet();
  527.     qdsCustomer   = dm.getCustomerDataSet();
  528.     qdsProduct    = dm.getProductDataSet();
  529.  
  530.     qdsOrder.open();
  531.     qdsOrderItem.open();
  532.     qdsPayMethod.open();
  533.     qdsShipMethod.open();
  534.     qdsStatus.open();
  535.     qdsCustomer.open();
  536.     qdsProduct.open();
  537.  
  538.     // Fill lookup list for ChoiceControls
  539.     cboPayMethod.setItems(qdsPayMethod, "PAYMETHOD");
  540.     cboShipMethod.setItems(qdsShipMethod, "SHIPMETHOD");
  541.     cboStatus.setItems(qdsStatus, "STATUS");
  542.  
  543.     // Display the Tax percent and Shipping percent
  544.     txtTaxPercent.setText((DataModule1.TAXPERCENT * 100) + "%" );
  545.     txtShipPercent.setText((DataModule1.SHIPPERCENT * 100) + "%");
  546.     
  547.   }
  548.  
  549.   /**
  550.    * Class method to access the singleton instance of the class.
  551.    */
  552.   public static OrderEntryFrame getOrderEntryFrame() {
  553.     if (myOrderEntryFrame == null)
  554.       myOrderEntryFrame = new OrderEntryFrame();
  555.  
  556.     return myOrderEntryFrame;
  557.   }
  558.  
  559.   /**
  560.    * Method to insert a new customer order record.
  561.    * Useful for inserting a new order from other forms in
  562.    * the application.
  563.    */
  564.   public void newOrder() {
  565.     try {
  566.       // Open the dataset if not already opened.
  567.       qdsOrder.open();
  568.       qdsOrderItem.open();
  569.       // Insert a new Order record at the end of the
  570.       // dataset
  571.       qdsOrder.insertRow(false);
  572.     }
  573.     catch (Exception e) {
  574.       e.printStackTrace();
  575.     }
  576.   }
  577.  
  578.   /**
  579.    * Method to insert a new customer order record
  580.    * and setting the customer ID that is passed as
  581.    * the parameter customerID.
  582.    * Useful for inserting a new order from other forms in
  583.    * the application.
  584.    */
  585.   public void newOrder(int customerID) {
  586.     try {
  587.       // Open the dataset if not already opened.
  588.       qdsOrder.open();
  589.       qdsOrderItem.open();
  590.       // Insert a new Order record at the end of the
  591.       // dataset
  592.       qdsOrder.insertRow(false);
  593.       qdsOrder.setInt("CUSTOMERID", customerID);
  594.     }
  595.     catch (Exception e) {
  596.       e.printStackTrace();
  597.     }
  598.   }
  599.  
  600.   /**
  601.    * Method to locate an order given the order ID.
  602.    * If matching record is found, the dataset cursor is positioned
  603.    * on the matching record, and returns true boolean result.
  604.    * Useful for locating order record from other forms in the application.
  605.    */
  606.   public boolean locateOrder(int orderID) {
  607.     boolean found = false;
  608.     try {
  609.       // Define a DataRow to hold the orderID to look for
  610.       // the Order Dataset. Open the dataset if not opened.
  611.       qdsOrder.open();
  612.       DataRow locateRow = new DataRow(qdsOrder, "ID");
  613.       locateRow.setInt("ID", orderID);
  614.  
  615.       found = qdsOrder.locate(locateRow, Locate.FIRST);
  616.     }
  617.     catch (Exception e) {
  618.       e.printStackTrace();
  619.     }
  620.  
  621.     return found;
  622.   }
  623.  
  624.   /**
  625.    * Initialize form controls when the form is activated.
  626.    */
  627.   void this_windowActivated(WindowEvent e) {
  628.     // determine which navigator buttons to enable
  629.  
  630.     // Note that we set the buttons here instead of in
  631.     // windowOpened because when the NavigatorControl rebuilds
  632.     // itself, the Save and Refresh buttons get re-enabled
  633.     int[] enabledFlags = {1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
  634.     for (int i = 0; i < enabledFlags.length; i++)
  635.       navigatorControl1.setButtonEnabled(i, enabledFlags[i] == 1);
  636.   }
  637.  
  638.   /**
  639.    * Before closing the window, check for any pending changes,
  640.    * and prompt user if there are changes pending.
  641.    * Note that we need to both check if there is anything to Post,
  642.    * and to check if there is anything to resolve.
  643.    */
  644.   void this_windowClosing(WindowEvent e) {
  645.     try {
  646.       int orderStatus = qdsOrder.getStatus();
  647.       int orderItemStatus = qdsOrderItem.getStatus();
  648.  
  649.       // determine if datasets are in edit or insert mode and
  650.       // needs to be posted.
  651.       boolean needsPosting = (qdsOrder.isEditing() ||
  652.                               qdsOrder.isEditingNewRow() ||
  653.                               qdsOrderItem.isEditing() ||
  654.                               qdsOrderItem.isEditingNewRow());
  655.       // determine if datasets have pending inserts or updates and
  656.       // need to be resolved.
  657.       boolean needsResolving = (((orderStatus & RowStatus.UPDATED) != 0) ||
  658.                                 ((orderStatus & RowStatus.INSERTED) != 0) ||
  659.                                 ((orderItemStatus & RowStatus.UPDATED) != 0) ||
  660.                                 ((orderItemStatus & RowStatus.INSERTED) != 0));
  661.  
  662.       if (needsPosting || needsResolving) {
  663.         int answer = CliffhangerApplication.messageDlg(res.getString("OEF_Save_Pending_Changes"),
  664.                                                        res.getString("OEF_Save_pending_changes?"),
  665.                                                        Message.YES_NO_CANCEL);
  666.         // Post changes and resolve them back to DB
  667.         if (answer == Message.YES) {
  668.           saveUpdates();
  669.         }
  670.         // If user chooses no, then cancel any inserts or edits
  671.         // and refresh the dataset.
  672.         else if (answer == Message.NO) {
  673.           cancelUpdates();
  674.         }
  675.         // If user cancels, just return
  676.         else //if (answer == Message.CANCEL)
  677.           return;
  678.       }
  679.  
  680.       setVisible(false);
  681.       dispose();
  682.  
  683.     }
  684.     catch (Exception ex) {
  685.       ex.printStackTrace();
  686.       new ExceptionDialog(this, res.getString("OEF_Error"), ex, true).show();
  687.     }
  688.   }
  689.   /**
  690.    * Method to save the inserts or changes made to the order and order item
  691.    * dataset.
  692.    */
  693.   private void saveUpdates() {
  694.     try {
  695.       if (qdsOrder.isEditing() || qdsOrder.isEditingNewRow()) {
  696.         qdsOrder.post();
  697.       }
  698.       if (qdsOrderItem.isEditing() || qdsOrderItem.isEditingNewRow()) {
  699.         qdsOrderItem.post();
  700.       }
  701.       qdsOrder.getDatabase().saveChanges(new DataSet[] {qdsOrder, qdsOrderItem, qdsProduct}, true);
  702.  
  703.       // Refresh the Product dataset to get the latest StockQty for products.
  704.       qdsProduct.refresh();
  705.     }
  706.     catch (Exception ex) {
  707.       ex.printStackTrace();
  708.       new ExceptionDialog(this, res.getString("OEF_Error"), ex, true).show();
  709.     }
  710.   }
  711.  
  712.   /**
  713.    * Method to cancel the inserts or changes made to the order and order item
  714.    * dataset.
  715.    */
  716.   private void cancelUpdates() {
  717.     try {
  718.       // Cancel any edits or inserts
  719.       qdsOrderItem.cancel();
  720.       qdsOrder.cancel();
  721.  
  722.       int orderStatus = qdsOrder.getStatus();
  723.  
  724.       if ((orderStatus & RowStatus.UPDATED) != 0) {
  725.         // refetch this row if it was an update
  726.         qdsOrder.refetchRow(qdsOrder);
  727.       }
  728.       else if ((orderStatus & RowStatus.INSERTED) != 0) {
  729.         // refresh the whole dataset if it was an insert
  730.         qdsOrder.refresh();
  731.         qdsOrder.last();
  732.       }
  733.  
  734.       int orderItemStatus = qdsOrderItem.getStatus();
  735.       if (((orderItemStatus & RowStatus.UPDATED) != 0) ||
  736.           ((orderItemStatus & RowStatus.INSERTED) != 0)) {
  737.         // refetch the orderItem dataset if modified
  738.         qdsOrderItem.refresh();
  739.       }
  740.     }
  741.     catch (Exception ex) {
  742.       ex.printStackTrace();
  743.     }
  744.   }
  745.  
  746.   /**
  747.    * When the Save button is clicked, save the changes in the master-detail
  748.    * relationship between Orders and OrderItem datasets.
  749.    * Post edits before calling resolving changes to the database.
  750.    */
  751.   void btnSave_actionPerformed(ActionEvent e) {
  752.     saveUpdates();
  753.   }
  754.  
  755.   /**
  756.    * When the Cancel button is clicked, cancel any pending changes made to both
  757.    * Orders and OrderItem datasets.
  758.    */
  759.   void btnCancel_actionPerformed(ActionEvent e) {
  760.     cancelUpdates();
  761.   }
  762.  
  763.   /**
  764.    * When Close button is clicked, call this frame's windowClosing
  765.    * event handler to properly handle all dataset pending updates.
  766.    */
  767.   void btnClose_actionPerformed(ActionEvent e) {
  768.     // close this Window
  769.     this.this_windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  770.   }
  771.  
  772.   /**
  773.    * When the Save Ship To button is clicked, save the Ship To information
  774.    * of the current order to the current Customer record.
  775.    */
  776.   void btnSaveShipTo_actionPerformed(ActionEvent e) {
  777.     saveShipToInfo();
  778.   }
  779.  
  780.   /**
  781.    * Save the Ship To information of the current order record to the
  782.    * Customer record.
  783.    * Note: This method also resolves the changes to the database.
  784.    */
  785.   void saveShipToInfo() {
  786.     try {
  787.       int customerID = qdsOrder.getInt("CUSTOMERID");
  788.       DataRow locateRow = new DataRow(qdsCustomer, "ID");
  789.       locateRow.setInt("ID", customerID);
  790.       if (qdsCustomer.locate(locateRow, Locate.FIRST)) {
  791.         qdsCustomer.editRow();
  792.         qdsCustomer.setString("SHIPNAME",       qdsOrder.getString("SHIPNAME"));
  793.         qdsCustomer.setString("SHIPADDR1",      qdsOrder.getString("SHIPADDR1"));
  794.         qdsCustomer.setString("SHIPADDR2",      qdsOrder.getString("SHIPADDR2"));
  795.         qdsCustomer.setString("SHIPCITY",       qdsOrder.getString("SHIPCITY"));
  796.         qdsCustomer.setString("SHIPSTATE",      qdsOrder.getString("SHIPSTATE"));
  797.         qdsCustomer.setString("SHIPPOSTALCODE", qdsOrder.getString("SHIPPOSTALCODE"));
  798.         qdsCustomer.setString("SHIPCOUNTRY",    qdsOrder.getString("SHIPCOUNTRY"));
  799.         qdsCustomer.post();
  800.         //qdsCustomer.saveChanges(qdsCustomer);
  801.       }
  802.     }
  803.     catch (Exception ex) {
  804.       ex.printStackTrace();
  805.       new ExceptionDialog(this, res.getString("OEF_Error"), ex, true).show();
  806.     }
  807.   }
  808.  
  809.   /**
  810.    * When the Find Customer button is clicked, Use the FindOrderCustomer dialog
  811.    * to find a customer for this Order record.
  812.    */
  813.   void btnFindCustomer_actionPerformed(ActionEvent e) {
  814.     FindOrderCustomer dialog = new FindOrderCustomer((Frame)this, res.getString("OEF_Find_Customer"), true);
  815.     try {
  816.       //Center the dialog
  817.       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  818.       Dimension dialogSize = dialog.getSize();
  819.       if (dialogSize.height > screenSize.height)
  820.         dialogSize.height = screenSize.height;
  821.       if (dialogSize.width > screenSize.width)
  822.         dialogSize.width = screenSize.width;
  823.       dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
  824.       dialog.show();
  825.       if (dialog.getResult() == FindOrderCustomer.OK) {
  826.         // use the selected customer for the order
  827.         qdsOrder.editRow();
  828.         qdsOrder.setInt("CUSTOMERID", dialog.getCustomerID());
  829.       }
  830.     }
  831.     catch (Exception ex) {
  832.       ex.printStackTrace();
  833.     }
  834.     finally {
  835.       dialog.dispose();
  836.     }
  837.   }
  838.  
  839.   /**
  840.    * When the New Customer button is clicked, Use the AddCustomerDlg dialog
  841.    * to create a new customer for this Order record.
  842.    */
  843.   void btnNewCustomer_actionPerformed(ActionEvent e) {
  844.     AddCustomerDlg dialog = new AddCustomerDlg((Frame)this, res.getString("OEF_Add_Customer"), true);
  845.     try {
  846.       //Center the window
  847.       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  848.       Dimension dialogSize = dialog.getSize();
  849.       if (dialogSize.height > screenSize.height)
  850.         dialogSize.height = screenSize.height;
  851.       if (dialogSize.width > screenSize.width)
  852.         dialogSize.width = screenSize.width;
  853.       dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
  854.       dialog.show();
  855.       if (dialog.getResult() == AddCustomerDlg.OK) {
  856.         // use the selected customer
  857.         qdsOrder.editRow();
  858.         qdsOrder.setInt("CUSTOMERID", dialog.getCustomerID());
  859.       }
  860.     }
  861.     catch (Exception ex) {
  862.       ex.printStackTrace();
  863.     }
  864.     finally {
  865.       dialog.dispose();
  866.     }
  867.   }
  868.  
  869.   /**
  870.    * When the Add Item button is clicked, insert a new OrderItem record.
  871.    */
  872.   void btnAddOrderItem_actionPerformed(ActionEvent e) {
  873.     try {
  874.       qdsOrderItem.insertRow(false);
  875.     }
  876.     catch (DataSetException ex) {
  877.       ex.printStackTrace();
  878.     }
  879.   }
  880.  
  881.   /**
  882.    * When the Delete Item button is clicked, delete the current OrderItem record.
  883.    */
  884.   void btnRemoveOrderItem_actionPerformed(ActionEvent e) {
  885.     try {
  886.       qdsOrderItem.deleteRow();
  887.     }
  888.     catch (DataSetException ex) {
  889.       ex.printStackTrace();
  890.     }
  891.   }
  892.  
  893.   /* If the payment method is COD, blank out the CC Num field */
  894.   void cboPayMethod_itemStateChanged(ItemEvent e) {
  895.     if(cboPayMethod.getSelectedItem().compareTo(res.getString("OEF_COD")) == 0)
  896.           txtCreditCardNum.setText("");
  897.   }
  898.  
  899. }
  900.  
  901. class OrderEntryFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
  902.   OrderEntryFrame adaptee;
  903.  
  904.   OrderEntryFrame_this_windowAdapter(OrderEntryFrame adaptee) {
  905.     this.adaptee = adaptee;
  906.   }
  907.  
  908.   public void windowClosing(WindowEvent e) {
  909.     adaptee.this_windowClosing(e);
  910.   }
  911.  
  912.   public void windowActivated(WindowEvent e) {
  913.     adaptee.this_windowActivated(e);
  914.   }
  915. }
  916.  
  917.  
  918. class OrderEntryFrame_btnSave_actionAdapter implements java.awt.event.ActionListener {
  919.   OrderEntryFrame adaptee;
  920.  
  921.   OrderEntryFrame_btnSave_actionAdapter(OrderEntryFrame adaptee) {
  922.     this.adaptee = adaptee;
  923.   }
  924.  
  925.   public void actionPerformed(ActionEvent e) {
  926.     adaptee.btnSave_actionPerformed(e);
  927.   }
  928. }
  929.  
  930. class OrderEntryFrame_btnCancel_actionAdapter implements java.awt.event.ActionListener {
  931.   OrderEntryFrame adaptee;
  932.  
  933.   OrderEntryFrame_btnCancel_actionAdapter(OrderEntryFrame adaptee) {
  934.     this.adaptee = adaptee;
  935.   }
  936.  
  937.   public void actionPerformed(ActionEvent e) {
  938.     adaptee.btnCancel_actionPerformed(e);
  939.   }
  940. }
  941.  
  942. class OrderEntryFrame_btnClose_actionAdapter implements java.awt.event.ActionListener {
  943.   OrderEntryFrame adaptee;
  944.  
  945.   OrderEntryFrame_btnClose_actionAdapter(OrderEntryFrame adaptee) {
  946.     this.adaptee = adaptee;
  947.   }
  948.  
  949.   public void actionPerformed(ActionEvent e) {
  950.     adaptee.btnClose_actionPerformed(e);
  951.   }
  952. }
  953.  
  954. class OrderEntryFrame_btnSaveShipTo_actionAdapter implements java.awt.event.ActionListener {
  955.   OrderEntryFrame adaptee;
  956.  
  957.   OrderEntryFrame_btnSaveShipTo_actionAdapter(OrderEntryFrame adaptee) {
  958.     this.adaptee = adaptee;
  959.   }
  960.  
  961.   public void actionPerformed(ActionEvent e) {
  962.     adaptee.btnSaveShipTo_actionPerformed(e);
  963.   }
  964. }
  965.  
  966. class OrderEntryFrame_btnFindCustomer_actionAdapter implements java.awt.event.ActionListener {
  967.   OrderEntryFrame adaptee;
  968.  
  969.   OrderEntryFrame_btnFindCustomer_actionAdapter(OrderEntryFrame adaptee) {
  970.     this.adaptee = adaptee;
  971.   }
  972.  
  973.   public void actionPerformed(ActionEvent e) {
  974.     adaptee.btnFindCustomer_actionPerformed(e);
  975.   }
  976. }
  977.  
  978. class OrderEntryFrame_btnNewCustomer_actionAdapter implements java.awt.event.ActionListener {
  979.   OrderEntryFrame adaptee;
  980.  
  981.   OrderEntryFrame_btnNewCustomer_actionAdapter(OrderEntryFrame adaptee) {
  982.     this.adaptee = adaptee;
  983.   }
  984.  
  985.   public void actionPerformed(ActionEvent e) {
  986.     adaptee.btnNewCustomer_actionPerformed(e);
  987.   }
  988. }
  989.  
  990. class OrderEntryFrame_btnAddOrderItem_actionAdapter implements java.awt.event.ActionListener {
  991.   OrderEntryFrame adaptee;
  992.  
  993.   OrderEntryFrame_btnAddOrderItem_actionAdapter(OrderEntryFrame adaptee) {
  994.     this.adaptee = adaptee;
  995.   }
  996.  
  997.   public void actionPerformed(ActionEvent e) {
  998.     adaptee.btnAddOrderItem_actionPerformed(e);
  999.   }
  1000. }
  1001.  
  1002. class OrderEntryFrame_btnRemoveOrderItem_actionAdapter implements java.awt.event.ActionListener {
  1003.   OrderEntryFrame adaptee;
  1004.  
  1005.   OrderEntryFrame_btnRemoveOrderItem_actionAdapter(OrderEntryFrame adaptee) {
  1006.     this.adaptee = adaptee;
  1007.   }
  1008.  
  1009.   public void actionPerformed(ActionEvent e) {
  1010.     adaptee.btnRemoveOrderItem_actionPerformed(e);
  1011.   }
  1012. }
  1013.  
  1014. class OrderEntryFrame_cboPayMethod_itemAdapter implements java.awt.event.ItemListener {
  1015.   OrderEntryFrame adaptee;
  1016.  
  1017.   OrderEntryFrame_cboPayMethod_itemAdapter(OrderEntryFrame adaptee) {
  1018.     this.adaptee = adaptee;
  1019.   }
  1020.  
  1021.   public void itemStateChanged(ItemEvent e) {
  1022.     adaptee.cboPayMethod_itemStateChanged(e);
  1023.   }
  1024. }
  1025.  
  1026.  
  1027.  
  1028.