?? 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 + -