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

Added comments.

parent ab0775aa
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,32 @@ import java.sql.*;
*/
public class TimeOff {
// Object that facilitates the connection to the database
private final Connection dbConnection;
/*
Name: TimeOff Constructor
Parameters:
Connection c: The connection to the database.
Description: Instantiates a TimeOff object and sets the global connection for the methods.
Return: TimeOff Object
*/
protected TimeOff(Connection c) {
this.dbConnection = c;
}
/*
Name: addTimeOff
Parameters:
int employeeID: The ID of an employee.
String startDate: The start date of the time off in "yyyy-mm-dd" format.
String endDate: The end date of the time off in "yyyy-mm-dd" format.
boolean approved: True if the time off is approved by a manager.
String reason: Why the time off was requested.
Description:
Return:
String: The details of the time off separated by commas.
*/
protected String addTimeOff(int employeeID, String startDate, String endDate, boolean approved, String reason){
String newTimeOff = "";
try {
......@@ -36,6 +56,14 @@ public class TimeOff {
return newTimeOff;
}
/*
Name: removeTimeOff
Parameters:
int timeOffID: The id of the time off request.
Description: Removes the time off request.
Return:
String: The time off id of the shift if it was removed, and -1 if there was a problem with the query.
*/
protected int removeTimeOff(int timeOffID){
try {
Statement myStatement = dbConnection.createStatement();
......@@ -47,13 +75,23 @@ public class TimeOff {
return timeOffID;
}
protected String setTimeOffApproval(int ID, String approved){
/*
Name: setTimeOffApproval
Parameters:
int timeOffID: The id of the time off request.
String approved: "true" if its approved and "false" if it's not.
Description: Change the approval status of a request.
Return:
String: If the time off approval was successfully changed than it returns the id and the approval separated by
commas, or if there was an error with the query then it returns an empty string.
*/
protected String setTimeOffApproval(int timeOffID, String approved){
String editedTimeOff = "";
System.out.println(ID + " and " + approved);
System.out.println(timeOffID + " and " + approved);
try {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("update TimeOff set approved=" + approved + " where ID=" + ID);
ResultSet myRs = myStatement.executeQuery("select * from TimeOff where ID=" + ID);
myStatement.executeUpdate("update TimeOff set approved=" + approved + " where ID=" + timeOffID);
ResultSet myRs = myStatement.executeQuery("select * from TimeOff where ID=" + timeOffID);
if (myRs.last()) {
editedTimeOff = myRs.getString("ID") + "," + myRs.getString("approved");
}
......@@ -65,6 +103,13 @@ public class TimeOff {
return editedTimeOff;
}
/*
Name: removeAllTimeOffByID
Parameters:
int employeeID: The id of an employee.
Description: Removes all time off request for a specified employee.
Return: void
*/
protected void removeAllTimeOffByID(int employeeID) {
try {
Statement myStatement = dbConnection.createStatement();
......@@ -74,6 +119,14 @@ public class TimeOff {
}
}
/*
Name: allTimeOff
Parameters: none
Description: Gets all the time off request.
Return:
String: All the time off data where all the time offs are separated by slashes and each detail is separated by
commas.
*/
protected String allTimeOff(){
StringBuilder response = new StringBuilder("allTimeOff");
try {
......
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