home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / AddCustomerDlg.java next >
Encoding:
Java Source  |  1998-05-08  |  12.6 KB  |  307 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.  
  21. //Title:        Cliffhanger Adventure Gear
  22. //Version:
  23. //Copyright:    Copyright (c) 1997 Borland International, Inc.
  24. //Author:       Application Methods, Inc..
  25. //Description:  Cliffhanger Adventure Gear order entry system
  26.  
  27. package borland.reference.cliffhanger;
  28.  
  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 java.util.*;
  36.  
  37. /**
  38.  * AddCustomerDlg implements the dialog for adding a new customer from the
  39.  * OrderEntryFrame. The CustomerFrame could not be used because a modal dialog
  40.  * is needed to get the new customer ID for the Order record.
  41.  */
  42. public class AddCustomerDlg extends Dialog {
  43.   private static DataModule1 dm = DataModule1.getDataModule();
  44.   private QueryDataSet qdsCustomer;
  45.   private int result;
  46.   private int customerID;
  47.   Panel pnlMain = new Panel();
  48.   BevelPanel pnlCustomerInfo = new BevelPanel();
  49.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  50.   FieldControl txtFirstName = new FieldControl();
  51.   FieldControl txtMI = new FieldControl();
  52.   FieldControl txtLastName = new FieldControl();
  53.   FieldControl txtAddr1 = new FieldControl();
  54.   FieldControl txtAddr2 = new FieldControl();
  55.   FieldControl txtCity = new FieldControl();
  56.   FieldControl txtState = new FieldControl();
  57.   FieldControl txtPostalCode = new FieldControl();
  58.   FieldControl txtCountry = new FieldControl();
  59.   FieldControl txtPhone = new FieldControl();
  60.   FieldControl txtEmail = new FieldControl();
  61.   LabelControl labelControl1 = new LabelControl();
  62.   LabelControl labelControl2 = new LabelControl();
  63.   LabelControl labelControl3 = new LabelControl();
  64.   LabelControl labelControl4 = new LabelControl();
  65.   LabelControl labelControl5 = new LabelControl();
  66.   LabelControl labelControl6 = new LabelControl();
  67.   LabelControl labelControl7 = new LabelControl();
  68.   LabelControl labelControl8 = new LabelControl();
  69.   LabelControl labelControl9 = new LabelControl();
  70.   LabelControl labelControl10 = new LabelControl();
  71.   LabelControl labelControl11 = new LabelControl();
  72.   BorderLayout borderLayout1 = new BorderLayout();
  73.   BevelPanel bevelPanel1 = new BevelPanel();
  74.   ButtonControl btnOK = new ButtonControl();
  75.   ButtonControl btnCancel = new ButtonControl();
  76.   FlowLayout flowLayout1 = new FlowLayout();
  77.  
  78.   // constants
  79.   static final int CANCEL = 0;
  80.   static final int OK = 1;
  81.   ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
  82.  
  83.   public AddCustomerDlg(Frame frame, String title, boolean modal) {
  84.     super(frame, title, modal);
  85.     try {
  86.       jbInit();
  87.       initData();
  88.       add(pnlMain);
  89.       pack();
  90.       // Insert a new customer record
  91.       newCustomer();
  92.     }
  93.     catch (Exception e) {
  94.       e.printStackTrace();
  95.     }
  96.   }
  97.  
  98.   public AddCustomerDlg(Frame frame) {
  99.     this(frame, "", false);
  100.   }
  101.  
  102.   public AddCustomerDlg(Frame frame, boolean modal) {
  103.     this(frame, "", modal);
  104.   }
  105.  
  106.   public AddCustomerDlg(Frame frame, String title) {
  107.     this(frame, title, false);
  108.   }
  109.  
  110.   private void jbInit() throws Exception{
  111.     pnlMain.setLayout(borderLayout1);
  112.     pnlMain.setSize(new Dimension(400, 284));
  113.     pnlCustomerInfo.setBevelInner(BevelPanel.FLAT);
  114.     pnlCustomerInfo.setBevelOuter(borland.jbcl.control.BevelPanel.FLAT);
  115.     pnlCustomerInfo.setMargins(new Insets(4, 4, 4, 4));
  116.     txtFirstName.setColumnName("FIRSTNAME");
  117.     txtFirstName.setDataSet(dm.getCustomerDataSet());
  118.     txtMI.setColumnName("MI");
  119.     txtMI.setDataSet(dm.getCustomerDataSet());
  120.     txtLastName.setDataSet(dm.getCustomerDataSet());
  121.     txtAddr1.setColumnName("ADDR1");
  122.     txtAddr1.setDataSet(dm.getCustomerDataSet());
  123.     txtAddr2.setColumnName("ADDR2");
  124.     txtAddr2.setDataSet(dm.getCustomerDataSet());
  125.     txtCity.setDataSet(dm.getCustomerDataSet());
  126.     txtState.setColumnName("STATE");
  127.     txtState.setDataSet(dm.getCustomerDataSet());
  128.     txtPostalCode.setColumnName("POSTALCODE");
  129.     txtPostalCode.setDataSet(dm.getCustomerDataSet());
  130.     txtCountry.setColumnName("COUNTRY");
  131.     txtCountry.setDataSet(dm.getCustomerDataSet());
  132.     txtPhone.setColumnName("PHONE");
  133.     txtPhone.setDataSet(dm.getCustomerDataSet());
  134.     txtEmail.setColumnName("EMAIL");
  135.     txtEmail.setDataSet(dm.getCustomerDataSet());
  136.     txtCity.setColumnName("CITY");
  137.     txtLastName.setColumnName("LASTNAME");
  138.     pnlCustomerInfo.setLayout(gridBagLayout1);
  139.     labelControl1.setText(res.getString("ACD_Name"));
  140.     labelControl2.setText(res.getString("ACD_Address_1"));
  141.     labelControl3.setText(res.getString("ACD_CityStateProv"));
  142.     labelControl4.setText(res.getString("ACD_Phone"));
  143.     labelControl5.setText(res.getString("ACD_EMail"));
  144.     labelControl6.setText(res.getString("ACD_PostalCode"));
  145.     labelControl7.setText(res.getString("ACD_Address_2"));
  146.     labelControl8.setText(res.getString("ACD_Country"));
  147.     labelControl9.setText(res.getString("ACD_First"));
  148.     labelControl10.setText(res.getString("ACD_MI"));
  149.     labelControl11.setText(res.getString("ACD_Last"));
  150.     bevelPanel1.setBevelInner(BevelPanel.FLAT);
  151.     bevelPanel1.setLayout(flowLayout1);
  152.     btnOK.setLabel(res.getString("ACD_OK"));
  153.     btnOK.addActionListener(new AddCustomerDlg_btnOK_actionAdapter(this));
  154.     btnCancel.setLabel(res.getString("ACD_Cancel"));
  155.     btnCancel.addActionListener(new AddCustomerDlg_btnCancel_actionAdapter(this));
  156.     pnlMain.add(pnlCustomerInfo, BorderLayout.CENTER);
  157.     pnlCustomerInfo.add(txtFirstName, new GridBagConstraints2(6, 1, 2, 1, 1.0, 0.0
  158.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 112, 0));
  159.     pnlCustomerInfo.add(txtMI, new GridBagConstraints2(8, 1, 2, 1, 1.0, 0.0
  160.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  161.     pnlCustomerInfo.add(txtLastName, new GridBagConstraints2(10, 1, 3, 1, 1.0, 0.0
  162.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 4), 107, 0));
  163.     pnlCustomerInfo.add(txtAddr1, new GridBagConstraints2(6, 2, 6, 1, 1.0, 0.0
  164.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 4), 224, 0));
  165.     pnlCustomerInfo.add(txtAddr2, new GridBagConstraints2(6, 3, 6, 1, 1.0, 0.0
  166.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 4), 224, 0));
  167.     pnlCustomerInfo.add(txtCity, new GridBagConstraints2(6, 4, 2, 1, 1.0, 0.0
  168.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 108, 0));
  169.     pnlCustomerInfo.add(txtState, new GridBagConstraints2(8, 4, 5, 1, 1.0, 0.0
  170.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 46), 17, 0));
  171.     pnlCustomerInfo.add(txtPostalCode, new GridBagConstraints2(6, 5, 2, 1, 1.0, 0.0
  172.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 108, 0));
  173.     pnlCustomerInfo.add(txtCountry, new GridBagConstraints2(6, 6, 2, 1, 1.0, 0.0
  174.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 107, 0));
  175.     pnlCustomerInfo.add(txtPhone, new GridBagConstraints2(6, 7, 2, 1, 1.0, 0.0
  176.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 0), 106, 0));
  177.     pnlCustomerInfo.add(txtEmail, new GridBagConstraints2(6, 9, 6, 1, 1.0, 0.0
  178.             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 10, 4), 223, 0));
  179.     pnlCustomerInfo.add(labelControl1, new GridBagConstraints2(0, 1, 6, 1, 0.0, 0.0
  180.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 27, 0));
  181.     pnlCustomerInfo.add(labelControl2, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0
  182.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
  183.     pnlCustomerInfo.add(labelControl3, new GridBagConstraints2(0, 4, 1, 1, 0.0, 0.0
  184.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  185.     pnlCustomerInfo.add(labelControl4, new GridBagConstraints2(0, 7, 3, 2, 0.0, 0.0
  186.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
  187.     pnlCustomerInfo.add(labelControl5, new GridBagConstraints2(0, 9, 2, 1, 0.0, 0.0
  188.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 10, 0), 0, 0));
  189.     pnlCustomerInfo.add(labelControl7, new GridBagConstraints2(0, 3, 5, 1, 0.0, 0.0
  190.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  191.     pnlCustomerInfo.add(labelControl8, new GridBagConstraints2(0, 6, 4, 1, 0.0, 0.0
  192.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  193.     pnlCustomerInfo.add(labelControl9, new GridBagConstraints2(6, 0, 1, 1, 0.0, 0.0
  194.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 12, 0, 0), 9, 0));
  195.     pnlCustomerInfo.add(labelControl10, new GridBagConstraints2(8, 0, 1, 1, 0.0, 0.0
  196.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 8, 0, 0), 0, 0));
  197.     pnlCustomerInfo.add(labelControl11, new GridBagConstraints2(10, 0, 1, 1, 0.0, 0.0
  198.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 9, 0, 0), 0, 0));
  199.     pnlCustomerInfo.add(labelControl6, new GridBagConstraints2(0, 5, 1, 1, 0.0, 0.0
  200.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
  201.     pnlMain.add(bevelPanel1, BorderLayout.SOUTH);
  202.     bevelPanel1.add(btnOK, null);
  203.     bevelPanel1.add(btnCancel, null);
  204.   }
  205.  
  206.   private void initData() {
  207.     qdsCustomer = dm.getCustomerDataSet();
  208.   }
  209.  
  210.   /**
  211.    * Method to insert a new customer record
  212.    */
  213.   public void newCustomer() {
  214.     try {
  215.       // Open the dataset if not already opened.
  216.       qdsCustomer.open();
  217.       // Insert a new Customer record at the end of the
  218.       // dataset
  219.       qdsCustomer.insertRow(false);
  220.     }
  221.     catch (Exception e) {
  222.       e.printStackTrace();
  223.     }
  224.   }
  225.  
  226.   /**
  227.    * When the OK button is clicked, save the new customer record, and
  228.    * set the result property of the dialog to OK.
  229.    */
  230.   void btnOK_actionPerformed(ActionEvent e) {
  231.     try {
  232.       // Post, saveChanges (resolve), refresh the dataset and navigate to
  233.       // the last record to get the added CustomerID.
  234.       qdsCustomer.post();
  235.       qdsCustomer.saveChanges(qdsCustomer);
  236.       qdsCustomer.refresh();
  237.       qdsCustomer.last();
  238.       customerID = qdsCustomer.getInt("ID");
  239.       result = OK;
  240.       setVisible(false);
  241.       dispose();
  242.     }
  243.     catch (Exception ex) {
  244.       ex.printStackTrace();
  245.     }
  246.   }
  247.  
  248.   /**
  249.    * When the Cancel button is clicked, cancel any unposted inserts or edits.
  250.    * Set the result property to CANCEL.
  251.    */
  252.   void btnCancel_actionPerformed(ActionEvent e) {
  253.     try {
  254.       qdsCustomer.cancel();
  255.     }
  256.     catch (Exception ex) {
  257.       ex.printStackTrace();
  258.     }
  259.     result = CANCEL;
  260.     setVisible(false);
  261.     dispose();
  262.   }
  263.  
  264.   /**
  265.    * Getter method for the result property
  266.    */
  267.   public int getResult() {
  268.     return this.result;
  269.   }
  270.  
  271.   /**
  272.    * getter method for the customerID property
  273.    */
  274.   public int getCustomerID() {
  275.     return this.customerID;
  276.   }
  277.  
  278. }
  279.  
  280. class AddCustomerDlg_btnOK_actionAdapter implements java.awt.event.ActionListener {
  281.   AddCustomerDlg adaptee;
  282.  
  283.   AddCustomerDlg_btnOK_actionAdapter(AddCustomerDlg adaptee) {
  284.     this.adaptee = adaptee;
  285.   }
  286.  
  287.   public void actionPerformed(ActionEvent e) {
  288.     adaptee.btnOK_actionPerformed(e);
  289.   }
  290. }
  291.  
  292. class AddCustomerDlg_btnCancel_actionAdapter implements java.awt.event.ActionListener {
  293.   AddCustomerDlg adaptee;
  294.  
  295.   AddCustomerDlg_btnCancel_actionAdapter(AddCustomerDlg adaptee) {
  296.     this.adaptee = adaptee;
  297.   }
  298.  
  299.   public void actionPerformed(ActionEvent e) {
  300.     adaptee.btnCancel_actionPerformed(e);
  301.   }
  302. }
  303.  
  304.  
  305.  
  306.  
  307.