From aecf521d964d8df9c270e9fb57838682abbf6e01 Mon Sep 17 00:00:00 2001 From: Kevin Pfannenstiel Date: Wed, 1 Feb 2023 09:50:47 +0100 Subject: [PATCH] Tweaks --- parentOrder.txt | 0 .../java/com/example/vpr_javafx/Data.java | 142 +++++++++--------- .../example/vpr_javafx/HelloController.java | 63 ++++++-- .../java/com/example/vpr_javafx/User.java | 16 +- .../example/vpr_javafx/MenuOverview-view.fxml | 126 ++++++++++------ .../com/example/vpr_javafx/Order-view.fxml | 29 ++++ .../classes/com/example/vpr_javafx/Data.class | Bin 12791 -> 12298 bytes .../example/vpr_javafx/HelloController.class | Bin 11951 -> 13642 bytes .../example/vpr_javafx/MenuOverview-view.fxml | 126 ++++++++++------ .../com/example/vpr_javafx/Order-view.fxml | 29 ++++ .../classes/com/example/vpr_javafx/User.class | Bin 1705 -> 1533 bytes 11 files changed, 348 insertions(+), 183 deletions(-) create mode 100644 parentOrder.txt create mode 100644 src/main/resources/com/example/vpr_javafx/Order-view.fxml create mode 100644 target/classes/com/example/vpr_javafx/Order-view.fxml diff --git a/parentOrder.txt b/parentOrder.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/example/vpr_javafx/Data.java b/src/main/java/com/example/vpr_javafx/Data.java index d7be404..96ab4ce 100644 --- a/src/main/java/com/example/vpr_javafx/Data.java +++ b/src/main/java/com/example/vpr_javafx/Data.java @@ -3,9 +3,7 @@ package com.example.vpr_javafx; import javafx.scene.control.Alert; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; -import org.w3c.dom.Text; -import java.awt.*; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -18,7 +16,6 @@ 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. @@ -49,8 +46,8 @@ public class Data { { String[] parts = lines.get(i).split(";"); - String phoneNumber = parts[3]; - String password = parts[5]; + String phoneNumber = parts[2]; + String password = parts[4]; user.put(phoneNumber, password); } @@ -77,12 +74,11 @@ public class Data { String[] parts = row.split(";"); String nameParent1 = parts[0]; - String nameParent2 = parts[1]; - String billAddress = parts[2]; - String phonenumber = parts[3]; - String nameChildren = parts[4]; - String password = parts[5]; - userList.add(new com.example.vpr_javafx.User(nameParent1, nameParent2, billAddress, phonenumber, nameChildren, password)); + String billAddress = parts[1]; + String phonenumber = parts[2]; + String nameChildren = parts[3]; + String password = parts[4]; + userList.add(new com.example.vpr_javafx.User(nameParent1, billAddress, phonenumber, nameChildren, password)); } return userList; @@ -287,11 +283,8 @@ public class Data { /** * The method validates the user input * - * @param tfPhone Phone number the user typed in - * @param pfPassword Password the user typed in - * @param controller Controller - * @return phoneNumberValid && passwordValid - * @author Kevin Maier, Kevin Pfannenstiel + * @return boolean inputValid + * @author Kevin Maier, Kevin Pfannenstiel */ public boolean validateData(TextField tfPhone, PasswordField pfPassword, HelloController controller) { @@ -300,8 +293,6 @@ public class Data { boolean phoneNumberValid = false; boolean passwordValid = false; - Alert alert = new Alert(Alert.AlertType.WARNING); - HashMap users = readLoginData(); String phoneNumber = tfPhone.getText(); @@ -312,8 +303,10 @@ public class Data { if (password.isEmpty() || phoneNumber.isEmpty()) { - alert.setContentText("Login fehlgeschlagen. Anmeldedaten unvollständig."); + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setContentText("Login fehlgeschlagen. Es wurde nichts eingegeben."); alert.show(); + return false; } Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber); @@ -324,18 +317,22 @@ public class Data { if (!users.containsKey(phoneNumber) || !phoneNumberMatchFound || phoneNumber.length() >= 15) { + Alert alert = new Alert(Alert.AlertType.WARNING); alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch."); alert.show(); + return false; } else { phoneNumberValid = true; } - if (!users.get(phoneNumber).equals(password) || !passwordMatchFound) + if (!users.get(phoneNumber).equals(password) || !passwordMatchFound || password.length() <8) { + Alert alert = new Alert(Alert.AlertType.WARNING); alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch."); alert.show(); + return false; } else { @@ -346,6 +343,57 @@ public class Data { return phoneNumberValid && passwordValid; } + + /** + * The method changes the orders.txt file by removing canceled orders + * + * @return ArrayList\ changedOrderList + * @author Felix Düsterhaus + */ + + 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(";"); + + 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 { + 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(); + } + return changedOrderList; + } + /** * * @param tfPhone @@ -417,59 +465,5 @@ public class Data { return phoneNumberValid && passwordValid && postalCodeValid; } - - - /** - * The method changes the orders.txt file by removing canceled orders - * - * @return ArrayList\ changedOrderList - * @author Felix Düsterhaus - */ - - public ArrayList changeOrder(String userLogin) { - - ArrayList changedOrderList = new ArrayList<>(); - List rows = getRows(); - int changedEntries = 0; - - //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); - - 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 { - FileWriter writer = new FileWriter("orders2.txt"); - for(com.example.vpr_javafx.Order str: changedOrderList) { - writer.write(str + System.lineSeparator()); - } - writer.close(); - - - - - - } 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/com/example/vpr_javafx/HelloController.java b/src/main/java/com/example/vpr_javafx/HelloController.java index bf5ad6a..57fd2f6 100644 --- a/src/main/java/com/example/vpr_javafx/HelloController.java +++ b/src/main/java/com/example/vpr_javafx/HelloController.java @@ -1,5 +1,7 @@ package com.example.vpr_javafx; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -10,16 +12,13 @@ import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.StackPane; import javafx.stage.Stage; - -import java.io.Console; -import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; public class HelloController { @@ -85,8 +84,6 @@ public class HelloController { private ImageView imgImage9; @FXML private ImageView imgImage10; - @FXML - private AnchorPane anchorPane; @FXML private TextField tfPhone; @@ -133,6 +130,9 @@ public class HelloController { @FXML private RadioButton rbFriH2; + @FXML + private ListView orderList; + @FXML final String imagePathUrl = "file:target/classes/com/example/vpr_javafx/pics/"; @@ -365,11 +365,10 @@ public class HelloController { rbThurH2.setVisible(true); rbFriH1.setVisible(true); rbFriH2.setVisible(true); - } @FXML - protected void resetSelection(ActionEvent event) throws IOException + protected void resetSelection(ActionEvent event) { rbMonH1.setSelected(false); rbMonH2.setSelected(false); @@ -384,14 +383,60 @@ public class HelloController { chosenMeals.clear(); } + @FXML + protected void toOrder(ActionEvent event) throws IOException + { + try (FileWriter writer = new FileWriter("parentOrder.txt", true)) + { + writer.write(getLabelValueWithRadio().toString() + System.lineSeparator()); + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setContentText("Bestellung abgeschickt."); + + Parent rootParent = FXMLLoader.load(getClass().getResource("Order-view.fxml")); + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + Scene scene = new Scene(rootParent); + stage.setScene(scene); + stage.show(); + + ObservableList orders = FXCollections.observableArrayList(getLabelValueWithRadio()); + orderList = new ListView<>(orders); + StackPane rootStackPane = new StackPane(); + rootStackPane.getChildren().add(orderList); + Scene scene2 = new Scene(rootStackPane); + stage.setScene(scene2); + stage.show(); + + } + catch (IOException e) + { + e.printStackTrace(); + } + } @FXML - protected ArrayList getLabelValueWithRadio(ActionEvent event) + protected void removeFromOrder() throws IOException + { + + } + + + @FXML + protected ArrayList getLabelValueWithRadio() { chosenMeals = new ArrayList<>(); String mainDish; String dessert; + Data data = new Data("user.txt"); + for (User user : data.readUser()) + { + if (tfPhone.getText().equals(user.getPhonenumber()) && pfPassword.getText().equals(user.getPassword())) + { + chosenMeals.add(user.toString()); + break; + } + } + if (rbMonH1.isSelected()) { mainDish = lMonH1.getText(); diff --git a/src/main/java/com/example/vpr_javafx/User.java b/src/main/java/com/example/vpr_javafx/User.java index 50da10a..e4a1bb7 100644 --- a/src/main/java/com/example/vpr_javafx/User.java +++ b/src/main/java/com/example/vpr_javafx/User.java @@ -8,7 +8,6 @@ package com.example.vpr_javafx; */ public class User { private String nameParent1; - private String nameParent2; private String billAddress; private String phoneNumber; private String nameChildren; @@ -18,16 +17,14 @@ public class User { * constructor * * @param nameParent1 name of the first parent of the child - * @param nameParent2 name of the second parent of the child * @param billAddress the address the bill should be sent to * @param phoneNumber phonenumber of one of the parents and also the username * @param nameChildren name of the children * @param password password of the user * @author Madeleine Vigier */ - public User(String nameParent1, String nameParent2, String billAddress, String phoneNumber, String nameChildren, String password) { + public User(String nameParent1, String billAddress, String phoneNumber, String nameChildren, String password) { this.nameParent1 = nameParent1; - this.nameParent2 = nameParent2; this.billAddress = billAddress; this.phoneNumber = phoneNumber; this.nameChildren = nameChildren; @@ -64,15 +61,6 @@ public class User { return nameParent1; } - /** - * the method getNameParent2() gets nameParent2 - * - * @return nameParent2 - * @author Madeleine Vigier - */ - public String getNameParent2() { - return nameParent2; - } /** * the methode toString() returns a String representation of an object @@ -82,6 +70,6 @@ public class User { */ @Override public String toString() { - return nameParent1 + ";" + nameParent2 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password; + return nameParent1 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password; } } diff --git a/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml b/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml index 2bf9cb2..b086191 100644 --- a/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml +++ b/src/main/resources/com/example/vpr_javafx/MenuOverview-view.fxml @@ -8,7 +8,7 @@ -