-
Dennis Toth authoredDennis Toth authored
StudentModificationController.java 3.34 KiB
package com.example.grademanager_gui;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Optional;
public class StudentModificationController {
ObservableList<String> genderList = FXCollections.observableArrayList("männlich", "weiblich", "divers");
@FXML
protected ComboBox<String> genderComboBox;
protected void setGenderComboBox() {
genderComboBox.setItems(genderList);
}
@FXML
protected void initialize() {
setGenderComboBox();
}
@FXML
protected String gender;
@FXML
protected TextField firstName;
@FXML
protected TextField lastName;
@FXML
protected TextField placeOfResidence;
@FXML
protected TextField birthPlace;
@FXML
protected TextField officialEmail;
@FXML
protected TextField privateEmail;
@FXML
protected TextField personalCourses;
@FXML
protected TextField status;
@FXML
protected boolean paidFees;
@FXML
protected TextField bachelorSemester;
@FXML
protected TextField grades;
@FXML
protected TextField warning;
@FXML
protected RadioButton yes;
@FXML
protected RadioButton no;
private Stage stage;
private Scene scene;
private FXMLLoader root;
@FXML
protected void onSaveButtonClick(ActionEvent event) throws IOException {
if(genderComboBox.getValue() != null && !firstName.getText().isBlank() && !lastName.getText().isBlank() &&
!placeOfResidence.getText().isBlank() && !birthPlace.getText().isBlank() &&
!officialEmail.getText().isBlank() && !privateEmail.getText().isBlank() &&
!personalCourses.getText().isBlank() && !status.getText().isBlank() &&
(yes.isSelected() || no.isSelected()) && !bachelorSemester.getText().isBlank() &&
!grades.getText().isBlank())
{
gender = genderComboBox.getValue();
paidFees = yes.isSelected();
switchToMain(event);
}
else {
warning.setText("Bitte alle Felder ausfüllen");
}
}
@FXML
protected void switchToMain(ActionEvent event) throws IOException {
root = new FXMLLoader(Main.class.getResource("main.fxml"));
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
scene = new Scene(root.load(), 960, 540);
stage.setTitle("Main");
stage.setScene(scene);
stage.show();
}
@FXML
protected void abortAndSwitchToMain(ActionEvent event) throws IOException {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Bestätigung erforderlich");
alert.setHeaderText("Daten wurden nicht gespeichert. Änderungen verwerfen?");
ButtonType buttonTypeOne = new ButtonType("Ja");
ButtonType buttonTypeCancel = new ButtonType("Abbrechen", ButtonBar.ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeOne){
switchToMain(event);
}
}
}