📄 addcustomerdlg.java
字号:
/**
* Copyright (c) 1996-2004 Borland Software Corporation. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland Software as part
* of a Borland Software product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland Software.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND SOFTWARE, ITS
* RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
* CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
* DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
* ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
* DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
* DERIVED FROM THIS SOURCE CODE FILE.
*/
//------------------------------------------------------------------------------
// Copyright (c) 1996-2004 Borland Software Corporation. All Rights Reserved.
//------------------------------------------------------------------------------
package com.borland.samples.orderentry;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import com.borland.dbswing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;
/**
* AddCustomerDlg implements the dialog for adding a new customer from the
* OrderEntryFrame. The CustomerFrame could not be used because a modal dialog
* is needed to get the new customer ID for the Order record.
*/
public class AddCustomerDlg extends JDialog {
private static DataModule1 dm = DataModule1.getDataModule();
private QueryDataSet qdsCustomer;
private int result;
private int customerID;
JPanel pnlMain = new JPanel();
JPanel pnlCustomerInfo = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JdbTextField txtFirstName = new JdbTextField();
JdbTextField txtMI = new JdbTextField();
JdbTextField txtLastName = new JdbTextField();
JdbTextField txtAddr1 = new JdbTextField();
JdbTextField txtAddr2 = new JdbTextField();
JdbTextField txtCity = new JdbTextField();
JdbTextField txtState = new JdbTextField();
JdbTextField txtPostalCode = new JdbTextField();
JdbTextField txtCountry = new JdbTextField();
JdbTextField txtPhone = new JdbTextField();
JdbTextField txtEmail = new JdbTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JButton btnOK = new JButton();
JButton btnCancel = new JButton();
// constants
static final int CANCEL = 0;
static final int OK = 1;
ResourceBundle res = Res.getBundle("com.borland.samples.orderentry.Res");
public AddCustomerDlg(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
initData();
getContentPane().add(pnlMain);
pack();
// Insert a new customer record
newCustomer();
}
catch (Exception e) {
e.printStackTrace();
}
}
public AddCustomerDlg(Frame frame) {
this(frame, "", false);
}
public AddCustomerDlg(Frame frame, boolean modal) {
this(frame, "", modal);
}
public AddCustomerDlg(Frame frame, String title) {
this(frame, title, false);
}
private void jbInit() throws Exception{
pnlMain.setLayout(borderLayout1);
pnlMain.setSize(new Dimension(400, 284));
txtFirstName.setColumnName("FIRSTNAME");
txtFirstName.setDataSet(dm.getCustomerDataSet());
txtMI.setColumnName("MI");
txtMI.setDataSet(dm.getCustomerDataSet());
txtLastName.setDataSet(dm.getCustomerDataSet());
txtAddr1.setColumnName("ADDR1");
txtAddr1.setDataSet(dm.getCustomerDataSet());
txtAddr2.setColumnName("ADDR2");
txtAddr2.setDataSet(dm.getCustomerDataSet());
txtCity.setDataSet(dm.getCustomerDataSet());
txtState.setColumnName("STATE");
txtState.setDataSet(dm.getCustomerDataSet());
txtPostalCode.setColumnName("POSTALCODE");
txtPostalCode.setDataSet(dm.getCustomerDataSet());
txtCountry.setColumnName("COUNTRY");
txtCountry.setDataSet(dm.getCustomerDataSet());
txtPhone.setColumnName("PHONE");
txtPhone.setDataSet(dm.getCustomerDataSet());
txtEmail.setColumnName("EMAIL");
txtEmail.setDataSet(dm.getCustomerDataSet());
txtCity.setColumnName("CITY");
txtLastName.setColumnName("LASTNAME");
pnlCustomerInfo.setLayout(gridBagLayout1);
jLabel1.setText(res.getString("ACD_Name"));
jLabel2.setText(res.getString("ACD_Address_1"));
jLabel3.setText(res.getString("ACD_CityStateProv"));
jLabel4.setText(res.getString("ACD_Phone"));
jLabel5.setText(res.getString("ACD_EMail"));
jLabel6.setText(res.getString("ACD_PostalCode"));
jLabel7.setText(res.getString("ACD_Address_2"));
jLabel8.setText(res.getString("ACD_Country"));
jLabel9.setText(res.getString("ACD_First"));
jLabel10.setText(res.getString("ACD_MI"));
jLabel11.setText(res.getString("ACD_Last"));
btnOK.setText(res.getString("ACD_OK"));
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnOK_actionPerformed(e);
}
});
btnCancel.setText(res.getString("ACD_Cancel"));
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCancel_actionPerformed(e);
}
});
pnlMain.add(pnlCustomerInfo, BorderLayout.CENTER);
pnlCustomerInfo.add(txtFirstName, new GridBagConstraints(6, 1, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 112, 0));
pnlCustomerInfo.add(txtMI, new GridBagConstraints(8, 1, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
pnlCustomerInfo.add(txtLastName, new GridBagConstraints(10, 1, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 4), 107, 0));
pnlCustomerInfo.add(txtAddr1, new GridBagConstraints(6, 2, 6, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 4), 224, 0));
pnlCustomerInfo.add(txtAddr2, new GridBagConstraints(6, 3, 6, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 4), 224, 0));
pnlCustomerInfo.add(txtCity, new GridBagConstraints(6, 4, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 108, 0));
pnlCustomerInfo.add(txtState, new GridBagConstraints(8, 4, 5, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 46), 17, 0));
pnlCustomerInfo.add(txtPostalCode, new GridBagConstraints(6, 5, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 108, 0));
pnlCustomerInfo.add(txtCountry, new GridBagConstraints(6, 6, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 107, 0));
pnlCustomerInfo.add(txtPhone, new GridBagConstraints(6, 7, 2, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 0), 106, 0));
pnlCustomerInfo.add(txtEmail, new GridBagConstraints(6, 9, 6, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 10, 4), 223, 0));
pnlCustomerInfo.add(jLabel1, new GridBagConstraints(0, 1, 6, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 27, 0));
pnlCustomerInfo.add(jLabel2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel3, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel4, new GridBagConstraints(0, 7, 3, 2, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel5, new GridBagConstraints(0, 9, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 10, 0), 0, 0));
pnlCustomerInfo.add(jLabel7, new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel8, new GridBagConstraints(0, 6, 4, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel9, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 12, 0, 0), 9, 0));
pnlCustomerInfo.add(jLabel10, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 8, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel11, new GridBagConstraints(10, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 9, 0, 0), 0, 0));
pnlCustomerInfo.add(jLabel6, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
pnlMain.add(jPanel1, BorderLayout.SOUTH);
jPanel1.add(btnOK, null);
jPanel1.add(btnCancel, null);
}
private void initData() {
qdsCustomer = dm.getCustomerDataSet();
}
/**
* Method to insert a new customer record
*/
public void newCustomer() {
try {
// Open the dataset if not already opened.
qdsCustomer.open();
// Insert a new Customer record at the end of the
// dataset
qdsCustomer.insertRow(false);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* When the OK button is clicked, save the new customer record, and
* set the result property of the dialog to OK.
*
* @param e ActionEvent
*/
void btnOK_actionPerformed(ActionEvent e) {
try {
// Post, saveChanges (resolve), refresh the dataset and navigate to
// the last record to get the added CustomerID.
qdsCustomer.post();
qdsCustomer.saveChanges(qdsCustomer);
qdsCustomer.refresh();
qdsCustomer.last();
customerID = qdsCustomer.getInt("ID");
result = OK;
setVisible(false);
dispose();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* When the Cancel button is clicked, cancel any unposted inserts or edits.
* Set the result property to CANCEL.
* @param e ActionEvent
*/
void btnCancel_actionPerformed(ActionEvent e) {
try {
qdsCustomer.cancel();
}
catch (Exception ex) {
ex.printStackTrace();
}
result = CANCEL;
setVisible(false);
dispose();
}
/**
* Getter method for the result property
* @return int
*/
public int getResult() {
return this.result;
}
/**
* getter method for the customerID property
* @return int
*/
public int getCustomerID() {
return this.customerID;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -