📄 updatecar.java
字号:
this.getContentPane().add(jButton2, new XYConstraints(79, 473, 104, 49));
this.getContentPane().add(jButton3, new XYConstraints(248, 473, 103, 49));
jLabel1.setText("请输入车牌号:");
this.setSize(590, 588);
this.setLocation(170, 50);
this.setVisible(true);
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(148, 145, 140));
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JTextField findcarid_t = new JTextField();
JButton jButton1 = new JButton(new ImageIcon("image\\114.gif"));
JLabel jLabel2 = new JLabel();
JTextField countid_t = new JTextField();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField lightid_t = new JTextField();
JTextField drivername_t = new JTextField();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JTextField startid_t = new JTextField();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JTextField protecthour_t = new JTextField();
JTextField carid_t = new JTextField();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
JLabel jLabel12 = new JLabel();
JTextField breaklowcount_t = new JTextField();
JLabel jLabel13 = new JLabel();
JLabel jLabel14 = new JLabel();
JLabel jLabel15 = new JLabel();
JTextField factory_t = new JTextField();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel16 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JTextField underid_t = new JTextField();
JLabel jLabel17 = new JLabel();
JTextField businessid_t = new JTextField();
JLabel jLabel18 = new JLabel();
JLabel jLabel19 = new JLabel();
JButton jButton2 = new JButton(new ImageIcon("image\\bao.png"));
JButton jButton3 = new JButton(new ImageIcon("image\\back.gif"));
JButton jButton4 = new JButton(new ImageIcon("image\\delete.png"));
JTextField driveid_t = new JTextField();
JTextField yingdate = new JTextField();
JTextField yeardate = new JTextField();
JTextField toudate = new JTextField();
JTextField nextyingdate = new JTextField();
JTextField nextyeardate = new JTextField();
public void jButton3_actionPerformed(ActionEvent e) {
if (db != null)
db.closeConnection();
this.dispose();
}
public void jButton2_actionPerformed(ActionEvent e) {
try {
String strSQL = "update car set 车牌号='" +
carid_t.getText().trim() + "',制造商='" +
factory_t.getText().trim() + "',发动机号='" +
startid_t.getText().trim() + "',底盘编号='" +
underid_t.getText().trim() + "',燃油类型='" +
jComboBox1.getSelectedItem() + "',营运证号='" +
businessid_t.getText().trim() + "',计价器号='" +
countid_t.getText().trim() + "',顶灯号='" +
lightid_t.getText().trim() + "',驾驶员姓名='" +
drivername_t.getText().trim() + "',驾驶证号='" +
driveid_t.getText().trim() + "',营审日期='" +
yingdate.getText().trim() + "',次营审日期='" +
nextyingdate.getText().trim() + "',年审日期='" +
yeardate.getText().trim() + "',下次年审='" +
nextyeardate.getText().trim() + "',投保日期='" +
toudate.getText().trim() + "',投保时长='" +
protecthour_t.getText().trim() + "',车辆状态='" +
jComboBox2.getSelectedItem() + "',违章次数='" +
breaklowcount_t.getText().trim() +
"' where 车牌号='" + findcarid_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 car where 车牌号='" +
findcarid_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 jButton1_actionPerformed(ActionEvent e) {
db = new DataBaseManager();
try { //车牌号,制造商,发动机号,底盘编号,燃油类型,营运证号,计价器号,顶灯号,驾驶员姓名,驾驶证号,营审日期 ,次营审日期,年审日期,下次年审,投保日期,投保时长,车辆状态,违章次数
String str1 = "select * from car where 车牌号='" +
findcarid_t.getText().trim() + "'";
if (findcarid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "请输入车牌号!");
else if (!db.getResult(str1).first()) {
String s = "没有编号为" + findcarid_t.getText().trim() +
"的车辆,请重新输入车牌号。";
JOptionPane.showMessageDialog(null, s);
findcarid_t.setText("");
} else {
String str = "select * from car where 车牌号='" +
findcarid_t.getText().trim() + "'";
r = db.getResult(str);
r.first();
carid_t.setText(findcarid_t.getText());
factory_t.setText(r.getString("制造商"));
startid_t.setText(r.getString("发动机号"));
underid_t.setText(r.getString("底盘编号"));
jComboBox1.setSelectedItem(r.getString("燃油类型"));
businessid_t.setText(r.getString("营运证号"));
countid_t.setText(r.getString("计价器号"));
lightid_t.setText(r.getString("顶灯号"));
drivername_t.setText(r.getString("驾驶员姓名"));
driveid_t.setText(r.getString("驾驶证号"));
yingdate.setText(r.getString("营审日期"));
nextyingdate.setText(r.getString("次营审日期"));
yeardate.setText(r.getString("年审日期"));
nextyeardate.setText(r.getString("下次年审"));
nextyeardate.setText(r.getString("投保日期"));
protecthour_t.setText(r.getString("投保时长"));
jComboBox2.setSelectedItem(r.getString("车辆状态"));
breaklowcount_t.setText(r.getString("违章次数"));
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
public void findcarid_t_focusLost(FocusEvent focusEvent) {
if (findcarid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null,
"关键字不能为空!");
}
public void findcarid_t_keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
db = new DataBaseManager();
try { //车牌号,制造商,发动机号,底盘编号,燃油类型,营运证号,计价器号,顶灯号,驾驶员姓名,驾驶证号,营审日期 ,次营审日期,年审日期,下次年审,投保日期,投保时长,车辆状态,违章次数
String str1 = "select * from car where 车牌号='" +
findcarid_t.getText().trim() + "'";
if (findcarid_t.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "请输入车牌号!");
else if (!db.getResult(str1).first()) {
String s = "没有编号为" + findcarid_t.getText().trim() +
"的车辆,请重新输入车牌号。";
JOptionPane.showMessageDialog(null, s);
findcarid_t.setText("");
} else {
String str = "select * from car where 车牌号='" +
findcarid_t.getText().trim() + "'";
r = db.getResult(str);
r.first();
carid_t.setText(findcarid_t.getText());
factory_t.setText(r.getString("制造商"));
startid_t.setText(r.getString("发动机号"));
underid_t.setText(r.getString("底盘编号"));
jComboBox1.setSelectedItem(r.getString("燃油类型"));
businessid_t.setText(r.getString("营运证号"));
countid_t.setText(r.getString("计价器号"));
lightid_t.setText(r.getString("顶灯号"));
drivername_t.setText(r.getString("驾驶员姓名"));
driveid_t.setText(r.getString("驾驶证号"));
yingdate.setText(r.getString("营审日期"));
nextyingdate.setText(r.getString("次营审日期"));
yeardate.setText(r.getString("年审日期"));
nextyeardate.setText(r.getString("下次年审"));
nextyeardate.setText(r.getString("投保日期"));
protecthour_t.setText(r.getString("投保时长"));
jComboBox2.setSelectedItem(r.getString("车辆状态"));
breaklowcount_t.setText(r.getString("违章次数"));
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
class UpdateCar_jButton1_actionAdapter implements ActionListener {
private UpdateCar adaptee;
UpdateCar_jButton1_actionAdapter(UpdateCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class UpdateCar_jButton4_actionAdapter implements ActionListener {
private UpdateCar adaptee;
UpdateCar_jButton4_actionAdapter(UpdateCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class UpdateCar_jButton2_actionAdapter implements ActionListener {
private UpdateCar adaptee;
UpdateCar_jButton2_actionAdapter(UpdateCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class UpdateCar_jButton3_actionAdapter implements ActionListener {
private UpdateCar adaptee;
UpdateCar_jButton3_actionAdapter(UpdateCar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -