Skip to content

Commit

Permalink
created the index.html/styles.css and the docs dir
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsilva010 committed Apr 13, 2024
1 parent 88acf6f commit e527ab6
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/Controllers/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public void loadAddStudentToCourseView(ActionEvent event) {
main.loadAddStudentToCourseView();
}

public void loadViewFacultyCoursesView(ActionEvent event) {
main.loadViewFacultyCoursesView();
}

@FXML
public void loadCreateNewCourseView(ActionEvent event) {
main.loadCreateNewCourseView();
Expand Down
78 changes: 78 additions & 0 deletions src/Controllers/ViewFacultyCoursesController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package Controllers;

import java.util.ArrayList;

import DAOs.FacultyDAO;
import DAOs.ScheduleDAO;
import Models.Schedule;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;

public class ViewFacultyCoursesController {

@FXML
private TableColumn<Schedule, Long> CRNColumn;

@FXML
private TableColumn<Schedule, String> CourseIDColumn;

@FXML
private TableColumn<Schedule, String> TermColumn;

@FXML
private TableColumn<Schedule, String> courseNameColumn;

@FXML
private Button searchButton;

@FXML
private TableView<Schedule> tableView;

@FXML
private Text textFacultyCourses;

@FXML
private Text textInstructorName;

@FXML
private TextField tfFacultyID;

@FXML
void ClearIfDefaultText(MouseEvent event) {
if (tfFacultyID.getText().equals("Enter faculty ID")) {
tfFacultyID.setText("");
}
}

@FXML
void search(ActionEvent event) {
if (!tfFacultyID.getText().equals("Enter faculty ID") && !tfFacultyID.getText().equals("") && tfFacultyID.getText().length() == 9) {
ArrayList<Schedule> courses = ScheduleDAO.getCoursesByFaculty(tfFacultyID.getText());
tableView.getItems().clear();
tableView.getItems().addAll(courses);
textFacultyCourses.setText("Faculty Courses for: ");
textInstructorName.setText(FacultyDAO.getFacultyName(tfFacultyID.getText()));
CRNColumn.setCellValueFactory(new PropertyValueFactory<Schedule, Long>("CRN"));
CourseIDColumn.setCellValueFactory(new PropertyValueFactory<Schedule, String>("courseID"));
courseNameColumn.setCellValueFactory(new PropertyValueFactory<Schedule, String>("courseName"));
TermColumn.setCellValueFactory(new PropertyValueFactory<Schedule, String>("term"));
}
else {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error");
alert.setContentText("Please enter a valid faculty ID");
alert.showAndWait();
}
}

}
41 changes: 41 additions & 0 deletions src/DAOs/FacultyDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -95,12 +96,52 @@ public static boolean insertFaculty(Faculty faculty) {

try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "INSERT INTO Faculty (FacultyID, firstName, lastName, hireDate, title, salary, street, city, state, zipCode, phone, email, departmentID) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, faculty.getFacultyID());
pstmt.setString(2, faculty.getFirstName());
pstmt.setString(3, faculty.getLastName());
pstmt.setString(4, faculty.getHireDate());
pstmt.setString(5, faculty.getTitle());
pstmt.setDouble(6, faculty.getSalary());
pstmt.setString(7, faculty.getStreet());
pstmt.setString(8, faculty.getCity());
pstmt.setString(9, faculty.getState());
pstmt.setInt(10, faculty.getZipCode());
pstmt.setString(11, faculty.getPhone());
pstmt.setString(12, faculty.getEmail());
pstmt.setInt(13, faculty.getDepartmentID());
pstmt.executeUpdate();
return true;
} catch (SQLException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error loading Faculty");
alert.setContentText("An error occurred while loading the Faculty: " + e.getMessage());
alert.showAndWait();
return false;
}
}

