Skip to content
Snippets Groups Projects
Commit a64bba62 authored by Dennis Toth's avatar Dennis Toth
Browse files

Course modification added

parent 73a7163d
No related branches found
No related tags found
No related merge requests found
...@@ -4,13 +4,11 @@ ...@@ -4,13 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ce56effb-683b-43e9-9335-7e3aa5d26c29" name="Changes" comment="added additional text"> <list default="true" id="ce56effb-683b-43e9-9335-7e3aa5d26c29" name="Changes" comment="small bugfix in modification option">
<change afterPath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/StudentStatsController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/de/thdeg/grademanager/gui/student-stats.fxml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/StudentDetailsController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/StudentDetailsController.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/CourseModificationController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/CourseModificationController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/SwitchWindowHelper.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/SwitchWindowHelper.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/CoursesOfStudyDetailsController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/de/thdeg/grademanager/gui/CoursesOfStudyDetailsController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/de/thdeg/grademanager/gui/student-details.fxml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/de/thdeg/grademanager/gui/student-details.fxml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/resources/de/thdeg/grademanager/gui/courses-of-study-details.fxml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/de/thdeg/grademanager/gui/courses-of-study-details.fxml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
......
...@@ -33,11 +33,28 @@ public class CourseModificationController { ...@@ -33,11 +33,28 @@ public class CourseModificationController {
CourseModificationController.coursesOfStudy = coursesOfStudy; CourseModificationController.coursesOfStudy = coursesOfStudy;
} }
private static boolean newCourse = true;
private static Course course;
public static void setCourse(Course c) {
CourseModificationController.course = c;
newCourse = false;
}
@FXML @FXML
protected void initialize() { protected void initialize() {
semesterComboBox.setItems(bachelorSemesterList); semesterComboBox.setItems(bachelorSemesterList);
courseTypeComboBox.setItems(courseTypeList); courseTypeComboBox.setItems(courseTypeList);
examTypeComboBox.setItems(examTypeList); examTypeComboBox.setItems(examTypeList);
if (coursesOfStudy != null && course != null && !newCourse){
name.setText(course.getName());
semesterComboBox.setPromptText(Integer.toString(course.getSemester()));
courseTypeComboBox.setPromptText(course.getCourseType());
sws.setText(Integer.toString(course.getSws()));
ects.setText(Double.toString(course.getEcts()));
examTypeComboBox.setPromptText(course.getExamType());
}
} }
...@@ -59,51 +76,84 @@ public class CourseModificationController { ...@@ -59,51 +76,84 @@ public class CourseModificationController {
@FXML @FXML
protected void onSaveButtonClick(ActionEvent event) throws IOException { protected void onSaveButtonClick(ActionEvent event) throws IOException {
if (!name.getText().isBlank() && semesterComboBox.getValue() != null && if(newCourse) {
courseTypeComboBox.getValue() != null && !sws.getText().isBlank() && !ects.getText().isBlank() && if (!name.getText().isBlank() && semesterComboBox.getValue() != null &&
examTypeComboBox.getValue() != null) { courseTypeComboBox.getValue() != null && !sws.getText().isBlank() && !ects.getText().isBlank() &&
semester = semesterComboBox.getValue(); examTypeComboBox.getValue() != null) {
courseType = courseTypeComboBox.getValue(); semester = semesterComboBox.getValue();
examType = examTypeComboBox.getValue(); courseType = courseTypeComboBox.getValue();
try { examType = examTypeComboBox.getValue();
try {
CourseModificationController.coursesOfStudy.addCourse(new Course(
name.getText(), CourseModificationController.coursesOfStudy.addCourse(new Course(
semester.getSemester(), name.getText(),
courseType.getCourseType(), semester.getSemester(),
Integer.parseInt(sws.getText()), courseType.getCourseType(),
Double.parseDouble(ects.getText()), Integer.parseInt(sws.getText()),
examType.getExamType(), Double.parseDouble(ects.getText()),
false)); //TODO: Add UI-Element for isCredited examType.getExamType(),
false)); //TODO: Add UI-Element for isCredited
JpaService jpaService = JpaService.getInstance();
jpaService.runInTransaction(entityManager -> {
entityManager.merge(CourseModificationController.coursesOfStudy);
entityManager.flush();
return null;
});
SwitchWindowHelper.switchTo("CoursesOfStudy Details", event);
} catch (NumberFormatException e) {
warning.setText("Bitte ganze Zahlen eingeben für SWS und ECTS.");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Fehler");
alert.setHeaderText("Bitte ganze Zahlen eingeben für SWS und ECTS.");
Optional<ButtonType> result = alert.showAndWait();
}
} else {
warning.setText("Bitte alle Felder ausfüllen.");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Fehler");
alert.setHeaderText("Bitte alle Felder ausfüllen.");
Optional<ButtonType> result = alert.showAndWait();
}
} else {
if (!name.getText().isBlank() && !sws.getText().isBlank() && !ects.getText().isBlank()) {
course.setName(name.getText());
if(semesterComboBox.getValue() != null){
course.setSemester(semester.getSemester());
}
if(courseTypeComboBox.getValue() != null){
course.setCourseType(courseType.getCourseType());
}
course.setSws(Integer.parseInt(sws.getText()));
course.setEcts(Double.parseDouble(ects.getText()));
if(examTypeComboBox.getValue() != null){
course.setExamType(examType.getExamType());
}
JpaService jpaService = JpaService.getInstance(); JpaService jpaService = JpaService.getInstance();
jpaService.runInTransaction(entityManager -> { jpaService.runInTransaction(entityManager -> {entityManager.merge(coursesOfStudy); return null;});
entityManager.merge(CourseModificationController.coursesOfStudy); initialize();
entityManager.flush();
return null; newCourse = true;
});
SwitchWindowHelper.switchTo("CoursesOfStudy Details", event); SwitchWindowHelper.switchTo("CoursesOfStudy Details", event);
} catch (NumberFormatException e) { } else {
warning.setText("Bitte ganze Zahlen eingeben für SWS und ECTS.");
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Fehler"); alert.setTitle("Fehler");
alert.setHeaderText("Bitte ganze Zahlen eingeben für SWS und ECTS."); alert.setHeaderText("Bitte alle Felder ausfüllen.");
Optional<ButtonType> result = alert.showAndWait(); Optional<ButtonType> result = alert.showAndWait();
} }
} else {
warning.setText("Bitte alle Felder ausfüllen.");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Fehler");
alert.setHeaderText("Bitte alle Felder ausfüllen.");
Optional<ButtonType> result = alert.showAndWait();
} }
} }
@FXML @FXML
protected void abortAndSwitchToCoursesOfStudyDetails(ActionEvent event) throws IOException { protected void abortAndSwitchToCoursesOfStudyDetails(ActionEvent event) throws IOException {
newCourse = true;
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Bestätigung erforderlich"); alert.setTitle("Bestätigung erforderlich");
alert.setHeaderText("Daten wurden nicht gespeichert. Änderungen verwerfen?"); alert.setHeaderText("Daten wurden nicht gespeichert. Änderungen verwerfen?");
......
...@@ -8,7 +8,11 @@ import javafx.collections.FXCollections; ...@@ -8,7 +8,11 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
...@@ -104,6 +108,20 @@ public class CoursesOfStudyDetailsController { ...@@ -104,6 +108,20 @@ public class CoursesOfStudyDetailsController {
} }
} }
@FXML
protected void onCourseClick() throws IOException {
CourseModificationController.setCoursesOfStudy(coursesOfStudy);
CourseModificationController.setCourse(courseListView.getSelectionModel().getSelectedItem());
FXMLLoader root = new FXMLLoader(Main.class.getResource("course-modification.fxml"));
Stage stage = (Stage) (courseListView.getScene().getWindow());
Scene scene = new Scene(root.load(), 960, 540);
if (stage != null){
stage.setTitle("Course Mofidification");
stage.setScene(scene);
stage.show();
}
}
@FXML @FXML
protected void switchToMain(ActionEvent event) throws IOException { protected void switchToMain(ActionEvent event) throws IOException {
SwitchWindowHelper.switchTo("Main", event); SwitchWindowHelper.switchTo("Main", event);
......
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
<children> <children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Angelegte Kurse:" /> <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Angelegte Kurse:" />
<Region prefHeight="99.0" prefWidth="18.0" /> <Region prefHeight="99.0" prefWidth="18.0" />
<ListView fx:id="courseListView" editable="true" prefHeight="133.0" prefWidth="270.0" /> <ListView fx:id="courseListView" editable="true" onMouseClicked="#onCourseClick" prefHeight="133.0" prefWidth="270.0" />
</children> </children>
</HBox> </HBox>
</children> </children>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment