296 lines
12 KiB
Java
296 lines
12 KiB
Java
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(",");
|
|
if(FoodMgr.createFood(foodData,allergyData) < 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();
|
|
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<String> 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();
|
|
printConsole(FoodMgr.getVeganFood(false));
|
|
System.out.print("Veganes Hauptgericht Nr: ");
|
|
food_planData[1] = sc.nextLine();
|
|
printConsole(FoodMgr.getFood(false));
|
|
System.out.print("Zweites Hauptgericht Nr: ");
|
|
food_planData[2] = sc.nextLine();
|
|
printConsole(FoodMgr.getVeganFood(true));
|
|
System.out.print("Veganes Dessert Nr: ");
|
|
food_planData[3] = sc.nextLine();
|
|
printConsole(FoodMgr.getFood(true));
|
|
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<String> plan = FoodMgr.getFood_plan(date);
|
|
List<String> food = new ArrayList<>();
|
|
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]));
|
|
String[] foodParts = food.get(0).split(":");
|
|
sb.append(foodParts[1]);
|
|
sb.append(" Zweites Hauptgericht: ");
|
|
food = FoodMgr.getFoodById(Long.parseLong(parts[3]));
|
|
foodParts = food.get(0).split(":");
|
|
sb.append(foodParts[1]);
|
|
sb.append(" Veganesdessert: ");
|
|
food = FoodMgr.getFoodById(Long.parseLong(parts[4]));
|
|
foodParts = food.get(0).split(":");
|
|
sb.append(foodParts[1]);
|
|
sb.append(" Zweites Dessert: ");
|
|
food = FoodMgr.getFoodById(Long.parseLong(parts[5]));
|
|
foodParts = food.get(0).split(":");
|
|
sb.append(foodParts[1]);
|
|
food.add(sb.toString());
|
|
}
|
|
printConsole(food);
|
|
}
|
|
|
|
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<String> 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<String> 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;
|
|
}
|
|
}
|