202 lines
4.9 KiB
Java

package com.example.vpr_javafx;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
public class HelloController {
@FXML
private Label lMonH1;
@FXML
private Label lMonH2;
@FXML
private Label lMonD1;
@FXML
private Label lMonD2;
@FXML
private Label lTueH1;
@FXML
private Label lTueH2;
@FXML
private Label lTueD1;
@FXML
private Label lTueD2;
@FXML
private Label lWednH1;
@FXML
private Label lWednH2;
@FXML
private Label lWednD1;
@FXML
private Label lWednD2;
@FXML
private Label lThurH1;
@FXML
private Label lThurH2;
@FXML
private Label lThurD1;
@FXML
private Label lThurD2;
@FXML
private Label lFriH1;
@FXML
private Label lFriH2;
@FXML
private Label lFriD1;
@FXML
private Label lFriD2;
@FXML
private TextField tfPhone;
@FXML
private PasswordField pfPassword;
private Stage stage;
private Scene scene;
@FXML
protected void OnSignInButton(ActionEvent event) throws IOException
{
LoginDatei file = new LoginDatei("user.txt");
HashMap<String, String> users = file.readFile();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
if (users.containsKey(tfPhone.getText()))
{
if (users.containsValue(pfPassword.getText()))
{
Parent root = FXMLLoader.load(getClass().getResource("MenuSelect-view.fxml"));
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
else
{
alert.setContentText("Falsche Werte");
alert.show();
}
}
else
{
alert.setContentText("Falsche Werte");
alert.show();
}
}
@FXML
protected void FillLabels() {
try {
List<String> menu = Files.readAllLines(Paths.get("menue.txt"));
for (int i = 0; i < menu.size(); i++)
{
String[] parts = menu.get(i).split(";");
String dish = parts[1];
String sideDish = parts[2];
String dayMenu = dish+"\n"+sideDish;
if (i == 0)
{
lMonH1.setText(dayMenu);
}
else if (i == 1)
{
lMonD1.setText(dayMenu);
}
else if (i == 2)
{
lMonH2.setText(dayMenu);
}
else if (i == 3)
{
lMonD2.setText(dayMenu);
}
else if (i == 4)
{
lTueH1.setText(dayMenu);
}
else if (i == 5)
{
lTueD1.setText(dayMenu);
}
else if (i == 6)
{
lTueH2.setText(dayMenu);
}
else if (i == 7)
{
lTueD2.setText(dayMenu);
}
else if (i == 8)
{
lWednH1.setText(dayMenu);
}
else if (i == 9)
{
lWednD1.setText(dayMenu);
}
else if (i == 10)
{
lWednH2.setText(dayMenu);
}
else if (i == 11)
{
lWednD2.setText(dayMenu);
}
else if (i == 12)
{
lThurH1.setText(dayMenu);
}
else if (i == 13)
{
lThurD1.setText(dayMenu);
}
else if (i == 14)
{
lThurH2.setText(dayMenu);
}
else if (i == 15)
{
lThurD2.setText(dayMenu);
}
else if (i == 16)
{
lFriH1.setText(dayMenu);
}
else if (i == 17)
{
lFriD1.setText(dayMenu);
}
else if (i == 18)
{
lFriH2.setText(dayMenu);
}
else if (i == 19)
{
lFriD2.setText(dayMenu);
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}