changeorder-view hinzugefügt

This commit is contained in:
Felix Düsterhaus 2023-02-01 08:52:15 +01:00
parent 8ac02b756b
commit 30511d32b4
8 changed files with 70 additions and 21 deletions

View File

@ -1,6 +1,9 @@
package com.example.vpr_javafx;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Alert;
import javafx.scene.control.ListView;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import org.w3c.dom.Text;
@ -426,8 +429,9 @@ public class Data {
* @author Felix Düsterhaus
*/
public ArrayList<com.example.vpr_javafx.Order> changeOrder(String userLogin) {
public ArrayList<com.example.vpr_javafx.Order> changeOrder(String userLogin, ListView<String> ListViewDelete) {
ArrayList<String> chosenMeals = new ArrayList<>();
ObservableList<String> chosenMealsObservable = FXCollections.observableList(chosenMeals);
ArrayList<com.example.vpr_javafx.Order> changedOrderList = new ArrayList<>();
List<String> rows = getRows();
int changedEntries = 0;
@ -436,7 +440,7 @@ public class Data {
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);
ListViewDelete.getSelectionModel().getSelectedItems();
if (result == JOptionPane.YES_OPTION) {
for (String row : rows) {
String[] parts = row.split(";");
@ -451,20 +455,15 @@ public class Data {
changedEntries++;
}
}
try {
FileWriter writer = new FileWriter("orders2.txt");
for(com.example.vpr_javafx.Order str: changedOrderList) {
writer.write(str + System.lineSeparator());
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();
}
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.");

View File

@ -20,7 +20,5 @@ public class HelloApplication extends Application {
controller.writeAllergene();
}
public static void main(String[] args) {
launch();
}
public static void main(String[] args) {launch();}
}

View File

@ -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;
@ -113,6 +115,12 @@ public class HelloController {
@FXML
private Button btToOrder;
@FXML
private Button btToChangeOrder;
@FXML
private Button btDeleteSelection;
@FXML
private Button btToMenu;
@FXML
private RadioButton rbMonH1;
@FXML
private RadioButton rbMonH2;
@ -145,7 +153,10 @@ public class HelloController {
@FXML
private String imageUrl;
@FXML
private ArrayList<String> chosenMeals;
@FXML
private ListView<String> listViewDelete;
@FXML
protected void OnSignInButton(ActionEvent event) throws IOException
@ -365,7 +376,7 @@ public class HelloController {
rbThurH2.setVisible(true);
rbFriH1.setVisible(true);
rbFriH2.setVisible(true);
btToChangeOrder.setVisible(true);
}
@FXML
@ -384,6 +395,34 @@ public class HelloController {
chosenMeals.clear();
}
@FXML
protected void ToChangeOrder(ActionEvent event) throws IOException
{
Parent root = FXMLLoader.load(getClass().getResource("ChangeOrder-view.fxml"));
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@FXML
protected void deleteSelection() {
final int selectedId = listViewDelete.getSelectionModel().getSelectedIndex();
//String itemToRemove = listViewDelete.getSelectionModel().getSelectedItem();
listViewDelete.getItems().remove(selectedId);
Data data = new Data("order.txt");
data.changeOrder("12345", listViewDelete);
}
@FXML
protected void ToMenu(ActionEvent event) throws IOException
{
Parent root = FXMLLoader.load(getClass().getResource("MenuOverview-view.fxml"));
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@FXML
protected ArrayList<String> getLabelValueWithRadio(ActionEvent event)

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.vpr_javafx.HelloController">
<children>
<Button fx:id="btDeleteSelection" layoutX="457.0" layoutY="264.0" mnemonicParsing="false" text="Löschen" />
<Button fx:id="btToMenu" onAction="#ToMenu" layoutX="461.0" layoutY="305.0" mnemonicParsing="false" visible="false" text="Zurück" />
<ListView fx:id="listViewDelete" layoutX="200.0" layoutY="89.0" prefHeight="200.0" prefWidth="200.0" />
</children>
</AnchorPane>

View File

@ -70,7 +70,7 @@
</font></Label>
<PasswordField fx:id="pfPassword" style="-fx-background-color: #f0c8cb;" />
<Button mnemonicParsing="false" onAction="#OnSignInButton" style="-fx-background-color: #c7d0f0;" text="anmelden" textFill="WHITE" />
<Button onAction="#ToRegistration" style="-fx-background-color: #c7d0f0;" textFill="WHITE" mnemonicParsing="false" text="registrieren" />
<Button mnemonicParsing="false" onAction="#ToRegistration" style="-fx-background-color: #c7d0f0;" text="registrieren" textFill="WHITE" />
</items>
</ToolBar>
<Line endX="100.0" layoutX="245.0" layoutY="310.0" startX="-100.0" stroke="#746fa6" strokeWidth="3.0" />
@ -212,6 +212,7 @@
<ImageView fx:id="imgImage10" fitHeight="30.0" fitWidth="35.0" layoutX="112.0" layoutY="680.0" pickOnBounds="true" preserveRatio="true" />
<Button fx:id="btResetSelection" layoutX="779.0" layoutY="622.0" mnemonicParsing="false" onAction="#resetSelection" text="Auswahl aufheben" visible="false" />
<Button fx:id="btToOrder" layoutX="779.0" layoutY="675.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Bestellen" visible="false" />
<Button fx:id="btToChangeOrder" onAction="#ToChangeOrder" layoutX="779.0" layoutY="728.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Bestellung" visible="false" />
<RadioButton fx:id="rbMonH1" layoutX="359.0" layoutY="159.0" mnemonicParsing="false" onAction="#getLabelValueWithRadio" visible="false" />
<RadioButton fx:id="rbMonH2" layoutX="359.0" layoutY="201.0" mnemonicParsing="false" onAction="#getLabelValueWithRadio" visible="false" />
<RadioButton fx:id="rbTueH1" layoutX="360.0" layoutY="278.0" mnemonicParsing="false" onAction="#getLabelValueWithRadio" visible="false" />