order.txt testdatei + Data changeorder() geändert

This commit is contained in:
Felix Düsterhaus 2023-01-31 18:20:28 +01:00
parent 4ccb2c80f2
commit d222db8816
5 changed files with 34 additions and 24 deletions

View File

@ -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

View File

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.swing.*;
/** /**
* Data is a class to edit files. * Data is a class to edit files.
@ -354,43 +355,46 @@ public class Data {
public ArrayList<com.example.vpr_javafx.Order> changeOrder(String userLogin) { public ArrayList<com.example.vpr_javafx.Order> 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<com.example.vpr_javafx.Order> changedOrderList = new ArrayList<>(); ArrayList<com.example.vpr_javafx.Order> changedOrderList = new ArrayList<>();
List<String> rows = getRows(); List<String> rows = getRows();
int changedEntries = 0; int changedEntries = 0;
for (String row : rows) { //ImageIcon icon = new ImageIcon("file:target/classes/com/example/vpr_javafx/pics/vegetarisch.png");
String[] parts = row.split(";"); 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]; if (result == JOptionPane.YES_OPTION) {
String user = parts[1]; for (String row : rows) {
String mealtyp = parts[2]; String[] parts = row.split(";");
String deserttyp = parts[3];
if(!userLogin.equals(user)) { String date = parts[0];
changedOrderList.add(new com.example.vpr_javafx.Order(date, user, mealtyp, deserttyp)); String user = parts[1];
} else { String mealtyp = parts[2];
changedEntries++; 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"); FileWriter writer = new FileWriter("orders2.txt");
for(com.example.vpr_javafx.Order str: changedOrderList) { for(com.example.vpr_javafx.Order str: changedOrderList) {
writer.write(str + System.lineSeparator()); writer.write(str + System.lineSeparator());
} }
writer.close(); writer.close();
System.out.println("Daten gelöscht");
System.out.println(changedEntries + " Einträge entfernt.");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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; return changedOrderList;
} }

View File

@ -1,6 +1,7 @@
module com.example.vpr_javafx { module com.example.vpr_javafx {
requires javafx.controls; requires javafx.controls;
requires javafx.fxml; requires javafx.fxml;
requires java.desktop;
opens com.example.vpr_javafx to javafx.fxml; opens com.example.vpr_javafx to javafx.fxml;

Binary file not shown.