From 47354a4bd93def06fc231af7cf3aabc2e0cb4644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Fri, 17 May 2024 16:02:39 +0200 Subject: [PATCH] #25: Implement Editing of Nurses --- .../nhplus/nurse/AllNurseController.java | 46 +++++++++++++++++++ .../nhplus/patient/AllPatientController.java | 10 ++-- .../de/hitec/nhplus/nurse/AllNurseView.fxml | 3 ++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java b/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java index 77a7a5f..d6b89f8 100644 --- a/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java +++ b/src/main/java/de/hitec/nhplus/nurse/AllNurseController.java @@ -106,6 +106,17 @@ public class AllNurseController { this.textFieldPhoneNumber.clear(); } + /** + * Internal method that stores the changes in the database. + */ + private void doUpdate(TableColumn.CellEditEvent event) { + try { + this.dao.update(event.getRowValue()); + } catch (SQLException exception) { + exception.printStackTrace(); + } + } + @FXML public void handleAdd(){ String surname=this.textFieldSurName.getText(); @@ -137,4 +148,39 @@ public class AllNurseController { readAllAndShowInTableView(); } + @FXML + public void handleOnEditSurname(TableColumn.CellEditEvent event) { + String newSurName = event.getNewValue(); + if (!isValidSurName(newSurName)) { + showValidationError("Nachname"); + event.getTableView().refresh(); + return; + } + event.getRowValue().setSurName(newSurName); + this.doUpdate(event); + } + + @FXML + public void handleOnEditFirstname(TableColumn.CellEditEvent event) { + String newFirstName = event.getNewValue(); + if (!isValidFirstName(newFirstName)) { + showValidationError("Vorname"); + event.getTableView().refresh(); + return; + } + event.getRowValue().setFirstName(newFirstName); + this.doUpdate(event); + } + + @FXML + public void handleOnEditPhoneNumber(TableColumn.CellEditEvent event) { + String newPhoneNumber = event.getNewValue(); + if (!isValidPhoneNumber(newPhoneNumber)) { + showValidationError("Telefonnummer"); + event.getTableView().refresh(); + return; + } + event.getRowValue().setPhoneNumber(newPhoneNumber); + this.doUpdate(event); + } } diff --git a/src/main/java/de/hitec/nhplus/patient/AllPatientController.java b/src/main/java/de/hitec/nhplus/patient/AllPatientController.java index a5d20a6..051c56b 100644 --- a/src/main/java/de/hitec/nhplus/patient/AllPatientController.java +++ b/src/main/java/de/hitec/nhplus/patient/AllPatientController.java @@ -154,7 +154,7 @@ public class AllPatientController { public void handleOnEditFirstname(TableColumn.CellEditEvent event) { String newFirstName = event.getNewValue(); if (!isValidFirstName(newFirstName)) { - showValidationError("First Name"); + showValidationError("Vorname"); event.getTableView().refresh(); return; } @@ -166,7 +166,7 @@ public class AllPatientController { public void handleOnEditSurname(TableColumn.CellEditEvent event) { String newSurName = event.getNewValue(); if (!isValidSurName(newSurName)) { - showValidationError("Sur Name"); + showValidationError("Nachname"); event.getTableView().refresh(); return; } @@ -178,7 +178,7 @@ public class AllPatientController { public void handleOnEditDateOfBirth(TableColumn.CellEditEvent event) { String newDateString = event.getNewValue(); if (!isValidDate(newDateString)) { - showValidationError("Date"); + showValidationError("Geburtstag"); event.getTableView().refresh(); return; } @@ -190,7 +190,7 @@ public class AllPatientController { public void handleOnEditCareLevel(TableColumn.CellEditEvent event) { String newCareLevel = event.getNewValue(); if (!isValidCareLevel(newCareLevel)) { - showValidationError("Care Level"); + showValidationError("Pflegegrad"); event.getTableView().refresh(); return; } @@ -202,7 +202,7 @@ public class AllPatientController { public void handleOnEditRoomNumber(TableColumn.CellEditEvent event) { String newRoomNumber = event.getNewValue(); if (!isValidRoomNumber(newRoomNumber)) { - showValidationError("Room Number"); + showValidationError("Raum"); event.getTableView().refresh(); return; } diff --git a/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml b/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml index 3a7b76a..10b589a 100644 --- a/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml +++ b/src/main/resources/de/hitec/nhplus/nurse/AllNurseView.fxml @@ -22,16 +22,19 @@