diff --git a/WebContent/html/webpages/admin.jsp b/WebContent/html/webpages/admin.jsp index d3992f8..afdf899 100644 --- a/WebContent/html/webpages/admin.jsp +++ b/WebContent/html/webpages/admin.jsp @@ -73,7 +73,7 @@ div.approveConfirm {
Ticket ID | +Requestor Name | +Location Name | +Device Name | +Status | +Return Date | +
---|
Approved!
-You shouldn't be seeing this page :)
+ +<% +//make instance +String ticketidstr = request.getParameter("ticketid"); +String deviceidstr = request.getParameter("deviceid"); +String locationidstr = request.getParameter("locationid"); +int ticketid = Integer.parseInt(ticketidstr); +int deviceid = Integer.parseInt(deviceidstr); +int locationid = Integer.parseInt(locationidstr); + +//add form was submitted +if(request.getParameter("approve") != null){ + TicketQueries.acceptTicket(ticketid,deviceid,locationid); +} +//modify form was submitted +if(request.getParameter("reject") != null){ + TicketQueries.rejectTicket(ticketid); +} +%> + + + + \ No newline at end of file diff --git a/src/database/EmployeeQueries.java b/src/database/EmployeeQueries.java index 981329b..b10daf9 100644 --- a/src/database/EmployeeQueries.java +++ b/src/database/EmployeeQueries.java @@ -48,4 +48,29 @@ public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLExc access.closeConnection(); return employee; } + + public static User[] getAllUsers() throws SQLException, ClassNotFoundException{ + //database connect + System.getenv("VCAP_SERVICES"); + MySQLAccess access = new MySQLAccess(); + Statement stmt = access.getStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT * FROM employee"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + //Covers amount of rows, and 6 attributes (indices 0-5) + User[] users = new User[rows]; + + //iterate result set + while(resultSet.next()){ + users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number")); + counter++; + } + + access.closeConnection(); + return users; + } } \ No newline at end of file diff --git a/src/database/LocationQueries.java b/src/database/LocationQueries.java index cbac6d5..7dc01a1 100644 --- a/src/database/LocationQueries.java +++ b/src/database/LocationQueries.java @@ -139,4 +139,29 @@ public static void deleteLocation(int id) throws ClassNotFoundException, SQLExce stmt.close(); connect.close(); } + + public static Location[] getAllLocations() throws SQLException, ClassNotFoundException{ + //database connect + System.getenv("VCAP_SERVICES"); + MySQLAccess access = new MySQLAccess(); + Statement stmt = access.getStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT * FROM location"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + //Covers amount of rows, and 6 attributes (indices 0-5) + Location[] locations = new Location[rows]; + + //iterate result set + while(resultSet.next()){ + locations[counter] = new Location(resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Address"),resultSet.getString("Town"),resultSet.getString("State"),resultSet.getString("Zip_Code")); + counter++; + } + + access.closeConnection(); + return locations; + } } \ No newline at end of file diff --git a/src/database/TicketQueries.java b/src/database/TicketQueries.java index a851de0..ce71bbf 100644 --- a/src/database/TicketQueries.java +++ b/src/database/TicketQueries.java @@ -2,6 +2,7 @@ import java.sql.*; import java.util.Date; +import entities.Ticket; public class TicketQueries { @@ -27,4 +28,52 @@ public static void generateTicket(int requester, int location, int device, Strin statement.executeUpdate(query); access.closeConnection(); } -} \ No newline at end of file + + //get all tickets + public Ticket[] getTickets() throws SQLException, ClassNotFoundException{ + String status = "Requested"; + int i = 0; + MySQLAccess myaccess = new MySQLAccess(); + Statement statement = myaccess.getStatement(); + ResultSet resultSet = statement.executeQuery("Select COUNT(Ticket_ID) FROM ticket WHERE Status = '" +status + "'"); + resultSet.next(); + Ticket[] tickets = new Ticket[resultSet.getInt("COUNT(Ticket_ID)")]; + resultSet = statement.executeQuery("Select * FROM ticket WHERE Status = '" +status + "'"); + while(resultSet.next()){ + tickets[i] = new Ticket( + resultSet.getInt("Ticket_ID"), + resultSet.getInt("Requestor"), + //resultSet.getInt("Request_Date"), + resultSet.getInt("Location"), + resultSet.getInt("Device_ID"), + status, + resultSet.getString("Return_Date") + ); + i++; + } + myaccess.closeConnection(); + return tickets; + } + + public static void acceptTicket(int ticketid, int deviceid, int locationid) throws SQLException, ClassNotFoundException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); + Statement stmt = connect.createStatement(); + stmt.executeUpdate("UPDATE ticket SET Status = \"Approved\" WHERE Ticket_ID = " + ticketid); + stmt.executeUpdate("UPDATE devices SET Ticket_ID = " + ticketid + ", Status = \"Shipped\", Renter = 10, Location = " + locationid + " WHERE Device_ID = " + deviceid); + stmt.close(); + connect.close(); + } + + public static void rejectTicket(int id) throws SQLException, ClassNotFoundException{ + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317"); + Statement stmt = connect.createStatement(); + stmt.executeUpdate("UPDATE ticket SET Status = \"Rejected\" WHERE Ticket_ID = " + id); + stmt.close(); + connect.close(); + } +} + diff --git a/src/entities/Ticket.java b/src/entities/Ticket.java new file mode 100644 index 0000000..2ab6cc9 --- /dev/null +++ b/src/entities/Ticket.java @@ -0,0 +1,99 @@ +package entities; + +import java.math.BigInteger; + +//class for tickets +public class Ticket { + private int _id; + private int _requestor; + //private BigInteger _requestDate; + private int _location; + private int _deviceId; + private String _status; + private String _returnDate; + + public Ticket(int id, int requestor, int location, int deviceId, String status, String returnDate){ + this._id = id; + this._requestor = requestor; + //this._requestDate = requestDate; + this._location = location; + this._deviceId = deviceId; + this._status = status; + this._returnDate = returnDate; + } + + public String toString(){ + StringBuilder sb = new StringBuilder(); + String comma = ", "; + sb.append("{\"requestor\": ").append(_requestor).append(comma); + sb.append("\"id\": ").append(_id).append(comma); + sb.append("\"location\": ").append(_location).append(comma); + sb.append("\"deviceID\": ").append(_deviceId).append(comma); + sb.append("\"status\": \"").append(_status).append("\"").append(comma); + sb.append("\"return\": \"").append(_returnDate).append("\""); + sb.append("}"); + return sb.toString(); + } + + public static String arrayToString(Ticket[] array){ + StringBuilder sb = new StringBuilder(); + sb.append("["); + for(int i = 0; i < array.length; i++){ + sb.append(array[i].toString()); + if(i+1 != array.length){ + sb.append(","); + } + } + sb.append("]"); + return sb.toString(); + } + + public int getId(){ + return _id; + } + public void setId(int id){ + this._id = id; + } + + public int getRequestor(){ + return _requestor; + } + public void setRequestor(int requestor){ + this._requestor = requestor; + } + + /*public BigInteger getRequestDate(){ + return _requestDate; + } + public void setRequestDate(BigInteger requestDate){ + this._requestDate = requestDate; + }*/ + + public int getLocation(){ + return _location; + } + public void setLocation(int location){ + this._location = location; + } + + public int getDeviceId(){ + return _deviceId; + } + public void setDeviceId(int deviceId){ + this._deviceId = deviceId; + } + + public String getStatus(){ + return _status; + } + public void setStatus(String status){ + this._status = status; + } + + public String getReturnDate(){ + return _returnDate; + } + public void setReturnDate(String returnDate){ + this._returnDate = returnDate; + } +} diff --git a/src/entities/User.java b/src/entities/User.java index 5545d91..da619e3 100644 --- a/src/entities/User.java +++ b/src/entities/User.java @@ -13,6 +13,31 @@ public User(int id, int location, String name, String phone){ this.name = name; //later will do table lookup to determine by id this.phone = phone; } + + public String toString(){ + StringBuilder sb = new StringBuilder(); + String comma = ", "; + sb.append("{\"id\": ").append(id).append(comma); + sb.append("\"location\": ").append(location).append(comma); + sb.append("\"name\": \"").append(name).append("\"").append(comma); + sb.append("\"phone\": \"").append(phone).append("\""); + sb.append("}"); + return sb.toString(); + } + + public static String arrayToString(User[] array){ + StringBuilder sb = new StringBuilder(); + sb.append("["); + for(int i = 0; i < array.length; i++){ + sb.append(array[i].toString()); + if(i+1 != array.length){ + sb.append(","); + } + } + sb.append("]"); + return sb.toString(); + } + public int getID() { return id;