From cd395d19825dff6f6fab47de86b4999a2cee6037 Mon Sep 17 00:00:00 2001 From: Reshad Meher Date: Wed, 1 Feb 2023 10:04:20 +0100 Subject: [PATCH] test --- .gitignore | 4 +- .../CreateFoodController.java | 71 -------- .../CreateFoodplanController.java | 119 ------------- .../essensbestellungsverwaltung/FoodMgr.java | 17 -- .../InvoiceController.java | 67 ------- .../LoginController.java | 25 ++- .../ParentMenuController.java | 77 -------- .../WorkerMenuController.java | 95 ---------- .../createFoodplan-view.fxml | 164 +++++++++--------- .../invoice-view.fxml | 66 +------ .../parentMenu-view.fxml | 94 ---------- .../workerMenu-view.fxml | 129 -------------- 12 files changed, 105 insertions(+), 823 deletions(-) delete mode 100644 src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java delete mode 100644 src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodplanController.java delete mode 100644 src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java delete mode 100644 src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java delete mode 100644 src/main/java/com/bib/essensbestellungsverwaltung/WorkerMenuController.java delete mode 100644 src/main/resources/com/bib/essensbestellungsverwaltung/parentMenu-view.fxml delete mode 100644 src/main/resources/com/bib/essensbestellungsverwaltung/workerMenu-view.fxml diff --git a/.gitignore b/.gitignore index 1165112..5ff6309 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,4 @@ build/ .vscode/ ### Mac OS ### -.DS_Store - -/database.db \ No newline at end of file +.DS_Store \ No newline at end of file diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java b/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java deleted file mode 100644 index 7370fdf..0000000 --- a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodController.java +++ /dev/null @@ -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 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(""); - } -} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodplanController.java b/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodplanController.java deleted file mode 100644 index e7290c7..0000000 --- a/src/main/java/com/bib/essensbestellungsverwaltung/CreateFoodplanController.java +++ /dev/null @@ -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 foods; - private List desserts; - private FoodPlan currentPlan; - - - @FXML - public void initialize() { - foods = FoodMgr.getFood(false); - desserts = FoodMgr.getFood(true); - ObservableList foodOptions = FXCollections.observableArrayList(foods.stream().map(food -> food.getId() + ": " + food.getName()).toList().toArray(new String[0])); - firstMeal.setItems(foodOptions); - secondMeal.setItems(foodOptions); - - ObservableList 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); - } - - } -} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/FoodMgr.java b/src/main/java/com/bib/essensbestellungsverwaltung/FoodMgr.java index b1f612e..ac1bcc1 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/FoodMgr.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/FoodMgr.java @@ -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 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])); diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java b/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java deleted file mode 100644 index aebd7ba..0000000 --- a/src/main/java/com/bib/essensbestellungsverwaltung/InvoiceController.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.bib.essensbestellungsverwaltung; - -import javafx.fxml.FXML; -import javafx.scene.control.ChoiceBox; -import javafx.scene.control.Spinner; -import javafx.scene.input.MouseEvent; -import javafx.scene.text.Text; - -import java.util.Calendar; - -public class InvoiceController { - @FXML - Text responseText; - @FXML - ChoiceBox monatChoiceBox; - - @FXML - Spinner jahrSpinner; - - @FXML - public void initialize() { - monatChoiceBox.setValue(intToMonth(Calendar.getInstance().get(Calendar.MONTH) + 1)); - jahrSpinner.getValueFactory().setValue(Calendar.getInstance().get(Calendar.YEAR)); - } - - @FXML - void onRechnungErstellenClick(MouseEvent mouseEvent) { - responseText.setText(monatChoiceBox.getValue().toString() + jahrSpinner.getValue()); - // hier rechnung erstellen - } - - private int monthToInt(String month) { - return switch (month) { - case "Januar" -> 1; - case "Februar" -> 2; - case "März" -> 3; - case "April" -> 4; - case "Mai" -> 5; - case "Juni" -> 6; - case "Juli" -> 7; - case "August" -> 8; - case "September" -> 9; - case "Oktober" -> 10; - case "November" -> 11; - case "Dezember" -> 12; - default -> -1; - }; - } - - private String intToMonth(int month) { - return switch (month) { - case 1 -> "Januar"; - case 2 -> "Februar"; - case 3 -> "März"; - case 4 -> "April"; - case 5 -> "Mai"; - case 6 -> "Juni"; - case 7 -> "Juli"; - case 8 -> "August"; - case 9 -> "September"; - case 10 -> "Oktober"; - case 11 -> "November"; - case 12 -> "Dezember"; - default -> ""; - }; - } -} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java b/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java index 87b5479..90fc05a 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java @@ -1,4 +1,4 @@ -/*Richard Reiswich*/ +/*Reshad Meher*/ package com.bib.essensbestellungsverwaltung; import javafx.fxml.FXML; @@ -7,10 +7,8 @@ import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; -import javafx.stage.Stage; - import java.io.IOException; -import java.util.HashMap; + public class LoginController { @FXML @@ -18,26 +16,27 @@ public class LoginController { @FXML private PasswordField pfPassword; - - HashMap benutzerMap = new HashMap(); @FXML protected void onBtLoginClick() throws IOException { - benutzerMap.put("Reshad","1234"); String email = tfEmail.getText(); String password = pfPassword.getText(); - if(benutzerMap.containsKey(email) && benutzerMap.containsValue(password)){ - // if user is worker: StartViewApplication.changeScene("workerMenu-view.fxml"); - StartViewApplication.changeScene("parentMenu-view.fxml"); + long loginPruefen = AccountMgr.login(email,password); + if(loginPruefen > 0){ + FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("menue-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 950,700); + StartViewApplication.primary.setScene(scene); }else { Alert alert = new Alert(Alert.AlertType.ERROR,"Email oder Passwort ist falsch"); alert.showAndWait(); } - tfEmail.setText(""); pfPassword.setText(""); } @FXML - protected void changeToSignUp() throws IOException { - StartViewApplication.changeScene("signUp-view.fxml"); + protected void onBtSingnupClick() throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("signUp-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 950,700); + StartViewApplication.primary.setScene(scene); + } } diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java b/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java deleted file mode 100644 index 4f21d1b..0000000 --- a/src/main/java/com/bib/essensbestellungsverwaltung/ParentMenuController.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.bib.essensbestellungsverwaltung; - -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.control.Button; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.BorderPane; - -import java.io.IOException; - -public class ParentMenuController { - - @FXML - BorderPane contentView; - @FXML - Button essensplanButton; - @FXML - Button kinderButton; - @FXML - Button bestellungButton; - @FXML - Button einstellungenButton; - - @FXML - public void initialize() { - changePage("menue-view.fxml"); - setButtonActive(essensplanButton); - } - - - @FXML - public void onEssensplanClick(MouseEvent mouseEvent) { - setButtonActive(essensplanButton); - changePage("menue-view.fxml"); - } - - @FXML - public void onKinderClick(MouseEvent mouseEvent) { - setButtonActive(kinderButton); - changePage("child-view.fxml"); - } - - @FXML - public void onBestellungClick(MouseEvent mouseEvent) { - setButtonActive(bestellungButton); - changePage("dailyOrder-view.fxml"); - } - - @FXML - public void onEinstellungenClick(MouseEvent mouseEvent) { - setButtonActive(einstellungenButton); - changePage("menue-view.fxml"); - } - - @FXML - public void onAusloggenClick(MouseEvent mouseEvent) throws IOException { - StartViewApplication.changeScene("workerMenu-view.fxml"); - } - - private void changePage(String page) { - try { - Parent root = FXMLLoader.load(getClass().getResource(page)); - contentView.setCenter(root); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void setButtonActive(Button b) { - einstellungenButton.getStyleClass().remove("active"); - kinderButton.getStyleClass().remove("active"); - bestellungButton.getStyleClass().remove("active"); - essensplanButton.getStyleClass().remove("active"); - b.getStyleClass().add("active"); - } -} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/WorkerMenuController.java b/src/main/java/com/bib/essensbestellungsverwaltung/WorkerMenuController.java deleted file mode 100644 index 42d7bcb..0000000 --- a/src/main/java/com/bib/essensbestellungsverwaltung/WorkerMenuController.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.bib.essensbestellungsverwaltung; - -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.control.Button; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.BorderPane; - -import java.io.IOException; - -public class WorkerMenuController { - @FXML - public BorderPane contentView; - - @FXML - Button tagesbestellungButton; - @FXML - Button wochenplanButton; - @FXML - Button monatsabrechnungButton; - @FXML - Button mitarbeiterButton; - @FXML - Button mahlzeitButton; - @FXML - Button einstellungenButton; - - @FXML - public void initialize() { - changePage("menue-view.fxml"); - setButtonActive(tagesbestellungButton); - } - - @FXML - public void onTagesbestellungenClick(MouseEvent mouseEvent) { - changePage("menue-view.fxml"); - setButtonActive(tagesbestellungButton); - } - - @FXML - public void onWochenplanClick(MouseEvent mouseEvent) { - changePage("createFoodplan-view.fxml"); - setButtonActive(wochenplanButton); - } - - @FXML - public void onMonatsabrechnungClick(MouseEvent mouseEvent) { - changePage("invoice-view.fxml"); - setButtonActive(monatsabrechnungButton); - } - - - @FXML - public void onMitarbeiterClick(MouseEvent mouseEvent) { - changePage("createCoworker-view.fxml"); - setButtonActive(mitarbeiterButton); - } - - - @FXML - public void onMahlzeitClick(MouseEvent mouseEvent) { - changePage("createFood-view.fxml"); - setButtonActive(mahlzeitButton); - } - - - public void onEinstellungenClick(MouseEvent mouseEvent) { - setButtonActive(einstellungenButton); - } - - @FXML - public void onAusloggenClick(MouseEvent mouseEvent) throws IOException { - StartViewApplication.changeScene("parentMenu-view.fxml"); - } - - private void changePage(String page) { - try { - Parent root = FXMLLoader.load(getClass().getResource(page)); - contentView.setCenter(root); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void setButtonActive(Button b) { - tagesbestellungButton.getStyleClass().remove("active"); - monatsabrechnungButton.getStyleClass().remove("active"); - wochenplanButton.getStyleClass().remove("active"); - mahlzeitButton.getStyleClass().remove("active"); - mitarbeiterButton.getStyleClass().remove("active"); - einstellungenButton.getStyleClass().remove("active"); - b.getStyleClass().add("active"); - } -} diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/createFoodplan-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/createFoodplan-view.fxml index 8e69006..6b93e3e 100644 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/createFoodplan-view.fxml +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/createFoodplan-view.fxml @@ -1,83 +1,87 @@ - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/workerMenu-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/workerMenu-view.fxml deleted file mode 100644 index 34790cc..0000000 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/workerMenu-view.fxml +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-