我的按钮侦听器在更新信息时不执行任何操作,如何解决? 这是我在editcontroller类中的按钮:
@FXML
private void patientSaveOnAction(ActionEvent event){
LocalDate date = dpDateOfBirth.getValue();
Date today = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
int sex = radioMale.isSelected() ? 1 : radioFeMale.isSelected() ? 2 : 0;
isNotNull();
if (validatePhoneNumber() && validateMail() && validateName() && age()){
//validatePhoneNumber() && validateMail() && validateName() && age()
//patientGetway.update(new Patient(0,copyImage(),tfName.getText(),date,sex,tfEmail.getText(),tfPhone.getText(),taAddress.getText(),dateFormat.format(today)))
if (patientGetway.update(new Patient(0,copyImage(),tfName.getText(),date,sex,tfEmail.getText(),tfPhone.getText(),taAddress.getText(),dateFormat.format(today)))){
resetForm();
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Patient updated successfully");
alert.setHeaderText("Patient updated");
alert.setContentText("Patient updated successfullly");
alert.showAndWait();
}
}
}
这些是我在同一类中的方法
private boolean isNotNull(){
boolean isValid = false;
if (tfPhone.getText().isEmpty() ||tfName.getText().isEmpty()||tfEmail.getText().isEmpty()||taAddress.getText().isEmpty()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("All field required");
alert.setHeaderText("All fields are required");
alert.setContentText("All text fields are required. please fill all text field");
alert.showAndWait();
isValid = false;
} else {
isValid = true;
}
return isValid;
}
这些方法用于验证有关日期,电子邮件,姓名和电话号码的信息 方法设置正确,但没有更新
private boolean age(){
String age = "";
LocalDate birthdate = dpDateOfBirth.getValue();
LocalDate now = LocalDate.now();
if(birthdate.isAfter(now)){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Validate the date of birth");
alert.setHeaderText(null);
alert.setContentText("please put a valid date");
alert.showAndWait();
return true;
}else{
age = String.valueOf(ChronoUnit.YEARS.between(birthdate, now));
return false;
}
}
private boolean validateMail(){
Pattern p = Pattern.compile("[a-zA-Z0-9][a-zA-Z0-9._]*@[a-zA-Z0-9]+([.][a-zA-Z]+)+");
Matcher m = p.matcher(tfEmail.getText());
if(m.find() && m.group().equals(tfEmail.getText())){
return true;
}else{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("validate email");
alert.setHeaderText(null);
alert.setContentText("please provide the valid email address");
alert.showAndWait();
return false;
}
}
private boolean validateName(){
Pattern p = Pattern.compile("[a-zA-Z]+");
Matcher m = p.matcher(tfName.getText());
if (m.find() && m.group().equals(tfName.getText())) {
return true;
}else{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("validate your name");
alert.setHeaderText(null);
alert.setContentText("please provide the valide name");
alert.showAndWait();
return false;
}
}
private boolean validatePhoneNumber(){
Pattern p = Pattern.compile("^\\+(?:[0-9] ?){6,14}[0-9]$");
Matcher m = p.matcher(tfPhone.getText());
if (m.find() && m.group().equals(tfPhone.getText())) {
return true;
}else{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("validate phone number");
alert.setHeaderText(null);
alert.setContentText("please provide the valid phone number");
alert.showAndWait();
return false;
}
}
这是我在班级中调用的另一个班级中的更新方法
public boolean update(Patient patient) {
DBConnection connection = new DBConnection();
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
boolean isUpdated = false;
if (patientBLL.isValid(patient) && patientBLL.isUnique(patient)) {
System.out.println(connection.geConnection());
con = connection.geConnection();
try {
pst = con.prepareStatement("update patient set thumbnail=?,name=?,date_of_birth=?,sex=?,email=?,phone=?,address=? where id=?");
pst.setString(1, patient.getThumbnail());
pst.setString(2, patient.getName());
pst.setString(3, String.valueOf(patient.getDateOrBirth()));
pst.setInt(4, patient.getSex());
pst.setString(5, patient.getEmail());
pst.setString(6, patient.getPhone());
pst.setString(7, patient.getAddress());
pst.setInt(8, patient.getId());
pst.executeUpdate();
pst.close();
con.close();
connection.con.close();
isUpdated = true;
} catch (SQLException ex) {
Logger.getLogger(PatientGetway.class.getName()).log(Level.SEVERE, null, ex);
}
}
return isUpdated;
}