Skip to content

Commit

Permalink
New text fields for address. Ticket generation is very close to worki…
Browse files Browse the repository at this point in the history
…ng; only the location part of the ticket is ignored. That's what the new text fields are for, and once I get them behaving as desired I'll be able to finish ticket generating.

Changed link in navbar to direct to /2017-CSE-Senior-Project-Team-2/html/webpages/ instead of /2017-CSE-Senior-Project-Team-2/html/webpages/index.html. Apache will find the index.* file if it exists there, and I have been using index.jsp.
  • Loading branch information
arc12012 committed Mar 15, 2017
1 parent 20d27ab commit b7bddb4
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 34 deletions.
2 changes: 1 addition & 1 deletion WebContent/html/javascript/navbar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion WebContent/html/webpages/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false">
<ul class="nav navbar-nav navbar-right">
<li><a href="index.jsp">Home</a></li>
<li><a href="../webpages/">Home</a></li>
<li><a href="requestPage.html">Device</a></li>
<li><a href="returnPage.html">Return Device</a></li>
<li><a href="listingPage.jsp">Device Listing</a></li>
Expand Down
2 changes: 1 addition & 1 deletion WebContent/html/webpages/orderForm.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<form name="orderForm" onsubmit="return submitOrderForm()">
<div class="form-group">
<input type="hidden" name="userID">
<input type="hidden" name="deviceIDs">
<input type="hidden" name="orderAll">
<div class="form-group">
<label for="name">Your name</label><br/>
<input type="text" class="form-control" name="name" placeholder="Name" />
</div>
Expand Down
25 changes: 23 additions & 2 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@ pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
<%
//First update employee
String userName = request.getParameter("name");
String phone = request.getParameter("phone");
int location = Integer.valueOf(request.getParameter("location"));
String location = request.getParameter("location");
MySQLAccess access = new MySQLAccess();
access.updateEmployee(1, userName, phone, location); //TODO get ID somehow
System.out.print("updated employee "+userName);
%>alert("updated employee "+userName);<%
// And now for the ticket
// TODO
// First we need to parse the string
String rawJSONString = request.getParameter("deviceIDs");
rawJSONString = rawJSONString.replace("[","");
rawJSONString = rawJSONString.replace("]","");
rawJSONString = rawJSONString.replace("\"","");
String[] idStringArray = rawJSONString.split(",");
int[] devIDs = new int[idStringArray.length];
int j=0;
for(int i=0; i<idStringArray.length; i++)
{
devIDs[j]=Integer.parseInt(idStringArray[i]);
j++;
}
// Now just call generateTicket once for each device
for(int i=0; i<devIDs.length; i++)
{
access.generateTicket(1, location, devIDs[i]);//TODO get ID somehow
}
%>
</script>
</body>
</html>
8 changes: 4 additions & 4 deletions WebContent/html/webpages/requestPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ <h4>Hardware Type</h4>
<h4>Manufacture</h4>
<li><label><input type="checkbox" class="sw-data-type" data-type = "computers"> Computers</label></li>
<li><label><input type="checkbox" class="sw-data-type" data-type = "cameras"> Cameras</label></li>
<li><label><input type="checkbox" class="hw-data-type" data-type = "smartphone"> Smartphone</label></li>
<li><label><input type="checkbox" class="hw-data-type" data-type = "storage`"> Storage Devices</label></li>
<li><label><input type="checkbox" class="hw-data-type" data-type = "tablet"> Tablet</label></li>
<li><label><input type="checkbox" class="hw-data-type" data-type = "other"> Other</label></li>
<li><label><input type="checkbox" class="sw-data-type" data-type = "smartphone"> Smartphone</label></li>
<li><label><input type="checkbox" class="sw-data-type" data-type = "storage`"> Storage Devices</label></li>
<li><label><input type="checkbox" class="sw-data-type" data-type = "tablet"> Tablet</label></li>
<li><label><input type="checkbox" class="sw-data-type" data-type = "other"> Other</label></li>
</ul>
</div>

Expand Down
54 changes: 44 additions & 10 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,47 @@ pageEncoding="ISO-8859-1"%>
<h4>Please provide additional order information</h4>
</div>
<div class="modal-body">
<form name="orderForm" onsubmit="return submitOrderForm()">
<form name="orderForm" onsubmit="return submitOrderForm()" action="orderFormHandler.jsp" method="post">
<input type="text" name="userID" style = "display: none;"/>
<input type="text" name="orderAll" style = "display: none;"/>
<input type="text" name="deviceIDs" style="display: none;">
<div class="form-group">
<label for="name">Your name</label><br/>
<input type="text" class="form-control" name="name" placeholder="Name" />
</div>
<div class="form-group">
<label for="phone">Phone Number</label><br/>
<input type="text" class="form-control" name="phone" placeholder="No need to format it nicely (maybe we will implement a nicer phone# field soon)">
<input type="text" class="form-control" name="phone" placeholder="203-867-5309">
</div>

