package com.bib.essensbestellungsverwaltung; /* @author Malte Schulze Hobeling */ import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class ConsoleLib { public static void createWorkerPrompt(){ Scanner sc = new Scanner(System.in); System.out.println("Registrierung eines neuen Mitarbeiters"); String[] userData = new String[4]; String[] addressData = new String[4]; System.out.print("Nachname: "); userData[0] = sc.nextLine(); System.out.print("Vorname: "); userData[1] = sc.nextLine(); System.out.print("Straße: "); addressData[0] = sc.nextLine(); System.out.print("Hausnummer: "); addressData[1] = sc.nextLine(); System.out.print("Postleitzahl: "); addressData[2] = sc.nextLine(); System.out.print("Stadt: "); addressData[3] = sc.nextLine(); System.out.print("Email: "); userData[3] = sc.nextLine(); System.out.print("Passwort: "); userData[2] = sc.nextLine(); long id = AccountMgr.createWorker(userData,addressData); if(id < 1){ System.out.println("Fehler beim erstellen"); } } public static void createParentPrompt(){ Scanner sc = new Scanner(System.in); System.out.println("Registrierung eines neuen Elternteils"); String[] userData = new String[4]; String[] addressData = new String[4]; System.out.print("Nachname: "); userData[0] = sc.nextLine(); System.out.print("Vorname: "); userData[1] = sc.nextLine(); System.out.print("Straße: "); addressData[0] = sc.nextLine(); System.out.print("Hausnummer: "); addressData[1] = sc.nextLine(); System.out.print("Postleitzahl: "); addressData[2] = sc.nextLine(); System.out.print("Stadt: "); addressData[3] = sc.nextLine(); System.out.print("Email: "); userData[3] = sc.nextLine(); System.out.print("Passwort: "); userData[2] = sc.nextLine(); long id = AccountMgr.createParent(userData,addressData); if(id < 1){ System.out.println("Fehler beim erstellen"); } } public static void createChildPrompt(String parentId){ Scanner sc = new Scanner(System.in); String[] childData = new String[3]; System.out.println("Registrierung eines neuen Kindes"); System.out.print("Nachname: "); childData[0] = sc.nextLine(); System.out.print("Vorname: "); childData[1] = sc.nextLine(); System.out.println("Bitte geben Sie die Nummer der passenden Adresse an: "); for (String s : Database.getTable("address")) { String[] parts = s.split(":"); System.out.printf("Nr.: %s Straße: %s Hausnr.: %s PLZ: %s Stadt: %s%n",parts[0],parts[1],parts[2],parts[3],parts[4]); } System.out.print("Adressnummer: "); childData[2] = sc.nextLine(); for (String s : Database.getTable("allergy")) { String[] parts = s.split(":"); System.out.printf("Nr. %s %s%n",parts[0],parts[1]); } System.out.println("Bitte Geben Sie die Nr der Allergien und Ihre Schwere an: "); System.out.print("Allergien (Nr mit , getrennt[1,4,5,16]): "); String allergies = sc.nextLine(); String[] allergyData = allergies.split(","); System.out.print("Schweren (1 Harmlos - 3 Kritisch[2,3,1,3]): "); String severities = sc.nextLine(); String[] severityData = severities.split(","); long id = AccountMgr.createChild(childData,allergyData,severityData); if(id < 1){ System.out.println("Fehler beim erstellen"); return; } String sId = String.valueOf(id); if(AccountMgr.matchParentChild(parentId,sId) == -1){ System.out.println("Fehler beim verknüpfen"); } } public static void createFoodPrompt(){ Scanner sc = new Scanner(System.in); String[] foodData = new String[4]; System.out.println("Registrierung eines neuen Essens"); System.out.print("Name: "); foodData[0] = sc.nextLine(); System.out.print("Beschreibung: "); foodData[1] = sc.nextLine(); System.out.print("Ist es ein Dessert?[0/1]: "); foodData[2] = sc.nextLine(); System.out.print("Ist es vegan[1], vegetarisch[2] oder fleischhaltig[3]: "); foodData[3] = sc.nextLine(); for (String s : Database.getTable("allergy")) { String[] parts = s.split(":"); System.out.printf("Nr. %s %s%n",parts[0],parts[1]); } System.out.println("Bitte geben Sie die Nr. aller zutreffenden Allergien mit Komma getrennt an [1,3,6]"); System.out.print("Allergienummer: "); String allergies = sc.nextLine(); String[] allergyData = allergies.split(","); FoodType foodType = FoodMgr.getFoodTypeById(Long.parseLong(foodData[3])); List allergyList = new ArrayList<>(); for (String data : allergyData) { allergyList.add(FoodMgr.getAllergyById(Long.parseLong(data))); } Food food = new Food(foodData[0],foodData[1],true,foodType,allergyList); if(FoodMgr.createFood(food) < 1){ System.out.println("Fehler"); } } public static long loginPrompt(){ System.out.println("Login"); Scanner sc = new Scanner(System.in); long id = -1; while (id == -1){ System.out.print("Email: "); String email = sc.nextLine(); if(email.isEmpty()){ return -1; } System.out.print("Passwort: "); String pw = sc.nextLine(); id = AccountMgr.login(email,pw); if(id == -1){ System.out.println("Login fehlgeschlagen"); } } System.out.println("Login erfolgreich"); return id; } public static void matchParentChildPrompt(String parentId){ System.out.println("Wählen Sie ihr Kind aus: "); Database.getTable("child"); Scanner sc = new Scanner(System.in); System.out.print("Nr: "); String childId = sc.nextLine(); if(AccountMgr.matchParentChild(parentId,childId) == -1){ System.out.println("Fehler"); } } public static void tablePrompt(){ Scanner sc = new Scanner(System.in); System.out.print("Table: "); String table = sc.nextLine(); printConsole(Database.getTable(table)); } public static void deletePrompt(){ Scanner sc = new Scanner(System.in); System.out.println("Löschen"); System.out.print("Tabelle: "); String table = sc.nextLine(); System.out.print("Id: "); long id = sc.nextLong(); sc.nextLine(); Database.delete(table,id); } public static void printConsole(List list){ for (String entry : list) { System.out.println(entry); } } public static void createFood_planPrompt(){ System.out.println("Erstellen eines Essensplans"); String[] food_planData = new String[5]; Scanner sc = new Scanner(System.in); System.out.print("Bitte geben Sie das Datum im Format YYYY-MM-DD an: "); food_planData[0] = sc.nextLine(); List veganMain = FoodMgr.getVeganFood(false); for (Food food : veganMain) { System.out.println(food.getId() + " : " + food.getName()); } System.out.print("Veganes Hauptgericht Nr: "); food_planData[1] = sc.nextLine(); List foodMain = FoodMgr.getFood(false); System.out.print("Zweites Hauptgericht Nr: "); food_planData[2] = sc.nextLine(); List veganDessert = FoodMgr.getVeganFood(true); for (Food food : veganDessert) { System.out.println(food.getId() + " : " + food.getName()); } System.out.print("Veganes Dessert Nr: "); food_planData[3] = sc.nextLine(); List foodDessert = FoodMgr.getFood(true); for (Food food : foodDessert) { System.out.println(food.getId() + " : " + food.getName()); } System.out.print("Zweites Dessert Nr: "); food_planData[4] = sc.nextLine(); long id = FoodMgr.createFood_plan(food_planData); if(id < 0){ System.out.println("Fehler"); } } public static void showFood_planPrompt(){ System.out.println("Essensplan zum Anzeigen auswählen"); Scanner sc = new Scanner(System.in); System.out.print("Bitte geben Sie das Datum im Format YYYY-MM-DD an: "); String date = sc.nextLine(); List plan = FoodMgr.getFood_plan(date); List foodList = new ArrayList<>(); Food food; StringBuilder sb; for (String day : plan) { sb = new StringBuilder(); String[] parts = day.split(":"); sb.append("Tag: "); sb.append(parts[1]); sb.append(" Veganesgericht: "); food = FoodMgr.getFoodById(Long.parseLong(parts[2])); sb.append(food.getName()); sb.append(" Zweites Hauptgericht: "); food = FoodMgr.getFoodById(Long.parseLong(parts[3])); sb.append(food.getName()); sb.append(" Veganesdessert: "); food = FoodMgr.getFoodById(Long.parseLong(parts[4])); sb.append(food.getName()); sb.append(" Zweites Dessert: "); food = FoodMgr.getFoodById(Long.parseLong(parts[5])); sb.append(food.getName()); foodList.add(sb.toString()); } printConsole(foodList); } public static void createFood_selectionPrompt(){ System.out.println("Essensauswahl"); Scanner sc = new Scanner(System.in); String[] food_selectionData = new String[3]; System.out.print("Kind ID: "); food_selectionData[0] = sc.nextLine(); System.out.print("Datum: "); String date = sc.nextLine(); String[] foodPlanParts = Database.select("food_plan", new String[]{"date"}, new String[]{date}).get(0).split(":"); food_selectionData[1] = foodPlanParts[0]; System.out.println("Hauptspeisen: "); System.out.println(Database.select("food",new String[]{"id"},new String[]{foodPlanParts[2]}).get(0)); System.out.println(Database.select("food",new String[]{"id"},new String[]{foodPlanParts[3]}).get(0)); System.out.print("Id: "); food_selectionData[2] = sc.nextLine(); if(FoodMgr.createFood_selection(food_selectionData) < 1){ System.out.println("Fehler"); } System.out.println("Nachspeisen: "); System.out.println(Database.select("food",new String[]{"id"},new String[]{foodPlanParts[4]}).get(0)); System.out.println(Database.select("food",new String[]{"id"},new String[]{foodPlanParts[5]}).get(0)); System.out.print("Id: "); food_selectionData[2] = sc.nextLine(); if(FoodMgr.createFood_selection(food_selectionData) < 1){ System.out.println("Fehler"); } } public static void dayOrderPrompt(){ System.out.println("Zusammenfassung des Tages"); System.out.print("Datum eingeben: "); Scanner sc = new Scanner(System.in); String date = sc.nextLine(); List dayOrder = FoodMgr.getDayOrder(date); for (String food : dayOrder) { System.out.println(food); } } public static void invoicePrompt(){ System.out.println("Monatsabrechnung"); System.out.print("Monat(YYYY-MM): "); Scanner sc = new Scanner(System.in); String date = sc.nextLine(); System.out.print("ID des Kindes: "); String id = sc.nextLine(); List invoice = AccountMgr.getInvoice(date,id); printConsole(invoice); } public static void changePricePrompt(){ System.out.print("Neuer Preis: "); Scanner sc = new Scanner(System.in); double price = sc.nextDouble(); sc.nextLine(); AccountMgr.price = price; } }