📄 createcarddialog.java~42~
字号:
package parkingsystem;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.sql.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import com.borland.dx.sql.dataset.*;
public class CreateCardDialog extends JDialog {
JPanel panel1 = new JPanel();
BorderLayout borderLayout2 = new BorderLayout();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
XYLayout xYLayout2 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JButton jButton2 = new JButton();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
ButtonGroup buttonGroup1 = new ButtonGroup();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel7 = new JLabel();
XYLayout xYLayout3 = new XYLayout();
JLabel jLabel8 = new JLabel();
JButton jButton3 = new JButton();
JPasswordField jPasswordField2 = new JPasswordField();
JRadioButton jRadioButton3 = new JRadioButton();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
JRadioButton jRadioButton4 = new JRadioButton();
JPanel jPanel3 = new JPanel();
JLabel jLabel12 = new JLabel();
JButton jButton4 = new JButton();
JPasswordField jPasswordField3 = new JPasswordField();
JRadioButton jRadioButton5 = new JRadioButton();
JLabel jLabel13 = new JLabel();
JLabel jLabel14 = new JLabel();
JLabel jLabel15 = new JLabel();
JRadioButton jRadioButton6 = new JRadioButton();
JPanel jPanel4 = new JPanel();
JLabel jLabel16 = new JLabel();
JLabel jLabel17 = new JLabel();
JLabel jLabel18 = new JLabel();
JTextField jTextField5 = new JTextField();
JTextField jTextField3 = new JTextField();
JButton jButton1 = new JButton();
JTextField jTextField4 = new JTextField();
QueryDataSet queryDataSet1,queryDataSet2;
Database database;
JRadioButton jRadioButton1 = new JRadioButton();
JLabel jLabel4 = new JLabel();
JRadioButton jRadioButton2 = new JRadioButton();
QueryDataSet queryDataSet3 = new QueryDataSet();
Database database1 = new Database();
public CreateCardDialog(Frame frame, String title, boolean modal,QueryDataSet queryDataSet1,QueryDataSet queryDataSet2,Database database) {
super(frame, title, modal);
this.queryDataSet1=queryDataSet1;
this.queryDataSet2=queryDataSet2;
this.database=database;
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
panel1.setLayout(xYLayout1);
this.getContentPane().setLayout(borderLayout2);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setBorder(BorderFactory.createEtchedBorder());
TitledBorder cardBorder=new TitledBorder("填入卡的相关信息");
TitledBorder owerBorder=new TitledBorder("添加车主信息");
jPanel1.setBorder(cardBorder);
jPanel1.setLayout(xYLayout2);
jPanel2.setBorder(owerBorder);
jPanel2.setLayout(xYLayout3);
jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel1.setText("卡 号:");
jLabel2.setText("密 码:");
jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel3.setText("车牌号:");
jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel5.setText("申请时长(月):");
jLabel6.setText("应收款:");
jLabel6.setFont(new java.awt.Font("Dialog", 0, 12));
jButton2.setText("清 空");
jButton2.addActionListener(new CreateCardDialog_jButton2_actionAdapter(this));
jButton2.setFont(new java.awt.Font("Dialog", 0, 12));
jTextField1.setFont(new java.awt.Font("Dialog", 0, 12));
jTextField1.setText("");
jTextField2.setFont(new java.awt.Font("Dialog", 0, 12));
jTextField2.setText("");
jPasswordField1.setVerifyInputWhenFocusTarget(true);
jPasswordField1.setText("");
jComboBox1.setFont(new java.awt.Font("Dialog", 0, 12));
jComboBox1.addActionListener(new CreateCardDialog_jComboBox1_actionAdapter(this));
jLabel7.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel7.setText("");
jLabel8.setText("卡类型:");
jLabel8.setFont(new java.awt.Font("Dialog", 0, 12));
jButton3.setFont(new java.awt.Font("Dialog", 0, 12));
jButton3.setText("清 空");
jPasswordField2.setText("");
jPasswordField2.setVerifyInputWhenFocusTarget(true);
jRadioButton3.setText("长期卡");
jRadioButton3.setSelected(true);
jRadioButton3.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel9.setText("卡 号:");
jLabel9.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel10.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel10.setText("车牌号:");
jLabel11.setText("");
jLabel11.setFont(new java.awt.Font("Dialog", 0, 12));
jRadioButton4.setFont(new java.awt.Font("Dialog", 0, 12));
jRadioButton4.setText("次卡");
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jLabel12.setText("卡类型:");
jLabel12.setFont(new java.awt.Font("Dialog", 0, 12));
jButton4.setFont(new java.awt.Font("Dialog", 0, 12));
jButton4.setText("清 空");
jPasswordField3.setText("");
jPasswordField3.setVerifyInputWhenFocusTarget(true);
jRadioButton5.setText("长期卡");
jRadioButton5.setSelected(true);
jRadioButton5.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel13.setText("卡 号:");
jLabel13.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel14.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel14.setText("车牌号:");
jLabel15.setText("");
jLabel15.setFont(new java.awt.Font("Dialog", 0, 12));
jRadioButton6.setFont(new java.awt.Font("Dialog", 0, 12));
jRadioButton6.setText("次卡");
jPanel4.setBorder(BorderFactory.createEtchedBorder());
jLabel16.setText("车主姓名:");
jLabel16.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel17.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel17.setText("住 址:");
jLabel18.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel18.setText("联系电话:");
jTextField5.setText("");
jTextField5.setFont(new java.awt.Font("Dialog", 0, 12));
jTextField3.setText("");
jTextField3.setFont(new java.awt.Font("Dialog", 0, 12));
jButton1.setText("确 定");
jButton1.addActionListener(new CreateCardDialog_jButton1_actionAdapter(this));
jButton1.setFont(new java.awt.Font("Dialog", 0, 12));
jTextField4.setFont(new java.awt.Font("Dialog", 0, 12));
jTextField4.setText("");
jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 12));
jRadioButton1.setSelected(true);
jRadioButton1.setText("长期卡");
jRadioButton1.addActionListener(new CreateCardDialog_jRadioButton1_actionAdapter(this));
jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
jLabel4.setText("选择新开卡类型:");
jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 12));
jRadioButton2.setText("次卡");
jRadioButton2.addActionListener(new CreateCardDialog_jRadioButton2_actionAdapter(this));
panel1.setFont(new java.awt.Font("Dialog", 0, 12));
panel1.setPreferredSize(new Dimension(400, 430));
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=carparkingdb", "sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
queryDataSet3.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select Price from cardtype where CardType=\'长期卡\'", null, true, Load.ALL));
getContentPane().add(panel1, BorderLayout.CENTER);
jPanel2.add(jLabel18, new XYConstraints(49, 40, 61, 28));
jPanel2.add(jLabel16, new XYConstraints(49, 2, 61, 28));
jPanel2.add(jTextField3, new XYConstraints(116, 5, 193, -1));
jPanel2.add(jTextField4, new XYConstraints(115, 42, 193, -1));
jPanel2.add(jLabel17, new XYConstraints(49, 78, 61, 28));
jPanel2.add(jTextField5, new XYConstraints(116, 80, 193, -1));
panel1.add(jPanel1, new XYConstraints(16, 53, 388, 165));
jPanel1.add(jLabel2, new XYConstraints(49, 32, 61, 28));
jPanel1.add(jPasswordField1, new XYConstraints(116, 36, 193, 23));
jPanel1.add(jLabel1, new XYConstraints(49, 1, 61, 28));
jPanel1.add(jTextField1, new XYConstraints(116, 5, 193, -1));
jPanel1.add(jLabel3, new XYConstraints(49, 62, 61, 28));
jPanel1.add(jTextField2, new XYConstraints(116, 66, 193, -1));
jPanel1.add(jLabel5, new XYConstraints(49, 103, 83, 28));
jPanel1.add(jComboBox1, new XYConstraints(139, 108, 79, 20));
jPanel1.add(jLabel6, new XYConstraints(232, 104, 61, 28));
jPanel1.add(jLabel7, new XYConstraints(279, 107, 93, 27));
panel1.add(jRadioButton1, new XYConstraints(144, 16, 76, 30));
panel1.add(jLabel4, new XYConstraints(24, 16, 108, 30));
panel1.add(jRadioButton2, new XYConstraints(246, 16, 102, 30));
panel1.add(jButton1, new XYConstraints(102, 368, 83, 30));
panel1.add(jButton2, new XYConstraints(239, 368, 83, 30));
panel1.add(jPanel2, new XYConstraints(16, 215, 388, 144));
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
//向jComboBox1中添加条目
for(int i=1;i<=12;i++){
jComboBox1.addItem(i+"");
}
}
void jRadioButton2_itemStateChanged(ItemEvent e) {
jComboBox1.setEnabled(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField5.setEditable(false);
}
void jRadioButton1_itemStateChanged(ItemEvent e) {
jComboBox1.setEnabled(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jTextField5.setEditable(true);
}
void jButton2_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jPasswordField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
}
void jButton1_actionPerformed(ActionEvent e) {
int cardID=Integer.parseInt(jTextField1.getText().trim());
String password=jPasswordField1.getText();
String carNum="";
int month=0;
String owerName="";
String telephone="";
String address="";
if(jRadioButton1.isSelected()){
carNum=jTextField2.getText();
month=Integer.parseInt(jComboBox1.getSelectedItem().toString());
owerName=jTextField3.getText();
telephone=jTextField4.getText();
address=jTextField5.getText();
//插入一条记录
queryDataSet1.last();//定位到数据集的最后一行
queryDataSet1.insertRow(false);//在最后添加一条记录
queryDataSet1.setInt("CardID",cardID);
queryDataSet1.setString("Password",password);
queryDataSet1.setString("CardType","长期卡");
queryDataSet1.setString("CarNum",carNum);
java.util.Date now=new java.util.Date();
Timestamp t=new Timestamp(now.getTime());
t.setMonth(t.getMonth()+Integer.parseInt(jComboBox1.getSelectedItem().toString()));
queryDataSet1.setTimestamp("TimeLimit",t);
queryDataSet1.refresh();
queryDataSet2.refresh();
queryDataSet2.insertRow(false);
queryDataSet2.setString("OwerName",owerName);
queryDataSet2.setString("Telephone",telephone);
queryDataSet2.setString("Address",address);
queryDataSet2.setInt("CardID",cardID);
QueryDataSet q[]={queryDataSet1,queryDataSet2};
database.saveChanges(queryDataSet1);
database.saveChanges(queryDataSet2);
database.saveChanges(queryDataSet2);
JOptionPane.showMessageDialog(this,"成功插入记录!");
}
/*queryDataSet2.insertRow(false);
queryDataSet2.setString("OwerName","胡");
queryDataSet2.setString("Telephone","137");
queryDataSet2.setString("Address","gg");
queryDataSet2.setInt("CardID",11111111);
database.saveChanges(queryDataSet2);*/
}
void jRadioButton1_actionPerformed(ActionEvent e) {
jTextField2.setEditable(true);
jComboBox1.setEnabled(true);
jTextField3.setEditable(true);
jTextField4.setEditable(true);
jTextField5.setEditable(true);
}
void jRadioButton2_actionPerformed(ActionEvent e) {
jTextField2.setEditable(false);
jComboBox1.setEnabled(false);
jTextField3.setEditable(false);
jTextField4.setEditable(false);
jTextField5.setEditable(false);
}
void jComboBox1_actionPerformed(ActionEvent e) {
queryDataSet3.open();
int month=Integer.parseInt(jComboBox1.getSelectedItem().toString());
java.math.BigDecimal l;
double money=queryDataSet3.getBigDecimal("Price").doubleValue()*month;
jLabel7.setText(money+"");
queryDataSet3.close();
}
}
class CreateCardDialog_jButton2_actionAdapter implements java.awt.event.ActionListener {
CreateCardDialog adaptee;
CreateCardDialog_jButton2_actionAdapter(CreateCardDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class CreateCardDialog_jButton1_actionAdapter implements java.awt.event.ActionListener {
CreateCardDialog adaptee;
CreateCardDialog_jButton1_actionAdapter(CreateCardDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class CreateCardDialog_jRadioButton1_actionAdapter implements java.awt.event.ActionListener {
CreateCardDialog adaptee;
CreateCardDialog_jRadioButton1_actionAdapter(CreateCardDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jRadioButton1_actionPerformed(e);
}
}
class CreateCardDialog_jRadioButton2_actionAdapter implements java.awt.event.ActionListener {
CreateCardDialog adaptee;
CreateCardDialog_jRadioButton2_actionAdapter(CreateCardDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jRadioButton2_actionPerformed(e);
}
}
class CreateCardDialog_jComboBox1_actionAdapter implements java.awt.event.ActionListener {
CreateCardDialog adaptee;
CreateCardDialog_jComboBox1_actionAdapter(CreateCardDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jComboBox1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -