diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java b/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java new file mode 100644 index 0000000..3c998ad --- /dev/null +++ b/src/main/java/com/bib/essensbestellungsverwaltung/ChildViewController.java @@ -0,0 +1,140 @@ +/*Schulte*/ + +package com.bib.essensbestellungsverwaltung; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Formattable; +import java.util.List; +import java.util.ResourceBundle; + +public class ChildViewController implements Initializable { + + @FXML + public TextField name; + @FXML + public TextField lastname; + @FXML + public TextField street; + @FXML + public TextField number; + @FXML + public TextField plz; + @FXML + public TextField city; + //@FXML + //public ComboBox group; + //@FXML + //public TextField age; + //@FXML + //public TextField allergies; + @FXML + public ListView allergiesList; + @FXML + public ComboBox selectAllergy; + @FXML + public ComboBox selectAllergySeverity; + + + + @FXML + protected void onBtClick(){ + + boolean childData = false; + + String childName = name.getText(); + String childLastname = lastname.getText(); + + String streetString = street.getText(); + String numberString = number.getText(); + String plzString = plz.getText(); + String cityString = city.getText(); + + + + if(childName.isEmpty() || childLastname.isEmpty() || streetString.isEmpty() || numberString.isEmpty() ||plzString.isEmpty() || cityString.isEmpty()){ + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Felder"); + alert.setHeaderText("Eingabe unvollständig"); + alert.setContentText("Bitte füllen sie alle Felder aus"); + alert.showAndWait(); + } + else childData = true; + + + + if(childData) { + + + Address adress = new Address(streetString, numberString, plzString, cityString); + + List childAllergyList = allergiesList.getItems(); + ArrayList allergySeverityArrayList = new ArrayList<>(); + + /*for (Allergy a : childAllergyList) { + AllergySeverity aS = new AllergySeverity(a, ) + }*/ //Allergy Severity doesn't work in my case so the List will be left empty for now + + + Child child = new Child(childLastname, childName, adress, allergySeverityArrayList); + + System.out.println(AccountMgr.createChild(child)); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Bestätigung"); + alert.setHeaderText("Bestätigung"); + alert.setContentText("Ihr Kind " + childName + " " + childLastname + " wurde Erfolgreich angelegt"); + alert.showAndWait(); + } + + + } + + public ArrayList allergyComboBox(){ + ArrayList allergyArrayList = new ArrayList<>(); + for (int i = 1; i < 23; i++){ + Allergy a = FoodMgr.getAllergyById(i); + allergyArrayList.add(a); + } + return allergyArrayList; + } + + + @FXML + public void addAllergy() { + + boolean allergyEmpty = (selectAllergy.getValue() == "Allergie Wählen"); + boolean severityEmpty = (selectAllergySeverity.getValue() == "Schwere"); + + if(allergyEmpty || severityEmpty) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("Fehler"); + alert.setHeaderText("Ungültige Auswahl"); + alert.setContentText("Bitte Wählen Sie Allergie und schwere aus"); + alert.showAndWait(); + } + + + + String addedAllergy = selectAllergy.getValue().toString(); + String addedSeverity = selectAllergySeverity.getValue().toString().split(":")[0]; + allergiesList.getItems().add(addedAllergy + ":" + addedSeverity); + + + selectAllergy.setValue("Allergie Wählen"); + selectAllergySeverity.setValue("Schwere"); + + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + selectAllergy.getItems().addAll(allergyComboBox()); + + selectAllergySeverity.getItems().addAll("1:Harmlos","2:Warnung","3:Kritisch"); + } +} diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml index dab0830..b022ce4 100644 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml @@ -3,7 +3,6 @@ - @@ -12,7 +11,7 @@ - + @@ -28,21 +27,21 @@ - + - + - + - + - + @@ -50,26 +49,46 @@ - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + @@ -83,11 +102,13 @@ - - - - - + + + + + + +