From e2b5cf520a47a1b97a5cf9badafd8bc105a307f1 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Wed, 1 Mar 2017 14:45:31 -0500 Subject: [PATCH 1/6] Initial commit Ideas are conceptualized, no testing done yet. May the debugging commence! --- WebContent/html/webpages/index.html | 2 +- WebContent/html/webpages/returnComplete.jsp | 37 +++++++++++++++ WebContent/html/webpages/returnPage.jsp | 50 ++++++++++++++------- src/database/MySQLAccess.java | 21 +++++++++ 4 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 WebContent/html/webpages/returnComplete.jsp diff --git a/WebContent/html/webpages/index.html b/WebContent/html/webpages/index.html index 5f5a100..6796a98 100644 --- a/WebContent/html/webpages/index.html +++ b/WebContent/html/webpages/index.html @@ -53,7 +53,7 @@

Request

Check out our selection of devices that YOU have the chance to check out!

- +
@@ -244,7 +247,9 @@ function returnDevice() } //place html in body document.getElementById("tablebody").innerHTML = html; - //show modal + //place input in form + $('#deviceArray').val(arrayToString(toReturn)); + //show modal $('#orderInfoModal').show(); } @@ -252,7 +257,22 @@ function returnDevice() function hidePopup(){ $('#orderInfoModal').hide(); } + +//Turns array to string, which can be submitted on the form when actually returning +//The string will contain the ID's of devices to be returned, and this will be sent to the database! +function arrayToString(array){ + var sb = "[" + for(var i = 0; i < array.length; i++){ + //get the return id, go to that index in queried devices, and get that id! + sb+= devices[array[i]].id; + if(i != array.length-1) + sb+="," + } + sb+="]" + return sb; +} - \ No newline at end of file + + \ No newline at end of file diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index 404d095..69c1138 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -80,6 +80,27 @@ public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundExceptio return devices; } + /** + * This function will take devices as input and return them. + * More specifically, the input will be a string that looks like an array. + * The values in this array correspond to device ID's. + * @param devices + * @throws ClassNotFoundException + * @throws SQLException + */ + public void returnDevices(String devices) throws ClassNotFoundException, SQLException{ + //connect to DB + 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(); + //make into string array; queries need to have numbers as strings! + String[] deviceArray = devices.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\s","").split(","); + for(int i = 0; i < deviceArray.length; i++){ + String current = deviceArray[i]; + } + } + public String[][] getResult(){ return result; } From 0454577d65a735ec00ef9fdac1bb8414c8e2bad8 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Wed, 1 Mar 2017 14:46:40 -0500 Subject: [PATCH 2/6] Forgot the most important part! Can't update database without a query. :smile: --- src/database/MySQLAccess.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index 69c1138..f66afe9 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -97,7 +97,8 @@ public void returnDevices(String devices) throws ClassNotFoundException, SQLExce //make into string array; queries need to have numbers as strings! String[] deviceArray = devices.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\s","").split(","); for(int i = 0; i < deviceArray.length; i++){ - String current = deviceArray[i]; + //update statement + stmt.executeUpdate("UPDATE devices SET Status = \"Available\" WHERE Device_ID = " + deviceArray[i]); } } From 8e9343c914229b3dcfb34c89024b6fb56937793c Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Wed, 1 Mar 2017 23:47:43 -0500 Subject: [PATCH 3/6] Commas added in places. Trying to switch branches. >_> --- WebContent/html/webpages/returnPage.jsp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WebContent/html/webpages/returnPage.jsp b/WebContent/html/webpages/returnPage.jsp index 6ea32a8..65eaa02 100644 --- a/WebContent/html/webpages/returnPage.jsp +++ b/WebContent/html/webpages/returnPage.jsp @@ -261,14 +261,14 @@ function hidePopup(){ //Turns array to string, which can be submitted on the form when actually returning //The string will contain the ID's of devices to be returned, and this will be sent to the database! function arrayToString(array){ - var sb = "[" + var sb = "["; for(var i = 0; i < array.length; i++){ //get the return id, go to that index in queried devices, and get that id! sb+= devices[array[i]].id; if(i != array.length-1) - sb+="," + sb+=","; } - sb+="]" + sb+="]"; return sb; } From 9d531f9b281dd8299dfec72386cea072665f5c4a Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Thu, 2 Mar 2017 13:55:04 -0500 Subject: [PATCH 4/6] THINGS RETURN WOW :squirrel: --- WebContent/html/webpages/returnPage.jsp | 2 +- src/database/MySQLAccess.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WebContent/html/webpages/returnPage.jsp b/WebContent/html/webpages/returnPage.jsp index 65eaa02..7cf5b9f 100644 --- a/WebContent/html/webpages/returnPage.jsp +++ b/WebContent/html/webpages/returnPage.jsp @@ -100,7 +100,7 @@
- Continue +
diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index f66afe9..da44493 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -36,7 +36,7 @@ public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNo 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(); - ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID); + ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID + " AND Status <> \"Available\" AND Status <> \"Returning \""); int counter = 0; resultSet.last(); @@ -98,8 +98,9 @@ public void returnDevices(String devices) throws ClassNotFoundException, SQLExce String[] deviceArray = devices.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\s","").split(","); for(int i = 0; i < deviceArray.length; i++){ //update statement - stmt.executeUpdate("UPDATE devices SET Status = \"Available\" WHERE Device_ID = " + deviceArray[i]); + stmt.executeUpdate("UPDATE devices SET Status = \"Returning\" WHERE Device_ID = " + deviceArray[i]); } + System.out.println("\nUpdates complete\n"); } public String[][] getResult(){ From b7de000372820e2b4a224e68febfe55f404127f7 Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Thu, 2 Mar 2017 20:26:12 -0500 Subject: [PATCH 5/6] Navbar generation was missing on the Completion page. --- WebContent/html/webpages/returnComplete.jsp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WebContent/html/webpages/returnComplete.jsp b/WebContent/html/webpages/returnComplete.jsp index 9ac1efa..08a267d 100644 --- a/WebContent/html/webpages/returnComplete.jsp +++ b/WebContent/html/webpages/returnComplete.jsp @@ -33,5 +33,7 @@ MySQLAccess myaccess = new MySQLAccess(); String devices = request.getParameter("devicesToReturn"); myaccess.returnDevices(devices); %> + + \ No newline at end of file From c5339d61474a84185a0dc5aa9d2b7216480e1edc Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Mon, 20 Mar 2017 22:48:58 -0400 Subject: [PATCH 6/6] Location Admin Page Complete --- WebContent/html/webpages/adminLocation.jsp | 389 ++++++++++++++++++ WebContent/html/webpages/locationRedirect.jsp | 64 +++ WebContent/html/webpages/profileSettings.html | 6 + src/database/MySQLAccess.java | 85 +++- src/entities/Location.java | 107 +++++ 5 files changed, 650 insertions(+), 1 deletion(-) create mode 100644 WebContent/html/webpages/adminLocation.jsp create mode 100644 WebContent/html/webpages/locationRedirect.jsp create mode 100644 src/entities/Location.java diff --git a/WebContent/html/webpages/adminLocation.jsp b/WebContent/html/webpages/adminLocation.jsp new file mode 100644 index 0000000..7e8db38 --- /dev/null +++ b/WebContent/html/webpages/adminLocation.jsp @@ -0,0 +1,389 @@ +<%@ page import = "database.MySQLAccess,entities.Location" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Synchrony Financial + + + + + + + + + + + + + + +
+ + + + + + +
+ +

Location Listing

+ + + + + + + + + + + + + +
NameAddressTownStateZip Code
+ +
+<% +//database connection +MySQLAccess myaccess = new MySQLAccess(); +//database query +Location[] locations = myaccess.getLocations(); +//string representation of array. +String locationString = Location.arrayToString(locations); +locationString = locationString.replace("'","\\'"); +%> + + + + + + \ No newline at end of file diff --git a/WebContent/html/webpages/locationRedirect.jsp b/WebContent/html/webpages/locationRedirect.jsp new file mode 100644 index 0000000..967f9da --- /dev/null +++ b/WebContent/html/webpages/locationRedirect.jsp @@ -0,0 +1,64 @@ +<%@ page import = "database.MySQLAccess,entities.Location" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + + + + Synchrony Financial + + + + + + + + + + +

Redirect Page

+

You shouldn't be seeing this page :)

+ +<% +//make instance +MySQLAccess myaccess = new MySQLAccess(); +String name = request.getParameter("name").replace("\"","\\\""); +String address = request.getParameter("address").replace("\"","\\\""); +String town = request.getParameter("town").replace("\"","\\\""); +String state = request.getParameter("state"); +String zip = request.getParameter("zip"); +//add form was submitted +if(request.getParameter("add") != null){ + Location location = new Location(name,address,town,state,zip); + myaccess.addLocation(location); +} +//modify form was submitted +if(request.getParameter("modify") != null){ + //getParameter() always returns string + String strID = request.getParameter("id"); + //turn to int for constructor + int id = Integer.parseInt(strID); + Location location = new Location(id,name,address,town,state,zip); + myaccess.modifyLocation(location); +} +//delete form was submitted +if(request.getParameter("delete") != null){ + String strID = request.getParameter("id"); + int id = Integer.parseInt(strID); + myaccess.deleteLocation(id); +} +%> + + + + + \ No newline at end of file diff --git a/WebContent/html/webpages/profileSettings.html b/WebContent/html/webpages/profileSettings.html index b907797..ea0abb4 100644 --- a/WebContent/html/webpages/profileSettings.html +++ b/WebContent/html/webpages/profileSettings.html @@ -57,8 +57,10 @@ + + +