Compare commits

..

No commits in common. "0d36d7718efd5b4691d2cff0cb7ee7b4ab331056" and "72c2e9da16fb118156634624fbe786e29b94cc48" have entirely different histories.

7 changed files with 181 additions and 391 deletions

2
.gitignore vendored
View File

@ -36,5 +36,3 @@ build/
### Mac OS ###
.DS_Store
/database.db

View File

@ -1,71 +0,0 @@
package com.bib.essensbestellungsverwaltung;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CreateFoodController {
@FXML
public TextField name;
@FXML
public TextArea description;
@FXML
public RadioButton isHauptgerichtRadio;
@FXML
public RadioButton isDessertRadio;
@FXML
public RadioButton isVegetarischRadio;
@FXML
public RadioButton isVeganRadio;
@FXML
public RadioButton isFleischRadio;
@FXML
public TextArea allergienTextBox;
@FXML
public Text responseText;
@FXML
public void onAbbrechen(ActionEvent actionEvent) {
clearInputs();
}
@FXML
public void onHinzufügen(ActionEvent actionEvent) {
String gerichtName = name.getText();
String beschreibung = description.getText();
if(!isHauptgerichtRadio.isSelected() && !isDessertRadio.isSelected()){
// art auswähelen
}
boolean isNachtisch = !isHauptgerichtRadio.isSelected();
if(!isVegetarischRadio.isSelected() && !isVeganRadio.isSelected() && isFleischRadio.isSelected()){
// Typ auswählen
}
int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3;
FoodType foodType = new FoodType(ft, "Vegan");
List<Allergy> allergies = new ArrayList<>();
// TODO: allergien hinzufügen
long id = FoodMgr.createFood(new Food(gerichtName, beschreibung, isNachtisch, foodType, allergies));
System.out.println("Food created with id: " + id);
responseText.setText("New Food Created");
clearInputs();
}
private void clearInputs(){
name.setText("");
description.setText("");
isHauptgerichtRadio.setSelected(false);
isDessertRadio.setSelected(false);
isVeganRadio.setSelected(false);
isVegetarischRadio.setSelected(false);
isFleischRadio.setSelected(false);
allergienTextBox.setText("");
}
}

View File

