diff --git a/db/nursingHome.db b/db/nursingHome.db index 5772512..ee002a5 100644 Binary files a/db/nursingHome.db and b/db/nursingHome.db differ diff --git a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java index 547d30f..8c2ca83 100644 --- a/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java +++ b/src/main/java/de/hitec/nhplus/medication/AllMedicationController.java @@ -18,6 +18,7 @@ import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.SelectionModel; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; @@ -48,6 +49,8 @@ public class AllMedicationController { private TableColumn columnAdministrationMethod; @FXML private TableColumn columnCurrentStock; + @FXML + public Button buttonChangeAvailable; private final ObservableList medications = FXCollections.observableArrayList(); private MedicationDao dao; @@ -120,6 +123,22 @@ public class AllMedicationController { } } + @FXML + public void handleChangeAvailable() { + Medication selectedItem = tableView.getSelectionModel().getSelectedItem(); + if (selectedItem == null) { + return; + } + + try { + selectedItem.setIsDeprecated(true); + this.dao.update(selectedItem); + } catch (SQLException exception) { + exception.printStackTrace(); + } + readAllAndShowInTableView(); + } + /** * Internal method to create a {@link MedicationModalController MedicationModal}. * diff --git a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java index fe38fe7..d992fe9 100644 --- a/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java +++ b/src/main/java/de/hitec/nhplus/medication/DeprecatedMedicationController.java @@ -6,6 +6,7 @@ import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; @@ -31,6 +32,8 @@ public class DeprecatedMedicationController { private TableColumn columnAdministrationMethod; @FXML private TableColumn columnCurrentStock; + @FXML + public Button buttonChangeAvailable; private final ObservableList medications = FXCollections.observableArrayList(); private MedicationDao dao; @@ -75,5 +78,20 @@ public class DeprecatedMedicationController { exception.printStackTrace(); } } + @FXML + public void handleChangeAvailable(){ + Medication selectedItem = tableView.getSelectionModel().getSelectedItem(); + if (selectedItem == null) { + return; + } + + try { + selectedItem.setIsDeprecated(false); + this.dao.update(selectedItem); + } catch (SQLException exception) { + exception.printStackTrace(); + } + readAllAndShowInTableView(); + } } diff --git a/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java b/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java index 9489737..ab80e1d 100644 --- a/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java +++ b/src/main/java/de/hitec/nhplus/medication/MedicationModalController.java @@ -39,6 +39,7 @@ public class MedicationModalController { @FXML public Button buttonSave; + private Stage stage; private Medication medication; private final ObservableList ingredients = FXCollections.observableArrayList(); diff --git a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java index 41f5f7d..f4f4655 100644 --- a/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java +++ b/src/main/java/de/hitec/nhplus/medication/database/MedicationDao.java @@ -86,7 +86,7 @@ public class MedicationDao implements Dao { SELECT medication.*, medication_ingredient.name FROM medication LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id - WHERE isDeprecated = false + WHERE medication.isDeprecated = false """; ResultSet result = connection.prepareStatement(SQL).executeQuery(); @@ -134,7 +134,7 @@ public class MedicationDao implements Dao { SELECT medication.*, medication_ingredient.name FROM medication LEFT JOIN medication_ingredient ON medication.id = medication_ingredient.id - WHERE isDeprecated = true + WHERE medication.isDeprecated = true """; ResultSet result = connection.prepareStatement(SQL).executeQuery(); @@ -196,7 +196,7 @@ public class MedicationDao implements Dao { preparedStatement.setString(4, medication.getAdministrationMethod()); preparedStatement.setInt(5, medication.getCurrentStock()); preparedStatement.setInt(6, medication.getId()); - preparedStatement.setBoolean(6, medication.isDeprecated()); + preparedStatement.setBoolean(7, medication.isDeprecated()); preparedStatement.executeUpdate(); final String ingredientDeleteSQL = """ diff --git a/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml b/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml index 157caac..d9456b9 100644 --- a/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml +++ b/src/main/resources/de/hitec/nhplus/medication/AllMedicationView.fxml @@ -75,6 +75,13 @@ prefWidth="90.0" text="Löschen" /> +