#10: Deletedate calculated & DeletreBurtton enabled/disabled
This commit is contained in:
parent
917aa8275f
commit
353146cbd7
4 changed files with 53 additions and 7 deletions
Binary file not shown.
|
@ -2,9 +2,13 @@ package de.hitec.nhplus.nurse;
|
|||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.database.NurseDao;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.treatment.database.TreatmentDao;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.ObservableMap;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
|
@ -13,6 +17,11 @@ import javafx.scene.control.cell.PropertyValueFactory;
|
|||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LockedNurseController {
|
||||
@FXML
|
||||
|
@ -33,7 +42,9 @@ public class LockedNurseController {
|
|||
public TableColumn<Nurse, String> columnDeleteDate;
|
||||
|
||||
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
|
||||
private final Map<Nurse, List<Treatment>> treatmentsPerNurse = new HashMap<>();
|
||||
private NurseDao dao;
|
||||
private TreatmentDao treatmentDao;
|
||||
|
||||
public void initialize() {
|
||||
this.readAllAndShowInTableView();
|
||||
|
@ -49,20 +60,32 @@ public class LockedNurseController {
|
|||
this.columnPhoneNumber.setCellValueFactory(new PropertyValueFactory<>("phoneNumber"));
|
||||
this.columnPhoneNumber.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
this.columnDeleteDate.setCellValueFactory(cellData -> {
|
||||
return new SimpleStringProperty(cellData.getValue().calculateDeleteDate());
|
||||
});
|
||||
this.columnDeleteDate.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().calculateDeleteDate(treatmentsPerNurse.get(cellData.getValue()))));
|
||||
//this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
buttonDelete.setDisable(true);
|
||||
|
||||
this.tableView.setItems(this.nurses);
|
||||
|
||||
}
|
||||
|
||||
private void readAllAndShowInTableView() {
|
||||
this.nurses.clear();
|
||||
this.treatmentsPerNurse.clear();
|
||||
|
||||
this.dao = DaoFactory.getInstance().createNurseDAO();
|
||||
this.treatmentDao = DaoFactory.getInstance().createTreatmentDao();
|
||||
try {
|
||||
this.nurses.addAll(this.dao.readAllLocked());
|
||||
this.nurses.forEach(
|
||||
nurse -> {
|
||||
try {
|
||||
this.treatmentsPerNurse.put(nurse, this.treatmentDao.readTreatmentsByNurse(nurse.getId()));
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
@ -80,6 +103,14 @@ public class LockedNurseController {
|
|||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
readAllAndShowInTableView();
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleMouseClick() {
|
||||
Nurse nurse = tableView.getSelectionModel().getSelectedItem();
|
||||
buttonDelete.setDisable(!(DateConverter.convertStringToLocalDate(nurse.calculateDeleteDate(treatmentsPerNurse.get(nurse))).isBefore(LocalDate.now())));
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package de.hitec.nhplus.nurse;
|
||||
|
||||
import de.hitec.nhplus.main.Person;
|
||||
import de.hitec.nhplus.treatment.Treatment;
|
||||
import de.hitec.nhplus.utils.DateConverter;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +38,7 @@ public class Nurse extends Person {
|
|||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||
this.locked = new SimpleBooleanProperty(false);
|
||||
}
|
||||
|
||||
public Nurse(
|
||||
String firstName,
|
||||
String surName,
|
||||
|
@ -60,9 +66,17 @@ public class Nurse extends Person {
|
|||
this.locked = new SimpleBooleanProperty(isLocked);
|
||||
}
|
||||
|
||||
public String calculateDeleteDate() {
|
||||
//TODO: Lese alle Behandlungen die Dieser Pfleger Durchgefürt hat & brechene mit ihnen das Datum
|
||||
return "Comming soon";
|
||||
public String calculateDeleteDate(List<Treatment> treatments) {
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate newestDate = LocalDate.of(1980, 1, 1);
|
||||
for (Treatment treatment : treatments) {
|
||||
if (DateConverter.convertStringToLocalDate(treatment.getDate()).isAfter(newestDate)) {
|
||||
newestDate = DateConverter.convertStringToLocalDate(treatment.getDate());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return DateConverter.convertLocalDateToString(newestDate.plusYears(10));
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<Insets top="8" left="8" right="8" bottom="8"/>
|
||||
</padding>
|
||||
<center>
|
||||
<TableView fx:id="tableView" layoutX="31.0" layoutY="40">
|
||||
<TableView fx:id="tableView" layoutX="31.0" layoutY="40" onMouseClicked="#handleMouseClick" >
|
||||
<columns>
|
||||
<TableColumn
|
||||
fx:id="columnId"
|
||||
|
@ -74,6 +74,7 @@
|
|||
onAction="#handleDelete"
|
||||
prefWidth="90.0"
|
||||
text="Löschen"
|
||||
|
||||
/>
|
||||
</HBox>
|
||||
</right>
|
||||
|
|
Loading…
Reference in a new issue