Compare commits
2 commits
5cf57bc05c
...
d8a7c9a59c
Author | SHA1 | Date | |
---|---|---|---|
|
d8a7c9a59c | ||
|
f212cfe760 |
11 changed files with 316 additions and 21 deletions
Binary file not shown.
|
@ -40,6 +40,14 @@ public class NurseFixture implements Fixture<Nurse> {
|
|||
"Armout",
|
||||
"9876543210"
|
||||
));
|
||||
|
||||
nurses.add(new Nurse(
|
||||
"Björnd",
|
||||
"Heideberger",
|
||||
"69420",
|
||||
true
|
||||
));
|
||||
|
||||
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
|
||||
for (Nurse nurse : nurses) {
|
||||
dao.create(nurse);
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.hitec.nhplus.main;
|
|||
import de.hitec.nhplus.Main;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.SelectionModel;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
|
@ -23,9 +24,17 @@ public class MainWindowController {
|
|||
@FXML
|
||||
private Tab treatmentTab;
|
||||
@FXML
|
||||
private AnchorPane nursePage;
|
||||
@FXML
|
||||
private Tab nurseTab;
|
||||
@FXML
|
||||
private TabPane nurseTabPane;
|
||||
@FXML
|
||||
private AnchorPane activeNursePage;
|
||||
@FXML
|
||||
private Tab activeNurseTab;
|
||||
@FXML
|
||||
private AnchorPane lockedNursePage;
|
||||
@FXML
|
||||
private Tab lockedNurseTab;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
@ -36,6 +45,11 @@ public class MainWindowController {
|
|||
treatmentTab.setOnSelectionChanged(event -> loadTreatmentsPage());
|
||||
nurseTab.setOnSelectionChanged(event -> loadNursePage());
|
||||
|
||||
|
||||
nurseTabPane.getSelectionModel().select(activeNurseTab);
|
||||
|
||||
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
|
||||
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
|
||||
}
|
||||
|
||||
private void loadPatientPage() {
|
||||
|
@ -69,15 +83,43 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
private void loadNursePage() {
|
||||
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
|
||||
Tab selectedTab = selectionModel.getSelectedItem();
|
||||
if(selectedTab == activeNurseTab){
|
||||
loadActiveNursePage();
|
||||
}
|
||||
if(selectedTab == lockedNurseTab){
|
||||
loadLockedNursePage();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadActiveNursePage() {
|
||||
System.out.println("TODO: Active Nurse");
|
||||
try {
|
||||
BorderPane nursePane = FXMLLoader.load(
|
||||
BorderPane activeNursePane = FXMLLoader.load(
|
||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml"))
|
||||
);
|
||||
nursePage.getChildren().setAll(nursePane);
|
||||
AnchorPane.setTopAnchor(nursePane, 0d);
|
||||
AnchorPane.setBottomAnchor(nursePane, 0d);
|
||||
AnchorPane.setLeftAnchor(nursePane, 0d);
|
||||
AnchorPane.setRightAnchor(nursePane, 0d);
|
||||
activeNursePage.getChildren().setAll(activeNursePane);
|
||||
AnchorPane.setTopAnchor(activeNursePane, 0d);
|
||||
AnchorPane.setBottomAnchor(activeNursePane, 0d);
|
||||
AnchorPane.setLeftAnchor(activeNursePane, 0d);
|
||||
AnchorPane.setRightAnchor(activeNursePane, 0d);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadLockedNursePage() {
|
||||
System.out.println("TODO: Locked Nurse");
|
||||
try {
|
||||
BorderPane lockedNursePane = FXMLLoader.load(
|
||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/LockedNurseView.fxml"))
|
||||
);
|
||||
lockedNursePage.getChildren().setAll(lockedNursePane);
|
||||
AnchorPane.setTopAnchor(lockedNursePane, 0d);
|
||||
AnchorPane.setBottomAnchor(lockedNursePane, 0d);
|
||||
AnchorPane.setLeftAnchor(lockedNursePane, 0d);
|
||||
AnchorPane.setRightAnchor(lockedNursePane, 0d);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ public class AllNurseController {
|
|||
@FXML
|
||||
public Button buttonAdd;
|
||||
@FXML
|
||||
public Button buttonLock;
|
||||
@FXML
|
||||
private TableView<Nurse> tableView;
|
||||
@FXML
|
||||
private TableColumn<Nurse, Long> columnId;
|
||||
|
@ -76,7 +78,7 @@ public class AllNurseController {
|
|||
this.nurses.clear();
|
||||
this.dao = DaoFactory.getInstance().createNurseDAO();
|
||||
try {
|
||||
this.nurses.addAll(this.dao.readAll());
|
||||
this.nurses.addAll(this.dao.readAllActive());
|
||||
}catch (SQLException exception){
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
@ -95,6 +97,21 @@ public class AllNurseController {
|
|||
readAllAndShowInTableView();
|
||||
clearTextfields();
|
||||
}
|
||||
@FXML
|
||||
public void handleLock(){
|
||||
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null){
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedItem.setLocked(true);
|
||||
this.dao.update(selectedItem);
|
||||
}catch (SQLException exception){
|
||||
exception.printStackTrace();
|
||||
}
|
||||
readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
private void clearTextfields() {
|
||||
this.textFieldFirstName.clear();
|
||||
|
@ -102,4 +119,5 @@ public class AllNurseController {
|
|||
this.textFieldPhoneNumber.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package de.hitec.nhplus.nurse;
|
||||
|
||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||
import de.hitec.nhplus.nurse.database.NurseDao;
|
||||
import javafx.application.Application;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class LockedNurseController {
|
||||
@FXML
|
||||
public Button buttonDelete;
|
||||
@FXML
|
||||
private Button buttonUnlock;
|
||||
@FXML
|
||||
public TableView<Nurse> tableView;
|
||||
@FXML
|
||||
public TableColumn<Nurse, Long> columnId;
|
||||
@FXML
|
||||
public TableColumn<Nurse, String> columnFirstName;
|
||||
@FXML
|
||||
public TableColumn<Nurse, String> columnSurName;
|
||||
@FXML
|
||||
public TableColumn<Nurse, String> columnDeleteDate;
|
||||
|
||||
private final ObservableList<Nurse> nurses = FXCollections.observableArrayList();
|
||||
private NurseDao dao;
|
||||
|
||||
public void initialize() {
|
||||
this.readAllAndShowInTableView();
|
||||
|
||||
this.columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
|
||||
|
||||
this.columnFirstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
|
||||
this.columnFirstName.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
this.columnSurName.setCellValueFactory(new PropertyValueFactory<>("surName"));
|
||||
this.columnSurName.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
this.columnDeleteDate.setCellValueFactory(new PropertyValueFactory<>("date"));
|
||||
this.columnDeleteDate.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
|
||||
this.tableView.setItems(this.nurses);
|
||||
}
|
||||
|
||||
private void readAllAndShowInTableView() {
|
||||
this.nurses.clear();
|
||||
this.dao = DaoFactory.getInstance().createNurseDAO();
|
||||
try {
|
||||
this.nurses.addAll(this.dao.readAllLocked());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleDelete() {
|
||||
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.dao.delete(selectedItem.getId());
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void changeUnlock() {
|
||||
Nurse selectedItem = this.tableView.getSelectionModel().getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
selectedItem.setLocked(false);
|
||||
this.dao.update(selectedItem);
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
readAllAndShowInTableView();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package de.hitec.nhplus.nurse;
|
||||
|
||||
import de.hitec.nhplus.main.Person;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
|
@ -9,6 +10,8 @@ import java.util.StringJoiner;
|
|||
public class Nurse extends Person {
|
||||
private SimpleIntegerProperty id;
|
||||
private final SimpleStringProperty phoneNumber;
|
||||
private final SimpleBooleanProperty locked;
|
||||
|
||||
|
||||
public Nurse(
|
||||
String firstName,
|
||||
|
@ -17,17 +20,30 @@ public class Nurse extends Person {
|
|||
) {
|
||||
super(firstName, surName);
|
||||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||
this.locked = new SimpleBooleanProperty(false);
|
||||
}
|
||||
public Nurse(
|
||||
String firstName,
|
||||
String surName,
|
||||
String phoneNumber,
|
||||
Boolean isLocked
|
||||
) {
|
||||
super(firstName, surName);
|
||||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||
this.locked = new SimpleBooleanProperty(isLocked);
|
||||
}
|
||||
|
||||
public Nurse(
|
||||
int id,
|
||||
String firstName,
|
||||
String surName,
|
||||
String phoneNumber
|
||||
String phoneNumber,
|
||||
Boolean isLocked
|
||||
) {
|
||||
super(firstName, surName);
|
||||
this.id = new SimpleIntegerProperty(id);
|
||||
this.phoneNumber = new SimpleStringProperty(phoneNumber);
|
||||
this.locked = new SimpleBooleanProperty(isLocked);
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
|
@ -50,6 +66,19 @@ public class Nurse extends Person {
|
|||
return phoneNumber;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked.get();
|
||||
}
|
||||
|
||||
public SimpleBooleanProperty lockedProperty() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
this.locked.set(locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(System.lineSeparator())
|
||||
|
|
|
@ -19,13 +19,14 @@ public class NurseDao extends DaoImp<Nurse> {
|
|||
protected PreparedStatement getCreateStatement(Nurse nurse) throws SQLException {
|
||||
final String SQL = """
|
||||
INSERT INTO nurse
|
||||
(firstName, surName, phoneNumber)
|
||||
VALUES (?, ?, ?)
|
||||
(firstName, surName, phoneNumber, isLocked)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setString(1, nurse.getFirstName());
|
||||
statement.setString(2, nurse.getSurName());
|
||||
statement.setString(3, nurse.getPhoneNumber());
|
||||
statement.setBoolean(4, nurse.isLocked());
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,8 @@ public class NurseDao extends DaoImp<Nurse> {
|
|||
result.getInt(1),
|
||||
result.getString(2),
|
||||
result.getString(3),
|
||||
result.getString(4)
|
||||
result.getString(4),
|
||||
result.getBoolean(5)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -62,20 +64,32 @@ public class NurseDao extends DaoImp<Nurse> {
|
|||
return list;
|
||||
}
|
||||
|
||||
public List<Nurse> readAllActive() throws SQLException {
|
||||
final String SQL = "SELECT * FROM nurse WHERE isLocked=false";
|
||||
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
|
||||
}
|
||||
|
||||
public List<Nurse> readAllLocked() throws SQLException {
|
||||
final String SQL = "SELECT * FROM nurse WHERE isLocked=true";
|
||||
return getListFromResultSet(this.connection.prepareStatement(SQL).executeQuery());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement getUpdateStatement(Nurse nurse) throws SQLException {
|
||||
final String SQL = """
|
||||
UPDATE nurse SET
|
||||
firstName = ?,
|
||||
surName = ?,
|
||||
phoneNumber = ?
|
||||
phoneNumber = ?,
|
||||
isLocked = ?
|
||||
WHERE id = ?
|
||||
""";
|
||||
PreparedStatement statement = this.connection.prepareStatement(SQL);
|
||||
statement.setString(1, nurse.getFirstName());
|
||||
statement.setString(2, nurse.getSurName());
|
||||
statement.setString(3, nurse.getPhoneNumber());
|
||||
statement.setInt(4, nurse.getId());
|
||||
statement.setBoolean(4, nurse.isLocked());
|
||||
statement.setInt(5, nurse.getId());
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
@ -86,4 +100,6 @@ public class NurseDao extends DaoImp<Nurse> {
|
|||
statement.setInt(1, id);
|
||||
return statement;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,14 @@
|
|||
<Tab fx:id="treatmentTab" text="Behandlungen">
|
||||
<AnchorPane fx:id="treatmentPage"/>
|
||||
</Tab>
|
||||
<Tab fx:id="nurseTab" text="Pfleger">
|
||||
<AnchorPane fx:id="nursePage"/>
|
||||
</Tab>
|
||||
<Tab fx:id="nurseTab" text="Pfleger">
|
||||
<TabPane fx:id="nurseTabPane" tabClosingPolicy="UNAVAILABLE">
|
||||
<Tab fx:id="activeNurseTab" text="Pfleger">
|
||||
<AnchorPane fx:id="activeNursePage"/>
|
||||
</Tab>
|
||||
<Tab fx:id="lockedNurseTab" text="Gesperrte Pfleger">
|
||||
<AnchorPane fx:id="lockedNursePage"/>
|
||||
</Tab>
|
||||
</TabPane>
|
||||
</Tab>
|
||||
</TabPane>
|
||||
|
|
|
@ -77,10 +77,11 @@
|
|||
text="Hinzufügen"
|
||||
/>
|
||||
<Button
|
||||
fx:id="buttonDelete"
|
||||
fx:id="buttonLock"
|
||||
mnemonicParsing="false"
|
||||
onAction="#handleLock"
|
||||
prefWidth="90.0"
|
||||
text="Löschen"
|
||||
text="Sperren"
|
||||
/>
|
||||
</HBox>
|
||||
</right>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<BorderPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="de.hitec.nhplus.nurse.LockedNurseController"
|
||||
>
|
||||
<padding>
|
||||
<Insets top="8" left="8" right="8" bottom="8"/>
|
||||
</padding>
|
||||
<center>
|
||||
<TableView fx:id="tableView" layoutX="31.0" layoutY="40">
|
||||
<columns>
|
||||
<TableColumn
|
||||
fx:id="columnId"
|
||||
minWidth="40.0"
|
||||
text="ID"
|
||||
/>
|
||||
<TableColumn
|
||||
fx:id="columnSurName"
|
||||
minWidth="140.0"
|
||||
text="Nachname"
|
||||
/>
|
||||
<TableColumn
|
||||
fx:id="columnFirstName"
|
||||
minWidth="140.0"
|
||||
text="Vorname"
|
||||
/>
|
||||
<TableColumn
|
||||
fx:id="columnDeleteDate"
|
||||
minWidth="140.0"
|
||||
text="Löschen ab"
|
||||
/>
|
||||
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
</center>
|
||||
<bottom>
|
||||
<BorderPane>
|
||||
<BorderPane.margin>
|
||||
<Insets top="8.0"/>
|
||||
</BorderPane.margin>
|
||||
<center>
|
||||
<HBox spacing="8.0">
|
||||
<padding>
|
||||
<Insets right="8.0"/>
|
||||
</padding>
|
||||
</HBox>
|
||||
</center>
|
||||
<right>
|
||||
<HBox>
|
||||
<spacing>8.0</spacing>
|
||||
<Button
|
||||
fx:id="buttonUnlock"
|
||||
mnemonicParsing="false"
|
||||
onAction="#changeUnlock"
|
||||
prefWidth="90.0"
|
||||
text="Entsperren"
|
||||
/>
|
||||
<Button
|
||||
fx:id="buttonDelete"
|
||||
mnemonicParsing="false"
|
||||
onAction="#handleDelete"
|
||||
prefWidth="90.0"
|
||||
text="Löschen"
|
||||
/>
|
||||
</HBox>
|
||||
</right>
|
||||
</BorderPane>
|
||||
</bottom>
|
||||
</BorderPane>
|
|
@ -3,5 +3,6 @@ CREATE TABLE nurse
|
|||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
firstName TEXT NOT NULL,
|
||||
surName TEXT NOT NULL,
|
||||
phoneNumber TEXT NOT NULL
|
||||
phoneNumber TEXT NOT NULL,
|
||||
isLocked BOOLEAN NOT NULL DEFAULT false
|
||||
)
|
Loading…
Reference in a new issue