@ -1,119 +0,0 @@
package com.bib.essensbestellungsverwaltung;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import java.time.LocalDate;
import java.util.List;
public class CreateFoodplanController {
@FXML
Button erstellenButton;
@FXML
DatePicker date;
@FXML
ChoiceBox firstMeal;
@FXML
ChoiceBox secondMeal;
@FXML
ChoiceBox firstDessert;
@FXML
ChoiceBox secondDessert;
private List<Food> foods;
private List<Food> desserts;
private FoodPlan currentPlan;
@FXML
public void initialize() {
foods = FoodMgr.getFood(false);
desserts = FoodMgr.getFood(true);
ObservableList<Object> foodOptions = FXCollections.observableArrayList(foods.stream().map(food -> food.getId() + ": " + food.getName()).toList().toArray(new String[0]));
firstMeal.setItems(foodOptions);
secondMeal.setItems(foodOptions);
ObservableList<Object> dessertOptions = FXCollections.observableArrayList(desserts.stream().map(dessert -> dessert.getId() + ": " + dessert.getName()).toList().toArray(new String[0]));
firstDessert.setItems(dessertOptions);
secondDessert.setItems(dessertOptions);
date.setValue(LocalDate.now());
onDateChange(null);
}
@FXML
public void onPlanErstellen(ActionEvent actionEvent) {
if (date.getValue() == null ||
firstMeal.getValue().toString().isBlank() ||
secondMeal.getValue().toString().isBlank() ||
firstDessert.getValue().toString().isBlank() ||
secondDessert.getValue().toString().isBlank()
) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Ungültige Eingabe");
alert.setHeaderText("Es wurden nicht alle Felder ausgefüllt");
alert.setContentText("Es kann sein, dass Sie erst Gerichte erstellen müssen, um alle Felder auszufüllen");
alert.showAndWait();
return;
}
int firstMealId = Integer.parseInt(firstMeal.getValue().toString().split(":")[0]);
int secondMealId = Integer.parseInt(secondMeal.getValue().toString().split(":")[0]);
int firstDessertId = Integer.parseInt(firstDessert.getValue().toString().split(":")[0]);
int secondDessertId = Integer.parseInt(secondDessert.getValue().toString().split(":")[0]);
Food f1 = foods.stream().filter(food -> food.getId() == firstMealId).findFirst().get();
Food f2 = foods.stream().filter(food -> food.getId() == secondMealId).findFirst().get();
Food d1 = desserts.stream().filter(dessert -> dessert.getId() == firstDessertId).findFirst().get();
Food d2 = desserts.stream().filter(dessert -> dessert.getId() == secondDessertId).findFirst().get();
String d = date.getValue().toString();
if (currentPlan != null) { // update Foodplan
long id = currentPlan.getId();
FoodPlan plan = new FoodPlan(id, d, f1, f2, d1, d2, false);
long i = FoodMgr.updateFood_plan(plan);
System.out.println("Foodplan updated: " + i);
} else { // create new Foodplan
FoodPlan plan = new FoodPlan(d, f1, f2, d1, d2);
long id = FoodMgr.createFood_plan(plan);
System.out.println("Foodplan created with id: " + id);
}
}
@FXML
public void onAbbrechen(ActionEvent actionEvent) {
}
@FXML
public void onDateChange(ActionEvent actionEvent) {
currentPlan = FoodMgr.getFoodPlan(date.getValue().toString());
if (currentPlan != null) { // current FoodPlan already exists and can be edited
firstMeal.setValue(currentPlan.getFoodVegan().getId() + ": " + currentPlan.getFoodVegan().getName());
secondMeal.setValue(currentPlan.getFoodSecond().getId() + ": " + currentPlan.getFoodSecond().getName());
firstDessert.setValue(currentPlan.getDessertVegan().getId() + ": " + currentPlan.getDessertVegan().getName());
secondDessert.setValue(currentPlan.getDessertSecond().getId() + ": " + currentPlan.getDessertSecond().getName());
erstellenButton.setText("Plan updaten");
} else { // current Foodplan does not exist
erstellenButton.setText("Plan erstellen");
firstMeal.setValue(null);
secondMeal.setValue(null);
firstDessert.setValue(null);
secondDessert.setValue(null);
}
}
}

View File

