📄 superadd.java~39~
字号:
}
}
public void tbsuper_mouseClicked(MouseEvent e) {
int row = this.tbsuper.getSelectedRow();
if (row > -1) {
this.txtid.setText(this.tbsuper.getValueAt(row, 0).toString());
this.txtpassword.setText(this.tbsuper.getValueAt(row, 1).toString());
this.cbotype.setSelectedItem(this.tbsuper.getValueAt(row, 2).
toString());
String register = this.tbsuper.getValueAt(row, 3).toString();
this.cboRegisteryear.setSelectedItem(register.substring(0, 4));
this.cboRegistermonth.setSelectedItem(register.substring(5, 7));
this.cboRegisterdate.setSelectedItem(register.substring(8, 10));
this.txtLogoff.setText(this.tbsuper.getValueAt(row, 4).toString());
this.cboAppearance.setSelectedItem(this.tbsuper.getValueAt(row, 5).
toString());
this.txaRemarks.setText(this.tbsuper.getValueAt(row, 6).toString());
}
}
public void jButton4_actionPerformed(ActionEvent e) {
this.txtid.setText("");
this.txtpassword.setText("");
this.cbotype.setSelectedItem("");
this.cbotype.setSelectedItem("");
this.cboRegisteryear.setSelectedItem("");
this.cboRegistermonth.setSelectedItem("");
this.cboRegisterdate.setSelectedItem("");
this.txtLogoff.setText("");
this.cboAppearance.setSelectedItem("");
this.txaRemarks.setText("");
this.cboRegisteryear.setEnabled(false);
this.cboRegistermonth.setEnabled(false);
this.cboRegisterdate.setEnabled(false);
this.cboAppearance.setEnabled(false);
try {
if (this.txtid.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入用户名");
return;
}
if (this.txtpassword.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入密码");
return;
}
if (this.cbotype.getSelectedItem().toString().equals("")) {
JOptionPane.showMessageDialog(this, "请选择用户类型");
return;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:studer");
PreparedStatement sql = conn.prepareStatement(
"insert into go (useid,mima,Type,Register,Remarks) values(?,?,?,?,?)");
sql.setString(1, this.txtid.getText());
sql.setString(2, this.txtpassword.getText());
sql.setString(3, this.cbotype.getSelectedItem().toString());
Date obj = new Date();
String str = obj.toString();
SimpleDateFormat sdfObj = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
sql.setString(4, sdfObj.format(obj));
sql.setString(5, this.txaRemarks.getText());
int row = sql.executeUpdate();
if (row > 0) {
JOptionPane.showMessageDialog(this, "添加成功!");
} else {
JOptionPane.showMessageDialog(this, "添加失败!");
}
sql.close();
conn.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "添加失败!");
}
}
public void jButton3_actionPerformed(ActionEvent e) {
try {
int row = this.tbsuper.getSelectedRow();
if (JOptionPane.showConfirmDialog(this, "你确定删除吗?", "删除提示",
JOptionPane.OK_CANCEL_OPTION) ==
JOptionPane.OK_OPTION) {
if (row < 0) {
JOptionPane.showMessageDialog(this, "请选择数据");
return;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection nod = DriverManager.getConnection(
"jdbc:odbc:studer");
PreparedStatement sql = nod.prepareStatement(
"delete from go where useid = ?");
sql.setString(1, this.tbsuper.getValueAt(row, 0).toString());
int i = sql.executeUpdate();
if (i > 0) {
mod.removeRow(row);
JOptionPane.showMessageDialog(this, "删除成功");
} else {
JOptionPane.showMessageDialog(this, "删除失败");
}
sql.close();
nod.close();
}
} catch (Exception ex) {
}
}
public void jButton2_actionPerformed(ActionEvent e) {
try {
String Registertime =
this.cboRegisteryear.getSelectedItem().toString() + "-" +
this.cboRegistermonth.getSelectedItem().toString() + "-" +
this.cboRegisterdate.getSelectedItem().toString() + " ";
if (this.txtid.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入用户名");
return;
}
if (this.txtpassword.getText().equals("")) {
JOptionPane.showMessageDialog(this, "请输入密码");
return;
}
if (this.cbotype.getSelectedItem().toString().equals("")) {
JOptionPane.showMessageDialog(this, "请选择用户类型");
return;
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
PreparedStatement sql = nod.prepareStatement(
"update stu go useid=?,mima=?,Type=?,Register=?,Remarks=? where useid ='" +
this.txtid.getText() + "'");
sql.setString(1, this.txtid.getText());
sql.setString(2, this.txtpassword.getText());
sql.setString(3, this.cbotype.getSelectedItem().toString());
Date obj = new Date();
String str = obj.toString();
SimpleDateFormat sdfObj = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
sql.setString(4, sdfObj.format(obj));
sql.setString(5, this.txaRemarks.getText().toString());
int i = sql.executeUpdate();
int row = tbsuper.getSelectedRow();
if (i > 0) {
tbsuper.setValueAt(this.txtid.getText(), row, 1);
tbsuper.setValueAt(this.txtpassword.getText(), row, 2);
tbsuper.setValueAt(this.cbotype.getSelectedItem(), row, 3);
tbsuper.setValueAt(this.txaRemarks.getText(), row, 4);
JOptionPane.showMessageDialog(this, "修改成功");
} else {
JOptionPane.showMessageDialog(this, "修改失败");
}
sql.close();
nod.close();
} catch (Exception ex) {
}
}
}
class superadd_tbsuper_mouseAdapter extends MouseAdapter {
private superadd adaptee;
superadd_tbsuper_mouseAdapter(superadd adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.tbsuper_mouseClicked(e);
}
}
class superadd_jButton4_actionAdapter implements ActionListener {
private superadd adaptee;
superadd_jButton4_actionAdapter(superadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
class superadd_jButton3_actionAdapter implements ActionListener {
private superadd adaptee;
superadd_jButton3_actionAdapter(superadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class superadd_jButton2_actionAdapter implements ActionListener {
private superadd adaptee;
superadd_jButton2_actionAdapter(superadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class superadd_jButton5_actionAdapter implements ActionListener {
private superadd adaptee;
superadd_jButton5_actionAdapter(superadd adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -