Skip to content
Snippets Groups Projects
Commit 9b209a8f authored by mik586's avatar mik586
Browse files

backup shiftype stuff

parent 7a53aca0
No related branches found
No related tags found
1 merge request!6Changed update implementation for employees so rather than sending the whole...
...@@ -25,7 +25,7 @@ public class RafisWeirdClass { ...@@ -25,7 +25,7 @@ public class RafisWeirdClass {
public static void main(String[] args) { public static void main(String[] args) {
RafisWeirdClass rafisWeirdClass = new RafisWeirdClass(); RafisWeirdClass rafisWeirdClass = new RafisWeirdClass();
rafisWeirdClass.schedule.addShift(3, "2022-03-10", 1200, 2100); rafisWeirdClass.schedule.addShift(3, "2022-03-10", 1200, 2100, "shift");
/* Testing stuff that should be cleaned up for the alpha /* Testing stuff that should be cleaned up for the alpha
String s = model.staff.getEmployees(); String s = model.staff.getEmployees();
System.out.println(); System.out.println();
......
...@@ -21,12 +21,12 @@ public class Schedule { ...@@ -21,12 +21,12 @@ public class Schedule {
Return: none Return: none
*/ */
protected void addShift(int ID, String date, int start, int end){ protected void addShift(int ID, String date, int start, int end, String shiftType){
Date newDate = Date.valueOf(date); Date newDate = Date.valueOf(date);
try { try {
Statement myStatement = dbConnection.createStatement(); Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("INSERT INTO shifts (employee_id, full_date, start_time, end_time) " + myStatement.executeUpdate("INSERT INTO shifts (employee_id, full_date, start_time, end_time, shiftType) " +
"VALUES ('" + ID +"', '"+ newDate +"', '"+ start +"', '"+ end +"')"); "VALUES ('" + ID +"', '"+ newDate +"', '"+ start +"', '"+ end +"')'" + shiftType +"'");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -60,12 +60,13 @@ public class Schedule { ...@@ -60,12 +60,13 @@ public class Schedule {
Description: Returns info for all shifts on a given date. Description: Returns info for all shifts on a given date.
Return: String Return: String
*/ */
protected String getShifts(String date){ protected String getShifts(String date, String shiftType){
Date newDate = Date.valueOf(date); Date newDate = Date.valueOf(date);
String response = "getShifts"; String response = "getShifts";
try { try {
Statement myStatement = dbConnection.createStatement(); Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date = " + newDate +")"); ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date = " + newDate +")" +
"AND WHERE (shift_type = "+ shiftType +")");
while (myRs.next()) { while (myRs.next()) {
response = response + "/" + myRs.getString("full_date") + "." + response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") + myRs.getString("employee_id") + "." + myRs.getString("start_time") +
...@@ -78,14 +79,14 @@ public class Schedule { ...@@ -78,14 +79,14 @@ public class Schedule {
return response; return response;
} }
protected String getShiftsByWeek(String startDate, String endDate){ protected String getShiftsByWeek(String startDate, String endDate, String shiftType){
Date newStart = Date.valueOf(startDate); Date newStart = Date.valueOf(startDate);
Date newEnd = Date.valueOf(endDate); Date newEnd = Date.valueOf(endDate);
String response = "getShiftsByWeek"; String response = "getShiftsByWeek";
try { try {
Statement myStatement = dbConnection.createStatement(); Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date >= " + newStart +")" + ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date >= " + newStart +")" +
"AND WHERE (full_date <= " + newEnd +")"); "AND WHERE (full_date <= " + newEnd +")" + "AND WHERE (shift_type = "+ shiftType +")");
while (myRs.next()) { while (myRs.next()) {
response = response + "/" + myRs.getString("full_date") + "." + response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") + myRs.getString("employee_id") + "." + myRs.getString("start_time") +
...@@ -98,14 +99,15 @@ public class Schedule { ...@@ -98,14 +99,15 @@ public class Schedule {
return response; return response;
} }
protected String getEmployeeShiftsByWeek(int ID, String startDate, String endDate){ protected String getEmployeeShiftsByWeek(int ID, String startDate, String endDate, String shiftType){
Date newStart = Date.valueOf(startDate); Date newStart = Date.valueOf(startDate);
Date newEnd = Date.valueOf(endDate); Date newEnd = Date.valueOf(endDate);
String response = "getEmployeeShiftsByWeek"; String response = "getEmployeeShiftsByWeek";
try { try {
Statement myStatement = dbConnection.createStatement(); Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date >= " + newStart +")" + ResultSet myRs = myStatement.executeQuery("SELECT FROM shifts WHERE (full_date >= " + newStart +")" +
"AND WHERE (full_date <= " + newEnd +") AND WHERE (employee_id = "+ ID + ")"); "AND WHERE (full_date <= " + newEnd +") AND WHERE (employee_id = "+ ID + ")" +
"AND WHERE (shift_type = "+ shiftType +")");
while (myRs.next()) { while (myRs.next()) {
response = response + "/" + myRs.getString("full_date") + "." + response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") + myRs.getString("employee_id") + "." + myRs.getString("start_time") +
......
...@@ -60,7 +60,7 @@ public class UserThread extends Thread { ...@@ -60,7 +60,7 @@ public class UserThread extends Thread {
break; break;
case "addShift": case "addShift":
try { try {
rafisWeirdClass.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4])); rafisWeirdClass.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4]), args[5]);
serverMessage = rafisWeirdClass.schedule.allShifts(); serverMessage = rafisWeirdClass.schedule.allShifts();
server.broadcast(serverMessage); server.broadcast(serverMessage);
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
......
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