@ -41,20 +41,6 @@ public class FoodMgr {
return Database.insert("food_plan",food_planH,food_planD);
}
/**
* updates a food_plan into the database
* @return number of rows affected or -1 on error
*/
public static long updateFood_plan(FoodPlan foodPlan){
String[] food_planH = {"id","food1","food2","dessert1","dessert2"};
String[] food_planD = {String.valueOf(foodPlan.getId()),
String.valueOf(foodPlan.getFoodVegan().getId()),
String.valueOf(foodPlan.getFoodSecond().getId()),
String.valueOf(foodPlan.getDessertVegan().getId()),
String.valueOf(foodPlan.getDessertSecond().getId())};
return Database.update("food_plan",food_planH,food_planD);
}
/**
* returns all non desserts or all desserts
* @param isDessert true for only desserts false for non desserts
@ -98,9 +84,6 @@ public class FoodMgr {
String[] food_planH = {"date"};
String[] food_planD = {date};
List<String> entry = Database.select("food_plan",food_planH,food_planD);
if(entry.size() < 1){
return null;
}
String[] parts = entry.get(0).split(":");
Food foodVegan = getFoodById(Long.parseLong(parts[2]));
Food foodSecond = getFoodById(Long.parseLong(parts[3]));

View File

@ -19,7 +19,7 @@ public class StartViewApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("login-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1300, 750);
Scene scene = new Scene(fxmlLoader.load(), 1200, 750);
primary = stage;
stage.setTitle("Essen Bestellung im Kindergarten");
stage.setScene(scene);

View File

@ -1,107 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextArea?>
<?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?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="731.0" stylesheets="@createFood.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.CreateFoodController">
<children>
<Label alignment="CENTER" layoutX="247.0" layoutY="29.0" prefHeight="44.0" prefWidth="237.0" text="Gericht hinzufügen">
<font>
<Font size="18.0" />
</font>
</Label>
<VBox layoutX="136.0" layoutY="73.0" prefHeight="388.0" prefWidth="459.0">
<children>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label prefHeight="33.0" prefWidth="121.0" text="Name des Gerichts" />
<TextField fx:id="name" prefHeight="25.0" prefWidth="290.0">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</TextField>
</children>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label prefHeight="33.0" prefWidth="121.0" text="Beschreibung" />
<TextArea fx:id="description" prefHeight="75.0" prefWidth="290.0" />
</children>
<padding>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="521.0" prefWidth="731.0" stylesheets="@createFood.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label alignment="CENTER" layoutX="234.0" layoutY="29.0" prefHeight="44.0" prefWidth="237.0" text="Gericht hinzufügen">
<font>
<Font size="18.0" />
</font>
</Label>
<VBox layoutX="112.0" layoutY="73.0" prefHeight="389.0" prefWidth="459.0">
<children>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label prefHeight="33.0" prefWidth="121.0" text="Name des Gerichts" />
<TextField prefHeight="25.0" prefWidth="290.0">
<HBox.margin>
<Insets top="5.0" />
</padding>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label text="Art des Gerichts">
<HBox.margin>
<Insets top="20.0" />
</HBox.margin>
</Label>
<RadioButton fx:id="isHauptgerichtRadio" mnemonicParsing="false" text="Hauptgericht">
<HBox.margin>
<Insets left="35.0" top="20.0" />
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="art" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="isDessertRadio" mnemonicParsing="false" text="Dessert" toggleGroup="$art">
<HBox.margin>
<Insets left="50.0" top="20.0" />
</HBox.margin>
</RadioButton>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
<padding>
<Insets top="5.0" />
</padding>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label text="Typ">
<HBox.margin>
<Insets top="20.0" />
</HBox.margin>
</Label>
<RadioButton fx:id="isVegetarischRadio" mnemonicParsing="false" prefHeight="17.0" prefWidth="91.0" text="Vegetarisch">
<HBox.margin>
<Insets left="100.0" top="20.0" />
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="typ" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="isVeganRadio" mnemonicParsing="false" text="Vegan" toggleGroup="$typ">
<HBox.margin>
<Insets left="20.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton fx:id="isFleischRadio" mnemonicParsing="false" text="Fleisch" toggleGroup="$typ">
<HBox.margin>
<Insets left="40.0" top="20.0" />
</HBox.margin>
</RadioButton>
</children>
</HBox>
<HBox prefHeight="76.0" prefWidth="459.0">
<children>
<Label prefHeight="41.0" prefWidth="171.0" text="Allergien mit Komma getrennt" />
<TextArea fx:id="allergienTextBox" prefHeight="76.0" prefWidth="246.0" />
</children>
</HBox>
<Text fx:id="responseText" fill="RED" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="459.13673400878906">
</HBox.margin>
</TextField>
</children>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label prefHeight="33.0" prefWidth="121.0" text="Beschreibung" />
<TextArea prefHeight="75.0" prefWidth="290.0" />
</children>
<padding>
<Insets top="5.0" />
</padding>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label text="Art des Gerichts">
<HBox.margin>
<Insets top="20.0" />
</HBox.margin>
</Label>
<RadioButton mnemonicParsing="false" text="Dessert">
<HBox.margin>
<Insets left="35.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Kein Dessert">
<HBox.margin>
<Insets left="50.0" top="20.0" />
</HBox.margin>
</RadioButton>
</children>
<VBox.margin>
<Insets top="20.0" />
<Insets />
</VBox.margin>
</Text>
</children>
</VBox>
<Button id="btCreateFood" layoutX="484.0" layoutY="481.0" mnemonicParsing="false" onAction="#onHinzufügen" prefHeight="34.0" prefWidth="146.0" text="Hinzufügen" />
<Button id="btCancelFood" layoutX="102.0" layoutY="473.0" mnemonicParsing="false" onAction="#onAbbrechen" prefHeight="50.0" prefWidth="162.0" text="Abbrechen" />
</children>
<padding>
<Insets top="5.0" />
</padding>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label text="Typ">
<HBox.margin>
<Insets top="20.0" />
</HBox.margin>
</Label>
<RadioButton mnemonicParsing="false" prefHeight="17.0" prefWidth="91.0" text="Vegetarisch">
<HBox.margin>
<Insets left="100.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Vegan">
<HBox.margin>
<Insets left="20.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Fleisch">
<HBox.margin>
<Insets left="40.0" top="20.0" />
</HBox.margin>
</RadioButton>
</children>
</HBox>
<HBox prefHeight="76.0" prefWidth="459.0">
<children>
<Label prefHeight="41.0" prefWidth="171.0" text="Allergien mit Komma getrennt" />
<TextArea prefHeight="76.0" prefWidth="246.0" />
</children>
</HBox>
</children>
</VBox>
<Button id="btCreateFood" layoutX="106.0" layoutY="457.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="145.0" text="Hinzufügen" />
<Button id="btCancelFood" layoutX="366.0" layoutY="457.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="162.0" text="Abbrechen" />
</children>
</AnchorPane>

View File

@ -1,83 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?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?>
<HBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="950.0" stylesheets="@createFoodplan.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.CreateFoodplanController">
<children>
<VBox alignment="CENTER" prefHeight="599.0" prefWidth="357.0" spacing="20.0">
<children>
<Label text="Essensplan erstellen">
<font>
<Font size="18.0" />
</font>
</Label>
<VBox prefHeight="285.0" prefWidth="358.0">
<children>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Datum JJJJ-MMM-TT">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
<DatePicker fx:id="date" onAction="#onDateChange" />
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Veganes Hauptgericht">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
<ChoiceBox fx:id="firstMeal" prefWidth="150.0" />
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Zweites Hauptgericht">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
<ChoiceBox fx:id="secondMeal" prefWidth="150.0" />
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Veganes Dessert">
<HBox.margin>
<Insets />
</HBox.margin>
<padding>
<Insets top="5.0" />
</padding>
</Label>
<ChoiceBox fx:id="firstDessert" prefWidth="150.0" />
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Zweites Dessert">
<padding>
<Insets top="5.0" />
</padding>
</Label>
<ChoiceBox fx:id="secondDessert" prefWidth="150.0" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<Button id="btCreateFoodplan" fx:id="erstellenButton" mnemonicParsing="false" onAction="#onPlanErstellen" prefHeight="68.0" prefWidth="133.0" text="Plan erstellen" />
<Button id="btCancelFoodplan" mnemonicParsing="false" onAction="#onAbbrechen" prefHeight="68.0" prefWidth="133.0" text="Abbrechen" />
</children>
</HBox>
</children>
</VBox>
</children>
</VBox>
</children>
</HBox>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="599.0" prefWidth="900.0" stylesheets="@createFoodplan.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="359.0" layoutY="36.0" text="Essensplan erstellen">
<font>
<Font size="18.0" />
</font>
</Label>
<VBox layoutX="134.0" layoutY="124.0" prefHeight="327.0" prefWidth="632.0">
<children>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Datum JJJJ-MMM-TT">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
<TextField />
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Veganes Hauptgericht">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
<TextField>
<HBox.margin>
<Insets />
</HBox.margin>
</TextField>
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Zweites Hauptgericht">
<HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</Label>
<TextField>
<HBox.margin>
<Insets />
</HBox.margin>
</TextField>
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Veganes Dessert">
<HBox.margin>
<Insets />
</HBox.margin>
<padding>
<Insets top="5.0" />
</padding>
</Label>
<TextField />
</children>
</HBox>
<HBox prefHeight="50.0" prefWidth="632.0">
<children>
<Label prefHeight="17.0" prefWidth="133.0" text="Zweites Dessert">
<padding>
<Insets top="5.0" />
</padding>
</Label>
<TextField />
</children>
</HBox>
</children>
</VBox>
<Button id="btCreateFoodplan" layoutX="112.0" layoutY="427.0" mnemonicParsing="false" prefHeight="68.0" prefWidth="133.0" text="Plan erstellen" />
<Button id="btCancelFoodplan" layoutX="299.0" layoutY="427.0" mnemonicParsing="false" prefHeight="68.0" prefWidth="133.0" text="Abbrechen" />
</children>
</AnchorPane>