📄 findordercustomer.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.*;
/**
* FindOrderCustomer implements the dialog for choosing a customer from the
* OrderEntryFrame. The CustomerFrame could not be used because a modal dialog
* is needed to get the customer ID for the Order record.
*/
public class FindOrderCustomer extends JDialog {
private static DataModule1 dm = DataModule1.getDataModule();
private QueryDataSet qdsCustomer;
private int result;
private int customerID;
JPanel contentPane;
JPanel panel1 = new JPanel();
JPanel pnlTop = new JPanel();
JPanel pnlButtons = new JPanel();
JButton btnOK = new JButton();
JButton btnCancel = new JButton();
JLabel lblField = new JLabel();
JLabel lblValue = new JLabel();
JdbComboBox cboField = new JdbComboBox();
JdbNavField jdbNavField1 = new JdbNavField();
JScrollPane jScrollPane1 = new JScrollPane();
JdbTable jdbTable1 = new JdbTable();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
JPanel pnlLocate = new JPanel();
// constants
static final int CANCEL = 0;
static final int OK = 1;
ResourceBundle res = Res.getBundle("com.borland.samples.orderentry.Res");
public FindOrderCustomer(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
initData();
contentPane.add(panel1);
pack();
}
catch (Exception e) {
e.printStackTrace();
}
}
public FindOrderCustomer(Frame frame) {
this(frame, "", false);
}
public FindOrderCustomer(Frame frame, boolean modal) {
this(frame, "", modal);
}
public FindOrderCustomer(Frame frame, String title) {
this(frame, title, false);
}
private void jbInit() throws Exception{
contentPane = (JPanel) this.getContentPane();
result = CANCEL;
customerID = 0;
pnlTop.setLayout(borderLayout2);
pnlButtons.setLayout(gridBagLayout1);
pnlLocate.setLayout(gridBagLayout2);
panel1.setSize(new Dimension(350, 250));
btnOK.setText(res.getString("FOC_OK"));
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnOK_actionPerformed(e);
}
});
btnCancel.setText(res.getString("FOC_Cancel"));
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCancel_actionPerformed(e);
}
});
lblField.setText(res.getString("FOC_Field"));
lblValue.setText(res.getString("FOC_Value"));
jdbNavField1.setDataSet(dm.getCustomerDataSet());
cboField.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
cboField_itemStateChanged(e);
}
});
cboField.setItems(new String [] { res.getString("DM_CustomerDS_LASTNAME"), res.getString("DM_CustomerDS_FIRSTNAME"), res.getString("DM_CustomerDS_PHONE"), res.getString("DM_CustomerDS_ID") });
jdbNavField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(KeyEvent e) {
jdbNavField1_keyPressed(e);
}
});
jdbTable1.setDataSet(dm.getCustomerDataSet());
jdbTable1.setEditable(false);
jScrollPane1.getViewport().add(jdbTable1);
panel1.setLayout(borderLayout1);
panel1.add(pnlTop, BorderLayout.NORTH);
pnlTop.add(pnlLocate, BorderLayout.CENTER);
pnlTop.add(pnlButtons, BorderLayout.EAST);
pnlButtons.add(btnOK, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
pnlButtons.add(btnCancel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
pnlLocate.add(lblField, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
pnlLocate.add(lblValue, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
pnlLocate.add(cboField, new GridBagConstraints(1, 0, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
pnlLocate.add(jdbNavField1, new GridBagConstraints(1, 1, 3, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
panel1.add(jScrollPane1, BorderLayout.CENTER);
}
private void initData() {
qdsCustomer = dm.getCustomerDataSet();
}
/**
* 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;
}
/**
* When the OK button is clicked, set the customerID property of the dialog,
* set the result property of the dialog to OK, then close the dialog window.
*
* @param e ActionEvent
* return void
*/
void btnOK_actionPerformed(ActionEvent e) {
try {
customerID = qdsCustomer.getInt("ID");
}
catch (Exception ex) {
ex.printStackTrace();
}
result = OK;
setVisible(false);
dispose();
}
/**
* When the Cancel button is clicked, cancel any unposted inserts or edits.
* Set the result property to CANCEL, then close the dialog window.
*
* @param e ActionEvent
* return void
*/
void btnCancel_actionPerformed(ActionEvent e) {
result = CANCEL;
setVisible(false);
dispose();
}
/**
* The itemStateChanged event is triggered when the user selects a new item
* off the choiceControl's drop down list of possible fields to search on.
* Reset the text property of the locatorControl to be ready for a new
* search value.
*
* @param e ItemEvent
* return void
*/
void cboField_itemStateChanged(ItemEvent e) {
jdbNavField1.setText("");
}
/**
* When the user types in the locatorControl, make sure that the ColumnName
* property of the locatorControl is set to the column name selected in the
* ChoiceControl.
*
* @param e KeyEvent
* return void
*/
void jdbNavField1_keyPressed(KeyEvent e) {
// Set the columnName property of the locatorControl
// if it is not set.
try {
if ((jdbNavField1.getColumnName() == null) ||
(jdbNavField1.getDataSet().getColumn(jdbNavField1.getColumnName()).getCaption().compareTo(cboField.getSelectedItem()) != 0)) {
Column [] columns = jdbNavField1.getDataSet().getColumns();
for (int index = 0; index < columns.length; index++) {
if (columns[index].getCaption().compareTo(cboField.getSelectedItem()) == 0) {
jdbNavField1.setColumnName(columns[index].getColumnName());
break;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -