private class LableListener implements MouseMotionListener {
@Override
public void mouseClicked(MouseEvent e) {
String id = idTextField.getText().trim();
String name = NameTextField.getText().trim();
String pw = pwTextField.getText().trim();
Student student = new Student().setStudent(id, name, pw);
int idFlag; boolean existflag;
idFlag = ConnectionStudent.IDCheck(id);
existflag = ConnectionStudent.IDExist(id);
String lable = e.getComponent().toString();
switch (lable) {
case "insert":
if(idFlag == -1) {
JOptionPane.showConfirmDialog(InfoSutdent.this, "用户ID位数不为6位", "插入数据错误", JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE);
}else if(idFlag == -2) {
JOptionPane.showConfirmDialog(InfoSutdent.this, "ID存在非数字", "插入数据错误", JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE);
}else if(idFlag == 0) {
JOptionPane.showConfirmDialog(InfoSutdent.this, "请输入学号", "插入数据错误", JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE);
}else if (existflag == true) {
JOptionPane.showConfirmDialog(InfoSutdent.this, "学号重复", "插入数据错误", JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE);
}else {
ConnectionStudent.insertAll(id, name, pw);
}
break;
case "delete":
ConnectionStudent.deleteRecord(id);
break;
case "update":
ConnectionStudent.updateother(id, name, pw);
break;
}
model = new ResultSetTableModel();
table.setModel(model);
}
}
private class ButtonListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
int id = Integer.parseInt(idField.getText().trim());
String name = nameField.getText().trim();
String gender = genderCombo.getSelectedItem().toString().trim();
String dob = dobField.getText().trim();
int batch = Integer.parseInt(batchField.getText().trim());
Student student = new Student(id, name, gender, dob, batch);
JButton button = (JButton)e.getSource();
String text = button.getText();
String button = e.getActionCommand();
switch (button) {
case "Insert":
try {
sqlHelper.insertTable(student);
} catch (StudentExistException exception) {
JOptionPane.showConfirmDialog(JTableDemo2.this, "该学号已存在", "插入数据错误", JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE);
}
break;
case "Delete":
sqlHelper.deleteTable(student);
break;
case "Update":
sqlHelper.updateTable(student);
break;
}
model = new ResultSetTableModel();
table.setModel(model);
}
}