diff --git a/order.txt b/order.txt index e69de29..087e457 100644 --- a/order.txt +++ b/order.txt @@ -0,0 +1,5 @@ +2002-02-12;1234567;Vegan;DessertV +2002-02-12;12345678;Vegan;DessertV +2002-02-12;123464353;Vegan;DessertV +2002-02-12;724373;Vegan;DessertV +2002-02-12;73473;Vegan;DessertV \ No newline at end of file diff --git a/src/main/java/com/example/vpr_javafx/Data.java b/src/main/java/com/example/vpr_javafx/Data.java index aea4a35..1fd7dd3 100644 --- a/src/main/java/com/example/vpr_javafx/Data.java +++ b/src/main/java/com/example/vpr_javafx/Data.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.swing.*; /** * Data is a class to edit files. @@ -354,43 +355,46 @@ public class Data { public ArrayList changeOrder(String userLogin) { - /* - File orderFile = new File("C:/Unterricht/VPR/orders.txt"); - if (orderFile.delete()) { - System.out.println("Datei gelöscht: " + orderFile.getName()); - } else { - System.out.println("Fehler, " + orderFile.getName() + " nicht gelöscht."); - } - */ - ArrayList changedOrderList = new ArrayList<>(); List rows = getRows(); int changedEntries = 0; - for (String row : rows) { - String[] parts = row.split(";"); + //ImageIcon icon = new ImageIcon("file:target/classes/com/example/vpr_javafx/pics/vegetarisch.png"); + UIManager.put("OptionPane.noButtonText", "Nein"); + UIManager.put("OptionPane.yesButtonText", "Ja"); + int result = JOptionPane.showInternalConfirmDialog(null, "Bestellungen wirklich Löschen?", "Bestätigung", JOptionPane.YES_NO_OPTION); - String date = parts[0]; - String user = parts[1]; - String mealtyp = parts[2]; - String deserttyp = parts[3]; - if(!userLogin.equals(user)) { - changedOrderList.add(new com.example.vpr_javafx.Order(date, user, mealtyp, deserttyp)); - } else { - changedEntries++; + if (result == JOptionPane.YES_OPTION) { + for (String row : rows) { + String[] parts = row.split(";"); + + String date = parts[0]; + String user = parts[1]; + String mealtyp = parts[2]; + String deserttyp = parts[3]; + if(!userLogin.equals(user)) { + changedOrderList.add(new com.example.vpr_javafx.Order(date, user, mealtyp, deserttyp)); + } else { + changedEntries++; + } } - } - - try { + try { FileWriter writer = new FileWriter("orders2.txt"); for(com.example.vpr_javafx.Order str: changedOrderList) { writer.write(str + System.lineSeparator()); } writer.close(); - System.out.println("Daten gelöscht"); - System.out.println(changedEntries + " Einträge entfernt."); + + + + + } catch (IOException e) { e.printStackTrace(); + } + JOptionPane.showMessageDialog(null, changedEntries + " Bestellungen Gelöscht, Sie können eine neue Bestellung aufgeben"); + } else { + JOptionPane.showMessageDialog(null, "Bestellung nicht gelöscht."); } return changedOrderList; } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 9985380..620978c 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,6 +1,7 @@ module com.example.vpr_javafx { requires javafx.controls; requires javafx.fxml; + requires java.desktop; opens com.example.vpr_javafx to javafx.fxml; diff --git a/target/classes/com/example/vpr_javafx/Data.class b/target/classes/com/example/vpr_javafx/Data.class index 20f929b..3666df4 100644 Binary files a/target/classes/com/example/vpr_javafx/Data.class and b/target/classes/com/example/vpr_javafx/Data.class differ diff --git a/target/classes/module-info.class b/target/classes/module-info.class index 03f8e29..a911f75 100644 Binary files a/target/classes/module-info.class and b/target/classes/module-info.class differ