📄 updatedriver.java
字号:
jLabel1.setText("请输入驾驶员驾证号:");
this.setVisible(true);
this.setSize(546, 521);
this.setLocation(170, 50);
addWindowListener(new WindowAdapter() {
public void WindowClosing(WindowEvent e) {
if (db != null)
db.closeConnection();
dispose();
}
});
}
DataBaseManager db = null;
ResultSet r;
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
Border border1 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 163, 151));
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JTextField finddriverid_t = new JTextField();
JButton jButton1 = new JButton(new ImageIcon("image\\114.gif"));
JLabel jLabel2 = new JLabel();
JTextField address_t = new JTextField();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField idcard_t = new JTextField();
JLabel jLabel7 = new JLabel();
JTextField driveid_t = new JTextField();
JLabel jLabel8 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JTextField getdate_t = new JTextField();
JTextField tel_t = new JTextField();
JTextField drivername_t = new JTextField();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JButton jButton5 = new JButton(new ImageIcon("image\\back.gif"));
JButton jButton2 = new JButton(new ImageIcon("image\\bao.png"));
JButton jButton4 = new JButton(new ImageIcon("image\\delete.png"));
JLabel jLabel3 = new JLabel();
JComboBox jComboBox3 = new JComboBox();
JLabel jLabel11 = new JLabel();
JComboBox jComboBox4 = new JComboBox();
public void jButton5_actionPerformed(ActionEvent e) {
if (db != null)
db.closeConnection();
this.dispose();
}
public void jButton1_actionPerformed(ActionEvent e) {
db = new DataBaseManager();
try {
String str1 = "select * from driver where 驾驶证号='" +
finddriverid_t.getText().trim() + "'";
if (finddriverid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "请输入驾驶证号!");
else if (!db.getResult(str1).first()) {
String s = "没有编号为" + finddriverid_t.getText().trim() +
"的驾驶员,请重新输入驾驶证号。";
JOptionPane.showMessageDialog(null, s);
finddriverid_t.setText("");
} else {
String str = "select * from driver where 驾驶证号='" +
finddriverid_t.getText().trim() + "'";
r = db.getResult(str);
r.first();
driveid_t.setText(finddriverid_t.getText());
drivername_t.setText(r.getString("驾驶员姓名"));
jComboBox1.setSelectedItem(r.getString("性别"));
jComboBox3.setSelectedItem(r.getString("民族"));
jComboBox4.setSelectedItem(r.getString("文化程度"));
getdate_t.setText(r.getString("驾证初领日"));
idcard_t.setText(r.getString("身份证号"));
address_t.setText(r.getString("住址"));
tel_t.setText(r.getString("联系电话"));
jComboBox2.setSelectedItem(r.getString("准驾类型"));
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
public void jButton2_actionPerformed(ActionEvent e) {
try { //驾驶证号,驾驶员姓名,性别,民族,文化程度,驾证初领日,身份证号,住址,联系电话,准驾类型,照片
String strSQL = "update driver set 驾驶证号='" +
driveid_t.getText().trim() + "',驾驶员姓名='" +
drivername_t.getText().trim() + "',性别='" +
jComboBox1.getSelectedItem() + "',民族='" +
jComboBox3.getSelectedItem() + "',文化程度='" +
jComboBox4.getSelectedItem() + "',驾证初领日='" +
getdate_t.getText().trim() + "',身份证号='" +
idcard_t.getText().trim() + "',住址='" +
address_t.getText().trim() + "',联系电话='" +
tel_t.getText().trim() + "',准驾类型='" +
jComboBox2.getSelectedItem() +
"' where 驾驶证号='" + finddriverid_t.getText().trim() +
"'";
if (db.updateSql(strSQL)) {
JOptionPane.showMessageDialog(null, "信息修改成功!");
} else {
JOptionPane.showMessageDialog(null, "信息修改失败!");
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
public void jButton4_actionPerformed(ActionEvent e) {
try {
String str2 = "delete from driver where 驾驶证号='" +
finddriverid_t.getText().trim() + "'";
String q = "确定要删除吗?";
int ok = JOptionPane.showConfirmDialog(null, q, "确认",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (ok == JOptionPane.YES_OPTION) {
if (db.updateSql(str2))
JOptionPane.showMessageDialog(null, "删除成功!");
else
JOptionPane.showMessageDialog(null, "删除失败!");
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
public void finddriverid_t_focusLost(FocusEvent focusEvent) {
if (finddriverid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "关键字不能为空!");
}
public void getdate_t_focusLost(FocusEvent e) {
}
public void finddriverid_t_keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
db = new DataBaseManager();
try {
String str1 = "select * from driver where 驾驶证号='" +
finddriverid_t.getText().trim() + "'";
if (finddriverid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "请输入驾驶证号!");
else if (!db.getResult(str1).first()) {
String s = "没有编号为" + finddriverid_t.getText().trim() +
"的驾驶员,请重新输入驾驶证号。";
JOptionPane.showMessageDialog(null, s);
finddriverid_t.setText("");
} else {
String str = "select * from driver where 驾驶证号='" +
finddriverid_t.getText().trim() + "'";
r = db.getResult(str);
r.first();
driveid_t.setText(finddriverid_t.getText());
drivername_t.setText(r.getString("驾驶员姓名"));
jComboBox1.setSelectedItem(r.getString("性别"));
jComboBox3.setSelectedItem(r.getString("民族"));
jComboBox4.setSelectedItem(r.getString("文化程度"));
getdate_t.setText(r.getString("驾证初领日"));
idcard_t.setText(r.getString("身份证号"));
address_t.setText(r.getString("住址"));
tel_t.setText(r.getString("联系电话"));
jComboBox2.setSelectedItem(r.getString("准驾类型"));
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
}
class Updatedriver_jButton5_actionAdapter implements ActionListener {
private Updatedriver adaptee;
Updatedriver_jButton5_actionAdapter(Updatedriver adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -