Finale Änderung
parent
e44f710161
commit
d0834f7282
|
|
@ -25,43 +25,39 @@ public class Bestellsystem {
|
|||
Bestellung bestellung = new Bestellung(tischNummer);
|
||||
|
||||
while (true) {
|
||||
|
||||
System.out.print("Bitte bestelle ein Gericht (oder 'fertig', um abzuschließen): ");
|
||||
String gericht = scanner.nextLine();
|
||||
boolean istVerfuegbar = false;
|
||||
|
||||
|
||||
if (gericht.equalsIgnoreCase("fertig")) {
|
||||
speichereBestellung(bestellung);
|
||||
System.out.println("Bestand wurde aktualisiert");
|
||||
break;
|
||||
}
|
||||
System.out.print("Bitte bestelle ein Gericht (oder 'fertig', um abzuschließen): ");
|
||||
String gericht = scanner.nextLine();
|
||||
boolean istVerfuegbar = false;
|
||||
|
||||
// Überprüfen, ob das Gericht im Menü verfügbar ist
|
||||
try {
|
||||
for (Dish dish : menu.getDishes()) {
|
||||
if (gericht.equalsIgnoreCase(dish.getName())) {
|
||||
// Zutaten für das Gericht verwenden (Bestand aktualisieren)
|
||||
SystemController.inventory.useIngredients(dish.getIngredients());
|
||||
bestellung.addGericht(gericht); // Gericht zur Bestellung hinzufügen
|
||||
istVerfuegbar = true;
|
||||
bestellungen.add(bestellung); // Bestellung zur Liste der Bestellungen hinzufügen
|
||||
System.out.println("Bestellung wurde aktualisiert");
|
||||
System.out.println(bestellung.getBestellungDetails()); // Bestellungsdetails anzeigen
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fehler beim Hinzufügen des Gerichts zur Bestellung: " + e.getMessage());
|
||||
}
|
||||
if (gericht.equalsIgnoreCase("fertig")) {
|
||||
speichereBestellung(bestellung);
|
||||
System.out.println("Bestand wurde aktualisiert");
|
||||
break;
|
||||
}
|
||||
|
||||
// Wenn das Gericht nicht im Menü ist, eine Fehlermeldung anzeigen
|
||||
if (!istVerfuegbar) {
|
||||
System.out.println("Gericht ist nicht im Menü.");
|
||||
}
|
||||
try {
|
||||
for (Dish dish : menu.getDishes()) {
|
||||
if (gericht.equalsIgnoreCase(dish.getName())) {
|
||||
|
||||
SystemController.inventory.useIngredients(dish.getIngredients());
|
||||
bestellung.addGericht(gericht);
|
||||
istVerfuegbar = true;
|
||||
bestellungen.add(bestellung);
|
||||
System.out.println("Bestellung wurde aktualisiert");
|
||||
System.out.println(bestellung.getBestellungDetails());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fehler beim Hinzufügen des Gerichts zur Bestellung: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (!istVerfuegbar) {
|
||||
System.out.println("Gericht ist nicht im Menü.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void loescheBestellung() {
|
||||
ladeUndZeigeBestellungen();
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class Bestellung {
|
|||
String id = parts[0].trim();
|
||||
String tischNummer = parts[1].trim();
|
||||
|
||||
// Bestellte Gerichte
|
||||
|
||||
List<String> gerichte = new ArrayList<>();
|
||||
String[] gerichteArray = parts[2].split(",");
|
||||
for (String gericht : gerichteArray) {
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
01,Dima,Cheeseburger, Ramen,2,100€
|
||||
02,Ali,Ramen,2
|
||||
01,Dima,Cheeseburger, Ramen,2,100€
|
||||
02,Ali,Ramen,2
|
||||
03,babbas,Cheeseburger,2
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import java.util.Map;
|
|||
class Dish {
|
||||
private String name;
|
||||
private Map<String, Integer> ingredients;
|
||||
private double price; // Preis für jedes Gericht
|
||||
|
||||
private double price;
|
||||
public Dish(String name, Map<String, Integer> ingredients, double price) {
|
||||
this.name = name;
|
||||
this.ingredients = ingredients;
|
||||
|
|
|
|||
|
|
@ -16,36 +16,32 @@ public class FinancialManager {
|
|||
|
||||
private final String FINANCIAL_REPORT_FILE = "src/financial_report.txt";
|
||||
|
||||
|
||||
public void addRevenue(double amount) {
|
||||
this.totalRevenue += amount;
|
||||
LocalDate today = LocalDate.now();
|
||||
dailyRevenue.put(today, dailyRevenue.getOrDefault(today, 0.0) + amount);
|
||||
|
||||
// Einnahmen für die Woche und den Monat aktualisieren
|
||||
LocalDate startOfWeek = today.minusDays(today.getDayOfWeek().getValue() - 1);
|
||||
weeklyRevenue.put(startOfWeek, weeklyRevenue.getOrDefault(startOfWeek, 0.0) + amount);
|
||||
|
||||
LocalDate startOfMonth = today.withDayOfMonth(1);
|
||||
monthlyRevenue.put(startOfMonth, monthlyRevenue.getOrDefault(startOfMonth, 0.0) + amount);
|
||||
|
||||
saveFinancialReport(); // Finanzdaten in die Datei speichern
|
||||
saveFinancialReport();
|
||||
}
|
||||
|
||||
// Methode zur Hinzufügung von Ausgaben
|
||||
public void addExpense(double amount) {
|
||||
this.totalExpenses += amount;
|
||||
LocalDate today = LocalDate.now();
|
||||
dailyExpenses.put(today, dailyExpenses.getOrDefault(today, 0.0) + amount);
|
||||
|
||||
// Ausgaben für die Woche und den Monat aktualisieren
|
||||
LocalDate startOfWeek = today.minusDays(today.getDayOfWeek().getValue() - 1);
|
||||
weeklyExpenses.put(startOfWeek, weeklyExpenses.getOrDefault(startOfWeek, 0.0) + amount);
|
||||
|
||||
LocalDate startOfMonth = today.withDayOfMonth(1);
|
||||
monthlyExpenses.put(startOfMonth, monthlyExpenses.getOrDefault(startOfMonth, 0.0) + amount);
|
||||
|
||||
saveFinancialReport(); // Finanzdaten in einer txt Datei speichern
|
||||
saveFinancialReport();
|
||||
}
|
||||
|
||||
public double getRevenueForPeriod(String period) {
|
||||
|
|
@ -80,22 +76,18 @@ public class FinancialManager {
|
|||
}
|
||||
}
|
||||
|
||||
// Getter für Gesamtumsatz
|
||||
public double getTotalRevenue() {
|
||||
return totalRevenue;
|
||||
}
|
||||
|
||||
// Getter für Gesamtausgaben
|
||||
public double getTotalExpenses() {
|
||||
return totalExpenses;
|
||||
}
|
||||
|
||||
// Berechnung des Nettogewinns
|
||||
public double getNetProfit() {
|
||||
return totalRevenue - totalExpenses;
|
||||
}
|
||||
|
||||
// Methode zur Speicherung des Finanzberichts in einer Datei
|
||||
private void saveFinancialReport() {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(FINANCIAL_REPORT_FILE, true))) {
|
||||
writer.write("Datum: " + LocalDate.now());
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@ import java.util.*;
|
|||
public class Inventory {
|
||||
|
||||
private Map<String, Integer> stock = new HashMap<>();
|
||||
private FinancialManager financialManager; // Deklaration der Instanzvariable
|
||||
|
||||
private FinancialManager financialManager;
|
||||
public Inventory(FinancialManager financialManager) {
|
||||
this.financialManager = financialManager; // Initialisierung des FinancialManagers im Konstruktor
|
||||
this.financialManager = financialManager;
|
||||
}
|
||||
|
||||
private final String STOCK_FILE = "src/stock.txt"; // Datei für den Bestand
|
||||
private final String STOCK_FILE = "src/stock.txt";
|
||||
|
||||
public void loadStockFromFile() {
|
||||
stock.clear();
|
||||
|
|
@ -31,7 +30,7 @@ public class Inventory {
|
|||
}
|
||||
}
|
||||
|
||||
// Speichert den aktuellen Bestand in die Datei
|
||||
|
||||
public void saveStockToFile() {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(STOCK_FILE))) {
|
||||
for (Map.Entry<String, Integer> entry : stock.entrySet()) {
|
||||
|
|
@ -43,7 +42,7 @@ public class Inventory {
|
|||
}
|
||||
}
|
||||
|
||||
// Zeigt den aktuellen Bestand an
|
||||
|
||||
public void viewStock() {
|
||||
if (stock.isEmpty()) {
|
||||
System.out.println("Der Bestand ist leer.");
|
||||
|
|
@ -73,42 +72,42 @@ public class Inventory {
|
|||
}
|
||||
|
||||
public void addIngredients(String productName, int amountToAdd, FinancialManager financialManager) {
|
||||
double ingredientCost = 1.0; // Beispielhafter Preis für Zutaten (z.B. 1 Euro pro Stück)
|
||||
double ingredientCost = 1.0;
|
||||
|
||||
stock.put(productName, stock.getOrDefault(productName, 0) + amountToAdd);
|
||||
|
||||
// Berechne die Ausgaben für die Erweiterung des Bestands
|
||||
|
||||
double totalCost = ingredientCost * amountToAdd;
|
||||
|
||||
// Gebe die Kosten in den Finanzen an
|
||||
|
||||
financialManager.addExpense(totalCost);
|
||||
|
||||
System.out.println("Bestand für " + productName + " wurde um " + amountToAdd + " Stück erhöht.");
|
||||
}
|
||||
|
||||
// Gibt den Preis für eine bestimmte Zutat zurück (Beispielpreise)
|
||||
private double getPriceForIngredient(String ingredientName) {
|
||||
switch (ingredientName.toLowerCase()) {
|
||||
case "salat":
|
||||
return 1.5; // Preis für Salat pro Einheit
|
||||
case "tomaten":
|
||||
return 0.8; // Preis für Tomaten pro Einheit
|
||||
case "cheeseburger":
|
||||
return 3.0; // Preis für Cheeseburger pro Einheit
|
||||
default:
|
||||
return 1.0; // Standardpreis pro Einheit
|
||||
}
|
||||
}
|
||||
|
||||
// private double getPriceForIngredient(String ingredientName) {
|
||||
// switch (ingredientName.toLowerCase()) {
|
||||
// case "salat":
|
||||
// return 1.5;
|
||||
// case "tomaten":
|
||||
// return 0.8;
|
||||
// case "cheeseburger":
|
||||
// return 3.0;
|
||||
// default:
|
||||
// return 1.0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// In der Inventory-Klasse:
|
||||
|
||||
public boolean showIngredientsAvailable(Map<String, Integer> ingredients) {
|
||||
for (Map.Entry<String, Integer> entry : ingredients.entrySet()) {
|
||||
String ingredient = entry.getKey();
|
||||
int requiredAmount = entry.getValue();
|
||||
|
||||
// Überprüfe, ob der Lagerbestand ausreicht
|
||||
|
||||
if (!stock.containsKey(ingredient) || stock.get(ingredient) < requiredAmount) {
|
||||
System.out.println("Nicht genügend Bestand für: " + ingredient); // Fehlermeldung
|
||||
System.out.println("Nicht genügend Bestand für: " + ingredient);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -124,12 +123,12 @@ public class Inventory {
|
|||
}
|
||||
}
|
||||
|
||||
// Getter für den Bestand
|
||||
|
||||
public Map<String, Integer> getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
// Setter für den Bestand
|
||||
|
||||
public void setStock(Map<String, Integer> stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,20 +96,17 @@ class SystemController {
|
|||
}
|
||||
|
||||
private void updateFinancialReport(List<Dish> orderedDishes) {
|
||||
// Prüfen, ob die Liste der bestellten Gerichte leer ist
|
||||
if (orderedDishes.isEmpty()) {
|
||||
System.out.println("Keine Bestellung aufgegeben. Kein Preis berechnet.");
|
||||
return; // Wenn keine Gerichte bestellt wurden, wird der Vorgang abgebrochen
|
||||
}
|
||||
return; }
|
||||
|
||||
double totalAmount = 0;
|
||||
|
||||
// Berechnung des Gesamtbetrags für die bestellten Gerichte
|
||||
for (Dish dish : orderedDishes) {
|
||||
totalAmount += dish.getPrice(); // Gesamtbetrag basierend auf den Preisen der bestellten Gerichte
|
||||
totalAmount += dish.getPrice();
|
||||
}
|
||||
|
||||
// Einnahmen im Finanzmanager hinzufügen
|
||||
|
||||
financialManager.addRevenue(totalAmount);
|
||||
|
||||
System.out.println("Gesamtkosten der Bestellung: " + totalAmount + " €");
|
||||
|
|
@ -208,18 +205,18 @@ class SystemController {
|
|||
|
||||
System.out.print("Bitte wähle eine Option: ");
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine(); // Eingabepuffer leeren
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1 -> inventory.viewStock(); // Bestand ansehen
|
||||
case 1 -> inventory.viewStock();
|
||||
case 2 -> {
|
||||
System.out.println("Welchen Bestand möchten Sie ändern?");
|
||||
String name = scanner.nextLine();
|
||||
System.out.println("Neue Anzahl ---->");
|
||||
try {
|
||||
int anzahl = scanner.nextInt();
|
||||
inventory.overwriteStock(name, anzahl); // Bestellungen im Speicher anzeigen
|
||||
inventory.saveStockToFile(); // Echtzeitspeicherung der Daten
|
||||
inventory.overwriteStock(name, anzahl);
|
||||
inventory.saveStockToFile();
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Fehler! Überprüfen Sie Ihre Eingabe");
|
||||
}
|
||||
|
|
@ -231,8 +228,8 @@ class SystemController {
|
|||
System.out.println("Anzahl :");
|
||||
try {
|
||||
int anzahl = scanner.nextInt();
|
||||
inventory.addIngredients(name, anzahl, financialManager); // Bestellungen im Speicher anzeigen
|
||||
inventory.saveStockToFile(); // Echtzeitspeicherung der Daten
|
||||
inventory.addIngredients(name, anzahl, financialManager);
|
||||
inventory.saveStockToFile();
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Fehler! Überprüfen Sie Ihre Eingabe");
|
||||
}
|
||||
|
|
@ -254,18 +251,17 @@ class SystemController {
|
|||
|
||||
System.out.print("Bitte wähle eine Option: ");
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine(); // Eingabepuffer leeren
|
||||
|
||||
scanner.nextLine();
|
||||
switch (choice) {
|
||||
case 1 -> {
|
||||
menu.displayMenu(inventory);
|
||||
Bestellsystem.erstelleBestellung(); // Neue Bestellung erstellen
|
||||
Bestellsystem.erstelleBestellung();
|
||||
}
|
||||
case 2 -> {
|
||||
Bestellsystem.ladeUndZeigeBestellungen(); // Bestellungen aus Datei anzeigen
|
||||
Bestellsystem.ladeUndZeigeBestellungen();
|
||||
}
|
||||
case 3 -> {
|
||||
Bestellsystem.loescheBestellung(); // Bestellungen aus Datei löschen
|
||||
Bestellsystem.loescheBestellung();
|
||||
}
|
||||
case 4 -> managingOrders = false;
|
||||
default -> System.out.println("Ungültige Auswahl. Bitte versuche es erneut.");
|
||||
|
|
@ -285,33 +281,33 @@ class SystemController {
|
|||
System.out.println("6. Zurück zum Hauptmenü");
|
||||
System.out.print("Bitte wähle eine Option: ");
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine(); // Eingabepuffer leeren
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1 -> showShiftPlan(user.username); // Schichtplan für den eingeloggten Mitarbeiter anzeigen
|
||||
case 1 -> showShiftPlan(user.username);
|
||||
case 2 -> {
|
||||
if (user.role == Role.MANAGER) {
|
||||
createAbsence(user.username); // Abwesenheit für Mitarbeiter erstellen
|
||||
createAbsence(user.username);
|
||||
} else {
|
||||
System.out.println("Keine Rechte, um neue Nutzer zu erstellen.");
|
||||
}
|
||||
}
|
||||
case 3 -> {
|
||||
if (user.role == Role.MANAGER) {
|
||||
showAbsences(); // Abwesenheiten zeigen
|
||||
showAbsences();
|
||||
} else {
|
||||
System.out.println("Keine Rechte, um neue Nutzer zu erstellen.");
|
||||
}
|
||||
}
|
||||
case 4 -> giveFeedback(); // Feedback geben
|
||||
case 4 -> giveFeedback();
|
||||
case 5 -> {
|
||||
if (user.role == Role.MANAGER) {
|
||||
showFeedback(); // Feedbacks zeigen
|
||||
showFeedback();
|
||||
} else {
|
||||
System.out.println("Keine Rechte, um neue Nutzer zu erstellen.");
|
||||
}
|
||||
}
|
||||
case 6 -> managingEmployees = false; // Zurück zum Hauptmenü
|
||||
case 6 -> managingEmployees = false;
|
||||
default -> System.out.println("Ungültige Auswahl. Bitte versuche es erneut.");
|
||||
}
|
||||
}
|
||||
|
|
@ -376,7 +372,7 @@ class SystemController {
|
|||
String shiftDate = parts[1];
|
||||
String shiftTime = parts[2];
|
||||
|
||||
// Erstelle neuen Shift-Objekt und füge es der Liste hinzu
|
||||
|
||||
Shift shift = new Shift(username, shiftDate, shiftTime);
|
||||
shifts.add(shift);
|
||||
}
|
||||
|
|
@ -394,7 +390,6 @@ class SystemController {
|
|||
String date = parts[1];
|
||||
String reason = parts[2];
|
||||
|
||||
// Erstelle neues Absence-Objekt und füge es der Liste hinzu
|
||||
Absence absence = new Absence(username, date, reason);
|
||||
absences.add(absence);
|
||||
}
|
||||
|
|
@ -411,7 +406,7 @@ class SystemController {
|
|||
String username = parts[0];
|
||||
String feedback = parts[1];
|
||||
|
||||
// Erstelle neues Feedback-Objekt und füge es der Liste hinzu
|
||||
|
||||
Feedback feedbackObj = new Feedback(username, feedback);
|
||||
feedbacks.add(feedbackObj);
|
||||
}
|
||||
|
|
@ -445,7 +440,7 @@ class SystemController {
|
|||
|
||||
public void saveShiftToFile(String shift) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter("src/shifts.txt", true))) {
|
||||
writer.write(shift); // Schicht als String speichern
|
||||
writer.write(shift);
|
||||
writer.newLine();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Fehler beim Speichern der Schicht: " + e.getMessage());
|
||||
|
|
@ -532,7 +527,7 @@ class SystemController {
|
|||
|
||||
System.out.print("Bitte wähle eine Option: ");
|
||||
int choice = scanner.nextInt();
|
||||
scanner.nextLine(); // Eingabepuffer leeren
|
||||
scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1 -> {
|
||||
|
|
@ -552,9 +547,9 @@ class SystemController {
|
|||
System.out.println("Gesamte Einnahmen: " + totalRevenue + " €");
|
||||
}
|
||||
case 5 -> {
|
||||
displayFinancialReportFromFile(); // Finanzbericht aus Datei anzeigen
|
||||
displayFinancialReportFromFile();
|
||||
}
|
||||
case 6 -> viewingReport = false; // Zurück zum Hauptmenü
|
||||
case 6 -> viewingReport = false;
|
||||
default -> System.out.println("Ungültige Auswahl. Bitte versuche es erneut.");
|
||||
}
|
||||
}
|
||||
|
|
@ -565,7 +560,7 @@ class SystemController {
|
|||
String line;
|
||||
System.out.println("\n--- Finanzbericht aus Datei ---");
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println(line); // Jede Zeile des Berichts anzeigen
|
||||
System.out.println(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Fehler beim Lesen des Finanzberichts aus der Datei: " + e.getMessage());
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
Arim;22.02.2025;Krank
|
||||
Arim;22.02.2025;Krank
|
||||
Dimitry ;25.04.2025;Krankheit
|
||||
Arim;22.02.2025;Krank
|
||||
Arim;22.02.2025;Krank
|
||||
Dimitry ;25.04.2025;Krankheit
|
||||
Abbas;26.03.2025;Krankheit
|
||||
Arim;22.02.2025;Krank
|
||||
Arim;22.02.2025;Krank
|
||||
Dimitry ;25.04.2025;Krankheit
|
||||
Arim;22.02.2025;Krank
|
||||
Arim;22.02.2025;Krank
|
||||
Dimitry ;25.04.2025;Krankheit
|
||||
Abbas;26.03.2025;Krankheit
|
||||
Ali;30.06.2025;Krank
|
||||
|
|
@ -3,3 +3,5 @@ Abbas;Schlecht
|
|||
Arim;Gut
|
||||
Dimitry;Gut arbeit
|
||||
Abbas;Guter man
|
||||
Dimitry, Alles Super
|
||||
Dimitry, wufufw
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
Ali;25.03.2024;13 Uhr
|
||||
Abbas;22.01.2024;14 Uhr
|
||||
Dimitry;15.01.2024; 15 Uhr
|
||||
Dimitry,2025-01-14,12:00-18:00
|
||||
|
|
|
|||
|
|
@ -0,0 +1,171 @@
|
|||
package userinterface;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class FinancePanel extends JPanel {
|
||||
private final String financialReportFilePath = "src/financial_report.txt";
|
||||
|
||||
public FinancePanel(JFrame frame, JPanel mainPanel) {
|
||||
this.setLayout(new BorderLayout());
|
||||
JLabel label = new JLabel("Finanzen verwalten", SwingConstants.CENTER);
|
||||
label.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
this.add(label, BorderLayout.NORTH);
|
||||
|
||||
JPanel selectionPanel = new JPanel();
|
||||
JButton dailyButton = new JButton("Tägliche Finanzen anzeigen");
|
||||
JButton weeklyButton = new JButton("Wöchentliche Finanzen anzeigen");
|
||||
JButton monthlyButton = new JButton("Monatliche Finanzen anzeigen");
|
||||
selectionPanel.add(dailyButton);
|
||||
selectionPanel.add(weeklyButton);
|
||||
selectionPanel.add(monthlyButton);
|
||||
this.add(selectionPanel, BorderLayout.CENTER);
|
||||
|
||||
JButton backButton = new JButton("Zurück zum Hauptmenü");
|
||||
backButton.addActionListener(e -> switchPanel(frame, mainPanel));
|
||||
this.add(backButton, BorderLayout.SOUTH);
|
||||
|
||||
dailyButton.addActionListener(e -> showDailyFinances());
|
||||
weeklyButton.addActionListener(e -> showWeeklyFinances());
|
||||
monthlyButton.addActionListener(e -> showMonthlyFinances(frame));
|
||||
}
|
||||
|
||||
private void switchPanel(JFrame frame, JPanel mainPanel) {
|
||||
frame.getContentPane().removeAll();
|
||||
frame.add(mainPanel, BorderLayout.CENTER);
|
||||
frame.revalidate();
|
||||
frame.repaint();
|
||||
}
|
||||
|
||||
private void showDailyFinances() {
|
||||
Date today = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String todayStr = sdf.format(today);
|
||||
|
||||
double total = 0.0;
|
||||
List<String[]> entries = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(financialReportFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String[] data = line.split(",");
|
||||
if (data.length >= 3 && data[0].equals(todayStr)) {
|
||||
entries.add(data);
|
||||
total += Double.parseDouble(data[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Finanzen!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
displayFinanceTable("Tägliche Finanzen", entries, total);
|
||||
}
|
||||
|
||||
private void showWeeklyFinances() {
|
||||
Calendar today = Calendar.getInstance();
|
||||
today.set(Calendar.HOUR_OF_DAY, 0);
|
||||
today.set(Calendar.MINUTE, 0);
|
||||
today.set(Calendar.SECOND, 0);
|
||||
today.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
Calendar weekStart = (Calendar) today.clone();
|
||||
weekStart.add(Calendar.DAY_OF_YEAR, -6);
|
||||
|
||||
double total = 0.0;
|
||||
List<String[]> entries = new ArrayList<>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(financialReportFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String[] data = line.split(",");
|
||||
if (data.length >= 3) {
|
||||
try {
|
||||
Date entryDate = sdf.parse(data[0]);
|
||||
if (!entryDate.before(weekStart.getTime()) && !entryDate.after(today.getTime())) {
|
||||
entries.add(data);
|
||||
total += Double.parseDouble(data[2]);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
System.err.println("Ungültiges Datum übersprungen: " + data[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Finanzen!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
displayFinanceTable("Wöchentliche Finanzen", entries, total);
|
||||
}
|
||||
|
||||
private void showMonthlyFinances(JFrame frame) {
|
||||
String month = JOptionPane.showInputDialog(frame, "Bitte geben Sie den Monat im Format YYYY-MM ein:",
|
||||
"Monat auswählen", JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
if (month == null || !month.matches("\\d{4}-\\d{2}")) {
|
||||
JOptionPane.showMessageDialog(this, "Ungültiges Format! Bitte geben Sie den Monat im Format YYYY-MM ein.",
|
||||
"Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
double total = 0.0;
|
||||
List<String[]> entries = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(financialReportFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String[] data = line.split(",");
|
||||
if (data.length >= 3 && data[0].startsWith(month)) {
|
||||
entries.add(data);
|
||||
total += Double.parseDouble(data[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Finanzen!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
displayFinanceTable("Monatliche Finanzen", entries, total);
|
||||
}
|
||||
|
||||
private void displayFinanceTable(String title, List<String[]> entries, double total) {
|
||||
JDialog dialog = new JDialog((JFrame) SwingUtilities.getWindowAncestor(this), title, true);
|
||||
dialog.setSize(600, 400);
|
||||
dialog.setLayout(new BorderLayout());
|
||||
|
||||
DefaultTableModel model = new DefaultTableModel(new String[] { "Datum", "Beschreibung", "Einnahmen" }, 0);
|
||||
for (String[] entry : entries) {
|
||||
model.addRow(entry);
|
||||
}
|
||||
|
||||
JTable table = new JTable(model);
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
dialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
JLabel totalLabel = new JLabel("Gesamteinnahmen: " + total + " EUR", SwingConstants.CENTER);
|
||||
totalLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
||||
dialog.add(totalLabel, BorderLayout.SOUTH);
|
||||
|
||||
JButton closeButton = new JButton("Schließen");
|
||||
closeButton.addActionListener(e -> dialog.dispose());
|
||||
dialog.add(closeButton, BorderLayout.NORTH);
|
||||
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +1,84 @@
|
|||
package userinterface;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainMenu {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame("Restaurantverwaltungssystem");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(800, 600);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
JLabel headerLabel = new JLabel("Restaurantverwaltungssystem", SwingConstants.CENTER);
|
||||
headerLabel.setFont(new Font("Arial", Font.BOLD, 30));
|
||||
frame.add(headerLabel, BorderLayout.NORTH);
|
||||
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new GridLayout(2, 3, 20, 20));
|
||||
|
||||
JButton reservierungenButton = new JButton("Reservierungen verwalten");
|
||||
JButton lagerButton = new JButton("Lagerbestand verwalten");
|
||||
JButton bestellungenButton = new JButton("Bestellungen verwalten");
|
||||
JButton personalButton = new JButton("Personal verwalten");
|
||||
JButton finanzenButton = new JButton("Finanzen verwalten");
|
||||
JButton beendenButton = new JButton("Beenden");
|
||||
|
||||
mainPanel.add(reservierungenButton);
|
||||
mainPanel.add(lagerButton);
|
||||
mainPanel.add(bestellungenButton);
|
||||
mainPanel.add(personalButton);
|
||||
mainPanel.add(finanzenButton);
|
||||
mainPanel.add(beendenButton);
|
||||
|
||||
frame.add(mainPanel, BorderLayout.CENTER);
|
||||
|
||||
reservierungenButton.addActionListener(e -> switchPanel(frame, mainPanel, new ReservationPanel(frame, mainPanel)));
|
||||
lagerButton.addActionListener(e -> switchPanel(frame, mainPanel, new InventoryPanel(frame, mainPanel)));
|
||||
bestellungenButton.addActionListener(e -> switchPanel(frame, mainPanel, new OrdersPanel(frame, mainPanel)));
|
||||
personalButton.addActionListener(e -> JOptionPane.showMessageDialog(frame, "Personal verwalten: Noch nicht implementiert."));
|
||||
finanzenButton.addActionListener(e -> JOptionPane.showMessageDialog(frame, "Finanzen verwalten: Noch nicht implementiert."));
|
||||
beendenButton.addActionListener(e -> System.exit(0));
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void switchPanel(JFrame frame, JPanel mainPanel, JPanel newPanel) {
|
||||
frame.getContentPane().removeAll();
|
||||
frame.add(newPanel, BorderLayout.CENTER);
|
||||
frame.revalidate();
|
||||
frame.repaint();
|
||||
}
|
||||
}
|
||||
package userinterface;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class MainMenu {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String role = UserAuthentication.authenticateAndReturnRole();
|
||||
|
||||
if (role == null) {
|
||||
JOptionPane.showMessageDialog(null, "Anmeldung fehlgeschlagen!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Restaurantverwaltungssystem");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(800, 600);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
JLabel headerLabel = new JLabel("Restaurantverwaltungssystem", SwingConstants.CENTER);
|
||||
headerLabel.setFont(new Font("Arial", Font.BOLD, 30));
|
||||
frame.add(headerLabel, BorderLayout.NORTH);
|
||||
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new GridLayout(2, 3, 20, 20));
|
||||
|
||||
if (role.equalsIgnoreCase("MANAGER")) {
|
||||
JButton reservierungenButton = new JButton("Reservierungen verwalten");
|
||||
JButton lagerButton = new JButton("Lagerbestand verwalten");
|
||||
JButton bestellungenButton = new JButton("Bestellungen verwalten");
|
||||
JButton personalButton = new JButton("Personal verwalten");
|
||||
JButton finanzenButton = new JButton("Finanzen verwalten");
|
||||
JButton beendenButton = new JButton("Beenden");
|
||||
|
||||
mainPanel.add(reservierungenButton);
|
||||
mainPanel.add(lagerButton);
|
||||
mainPanel.add(bestellungenButton);
|
||||
mainPanel.add(personalButton);
|
||||
mainPanel.add(finanzenButton);
|
||||
mainPanel.add(beendenButton);
|
||||
|
||||
reservierungenButton
|
||||
.addActionListener(e -> switchPanel(frame, mainPanel, new ReservationPanel(frame, mainPanel)));
|
||||
lagerButton.addActionListener(e -> switchPanel(frame, mainPanel, new InventoryPanel(frame, mainPanel)));
|
||||
bestellungenButton.addActionListener(e -> switchPanel(frame, mainPanel, new OrdersPanel(frame, mainPanel)));
|
||||
personalButton.addActionListener(e -> switchPanel(frame, mainPanel, new PersonnelPanel(frame, mainPanel)));
|
||||
finanzenButton.addActionListener(e -> switchPanel(frame, mainPanel, new FinancePanel(frame, mainPanel)));
|
||||
beendenButton.addActionListener(e -> System.exit(0));
|
||||
} else if (role.equalsIgnoreCase("SERVICE")) {
|
||||
JButton bestellungenButton = new JButton("Bestellungen verwalten");
|
||||
JButton reservierungenButton = new JButton("Reservierungen verwalten");
|
||||
JButton beendenButton = new JButton("Beenden");
|
||||
|
||||
mainPanel.add(bestellungenButton);
|
||||
mainPanel.add(reservierungenButton);
|
||||
mainPanel.add(beendenButton);
|
||||
|
||||
bestellungenButton.addActionListener(e -> switchPanel(frame, mainPanel, new OrdersPanel(frame, mainPanel)));
|
||||
reservierungenButton
|
||||
.addActionListener(e -> switchPanel(frame, mainPanel, new ReservationPanel(frame, mainPanel)));
|
||||
beendenButton.addActionListener(e -> System.exit(0));
|
||||
} else if (role.equalsIgnoreCase("KITCHEN")) {
|
||||
JButton lagerButton = new JButton("Lagerbestand verwalten");
|
||||
JButton beendenButton = new JButton("Beenden");
|
||||
|
||||
mainPanel.add(lagerButton);
|
||||
mainPanel.add(beendenButton);
|
||||
|
||||
lagerButton.addActionListener(e -> switchPanel(frame, mainPanel, new InventoryPanel(frame, mainPanel)));
|
||||
beendenButton.addActionListener(e -> System.exit(0));
|
||||
}
|
||||
|
||||
frame.add(mainPanel, BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void switchPanel(JFrame frame, JPanel mainPanel, JPanel newPanel) {
|
||||
frame.getContentPane().removeAll();
|
||||
frame.add(newPanel, BorderLayout.CENTER);
|
||||
frame.revalidate();
|
||||
frame.repaint();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,303 @@
|
|||
package userinterface;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonnelPanel extends JPanel {
|
||||
private DefaultTableModel tableModel;
|
||||
private JTable table;
|
||||
private List<String[]> absences;
|
||||
private final String absencesFilePath = "src/absences.txt";
|
||||
private final String feedbackFilePath = "src/feedback.txt";
|
||||
private final String shiftsFilePath = "src/shifts.txt";
|
||||
private DefaultTableModel shiftsTableModel;
|
||||
|
||||
public PersonnelPanel(JFrame frame, JPanel mainPanel) {
|
||||
this.setLayout(new BorderLayout());
|
||||
JLabel label = new JLabel("Personal verwalten", SwingConstants.CENTER);
|
||||
label.setFont(new Font("Arial", Font.BOLD, 24));
|
||||
this.add(label, BorderLayout.NORTH);
|
||||
|
||||
// Tabelle für Fehlzeiten
|
||||
String[] absenceColumns = {"Mitarbeitername", "Datum", "Grund"};
|
||||
tableModel = new DefaultTableModel(absenceColumns, 0);
|
||||
table = new JTable(tableModel);
|
||||
loadAbsences();
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
this.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// Steuerpanel unten
|
||||
JPanel controlPanel = new JPanel();
|
||||
JButton addAbsenceButton = new JButton("Fehlzeit eintragen");
|
||||
JButton deleteAbsenceButton = new JButton("Fehlzeit löschen");
|
||||
JButton addFeedbackButton = new JButton("Feedback hinzufügen");
|
||||
JButton viewFeedbackButton = new JButton("Feedback anzeigen");
|
||||
JButton manageShiftsButton = new JButton("Arbeitszeiten verwalten");
|
||||
JButton backButton = new JButton("Zurück");
|
||||
controlPanel.add(backButton);
|
||||
controlPanel.add(addAbsenceButton);
|
||||
controlPanel.add(deleteAbsenceButton);
|
||||
controlPanel.add(addFeedbackButton);
|
||||
controlPanel.add(viewFeedbackButton);
|
||||
controlPanel.add(manageShiftsButton);
|
||||
this.add(controlPanel, BorderLayout.SOUTH);
|
||||
// ActionListener für Buttons
|
||||
addAbsenceButton.addActionListener(e -> addAbsence());
|
||||
deleteAbsenceButton.addActionListener(e -> deleteAbsence());
|
||||
addFeedbackButton.addActionListener(e -> addFeedback());
|
||||
viewFeedbackButton.addActionListener(e -> viewFeedback(frame));
|
||||
manageShiftsButton.addActionListener(e -> manageShifts(frame));
|
||||
backButton.addActionListener(e -> switchPanel(frame, mainPanel));
|
||||
}
|
||||
|
||||
private void switchPanel(JFrame frame, JPanel mainPanel) {
|
||||
frame.getContentPane().removeAll();
|
||||
frame.add(mainPanel, BorderLayout.CENTER);
|
||||
frame.revalidate();
|
||||
frame.repaint();
|
||||
}
|
||||
|
||||
private void loadAbsences() {
|
||||
absences = new ArrayList<>();
|
||||
tableModel.setRowCount(0);
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(absencesFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String[] data = line.split(",");
|
||||
if (data.length >= 3) {
|
||||
absences.add(data);
|
||||
tableModel.addRow(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Fehlzeiten!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveAbsences() {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(absencesFilePath))) {
|
||||
for (String[] absence : absences) {
|
||||
writer.write(String.join(",", absence));
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Fehlzeiten!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAbsence() {
|
||||
JTextField nameField = new JTextField();
|
||||
JTextField dateField = new JTextField();
|
||||
JTextField reasonField = new JTextField();
|
||||
|
||||
Object[] fields = {
|
||||
"Mitarbeitername:", nameField,
|
||||
"Datum (YYYY-MM-DD):", dateField,
|
||||
"Grund:", reasonField
|
||||
};
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(this, fields, "Fehlzeit eintragen", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (option == JOptionPane.OK_OPTION) {
|
||||
String[] absence = {nameField.getText(), dateField.getText(), reasonField.getText()};
|
||||
absences.add(absence);
|
||||
tableModel.addRow(absence);
|
||||
saveAbsences();
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteAbsence() {
|
||||
int selectedRow = table.getSelectedRow();
|
||||
if (selectedRow == -1) {
|
||||
JOptionPane.showMessageDialog(this, "Bitte wählen Sie eine Fehlzeit aus!", "Warnung", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(this, "Möchten Sie diese Fehlzeit wirklich löschen?", "Bestätigung", JOptionPane.YES_NO_OPTION);
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
absences.remove(selectedRow);
|
||||
tableModel.removeRow(selectedRow);
|
||||
saveAbsences();
|
||||
}
|
||||
}
|
||||
|
||||
private void addFeedback() {
|
||||
JTextField nameField = new JTextField();
|
||||
JTextField feedbackField = new JTextField();
|
||||
|
||||
Object[] fields = {
|
||||
"Mitarbeitername:", nameField,
|
||||
"Feedback:", feedbackField
|
||||
};
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(this, fields, "Feedback hinzufügen", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (option == JOptionPane.OK_OPTION) {
|
||||
String feedback = nameField.getText() + ", " + feedbackField.getText();
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(feedbackFilePath, true))) {
|
||||
writer.write(feedback);
|
||||
writer.newLine();
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Speichern des Feedbacks!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void viewFeedback(JFrame frame) {
|
||||
JDialog feedbackDialog = new JDialog(frame, "Feedback anzeigen", true);
|
||||
feedbackDialog.setSize(600, 400);
|
||||
feedbackDialog.setLayout(new BorderLayout());
|
||||
|
||||
JTextArea feedbackArea = new JTextArea();
|
||||
feedbackArea.setEditable(false);
|
||||
JScrollPane scrollPane = new JScrollPane(feedbackArea);
|
||||
feedbackDialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
JButton closeButton = new JButton("Schließen");
|
||||
closeButton.addActionListener(e -> feedbackDialog.dispose());
|
||||
feedbackDialog.add(closeButton, BorderLayout.SOUTH);
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(feedbackFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
feedbackArea.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Feedbacks!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
feedbackDialog.setVisible(true);
|
||||
}
|
||||
|
||||
private void manageShifts(JFrame frame) {
|
||||
JDialog shiftsDialog = new JDialog(frame, "Arbeitszeiten verwalten", true);
|
||||
shiftsDialog.setSize(600, 400);
|
||||
shiftsDialog.setLayout(new BorderLayout());
|
||||
|
||||
// Tabelle für Schichten
|
||||
String[] columns = {"Mitarbeitername", "Datum", "Schichtzeit"};
|
||||
shiftsTableModel = new DefaultTableModel(columns, 0);
|
||||
JTable shiftsTable = new JTable(shiftsTableModel);
|
||||
loadShifts();
|
||||
JScrollPane scrollPane = new JScrollPane(shiftsTable);
|
||||
shiftsDialog.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// Steuerpanel
|
||||
JPanel controlPanel = new JPanel();
|
||||
JButton addButton = new JButton("Hinzufügen");
|
||||
JButton editButton = new JButton("Bearbeiten");
|
||||
JButton deleteButton = new JButton("Löschen");
|
||||
JButton closeButton = new JButton("Schließen");
|
||||
controlPanel.add(addButton);
|
||||
controlPanel.add(editButton);
|
||||
controlPanel.add(deleteButton);
|
||||
controlPanel.add(closeButton);
|
||||
shiftsDialog.add(controlPanel, BorderLayout.SOUTH);
|
||||
|
||||
// ActionListener für Buttons
|
||||
addButton.addActionListener(e -> addShift());
|
||||
editButton.addActionListener(e -> editShift(shiftsTable.getSelectedRow()));
|
||||
deleteButton.addActionListener(e -> deleteShift(shiftsTable.getSelectedRow()));
|
||||
closeButton.addActionListener(e -> shiftsDialog.dispose());
|
||||
|
||||
|
||||
shiftsDialog.setVisible(true);
|
||||
}
|
||||
|
||||
private void loadShifts() {
|
||||
shiftsTableModel.setRowCount(0);
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(shiftsFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String[] data = line.split(",");
|
||||
if (data.length >= 3) {
|
||||
shiftsTableModel.addRow(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden der Arbeitszeiten!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveShifts() {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(shiftsFilePath))) {
|
||||
for (int i = 0; i < shiftsTableModel.getRowCount(); i++) {
|
||||
String[] row = new String[shiftsTableModel.getColumnCount()];
|
||||
for (int j = 0; j < row.length; j++) {
|
||||
row[j] = (String) shiftsTableModel.getValueAt(i, j);
|
||||
}
|
||||
writer.write(String.join(",", row));
|
||||
writer.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Speichern der Arbeitszeiten!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void addShift() {
|
||||
JTextField nameField = new JTextField();
|
||||
JTextField dateField = new JTextField();
|
||||
JTextField timeField = new JTextField();
|
||||
|
||||
Object[] fields = {
|
||||
"Mitarbeitername:", nameField,
|
||||
"Datum (YYYY-MM-DD):", dateField,
|
||||
"Schichtzeit:", timeField
|
||||
};
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(this, fields, "Schicht hinzufügen", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (option == JOptionPane.OK_OPTION) {
|
||||
String[] shift = {nameField.getText(), dateField.getText(), timeField.getText()};
|
||||
shiftsTableModel.addRow(shift);
|
||||
saveShifts();
|
||||
}
|
||||
}
|
||||
|
||||
private void editShift(int selectedRow) {
|
||||
if (selectedRow == -1) {
|
||||
JOptionPane.showMessageDialog(this, "Bitte wählen Sie eine Schicht aus!", "Warnung", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
String name = (String) shiftsTableModel.getValueAt(selectedRow, 0);
|
||||
String date = (String) shiftsTableModel.getValueAt(selectedRow, 1);
|
||||
String time = (String) shiftsTableModel.getValueAt(selectedRow, 2);
|
||||
|
||||
JTextField nameField = new JTextField(name);
|
||||
JTextField dateField = new JTextField(date);
|
||||
JTextField timeField = new JTextField(time);
|
||||
|
||||
Object[] fields = {
|
||||
"Mitarbeitername:", nameField,
|
||||
"Datum (YYYY-MM-DD):", dateField,
|
||||
"Schichtzeit:", timeField
|
||||
};
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(this, fields, "Schicht bearbeiten", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (option == JOptionPane.OK_OPTION) {
|
||||
shiftsTableModel.setValueAt(nameField.getText(), selectedRow, 0);
|
||||
shiftsTableModel.setValueAt(dateField.getText(), selectedRow, 1);
|
||||
shiftsTableModel.setValueAt(timeField.getText(), selectedRow, 2);
|
||||
saveShifts();
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteShift(int selectedRow) {
|
||||
if (selectedRow == -1) {
|
||||
JOptionPane.showMessageDialog(this, "Bitte wählen Sie eine Schicht aus!", "Warnung", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(this, "Möchten Sie diese Schicht wirklich löschen?", "Bestätigung", JOptionPane.YES_NO_OPTION);
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
shiftsTableModel.removeRow(selectedRow);
|
||||
saveShifts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package userinterface;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
public class UserAuthentication {
|
||||
|
||||
private static final String usersFilePath = "src/users.txt";
|
||||
|
||||
public static String authenticateAndReturnRole() {
|
||||
JFrame frame = new JFrame("Login");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(400, 300);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
JLabel label = new JLabel("Bitte melden Sie sich an", SwingConstants.CENTER);
|
||||
label.setFont(new Font("Arial", Font.BOLD, 18));
|
||||
frame.add(label, BorderLayout.NORTH);
|
||||
|
||||
JPanel panel = new JPanel(new GridLayout(3, 2, 10, 10));
|
||||
JLabel usernameLabel = new JLabel("Benutzername:");
|
||||
JTextField usernameField = new JTextField();
|
||||
JLabel passwordLabel = new JLabel("Passwort:");
|
||||
JPasswordField passwordField = new JPasswordField();
|
||||
JButton loginButton = new JButton("Anmelden");
|
||||
panel.add(usernameLabel);
|
||||
panel.add(usernameField);
|
||||
panel.add(passwordLabel);
|
||||
panel.add(passwordField);
|
||||
frame.add(panel, BorderLayout.CENTER);
|
||||
frame.add(loginButton, BorderLayout.SOUTH);
|
||||
|
||||
final String[] role = { null };
|
||||
|
||||
loginButton.addActionListener(e -> {
|
||||
String username = usernameField.getText();
|
||||
String password = new String(passwordField.getPassword());
|
||||
String userRole = authenticate(username, password);
|
||||
if (userRole != null) {
|
||||
role[0] = userRole;
|
||||
frame.dispose();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(frame, "Ungültige Anmeldedaten!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
frame.setVisible(true);
|
||||
|
||||
while (role[0] == null) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
return role[0];
|
||||
}
|
||||
|
||||
private static String authenticate(String username, String password) {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(usersFilePath))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (!line.trim().isEmpty()) {
|
||||
String[] parts = line.split(":");
|
||||
if (parts.length == 3) {
|
||||
String fileUsername = parts[0];
|
||||
String filePassword = parts[2];
|
||||
if (fileUsername.equals(username) && filePassword.equals(password)) {
|
||||
return parts[1]; // Return role
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(null, "Fehler beim Laden der Benutzerdaten!", "Fehler",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
Dimitry:MANAGER:1234
|
||||
Abbas:MANAGER:1234
|
||||
Ananas Kopf:KITCHEN:1234
|
||||
Ananas:SERVICE:1234
|
||||
Arim:MANAGER:1234
|
||||
Ali:KITCHEN:1234
|
||||
|
|
|
|||
Loading…
Reference in New Issue