diff --git a/README.md b/README.md index 3ef86f083e9877c4b0421316737e56099e279c28..53b05deb126e3f710998563729953d6ff2fe1fb3 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,12 @@ To run the scheduling app properly you must have the database running and the se How to set up the MySQL database: - - Download and run the MySQL Installer, make sure that MySQL Server is installed (optionally install MySQL Workbench). - - Create a MySQL server and with whatever host address you like and an available port. If your running it locally than you can keep it these values as default. - - In MySQL open the sql file "ScheduleApp.sql" and execute the following commands: + - Download and run the MySQL Installer, make sure that MySQL Server is installed + (optionally install MySQL Workbench). + - Create a MySQL server and with whatever host address you like and an available + port. If your running it locally than you can keep it these values as default. + - In MySQL open the sql file "ScheduleApp.sql" and execute the following + commands: * create database ScheduleApp; * use ScheduleApp; * create table Employees( @@ -24,6 +27,9 @@ How to set up the MySQL database: PRIMARY KEY (shift_id), FOREIGN KEY (employee_ID) REFERENCES Employees(employee_ID) ); - - Open the 'server' tab at the top and select 'server status', and make sure that the server status is 'Running' + - Open the 'server' tab at the top and select 'server status', and make sure that + the server status is 'Running' -How to set up the Scheduling Server: \ No newline at end of file +How to set up the Scheduling Server: + + - \ No newline at end of file diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/Controller.java b/SchedulerApp/src/main/java/com/example/schedulerapp/Controller.java index 24da01c760f8102901804951e2d6200526d2dac2..61e8ae86b613a0f2d8d9fa73c05143b1a74382eb 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/Controller.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/Controller.java @@ -57,7 +57,6 @@ public class Controller { Stage popupStage; Scene popupScene; - RafisWeirdClass rafisWeirdClass = new RafisWeirdClass(); Model model = new Model("10.237.93.139" ,8989); DailyView dailyView; WeeklyView weeklyView; diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/Model.java b/SchedulerApp/src/main/java/com/example/schedulerapp/Model.java index 5c7b2d0ea24a9b1ca3151aa98820d34c9a2e0e66..ac4f3ed9a9653c782a10a9b7bc7f18df2081d86d 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/Model.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/Model.java @@ -135,6 +135,10 @@ public class Model { writer.println("removeShift/"+shiftID); } + void editShift(int shiftID, String day, int start, int end) { + writer.println("editShift/"+shiftID+"/"+day+"/"+start+"/"+end); + } + void printAllShifts() { System.out.println(this.shifts); } diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/RafisWeirdClass.java b/SchedulerApp/src/main/java/com/example/schedulerapp/RafisWeirdClass.java index dca7c52769b4c395f59ef3c5141d70ea4fd19a68..b69704eccd3a03a532f5af2d904fbda56dfd76cd 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/RafisWeirdClass.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/RafisWeirdClass.java @@ -6,18 +6,15 @@ public class RafisWeirdClass { protected Staff staff; protected Schedule schedule; private Connection dbConnection; - private final String dbURL = "jdbc:mysql://localhost:3306/ScheduleApp"; - private final String dbUser = "root"; - private final String dbPass = "password"; - public RafisWeirdClass(){ - connectDataBase(); + public RafisWeirdClass(String dbURL, String dbUser, String dbPass){ + connectDataBase(dbURL, dbUser, dbPass); this.staff = new Staff(dbConnection); this.schedule = new Schedule(dbConnection); } - protected String connectDataBase(){ + protected String connectDataBase(String dbURL, String dbUser, String dbPass){ try { dbConnection = DriverManager.getConnection(dbURL, dbUser, dbPass); } catch (Exception e) { @@ -28,12 +25,5 @@ public class RafisWeirdClass { } public static void main(String[] args) { - RafisWeirdClass rafisWeirdClass = new RafisWeirdClass(); - rafisWeirdClass.schedule.addShift(3, "2022-03-10", 1200, 2100); - /* Testing stuff that should be cleaned up for the alpha - String s = model.staff.getEmployees(); - System.out.println(); - - */ } } diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/Schedule.java b/SchedulerApp/src/main/java/com/example/schedulerapp/Schedule.java index 777aeb62fcaed44449ab0b2056d84ed261cb4352..5b0b46a04a0a8f48f3df8ce730a6652564fb9396 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/Schedule.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/Schedule.java @@ -31,39 +31,30 @@ public class Schedule { e.printStackTrace(); } } + /* - Name: removeShift + Name: removeShiftByID Parameters: - int ID: The employees unique ID. - Date: The date as a string in the form of "yyyy-mm-dd". - start: The employees shift start time. - end: The employees shift end time. - Description: Removes the employees shift matching the date, and shift duration. + int shiftID: The shift unique ID. + Description: Removes the employees shift matching the shift date. Return: none */ - protected void removeShift(String ID, String date, int start, int end){ - Date newDate = Date.valueOf(date); + protected void removeShiftByID(String shiftID){ try { Statement myStatement = dbConnection.createStatement(); - myStatement.executeUpdate("DELETE FROM shifts WHERE (employee_id =" + ID + ") " + - "AND WHERE (date = " + newDate +") AND WHERE (start_time = " + start + " ) " + - "AND WHERE (end_time = " + end +")"); + myStatement.executeUpdate("DELETE FROM shifts WHERE (shift_id =" + shiftID + ")"); } catch (SQLException e) { e.printStackTrace(); } } - /* - Name: removeShiftByID - Parameters: - int shiftID: The shift unique ID. - Description: Removes the employees shift matching the shift date. - Return: none - */ - protected void removeShiftByID(String shiftID){ + protected void editShift(Integer shift_id, String date, String start,String end){ + Date newDate = Date.valueOf(date); + System.out.println(newDate); try { Statement myStatement = dbConnection.createStatement(); - myStatement.executeUpdate("DELETE FROM shifts WHERE (shift_id =" + shiftID + ")"); + myStatement.executeUpdate("update shifts set full_date='" + newDate + "',start_time=" + start + ",end_time=" + end + + " where shift_id=" + shift_id); } catch (SQLException e) { e.printStackTrace(); } diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/ScheduleServer.java b/SchedulerApp/src/main/java/com/example/schedulerapp/ScheduleServer.java index 36eaecfdec50815abf58ba2b2e50891f4aee27b4..c14513e8b96f1c26752989864b23c8b3540d8796 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/ScheduleServer.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/ScheduleServer.java @@ -10,10 +10,10 @@ public class ScheduleServer { private final String ip; private final Set<UserThread> userThreads = new HashSet<>(); // notify when there are changes - public ScheduleServer(String ip, int port) { + public ScheduleServer(String ip, int port, String dbURL, String dbUser, String dbPass) { this.ip = ip; this.port = port; - this.rafisWeirdClass = new RafisWeirdClass(); + this.rafisWeirdClass = new RafisWeirdClass(dbURL, dbUser, dbPass); } public void execute() { @@ -46,7 +46,8 @@ public class ScheduleServer { public static void main(String[] args) { //Set "localhost" is working locally. Razer-Blade lan address (NOT static) is "172.16.1.99" - ScheduleServer server = new ScheduleServer("10.237.93.139", 8989); + ScheduleServer server = new ScheduleServer("10.237.93.139", 8989, + "jdbc:mysql://localhost:3306/ScheduleApp", "root", "password"); server.execute(); } } diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/Staff.java b/SchedulerApp/src/main/java/com/example/schedulerapp/Staff.java index 36dc181b963c28a823760327d251382b90e50da6..9240a8df45747eb8444926a523a1ea662736226c 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/Staff.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/Staff.java @@ -52,6 +52,7 @@ public class Staff { protected void removeEmployee(int ID){ try { Statement myStatement = dbConnection.createStatement(); + myStatement.executeUpdate("DELETE FROM shifts WHERE (employee_ID =" + ID + ")"); myStatement.executeUpdate("delete from Employees where employee_id = " + ID); } catch (Exception e) { System.out.println(e.fillInStackTrace()); diff --git a/SchedulerApp/src/main/java/com/example/schedulerapp/UserThread.java b/SchedulerApp/src/main/java/com/example/schedulerapp/UserThread.java index c9aba617dda1dbef38d5d456013fc112b734f02b..a55c56140a430d74ea4e4d471c9bfaa4bc11c49a 100644 --- a/SchedulerApp/src/main/java/com/example/schedulerapp/UserThread.java +++ b/SchedulerApp/src/main/java/com/example/schedulerapp/UserThread.java @@ -58,6 +58,15 @@ public class UserThread extends Thread { System.out.println("Client Message Error: " + clientMessage); } break; + case "editShift": + try { + rafisWeirdClass.schedule.editShift(Integer.parseInt(args[1]), args[2], args[3], args[4]); + serverMessage = rafisWeirdClass.schedule.allShifts(); + server.broadcast(serverMessage); + } catch (NumberFormatException e) { + System.out.println("Client Message Error: " + clientMessage); + } + break; case "addShift": try { rafisWeirdClass.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4]));