feat/kindErstellen #9

Merged
PBS2H21ASH merged 23 commits from feat/kindErstellen into stable 2023-02-05 20:40:12 +01:00
4 changed files with 196 additions and 102 deletions
Showing only changes of commit b37cd2ad38 - Show all commits

View File

@ -0,0 +1,142 @@
package com.bib.essensbestellungsverwaltung;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import org.controlsfx.control.CheckComboBox;
import java.util.ArrayList;
import java.util.List;
public class ChildController {
public TextField firstName;
public ChoiceBox childChoiceBox;
public TextField lastName;
public Button kindHinzufügenButton;
public CheckComboBox allergienComboBox;
public Button kindLoeschenButton;
private Child currentChild = null;
private long selectedChildId;
@FXML
public void initialize() {
kindLoeschenButton.setDisable(true);
updateChildChoiceBoxItems();
List<String> a = Database.getTable("allergy");
ObservableList<String> allergies = FXCollections.observableArrayList();
for (String allergie : a) {
allergies.add(allergie.split(":")[0] + ": " + allergie.split(":")[1]);
}
allergienComboBox.getItems().addAll(allergies);
}
public void onSelectChild(ActionEvent mouseEvent) {
selectedChildId = Integer.parseInt(childChoiceBox.getValue().toString().split(":")[0]);
System.out.println("Selected Child: " + selectedChildId);
clearInputs();
if(selectedChildId == 0) {
kindHinzufügenButton.setText("Kind Hinzufügen");
kindLoeschenButton.setDisable(true);
return;
}
// Get selected child and update fields
currentChild = AccountMgr.getChildById(selectedChildId);
firstName.setText(currentChild.getFirstname());
lastName.setText(currentChild.getName());
for (AllergySeverity a : currentChild.getAllergies()){
allergienComboBox.getCheckModel().check((int) a.getAllergy().getId() - 1);
}
kindHinzufügenButton.setText("Kind updaten");
kindLoeschenButton.setDisable(false);
}
public void onKindHinzufügen(ActionEvent actionEvent) {
if(childChoiceBox.getValue() == null){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Ungültige Eingabe");
alert.setHeaderText("Sie müssen ein Kind auswählen");
alert.showAndWait();
return;
}
if(lastName.getText().isBlank() || firstName.getText().isBlank()){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Ungültige Eingabe");
alert.setHeaderText("Es wurden nicht alle Felder ausgefüllt");
alert.showAndWait();
return;
}
Address adress = AccountMgr.currentUser.getAddress();
List<AllergySeverity> allergies = new ArrayList<>();
allergienComboBox.getCheckModel().getCheckedItems().stream().forEach(a -> {
long id = Integer.parseInt(a.toString().split(":")[0]);
String name = a.toString().split(":")[1].trim();
// TODO: Allergy Severity
allergies.add(new AllergySeverity(new Allergy(id, name, ""), 2, null));
});
if(selectedChildId == 0){
// TODO: Create child
long id = AccountMgr.createChild(new Child(lastName.getText(), firstName.getText(), adress, allergies));
System.out.println("Child created: " + id);
if(id <= 0){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Es ist ein fehler beim erstellen des Kinds aufgetreten");
alert.showAndWait();
return;
}
AccountMgr.matchParentChild(String.valueOf(AccountMgr.currentUser.getId()), String.valueOf(id));
childChoiceBox.getItems().add(id + ": " + firstName.getText() + " " + lastName.getText());
childChoiceBox.setValue(childChoiceBox.getItems().get(childChoiceBox.getItems().size() - 1));
clearInputs();
onSelectChild(null);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Kind erstellt");
alert.setHeaderText("Es wurde ein Kind erstellt");
alert.showAndWait();
}else {
long id = AccountMgr.updateChild(new Child(currentChild.getId(), lastName.getText(), firstName.getText(), adress, allergies));
System.out.println("Updated Child: " + id);
}
}
private void clearInputs(){
firstName.setText("");
lastName.setText("");
allergienComboBox.getCheckModel().clearChecks();
}
public void updateChildChoiceBoxItems(){
List<Child> childList = AccountMgr.getAllChildrenFromParentWithId(AccountMgr.currentUser.getId());
ObservableList<Object> childOptions = FXCollections.observableArrayList(childList.stream().map(c -> c.getId() + ": " + c.getFirstname() + " " + c.getName()).toList().toArray(new String[0]));
childOptions.add(0, "0: neues Kind erstellen");
childChoiceBox.setItems(childOptions);
}
public void onKindLoeschen(ActionEvent actionEvent) {
AccountMgr.deleteChildWithId(currentChild.getId());
System.out.println("Deleted Child: " + currentChild.getId());
childChoiceBox.getItems().remove(childChoiceBox.getItems().stream().filter(v -> v.equals(currentChild.getId() + ": " + currentChild.getFirstname() + " " + currentChild.getName())).findFirst().get());
childChoiceBox.setValue(childChoiceBox.getItems().get(1));
onSelectChild(null);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Kind wurde gelöscht");
alert.showAndWait();
}
}