public static String getFacultyName(String id) {
String user = System.getenv("USER");
String password = System.getenv("PASSWORD");
String url = System.getenv("URL");

try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "SELECT firstName, lastName FROM faculty WHERE facultyID = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
return rs.getString("firstName") + " " + rs.getString("lastName");
}
} catch (SQLException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error loading faculty");
alert.setContentText("An error occurred while loading the faculty: " + e.getMessage());
alert.showAndWait();
}
return null;
}
}
49 changes: 42 additions & 7 deletions src/DAOs/ScheduleDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ public static ArrayList<Schedule> getStudentCourses(String studentID) {
String password = System.getenv("PASSWORD");
String url = System.getenv("URL");

try(Connection conn = DriverManager.getConnection(url, user, password)) {
try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "SELECT * FROM Schedule WHERE " +
"CRN IN (SELECT CRN FROM CourseRoster WHERE studentID = ?)";
"CRN IN (SELECT CRN FROM CourseRoster WHERE studentID = ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, studentID);
ResultSet rs = pstmt.executeQuery();
ArrayList<Schedule> courses = new ArrayList<>();
while(rs.next()) {
while (rs.next()) {
Schedule course = new Schedule();
course.setCRN(rs.getLong("CRN"));
course.setCapacity(rs.getInt("Capacity"));
Expand All @@ -102,7 +102,7 @@ public static ArrayList<Schedule> getStudentCourses(String studentID) {
courses.add(course);
}
return courses;
} catch(SQLException e) {
} catch (SQLException e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Database Error");
Expand All @@ -118,16 +118,51 @@ public static String getGradeForStudent(String studentID, long CRN) {
String password = System.getenv("PASSWORD");
String url = System.getenv("URL");

try(Connection conn = DriverManager.getConnection(url, user, password)) {
try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "SELECT grade FROM CourseRoster WHERE studentID = ? AND CRN = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, studentID);
pstmt.setLong(2, CRN);
ResultSet rs = pstmt.executeQuery();
if(rs.next()) {
if (rs.next()) {
return rs.getString("grade");
}
} catch(SQLException e) {
} catch (SQLException e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Database Error");
alert.setContentText(e.getMessage());
alert.showAndWait();
}
return null;
}


public static ArrayList<Schedule> getCoursesByFaculty(String facultyID) {
String user = System.getenv("USER");
String password = System.getenv("PASSWORD");
String url = System.getenv("URL");

try (Connection conn = DriverManager.getConnection(url, user, password)) {
String sql = "SELECT * FROM Schedule WHERE facultyID = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, facultyID);
ResultSet rs = pstmt.executeQuery();
ArrayList<Schedule> courses = new ArrayList<>();
while (rs.next()) {
Schedule course = new Schedule();
course.setCRN(rs.getLong("CRN"));
course.setCapacity(rs.getInt("Capacity"));
course.setCreditHours(rs.getInt("CreditHours"));
course.setFacultyID(rs.getString("FacultyID"));
course.setRoom(rs.getString("Room"));
course.setTerm(rs.getString("Term"));
course.setCourseName(rs.getString("CourseName"));
course.setCourseID(rs.getString("CourseID"));
courses.add(course);
}
return courses;
} catch (SQLException e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Database Error");
Expand Down
20 changes: 20 additions & 0 deletions src/Main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import javafx.stage.Stage;

public class Main extends Application {


private static final String MAIN_VIEW = "/Views/MainView.fxml";

private static final String VIEW_FACULTY_COURSES_VIEW = "/Views/ViewFacultyCoursesView.fxml";

private static final String ADD_STUDENT_TO_COURSE_VIEW = "/Views/AddStudentToCourseView.fxml";

private static final String SEARCH_STUDENT_VIEW = "/Views/SearchStudentView.fxml";
Expand Down Expand Up @@ -57,6 +60,23 @@ private void loadMainView(Stage primaryStage) {
}
}

public void loadViewFacultyCoursesView() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(VIEW_FACULTY_COURSES_VIEW));
Parent root = loader.load();
Stage stage = new Stage();
stage.setTitle("View Faculty courses");
stage.setScene(new Scene(root));
stage.show();
} catch (IOException e) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error loading view");
alert.setContentText("An error occured loading the view:" + e.getMessage());
alert.showAndWait();
}
}

public void loadAddStudentToCourseView() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(ADD_STUDENT_TO_COURSE_VIEW));
Expand Down
2 changes: 1 addition & 1 deletion src/Views/MainView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" GridPane.rowIndex="4">
<children>
<Button alignment="CENTER" mnemonicParsing="false" prefHeight="57.0" prefWidth="155.0" style="-fx-background-insets: -10; -fx-padding: 10;" text="View Faculty Courses" wrapText="true">
<Button alignment="CENTER" mnemonicParsing="false" prefHeight="57.0" prefWidth="155.0" style="-fx-background-insets: -10; -fx-padding: 10;" text="View Faculty Courses" onAction="#loadViewFacultyCoursesView" wrapText="true">
<font>
<Font name="Times New Roman" size="13.0" />
</font>
Expand Down
59 changes: 59 additions & 0 deletions src/Views/ViewFacultyCoursesView.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Text?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controllers.ViewFacultyCoursesController">
<center>
<TableView fx:id="tableView" prefHeight="296.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="CRNColumn" prefWidth="75.0" text="CRN" />
<TableColumn fx:id="CourseIDColumn" prefWidth="75.0" text="Course ID" />
<TableColumn fx:id="courseNameColumn" prefWidth="75.0" text="Course Name" />
<TableColumn fx:id="TermColumn" prefWidth="75.0" text="Term" />
</columns>
</TableView>
</center>
<bottom>
<HBox alignment="CENTER" prefHeight="26.0" prefWidth="600.0" style="-fx-background-color: grey;" BorderPane.alignment="CENTER">
<children>
<Text fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0" text="Enter Faculty ID">
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</Text>
<TextField fx:id="tfFacultyID" alignment="CENTER" onMouseClicked="#ClearIfDefaultText" promptText="Faculty ID:" style="-fx-background-color: grey; -fx-text-fill: white;">
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</TextField>
<Button fx:id="searchButton" mnemonicParsing="false" onAction="#search" text="Search" textFill="WHITE">
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</Button>
</children>
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</HBox>
</bottom>
<top>
<HBox alignment="CENTER" prefHeight="32.0" prefWidth="600.0" style="-fx-background-color: grey;" BorderPane.alignment="CENTER">
<children>
<Text fx:id="textFacultyCourses" fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0" text="Faculty Courses " />
<Text fx:id="textInstructorName" fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0" text="">
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</Text>
</children>
</HBox>
</top>
</BorderPane>
Loading

0 comments on commit e527ab6

Please sign in to comment.