Skip to content
Snippets Groups Projects
Commit e086eb89 authored by Rafi's avatar Rafi
Browse files

Added a remove all shifts by employee id method to the Schedule class. Now...

Added a remove all shifts by employee id method to the Schedule class. Now when an employee is removed there shifts are deleted first from the database then they're deleted after.
parent 881dde2b
No related branches found
No related tags found
1 merge request!6Changed update implementation for employees so rather than sending the whole...
...@@ -90,6 +90,23 @@ public class Schedule { ...@@ -90,6 +90,23 @@ public class Schedule {
return editedShift; return editedShift;
} }
/*
Name: removeAllShiftsByID
Parameters:
intI ID: Employee ID
Description: Removes all shifts in the database for a specific employee
Return: void
*/
protected void removeAllShiftsByID(int ID) {
try {
Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("DELETE FROM shifts WHERE (employee_ID =" + ID + ")");
} catch (SQLException exception) {
System.out.println("Error removing all shifts by id.");
exception.printStackTrace();
}
}
/* /*
Name: allShifts Name: allShifts
Parameters: Parameters:
......
...@@ -60,7 +60,6 @@ public class Staff { ...@@ -60,7 +60,6 @@ public class Staff {
protected int removeEmployee(int ID){ protected int removeEmployee(int ID){
try { try {
Statement myStatement = dbConnection.createStatement(); Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("DELETE FROM shifts WHERE (employee_ID =" + ID + ")");
myStatement.executeUpdate("delete from Employees where employee_id = " + ID); myStatement.executeUpdate("delete from Employees where employee_id = " + ID);
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
......
...@@ -53,6 +53,7 @@ public class UserThread extends Thread { ...@@ -53,6 +53,7 @@ public class UserThread extends Thread {
case "removeEmployee": case "removeEmployee":
try { try {
int employeeID = Integer.parseInt(args[1]); int employeeID = Integer.parseInt(args[1]);
rafisWeirdClass.schedule.removeAllShiftsByID(employeeID);
if (employeeID == rafisWeirdClass.staff.removeEmployee(employeeID)) { if (employeeID == rafisWeirdClass.staff.removeEmployee(employeeID)) {
server.broadcast("removeEmployee/" + employeeID); server.broadcast("removeEmployee/" + employeeID);
} }
......
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