View File

@ -12,7 +12,6 @@ import java.io.IOException;
public class WorkerMenuController { public class WorkerMenuController {
@FXML @FXML
public BorderPane contentView; public BorderPane contentView;
@FXML @FXML
Button tagesbestellungButton; Button tagesbestellungButton;
@FXML @FXML

View File

@ -1,48 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.*?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.*?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.layout.*?>
<?import javafx.scene.control.DatePicker?> <?import javafx.scene.text.*?>
<?import javafx.scene.control.ListView?> <?import org.controlsfx.control.*?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="700.0" prefWidth="950.0" stylesheets="@child.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.ParentController"> <AnchorPane prefHeight="700.0" prefWidth="950.0" stylesheets="@child.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.ChildController">
<children> <children>
<Text layoutX="51.0" layoutY="90.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Kinder"> <Text layoutX="51.0" layoutY="90.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Kinder">
<font> <font>
<Font size="58.0" /> <Font size="58.0" />
</font> </font>
</Text> </Text>
<HBox id="contentContainer" alignment="CENTER" layoutX="8.0" layoutY="165.0" prefHeight="331.0" prefWidth="937.0"> <HBox id="contentContainer" alignment="CENTER" layoutX="8.0" layoutY="165.0" prefHeight="127.0" prefWidth="937.0">
<children> <children>
<VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0"> <VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0">
<children> <children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Name"> <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Vorname">
<VBox.margin> <VBox.margin>
<Insets bottom="15.0" top="15.0" /> <Insets bottom="15.0" top="15.0" />
</VBox.margin> </VBox.margin>
</Text> </Text>
<TextField prefWidth="97.0"> <TextField fx:id="firstName" prefWidth="97.0">
<VBox.margin> <VBox.margin>
<Insets bottom="15.0" top="15.0" /> <Insets bottom="15.0" top="15.0" />
</VBox.margin> </VBox.margin>
</TextField> </TextField>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Geburtsdatum">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<DatePicker prefHeight="26.0" prefWidth="226.0">
<VBox.margin>
<Insets top="13.0" />
</VBox.margin>
</DatePicker>
</children> </children>
<HBox.margin> <HBox.margin>
<Insets left="15.0" right="15.0" /> <Insets left="15.0" right="15.0" />
@ -50,44 +34,16 @@
</VBox> </VBox>
<VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0"> <VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0">
<children> <children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Alter"> <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Nachname">
<VBox.margin> <VBox.margin>
<Insets bottom="15.0" top="15.0" /> <Insets bottom="15.0" top="15.0" />
</VBox.margin> </VBox.margin>
</Text> </Text>
<TextField prefWidth="97.0"> <TextField fx:id="lastName" prefWidth="97.0">
<VBox.margin> <VBox.margin>
<Insets bottom="15.0" top="15.0" /> <Insets bottom="15.0" top="15.0" />
</VBox.margin> </VBox.margin>
</TextField> </TextField>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Gruppe">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<ComboBox prefHeight="26.0" prefWidth="230.0">
<VBox.margin>
<Insets top="13.0" />
</VBox.margin>
</ComboBox>
</children>
<HBox.margin>
<Insets left="15.0" right="15.0" />
</HBox.margin>
</VBox>
<VBox id="contentContainer" prefHeight="250.0" prefWidth="256.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Allergien">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<ListView prefHeight="101.0" prefWidth="227.0" />
<TextField id="tfAddAllergy" promptText="Allergie hinzufügen">
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</TextField>
</children> </children>
<HBox.margin> <HBox.margin>
<Insets left="15.0" right="15.0" /> <Insets left="15.0" right="15.0" />
@ -95,6 +51,19 @@
</VBox> </VBox>
</children> </children>
</HBox> </HBox>
<Button id="btAddChild" layoutX="419.0" layoutY="502.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="125.0" text="Kind hinzufügen" /> <Button id="btAddChild" fx:id="kindHinzufügenButton" layoutX="779.0" layoutY="646.0" mnemonicParsing="false" onAction="#onKindHinzufügen" prefHeight="26.0" prefWidth="125.0" text="Kind hinzufügen" />
<ChoiceBox fx:id="childChoiceBox" layoutX="704.0" layoutY="62.0" onAction="#onSelectChild" prefWidth="150.0" />
<Label layoutX="704.0" layoutY="44.0" text="Kind" />
<VBox id="contentContainer" layoutX="493.0" layoutY="330.0" prefHeight="250.0" prefWidth="256.0" spacing="20.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Allergien">
<VBox.margin>
<Insets bottom="15.0" top="15.0" />
</VBox.margin>
</Text>
<CheckComboBox fx:id="allergienComboBox" prefHeight="25.0" prefWidth="200.0" />
</children>
</VBox>
<Button id="btAddChild" fx:id="kindLoeschenButton" layoutX="621.0" layoutY="646.0" mnemonicParsing="false" onAction="#onKindLoeschen" prefHeight="26.0" prefWidth="125.0" text="Kind löschen" />
</children> </children>
</AnchorPane> </AnchorPane>

View File

@ -1,20 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<BorderPane fx:id="contentView" prefHeight="750.0" prefWidth="1200.0" stylesheets="@menue.css"
xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" <BorderPane fx:id="contentView" prefHeight="750.0" prefWidth="1200.0" stylesheets="@menue.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.WorkerMenuController">
fx:controller="com.bib.essensbestellungsverwaltung.WorkerMenuController">
<left> <left>
<VBox alignment="TOP_CENTER" prefHeight="750.0" prefWidth="350.0" spacing="10.0" <VBox alignment="TOP_CENTER" prefHeight="750.0" prefWidth="350.0" spacing="10.0" style="-fx-background-color: #69b6ff; -fx-padding: 20;" BorderPane.alignment="CENTER">
style="-fx-background-color: #69b6ff; -fx-padding: 20;" BorderPane.alignment="CENTER">
<children> <children>
<Button fx:id="tagesbestellungButton" alignment="CENTER_LEFT" mnemonicParsing="false" <Button fx:id="tagesbestellungButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onTagesbestellungenClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Tagesbestellung">
onMouseClicked="#onTagesbestellungenClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Tagesbestellung">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@ -26,9 +22,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="monatsabrechnungButton" alignment="CENTER_LEFT" mnemonicParsing="false" <Button fx:id="monatsabrechnungButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onMonatsabrechnungClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Monatsabrechnung">
onMouseClicked="#onMonatsabrechnungClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Monatsabrechnung">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@ -40,9 +34,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="wochenplanButton" alignment="CENTER_LEFT" mnemonicParsing="false" <Button fx:id="wochenplanButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onWochenplanClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Wochenplan">
onMouseClicked="#onWochenplanClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Wochenplan">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@ -54,9 +46,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="mahlzeitButton" alignment="CENTER_LEFT" mnemonicParsing="false" <Button fx:id="mahlzeitButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onMahlzeitClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Mahlzeit">
onMouseClicked="#onMahlzeitClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Mahlzeit">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@ -68,9 +58,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="mitarbeiterButton" alignment="CENTER_LEFT" mnemonicParsing="false" <Button fx:id="mitarbeiterButton" alignment="CENTER_LEFT" mnemonicParsing="false" onMouseClicked="#onMitarbeiterClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Mitarbeiter">
onMouseClicked="#onMitarbeiterClick" prefHeight="60.0" prefWidth="250.0"
styleClass="sidebar-nav_button" text="Mitarbeiter">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@ -87,9 +75,7 @@
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
</Region> </Region>
<Button fx:id="einstellungenButton" alignment="CENTER_LEFT" layoutX="10.0" layoutY="130.0" <Button fx:id="einstellungenButton" alignment="CENTER_LEFT" layoutX="10.0" layoutY="130.0" mnemonicParsing="false" onMouseClicked="#onEinstellungenClick" prefHeight="60.0" prefWidth="250.0" styleClass="sidebar-nav_button" text="Einstellungen">
mnemonicParsing="false" onMouseClicked="#onEinstellungenClick" prefHeight="60.0"
prefWidth="250.0" styleClass="sidebar-nav_button" text="Einstellungen">
<font> <font>
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
@ -108,11 +94,9 @@
</VBox> </VBox>
</left> </left>
<top> <top>
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="1200.0" style="-fx-background-color: #69b6ff;" <HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="1200.0" style="-fx-background-color: #69b6ff;" BorderPane.alignment="CENTER">
BorderPane.alignment="CENTER">
<children> <children>
<Button mnemonicParsing="false" onMouseClicked="#onAusloggenClick" styleClass="sidebar-nav_button" <Button mnemonicParsing="false" onMouseClicked="#onAusloggenClick" styleClass="sidebar-nav_button" text="Ausloggen">
text="Ausloggen">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>