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

Add shift type

parent 1398fbec
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ public class Model {
public static void main(String[] args) {
Model model = new Model();
model.schedule.addShift(3, "2022-03-10", 1200, 2100);
model.schedule.addShift(3, "2022-03-10", 1200, 2100, "shift");
/* Testing stuff that should be cleaned up for the alpha
String s = model.staff.getEmployees();
System.out.println();
......
......@@ -21,12 +21,12 @@ public class Schedule {
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);
try {
Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("INSERT INTO shifts (employee_id, full_date, start_time, end_time) " +
"VALUES ('" + ID +"', '"+ newDate +"', '"+ start +"', '"+ end +"')");
myStatement.executeUpdate("INSERT INTO shifts (employee_id, full_date, start_time, end_time, shiftType) " +
"VALUES ('" + ID +"', '"+ newDate +"', '"+ start +"', '"+ end +"')'" + shiftType +"'");
} catch (SQLException e) {
e.printStackTrace();
}
......@@ -60,12 +60,13 @@ public class Schedule {
Description: Returns info for all shifts on a given date.
Return: String
*/
protected String getShifts(String date){
protected String getShifts(String date, String shiftType){
Date newDate = Date.valueOf(date);
String response = "getShifts";
try {
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()) {
response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") +
......@@ -78,14 +79,14 @@ public class Schedule {
return response;
}
protected String getShiftsByWeek(String startDate, String endDate){
protected String getShiftsByWeek(String startDate, String endDate, String shiftType){
Date newStart = Date.valueOf(startDate);
Date newEnd = Date.valueOf(endDate);
String response = "getShiftsByWeek";
try {
Statement myStatement = dbConnection.createStatement();
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()) {
response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") +
......@@ -98,14 +99,15 @@ public class Schedule {
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 newEnd = Date.valueOf(endDate);
String response = "getEmployeeShiftsByWeek";
try {
Statement myStatement = dbConnection.createStatement();
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()) {
response = response + "/" + myRs.getString("full_date") + "." +
myRs.getString("employee_id") + "." + myRs.getString("start_time") +
......
......@@ -71,12 +71,12 @@ public class ScheduleClient {
return "No Employees";
}
void addShift(int id, String date, int start, int end){
writer.println("addShift/"+id+"/"+date+"/"+start+"/"+end);
void addShift(int id, String date, int start, int end, String shiftType){
writer.println("addShift/"+id+"/"+date+"/"+start+"/"+end+"/"+shiftType);
}
void removeShift(int id, String date, int start, int end){
writer.println("removeShift/"+id+"/"+date+"/"+start+"/"+end);
void removeShift(int id, String date, int start, int end, String shiftType){
writer.println("removeShift/"+id+"/"+date+"/"+start+"/"+end+"/"+shiftType);
}
void printAllShifts() {
......
......@@ -60,7 +60,7 @@ public class UserThread extends Thread {
break;
case "addShift":
try {
model.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4]));
model.schedule.addShift(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]), Integer.parseInt(args[4]), (args[5]));
serverMessage = model.schedule.allShifts();
server.broadcast(serverMessage);
} catch (NumberFormatException exception) {
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
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