327 lines
13 KiB
Java
327 lines
13 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();
|
|
Address address = new Address(addressData[0],addressData[1],addressData[2],addressData[3]);
|
|
Worker worker = new Worker(userData[0],userData[1],userData[2],userData[3],address);
|
|
long id = AccountMgr.createWorker(worker);
|
|
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();
|
|
Address address = new Address(addressData[0],addressData[1],addressData[2],addressData[3]);
|
|
Parent parent = new Parent(userData[0],userData[1],userData[2],userData[3],address);
|
|
long id = AccountMgr.createParent(parent);
|
|
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(",");
|
|
Address address = AccountMgr.getAddressById(Long.parseLong(childData[2]));
|
|
List<AllergySeverity> allergySeverities = new ArrayList<>();
|
|
for(int i = 0; i < allergyData.length; i++){
|
|
List<String> allergySeverity = Database.getEntryById("severity", Long.parseLong(severityData[i]));
|
|
String[] asParts = allergySeverity.get(0).split(":");
|
|
allergySeverities.add(new AllergySeverity(FoodMgr.getAllergyById(Long.parseLong(allergyData[0])),Long.parseLong(asParts[0]),asParts[1]));
|
|
}
|
|
Child child = new Child(childData[0],childData[1],address,allergySeverities);
|
|
long id = AccountMgr.createChild(child);
|
|
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<Allergy> allergyList = new ArrayList<>();
|
|
for (String data : allergyData) {
|
|
allergyList.add(FoodMgr.getAllergyById(Long.parseLong(data)));
|
|
}
|
|
boolean isDessert = !foodData[2].equals("0");
|
|
Food food = new Food(foodData[0],foodData[1],isDessert,foodType,allergyList);
|
|
if(FoodMgr.createFood(food) < 1){
|
|
System.out.println("Fehler");
|
|
}
|
|
}
|
|
|
|
public static User loginPrompt(){
|
|
System.out.println("Login");
|
|
Scanner sc = new Scanner(System.in);
|
|
User user = null;
|
|
while (user == null){
|
|
System.out.print("Email: ");
|
|
String email = sc.nextLine();
|
|
if(email.isEmpty()){
|
|
return null;
|
|
}
|
|
System.out.print("Passwort: ");
|
|
String pw = sc.nextLine();
|
|
long id = AccountMgr.login(email,pw);
|
|
if(id == -1){
|
|
System.out.println("Login fehlgeschlagen");
|
|
}else {
|
|
user = AccountMgr.getUserById(id);
|
|
}
|
|
}
|
|
System.out.println("Login erfolgreich");
|
|
return user;
|
|
}
|
|
|
|
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();
|
|
List<Food> 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<Food> foodMain = FoodMgr.getFood(false);
|
|
for (Food food : foodMain) {
|
|
System.out.println(food.getId() + " : " + food.getName());
|
|
}
|
|
System.out.print("Zweites Hauptgericht Nr: ");
|
|
food_planData[2] = sc.nextLine();
|
|
List<Food> 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<Food> 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();
|
|
FoodPlan foodPlan = new FoodPlan(food_planData[0],
|
|
FoodMgr.getFoodById(Long.parseLong(food_planData[1])),
|
|
FoodMgr.getFoodById(Long.parseLong(food_planData[2])),
|
|
FoodMgr.getFoodById(Long.parseLong(food_planData[3])),
|
|
FoodMgr.getFoodById(Long.parseLong(food_planData[4])));
|
|
long id = FoodMgr.createFood_plan(foodPlan);
|
|
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();
|
|
FoodPlan plan = FoodMgr.getFoodPlan(date);
|
|
List<String> foodList = new ArrayList<>();
|
|
StringBuilder sb;
|
|
sb = new StringBuilder();
|
|
sb.append("Tag: ");
|
|
sb.append(plan.getDate());
|
|
sb.append(" Veganesgericht: ");
|
|
sb.append(plan.getFoodVegan().getName());
|
|
sb.append(" Zweites Hauptgericht: ");
|
|
sb.append(plan.getFoodSecond().getName());
|
|
sb.append(" Veganesdessert: ");
|
|
sb.append(plan.getDessertVegan().getName());
|
|
sb.append(" Zweites Dessert: ");
|
|
sb.append(plan.getDessertSecond().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<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;
|
|
AccountMgr.setPriceInDb();
|
|
}
|
|
}
|