<div class="form-group">
<label for="location">Place to ship to</label><br/>
<input type="text" class="form-control" name="location" placeholder="Address" />
<input type="text" class="form-control" list="listid" name="location" placeholder="dropdown"/>
<datalist id="listid">
<option>t</option>
</datalist>
</div>
<div class="form-group-row">
<div class="col-md-6" style="margin: 0%">
<div class="form-group-row">
<label for="address">Street Address</label>
</div>
<input type="text" class="form-control" name="address" placeholder="Address"/>
<div class="form-group-row">
<label for="city">City</label>
</div>
<input type="text" class="form-control" name="city" placeholder="City"/>
</div>
<div class="col-md-6" style="margin: 0%">
<div class="form-group-row">
<label for="state">State</label>
</div>
<input type="text" class="form-control" name="state" placeholder="State"/>
<div class="form-group-row">
<label for="zip">Zip</label>
</div>
<input type="text" class="form-control" name="zip" placeholder="Zip Code"/>
</div>
</div>
<div class="form-group">
<label for="timeNeeded">How many weeks do you think you'll need it?</label><br/>
Expand Down Expand Up @@ -155,14 +184,13 @@ This function displays a list of devices that a user has currently in their shop
**/
function show(){
var cart = getCartItems(); //get all the cart items you want to show
alert("cart: "+JSON.stringify(cart));
var html = ''; //html string initially empty
var part1 = "nhpup.popup('";
var part2 = "');"
if(cart.length !== 0){ //only continue if there are cart items
html += '<p>Tickets have been generated below based on your desired selections.</p><br>'
for(var i = 0; i < cart.length; i++){ //iterate cart
var id = cart[i]; //this gets the id value from the cart
var id = cart[i].id; //this gets the id value from the cart
html += '<div> <input class = "deviceCheckbox" type = "checkbox" id = "' + id + '"> </input><a class = "divlink" href = "#" onmouseover = "'+ part1 + 'Hardware type: ' + cart[i].hardware + '<br><br>' + cart[i].description + part2 + '"><div id = "ticket' + id +'" class = "ticket"><p class = "tickettext">' + cart[i].name + '</p></div></a></div>'; //create listing of all the devices
}
}
Expand Down Expand Up @@ -201,7 +229,6 @@ function clickTicket(){
document.getElementById(id).checked = true;
checked.push(id);
}
alert("the 'checked' array looks like this: "+JSON.stringify(cart));
}
/**
Expand All @@ -218,7 +245,6 @@ function changeStatus(){
checked.splice(i,1); //remove from the array
}
}
alert("the 'checked' array looks like this: "+JSON.stringify(cart));
}
// These functions just redirect button pressed to call the showPopup method with the appropriate parameter
Expand Down Expand Up @@ -266,19 +292,19 @@ function submitOrderForm() {
// we must first append the employees ID as well as the ids of whatever devices are selected.
// First, employee id
userID=getUserID();
document.orderForm.append('<input type="hidden" name="userID" value="'+userID+'">');
document.orderForm.userID.value=userID;
// Now selected devices.
if(document.orderForm.orderAll.value=="true") //if the order form was opened using the order all button
{selectAllDevices();}
var selectedDeviceString=JSON.stringify(checked);
document.orderForm.append('<input type="hidden" name="deviceIDs" value="'+selectedDeviceString+'">');
document.orderForm.deviceIDs.value=selectedDeviceString;
// Finally remove selected items from the cart
var cart = getCartItems();
for(var i = 0; i < checked.length; i++){ //iterate all the checked off devices
for(var j = 0; j < cart.length; j++){ //iterate cart
if(cart[j] == id) //match id's
if(cart[j] == checked[i]) //match id's
cart.splice(j,1); //remove from the cart
}
}
Expand Down Expand Up @@ -342,12 +368,20 @@ function deleteAll(){
}
}
function getUserID() {
return 9; //TODO actually get a userID
}
function debug_add_item_to_cart() {
employee.id=5;
employee.location="test";
employee.name="test";
employee.phone="test";
var cart = [employee];
employee.id=6;
employee.location="test";
employee.name="test";
employee.phone="test";
cart.push(employee)
localStorage.setItem("cart",JSON.stringify(cart));
}
</script>
Expand Down
86 changes: 71 additions & 15 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package database;

import java.sql.*;
import java.util.Date;

import entities.User;

Expand Down Expand Up @@ -41,22 +42,52 @@ public void initializeEmployee(int id) throws ClassNotFoundException, SQLExcepti
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
statement.executeQuery("INSERT INTO employee (Employee_ID) VALUES ("+id+");");
statement.executeUpdate("INSERT INTO employee (Employee_ID) VALUES ("+id+");");
}

public void updateEmployee(int id, String name, String phone, int location) throws ClassNotFoundException, SQLException
public void updateEmployee(int id, String name, String phone, String location) throws ClassNotFoundException, SQLException
{
System.out.print("Updating employee "+id+": "+name+".\nPhone: "+phone+", location: "+location);
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
String query = "";
query+="UPDATE employee SET ";
query+="Name="+name;
query+=", Phone_Number="+phone;
query+=", Location_ID="+location;
query+=" WHERE Employee_ID="+id;
statement.executeQuery(query);
query+="SELECT Location_ID FROM Location ";
query+="WHERE Address="+location;
System.out.println(query);
ResultSet rs = statement.executeQuery(query);
if(rs.next())
// If there is already a record in locations matching given string, set
// employee's location FK to that location ID
{
query="";
query+="UPDATE employee SET ";
query+="Name='"+name;
query+="', Phone_Number='"+phone;
query+="', Location_ID="+rs.getInt("Location_ID");
query+=" WHERE Employee_ID="+id;
}
else
// Otherwise we need to make a whole new location entry
{
query+="SELECT COUNT(Location_ID) FROM location"; //generate a new key. Probably will run into trouble if a location is ever deleted
rs=statement.executeQuery(query);
rs.next();
query+="INSERT INTO location ";
query+="(Location_ID, Address) ";
query+="VALUES ("+(rs.getInt("COUNT(Location_ID)")+1)+", '"+location+"')";
statement.executeQuery(query);

// then update employee's location id
query="";
query+="UPDATE employee SET ";
query+="Name='"+name;
query+="', Phone_Number='"+phone;
query+="', Location_ID="+(rs.getInt("(COUNT(Location_ID)")+1);
query+=" WHERE Employee_ID="+id;
}
System.out.println(query);
statement.executeUpdate(query);
}

public User getEmployeeByID(int id) throws ClassNotFoundException, SQLException
Expand All @@ -78,22 +109,47 @@ public User getEmployeeByID(int id) throws ClassNotFoundException, SQLException
return employee;
}

public void generateTicket(int id, int requester, int location, int device, String stat, String std) throws ClassNotFoundException, SQLException
public int locationStringToInt(String locString) throws SQLException, ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Location_ID FROM location WHERE Address = '"+locString+"'");
resultSet.next();
return resultSet.getInt("Location_ID");
}

public String locationIntToString(int locInt) throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Address FROM location WHERE Location_ID = "+locInt);
resultSet.next();
return resultSet.getString("Address");
}

public void generateTicket(int requester, String location, int device) throws ClassNotFoundException, SQLException
{
long time = new Date().getTime(); //Using milliseconds because sql is annoying with dates.
int locID = locationStringToInt(location);
long ticketID = time+requester+device+locID;
String stat = "Requested";
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
String query = "";
query+="INSERT INTO ticket (Ticket_ID, Requester, Request_Date, Location, Device_ID, Status, Status_Date_Fields) ";
query+="INSERT INTO ticket (Ticket_ID, Requestor, Request_Date, Location, Device_ID, Status, Status_Date_Fields) ";
query+="VALUES (";
query+= id +", ";
query+= ticketID +", ";
query+= requester +", ";
query+= 0 +", ";
query+= "'"+time+"'" +", ";
query+= location +", ";
query+= device +", ";
query+= stat +", ";
query+= std +");";
statement.executeQuery(query);
query+= "'"+stat+"'" +", ";
query+= "'"+time+"'" +");";
System.out.println(query);
statement.executeUpdate(query);
}

}
50 changes: 50 additions & 0 deletions src/entities/ListedDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package entities;
/**
* Simple Modification of the RentedDevice class for use in the listed devices page.
* @author John Costa III
*
*/
public class ListedDevice {
private String Device_Name;
private String Device_Description;
private String Hardware;
private String Model;
public ListedDevice(String name, String desc, String hardware, String model) {
Device_Name = name;
Device_Description = desc;
Hardware = hardware;
Model = model;
}
/**
* Formatting the device to fit a JSON object.
* @author - Connor
*/
public String toString(){
StringBuilder sb = new StringBuilder();
String comma = ", ";
sb.append("{\"name\": \"").append(Device_Name).append("\"").append(comma);
sb.append("\"description\": \"").append(Device_Description).append("\"").append(comma);
sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma);
sb.append("\"model\": \"").append(Model).append("\"");
sb.append("}");
return sb.toString();
}
/**
* This is a static function which will turn a Listed Device array into its proper string. (modification)
* @author - Connor
* @param array
* @return
*/
public static String arrayToString(ListedDevice[] 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();
}
}

0 comments on commit b7bddb4

Please sign in to comment.