Skip to content
Snippets Groups Projects
Commit 54d382a2 authored by Rafi Zereselasie (raz070)'s avatar Rafi Zereselasie (raz070)
Browse files

Added more fields to the database.

Employees table now captures the email, phone number, isManager, and wage.
Shift table now captures the availability of the shift. Updated parsing so all employee and shift details are separated by commas.
parent 205dba5a
No related branches found
No related tags found
1 merge request!6Changed update implementation for employees so rather than sending the whole...
......@@ -19,7 +19,7 @@ create table Shifts(
INSERT INTO Employees (first_name,last_name) VALUES ('Rafi', 'Zereselasie');
select * from Employees;
select * from Employees where first_name='Rafi' and last_name='Zereselasie';
select * from Shifts;
update employees set last_name='fasdfa' where employee_ID=9
......@@ -31,6 +31,8 @@ drop table Employees;
drop table Shifts;
drop database ScheduleApp;
INSERT INTO Employees (first_name,last_name) VALUES ('Rafi', 'Zereselasie');
......
......@@ -8,9 +8,9 @@ import java.util.Map;
*/
public class Employee {
private int employeeID;
private boolean isManager;
private String firstName;
private String lastName;
private boolean isManager;
private String email;
private String phoneNumber;
private float wage;
......@@ -26,10 +26,15 @@ public class Employee {
*/
public Employee(String employeeData){
try {
String[] dataSplit = employeeData.split("\\.");
String[] dataSplit = employeeData.split(",");
this.employeeID = Integer.parseInt(dataSplit[0]);
this.firstName = dataSplit[1];
this.lastName = dataSplit[2];
this.isManager = Boolean.parseBoolean(dataSplit[3]);
this.email = dataSplit[4];
this.phoneNumber = dataSplit[5];
this.wage = Float.parseFloat(dataSplit[6]);
} catch (Exception exception) {
exception.printStackTrace();
}
......@@ -46,6 +51,15 @@ public class Employee {
return employeeID;
}
/*
Name: isManager
Parameters: none
Description: Check if an employee is a manager.
Return:
Boolean: true if manager, false if not.
*/
public boolean isManager() { return isManager; }
/*
Name: getFullName
Parameters: none
......
......@@ -108,12 +108,18 @@ public class Model {
writer.println("allEmployees");
}
void addEmployee(String first_name, String last_name) {
writer.println("addEmployee/" + first_name + "/" + last_name);
void addEmployee(String firstName, String lastName) {
writer.println("addEmployee/" + firstName + "/" + lastName + "/" + false + "/" + "empty" + "/" + "empty" +
0.0);
updateAllEmployees();
}
void addEmployee(String firstName, String lastName, boolean isManager, String email, String phoneNumber, float wage) {
writer.println("addEmployee/" + firstName + "/" + lastName + "/" + isManager + "/" + email + "/" + phoneNumber +
"/" + wage);
}
void removeEmployee(String employeeID) {
writer.println("removeEmployee/" + employeeID);
updateAllEmployees();
......@@ -150,6 +156,7 @@ public class Model {
notifySubscribers();
}
void removeShift(int shiftID){
writer.println("removeShift/"+shiftID);
notifySubscribers();
......
......@@ -33,11 +33,12 @@ public class Schedule {
myStatement.executeUpdate("INSERT INTO shifts (employee_id, full_date, start_time, end_time) " +
"VALUES ('" + ID +"', '"+ newDate +"', '"+ start +"', '"+ end +"')");
ResultSet myRs = myStatement.executeQuery("select * from Shifts where employee_id=" + ID +
" and full_date='" + newDate + "' and start_time=" + start + " and end_time=" + end);
" and full_date='" + newDate + "' and start_time=" + start + " and end_time=" + end + " and availability=false");
if (myRs.last()) {
newShift = myRs.getString("employee_id" ) + "." +
myRs.getString("full_date") + "." + myRs.getString("start_time") +
"." + myRs.getString("end_time") + "." + myRs.getString("shift_id");
newShift = myRs.getString("employee_id" ) + "," +
myRs.getString("full_date") + "," + myRs.getString("start_time") +
"," + myRs.getString("end_time") + "," + myRs.getString("shift_id") +
"," + myRs.getString("availability");
}
} catch (SQLException exception) {
exception.printStackTrace();
......@@ -75,18 +76,18 @@ public class Schedule {
Description: Edits the time and date of the of a shift if it has the same shift id
Return: none
*/
protected String editShift(Integer shiftID, String date, String start,String end){
protected String editShift(Integer shiftID, String date, String start,String end, String available){
String editedShift = "";
Date newDate = Date.valueOf(date);
System.out.println(newDate);
try {
Statement myStatement = dbConnection.createStatement();
myStatement.executeUpdate("update shifts set full_date='" + newDate + "',start_time=" + start + ",end_time=" + end
+ " where shift_id=" + shiftID);
+ ",availability=" + available + " where shift_id=" + shiftID);
ResultSet myRs = myStatement.executeQuery("select * from Shifts where shift_id=" + shiftID);
editedShift = myRs.getString("employee_id" ) + "." + myRs.getString("full_date") +
"." + myRs.getString("start_time") + "." + myRs.getString("end_time") +
"." + myRs.getString("shift_id");
editedShift = myRs.getString("employee_id" ) + "," + myRs.getString("full_date") +
"," + myRs.getString("start_time") + "," + myRs.getString("end_time") +
"," + myRs.getString("shift_id") + "," + myRs.getString("availability");
} catch (SQLException exception) {
exception.printStackTrace();
return editedShift;
......@@ -125,11 +126,12 @@ public class Schedule {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("SELECT * FROM shifts");
while (myRs.next()) {
response.append("/").append(myRs.getString("employee_id")).append(".")
.append(myRs.getString("full_date")).append(".")
.append(myRs.getString("start_time"))
.append(".").append(myRs.getString("end_time"))
.append(".").append(myRs.getString("shift_id"));
response.append("/").append(myRs.getString("employee_id"))
.append(",").append(myRs.getString("full_date"))
.append(",").append(myRs.getString("start_time"))
.append(",").append(myRs.getString("end_time"))
.append(",").append(myRs.getString("shift_id"))
.append(",").append(myRs.getString("availability"));
}
} catch (SQLException exception) {
exception.printStackTrace();
......
......@@ -26,7 +26,7 @@ public class Shift {
public Shift(String shiftData){
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddHHmm");
String[] dataSplit = shiftData.split("\\.");
String[] dataSplit = shiftData.split(",");
this.EmployeeID = Integer.parseInt(dataSplit[0]);
this.shiftID = Integer.parseInt(dataSplit[4]);
if (dataSplit[2].length() == 3) dataSplit[2] = "0" + dataSplit[2];
......@@ -34,7 +34,7 @@ public class Shift {
this.start = LocalDateTime.parse(dataSplit[1] + dataSplit[2], formatter);
this.end = LocalDateTime.parse(dataSplit[1] + dataSplit[3], formatter);
this.date = dataSplit[1];
this.available = false;
this.available = Boolean.parseBoolean(dataSplit[5]);
} catch (Exception exception) {
exception.printStackTrace();
}
......
......@@ -33,14 +33,20 @@ public class Staff {
Return:
String newEmployee: If the employee was added successfully, then it returns their new details, else returns an empty string.
*/
protected String addEmployee(String firstName, String lastName){
protected String addEmployee(String firstName, String lastName, String isManager, String email, String phoneNumber,
float wage){
String newEmployee = "";
try {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("insert into Employees (first_name,last_name) values ('" + firstName + "', '" + lastName + "')");
myStatement.executeUpdate("insert into Employees (first_name,last_name,isManager,email,phoneNumber,wage)" +
" values ('" + firstName + "','" + lastName + "'," + isManager + ",'" + email + "','" +
phoneNumber + "'," + wage + ")");
ResultSet myRs = myStatement.executeQuery("select * from Employees where first_name='Rafi' and last_name='Zereselasie'");
if (myRs.last()) {
newEmployee = myRs.getString("employee_ID") + "." + myRs.getString("first_name") + "." + myRs.getString("last_name");
newEmployee = myRs.getString("employee_ID") + "," + myRs.getString("first_name") +
"," + myRs.getString("last_name") + "," + myRs.getString("isManager") +
"," + myRs.getString("email") + "," + myRs.getString("phoneNumber") +
"," + myRs.getString("wage");
}
} catch (Exception exception) {
exception.printStackTrace();
......@@ -50,7 +56,6 @@ public class Staff {
return newEmployee;
}
/*
Name: removeEmployee
Parameters:
......@@ -77,12 +82,18 @@ public class Staff {
Return: none
*/
protected String getEmployees(){
StringBuilder response = new StringBuilder("allEmployees");
StringBuilder response = new StringBuilder();
try {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("select * from Employees");
while (myRs.next()) {
response.append("/").append(myRs.getString("employee_ID")).append(".").append(myRs.getString("first_name")).append(".").append(myRs.getString("last_name"));
response.append("/").append(myRs.getString("employee_ID")).append(",")
.append(myRs.getString("first_name")).append(",")
.append(myRs.getString("last_name")).append(",")
.append(myRs.getString("isManager")).append(",")
.append(myRs.getString("email")).append(",")
.append(myRs.getString("phoneNumber")).append(",")
.append(myRs.getString("wage"));
}
} catch (Exception exception) {
exception.printStackTrace();
......
......@@ -52,10 +52,15 @@ public class UserThread extends Thread {
String[] args = clientMessage.split("/");
switch (args[0]) {
case "addEmployee":
if(args.length == 3){
String newEmployee = dbQuery.staff.addEmployee(args[1], args[2]);
if (!newEmployee.isEmpty()){
server.broadcast("addEmployee/" + newEmployee);
if(args.length == 7){
try {
String newEmployee = dbQuery.staff.addEmployee(args[1], args[2], args[3], args[4], args[5],
Float.parseFloat(args[6]));
if (!newEmployee.isEmpty()){
server.broadcast("addEmployee/" + newEmployee);
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
break;
......@@ -72,7 +77,7 @@ public class UserThread extends Thread {
break;
case "editShift":
try {
String editedShift = dbQuery.schedule.editShift(Integer.parseInt(args[1]), args[2], args[3], args[4]);
String editedShift = dbQuery.schedule.editShift(Integer.parseInt(args[1]), args[2], args[3], args[4], args[5]);
if (!editedShift.isEmpty()) {
server.broadcast("editShift/" + editedShift);
}
......
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