diff --git a/Student Registration System/bin/.gitignore b/Student Registration System/bin/.gitignore index 9e3c0d2..468b6b5 100644 --- a/Student Registration System/bin/.gitignore +++ b/Student Registration System/bin/.gitignore @@ -15,3 +15,6 @@ /MyGUI.class /client/ /server/ +/dino.css +/styler/ +/dinos.css diff --git a/Student Registration System/src/client/controller/ClientPort.class b/Student Registration System/src/client/controller/ClientPort.class index 4ba7ffa..bf1e909 100644 Binary files a/Student Registration System/src/client/controller/ClientPort.class and b/Student Registration System/src/client/controller/ClientPort.class differ diff --git a/Student Registration System/src/client/controller/ClientPort.java b/Student Registration System/src/client/controller/ClientPort.java index 2911fc9..1836212 100644 --- a/Student Registration System/src/client/controller/ClientPort.java +++ b/Student Registration System/src/client/controller/ClientPort.java @@ -20,17 +20,17 @@ public class ClientPort { * The socket connected to the server */ Socket socket; - + /** * Server input to the port */ ObjectInputStream serverIn; - + /** * Server output to the port */ ObjectOutputStream serverOut; - + /** * Create a new client app and connect to the port * @param portNumber @@ -41,7 +41,7 @@ public ClientPort(String serverName, int portNumber) try { socket = new Socket(serverName, portNumber); - + //Create input and output streams serverIn = new ObjectInputStream(socket.getInputStream()); serverOut = new ObjectOutputStream(socket.getOutputStream()); @@ -53,7 +53,7 @@ public ClientPort(String serverName, int portNumber) } } - + /** * Listens for a single response from the server, and responds accordingly. */ @@ -62,7 +62,7 @@ public Package readResponse() { { //Listen for info from the server Package pac = (Package)serverIn.readObject(); - + //Deal with the package return pac; } @@ -74,16 +74,16 @@ public Package readResponse() { // !! We may want to change this? Needed to include it to satisfy Java return null; } - + /** * Attempts to close everything. */ private void closeAll() { //Deal with ending the communication System.out.println("Ended comunication with server"); - + //Close everything - try + try { serverIn.close(); serverOut.close(); @@ -94,7 +94,7 @@ private void closeAll() { System.err.println("Error closing socket: " + e.getMessage()); } } - + /** * Sends a request for the catalog to be sent */ @@ -102,13 +102,13 @@ public CourseLite[] requestCatalogue() throws Exception { //Make package Package pac = new Package(PackageType.REQUESTCOURSECATALOGUE, null); - + //Send package sendPackage(pac); - + // Gets package Package resp = readResponse(); - + // Deals with response switch(resp.getType()) { case CATALOGUE: @@ -116,16 +116,16 @@ public CourseLite[] requestCatalogue() throws Exception if(catalogue==null) throw new Exception("The catalogue is empty."); return catalogue; - + //If theres an error return what kind of error it is case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server- unexpected type."); } } - + /** * Sends a request for the schedule to be sent */ @@ -133,32 +133,32 @@ public CourseLite[] requestSchedule() throws Exception { //Make package Package pac = new Package(PackageType.REQUESTSCHEDULE, null); - + //Send package sendPackage(pac); - + //Reads response Package resp = readResponse(); - + switch(resp.getType()) { case SCHEDULE: CourseLite[] schedule = (CourseLite[])resp.getData(); if(schedule==null) throw new Exception("Your schedule is empty."); return schedule; - + //If theres an error return what kind of error it is case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server- unexpected type"); } } - + /** - * Sends a login request with id and password. + * Sends a login request with id and password. * Throws an exception with a relevant message if login wasn't successful. * @param id Entered student's ID to check * @param password Entered password to check @@ -169,32 +169,33 @@ public String attemptLogin(int id, String password) throws Exception //Make package String[] info = {Integer.toString(id),password}; Package pac = new Package(PackageType.LOGINREQUEST, info); - + //Send message sendPackage(pac); - + //Reads response Package resp = readResponse(); - + switch(resp.getType()) { - + case LOGINRESULT: - + if(resp.getData() != null) return (String)resp.getData(); else throw new Exception("Login attempt unsuccessful"); - + //If theres an error return what kind of error it is case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server, login unsuccessful"); } - + } - + + /** * Sends a message to the server to remove a certain course from student * @param courseName @@ -205,32 +206,32 @@ public String removeCourse(String courseName, int courseNumber) throws Exception //Make package String[] info = {courseName,Integer.toString(courseNumber)}; Package pac = new Package(PackageType.REMOVECOURSE, info); - + //Send message sendPackage(pac); - + //Get response Package resp = readResponse(); - + switch(resp.getType()) { - + case COURSECHANGED: - + if(resp.getData() != null) return (String)resp.getData(); else throw new Exception("Error Removing course"); - + //If theres an error return what kind of error it is case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server, unexpected type"); } - + } - + /** * Sends a message to the server to add a certain course * @param courseName @@ -242,31 +243,31 @@ public String addCourse(String courseName, int courseNumber, int offeringSecNumb //Make package String[] info = {courseName,Integer.toString(courseNumber), Integer.toString(offeringSecNumber)}; Package pac = new Package(PackageType.ADDCOURSE, info); - + //Send message sendPackage(pac); - + //Get response Package resp = readResponse(); - + switch(resp.getType()) { - + case COURSECHANGED: - + if(resp.getData() != null) return (String)resp.getData(); else throw new Exception("Error Adding course"); - + //If theres an error return what kind of error it is case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server, unexpected type"); } } - + /** * Sends a message to the server to try and find a certain course * @param courseName @@ -278,31 +279,31 @@ public CourseLite findCourse(String courseName, int courseNumber) throws Excepti //Make package String[] info = {courseName,Integer.toString(courseNumber)}; Package pac = new Package(PackageType.FINDCOURSE, info); - + //Send message sendPackage(pac); - + //Get response Package resp = readResponse(); - - + + switch(resp.getType()) { case COURSE: CourseLite course = (CourseLite)resp.getData(); if(course==null) throw new Exception("No course found!"); return course; - + //If there is a error return the message case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server, unexpected type"); } - + } - + /** * Sends a message to the server to make a course * @param courseName @@ -315,32 +316,32 @@ public String makeCourse(String courseName, int courseNumber, int numberOfOfferi //Make package String[] info = {courseName,Integer.toString(courseNumber),Integer.toString(numberOfOfferings),Integer.toString(maxStudentsPerOffering)}; Package pac = new Package(PackageType.NEWCOURSE, info); - + //Send message sendPackage(pac); - + //Get response Package resp = readResponse(); - + switch(resp.getType()) { - + case COURSECHANGED: - + if(resp.getData() != null) return (String)resp.getData(); else throw new Exception("Error making course"); - + //If theres an error return what kind of error it is case ERROR: throw new Exception((String)resp.getData()); - + default: throw new Exception("Error communicating with server, unexpected type"); } - + } - + // !! This needs to be called by the GUI when logging out so the server is notified /** * Sends logout package to the server @@ -349,15 +350,15 @@ public void logout() { //Make package Package pac = new Package(PackageType.LOGOUT, null); - + //Send message sendPackage(pac); - + // !! Add functionality to get confirmation of success // !! as well as error messages if necessary - + } - + /** * Sends a message to be printed on the server * @param message @@ -366,11 +367,11 @@ public void sendMessage(String message) { //Make package Package pac = new Package(PackageType.MESSAGE, message); - + //Send message sendPackage(pac); } - + /** * Send the passed package to the server * @param pac the package diff --git a/Student Registration System/src/client/controller/Controller.class b/Student Registration System/src/client/controller/Controller.class index 1cacc65..aa8f4db 100644 Binary files a/Student Registration System/src/client/controller/Controller.class and b/Student Registration System/src/client/controller/Controller.class differ diff --git a/Student Registration System/src/client/controller/Controller.java b/Student Registration System/src/client/controller/Controller.java index 640992e..717120b 100644 --- a/Student Registration System/src/client/controller/Controller.java +++ b/Student Registration System/src/client/controller/Controller.java @@ -12,6 +12,7 @@ public class Controller { private MyGUI view; + private String studentName; private Model model; private ClientPort clientPort; @@ -34,20 +35,29 @@ public Controller(MyGUI view) { public void login(int id, String password) throws Exception { try{ // If this doesn't throw an exception, login is successful. - String name = clientPort.attemptLogin(id, password); + studentName = clientPort.attemptLogin(id, password); // Code to perform to complete login // !! Name should be displayed somewhere on GUI - System.out.println("Logged in as: " + name); + System.out.println("Logged in as: " + studentName); model = new Model(); - view.setStudentMenu(); + if(studentName.equals("Administration")){ + view.setAdminMenu(); + }else + view.setStudentMenu(); }catch(Exception e){ // Throws exception to tell GUI to display exception message. throw new Exception(e.getMessage()); } } - + + /** + * Returns the name of the student who is logged in + */ + public String getStudentName() { + return studentName; + } /** * Tells client port to try to find a course. Sets it to @@ -152,11 +162,11 @@ public void unenroll() { /** * Makes a new course */ - public void makeCourse() { + public void makeCourse(String name, int num, int offerings, int spots) { try { // !! Needs to have actual data put in - String message = clientPort.makeCourse("Temp",666, 2, 666); + String message = clientPort.makeCourse(name, num, offerings, spots); // !! This should be displayed on the GUI somewhere System.out.println(message); @@ -187,4 +197,19 @@ public CourseLite[] getCatalogue() { } + /** + * Set the offering based on the drop down selection + */ + public void setOffering(int num) { + model.setSelectedOffering(num); + } + /** + * Check whether or not the student is enrolled in the course + * @return + */ + public boolean checkEnrolment() { + // TODO Auto-generated method stub + return model.getSelectedCourse().isStudentEnrolled(); + } + } diff --git a/Student Registration System/src/client/model/Model.class b/Student Registration System/src/client/model/Model.class index 9d7354b..908e49f 100644 Binary files a/Student Registration System/src/client/model/Model.class and b/Student Registration System/src/client/model/Model.class differ diff --git a/Student Registration System/src/client/model/Model.java b/Student Registration System/src/client/model/Model.java index adffd39..9fcb1ed 100644 --- a/Student Registration System/src/client/model/Model.java +++ b/Student Registration System/src/client/model/Model.java @@ -6,13 +6,17 @@ public class Model { CourseLite selectedCourse; - int selectedOffering; + int selectedOffering = 1; CourseLite[] catalogue; public void setSelectedCourse(CourseLite c){ - selectedCourse = c; - selectedOffering = c.getOfferingSecNumber(0); + selectedCourse = c; + } + + public void setSelectedOffering(int num) { + selectedOffering = num; + //System.out.println("Course offering is: " + selectedOffering + " with " + selectedCourse.getOfferingTotalSpots(selectedOffering-1) + " spots"); } public String getSelectedCourseName(){ @@ -32,7 +36,7 @@ public int getSecNumber() { } public String getSelectedCourseSpots() { - return selectedCourse.getOfferingTakenSpots(selectedOffering) + "/" + selectedCourse.getOfferingTotalSpots(selectedOffering); + return selectedCourse.getOfferingTakenSpots(selectedOffering-1) + "/" + selectedCourse.getOfferingTotalSpots(selectedOffering-1); } public void setCatalogue(CourseLite[] catalogue) { diff --git a/Student Registration System/src/client/view/MyGUI.class b/Student Registration System/src/client/view/MyGUI.class index 89c0b52..18e714a 100644 Binary files a/Student Registration System/src/client/view/MyGUI.class and b/Student Registration System/src/client/view/MyGUI.class differ diff --git a/Student Registration System/src/client/view/MyGUI.java b/Student Registration System/src/client/view/MyGUI.java index c42f1db..3d23e0d 100644 --- a/Student Registration System/src/client/view/MyGUI.java +++ b/Student Registration System/src/client/view/MyGUI.java @@ -1,4 +1,5 @@ package client.view; +import java.util.ArrayList; import java.util.Optional; import java.util.ResourceBundle.Control; @@ -10,6 +11,7 @@ // JAVAFX IMPORTS import javafx.application.Application; +import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; @@ -20,6 +22,7 @@ import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.ListView; +import javafx.scene.control.PasswordField; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; @@ -43,10 +46,11 @@ * searched for one course and the information is displayed, is you try searching for another * it just writes the label on top of the first one rather than replacing it. * Main things that need to be added are: - * 1. Sending the student information to the server and checking whether or not it is valid - * 2. once you confirm they are a student, reading their information about their schedule and name - * 3. adding/removing new courses to their schedule once the button enroll/unenroll is clicked then updating the courseList to display - * 4. adding information to the course catalogue + * + * + * ADMIN + * 3. allow admin to create a new courses (# of offerings, spots per offering, prerequisites) // EVERYTHING WORKING EXCEPT ADDING PREREQS + * * @author Taylor * */ @@ -57,9 +61,8 @@ public class MyGUI extends Application{ Stage window; Scene login, studentScene, adminScene, studentMenu; - int width = 700; - int height = 300; - VBox rightPanel; + int width = 1200; + int height = 800; @@ -89,17 +92,13 @@ public void start(Stage primaryStage) { //Layout 1 - Main window where user chooses between // Student and Admin login = new Scene(optionScene(), width, height); + login.getStylesheets().add("dinos.css"); //Layout 2 - Main Login window for Students where they // are prompted to input their id and password studentScene = new Scene(studentLogin(), width, height); + studentScene.getStylesheets().add("dinos.css"); - //Layout 3 - Admin's main window (INCOMPLETE) - adminScene = new Scene(adminLogin(), width, height); - - //Layout 4 - Student's main window with course search, - // their schedule, and where they can enroll in courses - //studentMenu = new Scene(studentMenu(), width, height); window.setScene(login); window.show(); @@ -116,6 +115,7 @@ public void start(Stage primaryStage) { private VBox makeLayout() { VBox layout = new VBox(); layout.setPadding(new Insets(10,10,10,10)); + layout.setSpacing(15); return layout; } /** @@ -130,7 +130,8 @@ private VBox optionScene() { //University of Calgary Title Label title = new Label("University of Calgary"); - + title.setId("bold-label"); + //Student Button Button student = new Button(); student.setText("Sign In"); @@ -139,7 +140,7 @@ private VBox optionScene() { //Admin Button Button admin = new Button(); admin.setText("Admin"); - admin.setOnAction(e -> window.setScene(adminScene)); + admin.setOnAction(e -> adminScene()); //HBox for the buttons so they are on the same line HBox buttons = new HBox(); @@ -160,10 +161,10 @@ private VBox optionScene() { */ private VBox studentLogin() { VBox layout = makeLayout(); - layout.setSpacing(50); HBox topPanel = new HBox(); VBox centrePanel = new VBox(); centrePanel.setSpacing(10); + centrePanel.setMinHeight(height); centrePanel.setAlignment(Pos.CENTER); //Student Id Block @@ -172,6 +173,7 @@ private VBox studentLogin() { idBlock.setAlignment(Pos.CENTER); Label idLabel = new Label("Student ID"); TextField idText = new TextField(); + idText.setId("text-input"); idBlock.getChildren().addAll(idLabel,idText); //Student Password Block @@ -179,7 +181,8 @@ private VBox studentLogin() { passwordBlock.setSpacing(10); passwordBlock.setAlignment(Pos.CENTER); Label passwordLabel = new Label("Password"); - TextField passwordText = new TextField(); + PasswordField passwordText = new PasswordField(); + passwordText.setId("text-input"); passwordBlock.getChildren().addAll(passwordLabel, passwordText); //Login Response Label @@ -213,58 +216,66 @@ private VBox studentLogin() { */ private VBox studentMenu() { VBox layout = makeLayout(); - layout.setSpacing(15); - HBox title = new HBox(); - title.setSpacing(220); - HBox panels = new HBox(); - panels.setSpacing(200); - VBox leftPanel = new VBox(); - leftPanel.setSpacing(10); - rightPanel = new VBox(); - rightPanel.setSpacing(10); - panels.getChildren().addAll(leftPanel, rightPanel); + HBox title = setTitle(); + HBox panels = setPanels(setLeftPanel(), setRightPanel()); - //Schedule List - ListView courseList = new ListView<>(); - fillCourses(courseList); - - //Welcome label - Label welcome = new Label("Welcome"); // Later, add name of student here - - //Log Out Button - Button logoutButton = new Button(); - logoutButton.setText("Log Out"); - logoutButton.setOnAction(e -> window.setScene(login)); + //Adding all the components to the layout + layout.getChildren().addAll(title, panels); - //Browse Catalogue Button - Button browse = new Button(); - browse.setText("Browse Catalogue"); - browse.setOnAction(e -> browseCatalogue()); - title.getChildren().addAll(welcome, browse, logoutButton); - title.setAlignment(Pos.CENTER); - - //View Courses search - Label courseLabel = new Label("View Course"); // later, add name of student here + return layout; - HBox searchPanel = new HBox(); - searchPanel.setSpacing(10); - TextField searchTag = new TextField("search for a course"); - Button search = new Button(); - search.setText("Search"); - search.setOnAction(e -> courseDisplay(searchTag, leftPanel)); - searchPanel.getChildren().addAll(searchTag, search); - leftPanel.getChildren().addAll(courseLabel, searchPanel); - - //Schedule Display - Label schedule = new Label("Your Schedule"); - rightPanel.getChildren().addAll(schedule, courseList); + } + + /** + * Shows the course display of a certain course + * @param courseName Name of the course + */ + private VBox courseDisplay(TextField courseName, int num) { + VBox layout = makeLayout(); + HBox title = setTitle(); + + VBox leftPanel = setLeftPanel(); + + HBox panels = setPanels(leftPanel, setRightPanel()); + + String input = courseName.getText(); + control.selectCourse(splitCName(input), splitCNumber(input)); + + HBox courseInfo = new HBox(); + courseInfo.setAlignment(Pos.CENTER); + courseInfo.setSpacing(10); + + //Lecture Drop-Down + ChoiceBox lectures = new ChoiceBox<>(); + for(int i = 0; i < control.getSelectedCourseOfferings();) { + lectures.getItems().add("Lecture " + (++i)); + } + + lectures.setValue("Lecture " + num); // default value + + //Listen for selection changes + lectures.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> changeOffering(newValue, courseName)); + + //Course Name Label + Label course = new Label(control.getSelectedCourseName()); + + courseInfo.getChildren().addAll(course, lectures); + + //Spots Available + Label spots = new Label("Spots: " + control.getSelectedCourseSpots()); + + //Enroll/Unenroll + Button enroll = new Button(); + enroll.setText("Enroll/Unenroll"); + enroll.setAlignment(Pos.CENTER); + enroll.setOnAction(e -> changeCourseEnrollment()); + + leftPanel.getChildren().addAll(courseInfo, spots, enroll); - //Adding all the components to the layout layout.getChildren().addAll(title, panels); return layout; - } @@ -278,23 +289,16 @@ private VBox adminLogin() { layout.setSpacing(50); HBox topPanel = new HBox(); VBox centrePanel = new VBox(); + centrePanel.setMinHeight(height - 100); centrePanel.setSpacing(10); centrePanel.setAlignment(Pos.CENTER); - //Student Id Block - HBox idBlock = new HBox(); - idBlock.setSpacing(10); - idBlock.setAlignment(Pos.CENTER); - Label idLabel = new Label("Username"); - TextField idText = new TextField(); - idBlock.getChildren().addAll(idLabel,idText); - - //Student Password Block + // Password Block HBox passwordBlock = new HBox(); passwordBlock.setSpacing(10); passwordBlock.setAlignment(Pos.CENTER); Label passwordLabel = new Label("Password"); - TextField passwordText = new TextField(); + PasswordField passwordText = new PasswordField(); passwordBlock.getChildren().addAll(passwordLabel, passwordText); //Login Response Label @@ -304,7 +308,7 @@ private VBox adminLogin() { Button loginButton = new Button(); loginButton.setText("Login"); loginButton.setOnAction(e -> { - loginStudent(idText, passwordText, loginResponse); + loginAdmin(passwordText, loginResponse); //!! MAKE FUNCTION }); //Go Back Button @@ -313,13 +317,56 @@ private VBox adminLogin() { goBack1.setOnAction(e -> window.setScene(login)); topPanel.getChildren().add(goBack1); - centrePanel.getChildren().addAll(idBlock, passwordBlock, loginButton, loginResponse); + centrePanel.getChildren().addAll(passwordBlock, loginButton, loginResponse); //Adding all the components to the layout layout.getChildren().addAll(topPanel, centrePanel); return layout; } + + /** + * ADMIN main menu + */ + private VBox adminMenu() { + VBox layout = makeLayout(); + + HBox title = new HBox(); + title.setSpacing(width*3/5); + + //Welcome label + Label welcome = new Label("Welcome, " + control.getStudentName()); + + //Log Out Button + Button logoutButton = new Button(); + logoutButton.setText("Log Out"); + logoutButton.setOnAction(e -> window.setScene(login)); + + title.getChildren().addAll(welcome, logoutButton); + + + VBox left = panelSetUp(); + VBox right = panelSetUp(); + HBox panels = new HBox(left, right); + + //Course Catalogue Label + Label catalogue = new Label(); + catalogue.setText("Course Catalogue"); + right.getChildren().addAll(catalogue, buildTable()); + + //Add a new course + Button newCourse = new Button("Add New Course"); + newCourse.setOnAction(e -> addCourseWindow()); + + left.getChildren().addAll(newCourse); + + //Adding all the components to the layout + layout.getChildren().addAll(title, panels); + + return layout; + + } + @@ -327,8 +374,97 @@ private VBox adminLogin() { /////////// END OF GRID PANES ////////////////////////////////// + /** + * add the welcome, logout button and browse button to the top panel + */ + private HBox setTitle() { + HBox title = new HBox(); + title.setSpacing(200); + + //Welcome label + Label welcome = new Label("Welcome, " + control.getStudentName()); + + //Log Out Button + Button logoutButton = new Button(); + logoutButton.setText("Log Out"); + logoutButton.setOnAction(e -> window.setScene(login)); + + //Browse Catalogue Button + Button browse = new Button(); + browse.setText("Browse Catalogue"); + browse.setOnAction(e -> browseCatalogue()); + title.getChildren().addAll(welcome, browse, logoutButton); + title.setAlignment(Pos.CENTER); + + return title; + } + /** + * add the course search to the left panel + * @return + */ + private VBox setLeftPanel() { + VBox leftPanel = panelSetUp(); + + //View Courses search + Label courseLabel = new Label("View Course"); + + HBox searchPanel = new HBox(); + searchPanel.setAlignment(Pos.CENTER); + searchPanel.setSpacing(10); + TextField searchTag = new TextField("search for a course"); + Button search = new Button("Search"); + search.setOnAction(e -> activateSearch(searchTag)); + searchPanel.getChildren().addAll(searchTag, search); + leftPanel.getChildren().addAll(courseLabel, searchPanel); + + return leftPanel; + } + /** + * Set up that can be used for panels, such as the left and right ones in the courseDisplay + * @return + */ + private VBox panelSetUp() { + VBox panel = new VBox(); + panel.setSpacing(10); + panel.setMinWidth(width/2); + panel.setPadding(new Insets(20,20,20,20)); + panel.setAlignment(Pos.TOP_CENTER); + return panel; + } - + /** + * add the schedule to the right panel + * @return + */ + private VBox setRightPanel() { + VBox rightPanel = panelSetUp(); + + //Schedule List + ListView courseList = new ListView<>(); + fillCourses(courseList); + courseList.setMaxWidth(width/2 - 100); + courseList.setMaxHeight(250); + + + //Schedule Display + Label schedule = new Label("Your Schedule"); + rightPanel.getChildren().addAll(schedule, courseList); + + return rightPanel; + } + /** + * add the left and right panel to the centre panel + * @param leftPanel + * @param rightPanel + * @return + */ + private HBox setPanels(VBox leftPanel, VBox rightPanel) { + HBox panels = new HBox(); + panels.setPadding(new Insets(10,10,10,10)); + panels.getChildren().addAll(leftPanel, rightPanel); + + return panels; + } /** @@ -353,9 +489,12 @@ private void loginStudent(TextField inputID, TextField inputPass, Label response responseLabel.setText(e.getMessage()); } } - + /** + * change the window to the student menu + */ public void setStudentMenu() { - window.setScene(new Scene (studentMenu(), width, height)); + Scene scene = new Scene(studentMenu(), width, height); + styleAndSwitch(scene); } /** @@ -377,74 +516,24 @@ private int splitCNumber(String courseName) { } /** - * Shows the course display of a certain course - * @param courseName Name of the course + * Splits course offering from string + * @param courseName + * @return course number */ - private void courseDisplay(TextField courseName, VBox leftPanel) { - - String input = courseName.getText(); - control.selectCourse(splitCName(input), splitCNumber(input)); - - HBox courseInfo = new HBox(); - courseInfo.setSpacing(10); - - //Lecture Drop-Down - ChoiceBox lectures = new ChoiceBox<>(); - for(int i = 0; i < control.getSelectedCourseOfferings();) - lectures.getItems().add("Lecture " + (++i)); - - lectures.setValue("Lecture 1"); // default value - - //Course Name Label - Label course = new Label(control.getSelectedCourseName()); - - courseInfo.getChildren().addAll(course, lectures); - - //Spots Available - Label spots = new Label("Spots: " + control.getSelectedCourseSpots()); - - //Course Pre-Requisites - Label preReqs = new Label("Pre-Requisites: "); - - //Other Available - Label other = new Label("Other: "); - - HBox buttons = new HBox(); - buttons.setSpacing(15); - - //Enroll/Unenroll - Button enroll = new Button(); - enroll.setText("Enroll/Unenroll"); - enroll.setOnAction(e -> changeCourseEnrollment()); - - //Search new Course - Button searchNew = new Button(); - searchNew.setText("Search New Course"); - searchNew.setOnAction(e -> window.setScene(new Scene(studentMenu(), width, height))); - - buttons.getChildren().addAll(enroll, searchNew); - - leftPanel.getChildren().addAll(courseInfo, spots, preReqs, buttons); - } - - private Boolean checkUnenrollment() { - CourseLite [] courses = control.getSchedule(); - if(courses != null) { - for(int i = 0; i < courses.length; i++) { - if(courses[i] == control.getSelectedCourse()) { - control.unenroll(); - System.out.println("UNENROLLED"); - return true; - } - }} - return false; + private int splitCOffering(String courseName) { + return Integer.parseInt(courseName.split(" ")[3]); } - + + /** + * Checks to see if the student is enrolled and unenrolls is they are, otherwise enrolls them in the course. + */ private void changeCourseEnrollment() { - Boolean check = checkUnenrollment(); - if(check == false) + if(control.checkEnrolment()) + control.unenroll(); + else control.enroll(); - window.setScene(new Scene (studentMenu(), width, height)); + Scene scene = new Scene (studentMenu(), width, height); + styleAndSwitch(scene); } /** * Gets the student's schedule from the controller and then fills a ListView in order @@ -455,9 +544,26 @@ private void fillCourses(ListView courseList){ CourseLite [] courses = control.getSchedule(); if(courses != null) { for(int i = 0; i < courses.length; i++) { - courseList.getItems().add(courses[i].getName() + " " + courses[i].getNumber()); + courseList.getItems().add(courses[i].getName() + " " + courses[i].getNumber() + " Section: " + courses[i].getEnrolledSectionNumber()); } } + courseList.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> changeView(newValue)); + } + + /** + * based on clicking a course in your schedule, change the left side of the screen to display the information + * @param value + */ + private void changeView(String value) { + String courseName = splitCName(value); + int courseNum = splitCNumber(value); + TextField course = new TextField(); + course.setText(courseName + " " + courseNum); + int num = splitCOffering(value); + control.setOffering(num); + + Scene scene = new Scene(courseDisplay(course, num), width, height); + styleAndSwitch(scene); } @@ -473,12 +579,26 @@ public void browseCatalogue() { VBox layout = new VBox(); + layout.getChildren().addAll(buildTable()); + + Scene scene = new Scene(layout); + scene.getStylesheets().add("dinos.css"); + catalogue.setScene(scene); + catalogue.showAndWait(); + + } + /** + * build the course catalogue table + * @return + */ + private TableView buildTable(){ ObservableList courses = FXCollections.observableArrayList(); if(control.getCatalogue() != null) { for(CourseLite c: control.getCatalogue()) { courses.add(c); } } + TableView table; TableColumn nameCol = new TableColumn<>("Course"); @@ -490,18 +610,152 @@ public void browseCatalogue() { TableColumn offeringsCol = new TableColumn<>("Number of Offerings"); offeringsCol.setCellValueFactory(new PropertyValueFactory<>("offeringCount")); - table = new TableView<>(); - table.setItems(courses); + + table = new TableView<>(courses); + table.setMinWidth(width/2 - 100); + table.setMinHeight(height - 200); + numberCol.setMinWidth(table.getMinWidth()/2); + offeringsCol.setMinWidth(table.getMinWidth()/2); table.getColumns().addAll(nameCol, numberCol, offeringsCol); + return table; + } + /** + * Change the offering based on lecture drop down + * !! NEEDS TO BE FIXED + * @param offering + * @param courseName + */ + private void changeOffering(String offering, TextField courseName) { + int num = splitCNumber(offering); + control.setOffering(num); + + Scene scene = new Scene(courseDisplay(courseName, num), width, height); + styleAndSwitch(scene); + } + + /** + * Log an admin in based on if the password is correct + * @param inputPass Password inputted by user + * @param responseLabel + */ + private void loginAdmin(TextField inputPass, Label responseLabel) { + try { + String password = inputPass.getText(); + inputPass.clear(); + control.login(0, password); + System.out.println("Passed control"); + + }catch(NumberFormatException e) { + responseLabel.setText("Invalid username entered! Please enter a student ID!"); + }catch(Exception e) { + // Sets the response label to an appropriate message based on issue + // Note: incomplete + responseLabel.setText(e.getMessage()); + } + + } + /** + * change the window to the administration menu + */ + public void setAdminMenu() { + Scene scene = new Scene(adminMenu(), width, height); + styleAndSwitch(scene); + } + + /** + * From admin, add course to the catalogue. + * asks user for # of offerings, spots per offering, prerequisites + * @return + */ + private void addCourseWindow() { + Stage newCourse = new Stage(); + + newCourse.initModality((Modality.APPLICATION_MODAL)); + newCourse.setTitle("Add New Course"); + + VBox layout = new VBox(); + layout.setPadding(new Insets(10,10,10,10)); + layout.setSpacing(10); + layout.setAlignment(Pos.CENTER); + + //Course name + HBox codeBlock = new HBox(); + codeBlock.setSpacing(10); + Label codeLabel = new Label("Course Code"); + TextField codeText = new TextField(); + codeBlock.getChildren().addAll(codeLabel, codeText); + + //number of offerings + HBox offeringsBlock = new HBox(); + offeringsBlock.setSpacing(10); + Label offeringsLabel = new Label("Number of Offerings"); + TextField offeringsText = new TextField(); + offeringsBlock.getChildren().addAll(offeringsLabel, offeringsText); + + //number of spots per offering + HBox spotsBlock = new HBox(); + spotsBlock.setSpacing(10); + Label spotsLabel = new Label("Number of Spots"); + TextField spotsText = new TextField(); + spotsBlock.getChildren().addAll(spotsLabel, spotsText); + + + HBox first = new HBox(); + first.setSpacing(10); + first.setAlignment(Pos.CENTER); + first.getChildren().add(codeBlock); + + HBox second = new HBox(); + second.setSpacing(10); + second.setAlignment(Pos.CENTER); + second.getChildren().addAll(offeringsBlock, spotsBlock); + + Button commit = new Button("Commit"); + commit.setOnAction(e -> addCourse(codeText, offeringsText, spotsText, newCourse)); - layout.getChildren().addAll(table); + + layout.getChildren().addAll(first, second, commit); Scene scene = new Scene(layout); - catalogue.setScene(scene); - catalogue.showAndWait(); + scene.getStylesheets().add("dinos.css"); + newCourse.setScene(scene); + newCourse.showAndWait(); + } + /** + * commit the new course to the catalogue + */ + private void addCourse(TextField course, TextField offering, TextField spot, Stage win) { + control.makeCourse(splitCName(course.getText()), splitCNumber(course.getText()), Integer.parseInt(offering.getText()), Integer.parseInt(spot.getText())); + setAdminMenu(); + win.close(); } - + + /** + * change the screen based on searching for a new course + * @param searchTag + */ + public void activateSearch(TextField searchTag) { + control.setOffering(1); + Scene scene = new Scene(courseDisplay(searchTag, 1), width, height); + styleAndSwitch(scene); + + } + /** + * make whichever scene passed adopt the style from dinos.css + * @param scene + */ + public void styleAndSwitch(Scene scene) { + scene.getStylesheets().add("dinos.css"); + window.setScene(scene); + } + /** + * switch to admin login + */ + public void adminScene() { + Scene scene = new Scene(adminLogin(), width, height); + styleAndSwitch(scene); + } } diff --git a/Student Registration System/src/dinos.css b/Student Registration System/src/dinos.css new file mode 100644 index 0000000..6b7acfb --- /dev/null +++ b/Student Registration System/src/dinos.css @@ -0,0 +1,27 @@ +.root{ + -fx-background-color: #383838; + -fx-font-size: 15pt; +} +.label{ + -fx-text-fill: #E8E8E8; +} +.button{ + -fx-background-color: linear-gradient(#DC9656, #AB4642); + -fx-text-fill: #FFFFFF; + -fx-background-radius: 4; +} +.choice-box>.label,{ + -fx-text-fill: #000000; +} +.table-view .column-header .label { + -fx-text-fill: black; +} + +#bold-label{ + -fx-font-size: 20pt; + -fx-font-weight: bold; +} +#text-input{ + -fx-font-size: 12pt; + -fx-text-fill: #000000; +} \ No newline at end of file diff --git a/Student Registration System/src/server/controller/RegistrationApp.class b/Student Registration System/src/server/controller/RegistrationApp.class index 837df4a..8f6c517 100644 Binary files a/Student Registration System/src/server/controller/RegistrationApp.class and b/Student Registration System/src/server/controller/RegistrationApp.class differ diff --git a/Student Registration System/src/server/controller/RegistrationApp.java b/Student Registration System/src/server/controller/RegistrationApp.java index 4797165..de790c8 100644 --- a/Student Registration System/src/server/controller/RegistrationApp.java +++ b/Student Registration System/src/server/controller/RegistrationApp.java @@ -241,6 +241,7 @@ public String validateStudent(int id, String password) throws Exception{ } } } + /** * Removes the selected student diff --git a/Student Registration System/src/server/controller/ServerApp.class b/Student Registration System/src/server/controller/ServerApp.class index 5d2c125..561b74c 100644 Binary files a/Student Registration System/src/server/controller/ServerApp.class and b/Student Registration System/src/server/controller/ServerApp.class differ diff --git a/Student Registration System/src/server/controller/ServerApp.java b/Student Registration System/src/server/controller/ServerApp.java index 181ffe5..43afd2d 100644 --- a/Student Registration System/src/server/controller/ServerApp.java +++ b/Student Registration System/src/server/controller/ServerApp.java @@ -119,8 +119,7 @@ private void dealWithPackage(Package pac) //Check if valid and return the result sendLoginResult(l); break; - - + //Add a course to the student case ADDCOURSE: System.out.println("Client " + clientNumber + ": Received Add Course"); diff --git a/Student Registration System/src/server/model/.gitignore b/Student Registration System/src/server/model/.gitignore new file mode 100644 index 0000000..ca44b08 --- /dev/null +++ b/Student Registration System/src/server/model/.gitignore @@ -0,0 +1 @@ +/Admin.class diff --git a/Student Registration System/src/server/model/DBManager.class b/Student Registration System/src/server/model/DBManager.class index 583c109..a8bb5b6 100644 Binary files a/Student Registration System/src/server/model/DBManager.class and b/Student Registration System/src/server/model/DBManager.class differ diff --git a/Student Registration System/src/server/model/DBManager.java b/Student Registration System/src/server/model/DBManager.java index 0ddb621..577eafa 100644 --- a/Student Registration System/src/server/model/DBManager.java +++ b/Student Registration System/src/server/model/DBManager.java @@ -24,6 +24,7 @@ public class DBManager { public DBManager () { courseList = new ArrayList(); studentList = new ArrayList(); + studentList.add(new Student("Administration", 0, "300")); } /** @@ -160,5 +161,5 @@ public void printAllStudents() { System.out.println(s); } } - + }