diff --git a/WebContent/html/webpages/orderForm.html b/WebContent/html/webpages/orderForm.html
deleted file mode 100644
index 52f7394..0000000
--- a/WebContent/html/webpages/orderForm.html
+++ /dev/null
@@ -1,21 +0,0 @@
-
\ No newline at end of file
diff --git a/WebContent/html/webpages/orderFormHandler.jsp b/WebContent/html/webpages/orderFormHandler.jsp
index 8b357af..32b5f00 100644
--- a/WebContent/html/webpages/orderFormHandler.jsp
+++ b/WebContent/html/webpages/orderFormHandler.jsp
@@ -12,11 +12,15 @@ pageEncoding="ISO-8859-1"%>
<%
MySQLAccess access = new MySQLAccess();
+// How are dates done?
+// %>alert(<%=request.getParameter("timeNeeded")%>);<%
+
// If location id is 0, it is a custom location which must be added to the database before employee preffered location can be updated
int location=-1;
if(Integer.parseInt(request.getParameter("location_dropdown"))==0)
{
location = access.addLocation(
+ "placeholder",
request.getParameter("state"),
request.getParameter("address"),
request.getParameter("town"),
diff --git a/WebContent/html/webpages/shoppingCart.jsp b/WebContent/html/webpages/shoppingCart.jsp
index e4e4209..00a1bb4 100644
--- a/WebContent/html/webpages/shoppingCart.jsp
+++ b/WebContent/html/webpages/shoppingCart.jsp
@@ -169,7 +169,7 @@ var employee = {
var checked = new Array();
var locations = getLocations();
-debug_add_item_to_cart();
+debug_add_items_to_cart();
show(); //on load, we want to show everything
@@ -292,7 +292,7 @@ function autoFillFields(orderAllBool) {
document.orderForm.name.value=employee.name;
document.orderForm.phone.value=employee.phone;
// already got locations on page load, now populate dropdown and mark appropriate option selected
- document.orderForm.location_dropdown.innerHTML="New Location... ";
+ document.orderForm.location_dropdown.innerHTML="New Location... ";
for (var i = locations.length - 1; i >= 0; i--) {
document.orderForm.location_dropdown.innerHTML+=
("
var loci = new Array(<%=loci.length%>);
<%
@@ -336,7 +336,7 @@ function getLocations() {
{
%>
loci[<%=i%>]={
- id:<%=loci[i].getId()%>,
+ id:<%=loci[i].getID()%>,
name:"<%=loci[i].getName()%>",
address:"<%=loci[i].getAddress()%>",
town:"<%=loci[i].getTown()%>",
@@ -433,17 +433,13 @@ function deleteAll(){
function getUserID() {
return 9; //TODO actually get a userID
}
-function debug_add_item_to_cart() {
+function debug_add_items_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)
+ cart.push({id:6,location:"test",name:"test",phone:"test"});
localStorage.setItem("cart",JSON.stringify(cart));
}
diff --git a/pom.xml b/pom.xml
index 7ef287a..c58e325 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,51 +3,32 @@
2017-CSE-Senior-Project-Team-2
2017-CSE-Senior-Project-Team-2
0.0.1-SNAPSHOT
- 2017-CSE-Senior-Project-Team-2
- our senior design project in maven, a test
src
maven-compiler-plugin
- 3.1
+ 3.5.1
1.8
1.8
+
+ maven-war-plugin
+ 3.0.0
+
+ WebContent
+
+
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
-
+
+ mysql
+ mysql-connector-java
+ 5.1.40
+
-
-
-
-
- never
-
-
- false
-
- central
- Central Repository
- http://repo.maven.apache.org/maven2
-
-
-
- never
-
-
- false
-
- testPivotal
- test repository for pivotal
- repo.spring.io
-
-
-
+ war
\ No newline at end of file
diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java
index 3fffe9a..949af2c 100644
--- a/src/database/MySQLAccess.java
+++ b/src/database/MySQLAccess.java
@@ -8,9 +8,6 @@
public class MySQLAccess {
- // String database = "jdbc:mysql://localhost:3306/seniordesign";
- // String user = "root";
- // String password = "1234";
String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317";
String user = "b372dfe7409692";
String password = "74f6e317";
@@ -42,8 +39,6 @@ public void connectDB() throws SQLException, ClassNotFoundException {
public String[][] getResult(){
return result;
- statement.close();
- connect.close();
}
@@ -91,9 +86,9 @@ public User getEmployeeByID(int id) throws ClassNotFoundException, SQLException
resultSet = statement.executeQuery("SELECT Address FROM location WHERE Location_ID = "+employee.getLocation());
resultSet.next();
employee.setLocationName(resultSet.getString("Address"));
- return employee;
statement.close();
connect.close();
+ return employee;
}
public int locationStringToInt(String locString) throws SQLException, ClassNotFoundException
@@ -103,9 +98,9 @@ public int locationStringToInt(String locString) throws SQLException, ClassNotFo
Statement statement = connect.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Location_ID FROM location WHERE Address = '"+locString+"'");
resultSet.next();
- return resultSet.getInt("Location_ID");
statement.close();
connect.close();
+ return resultSet.getInt("Location_ID");
}
public String locationIntToString(int locInt) throws ClassNotFoundException, SQLException
@@ -115,36 +110,52 @@ public String locationIntToString(int locInt) throws ClassNotFoundException, SQL
Statement statement = connect.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT Address FROM location WHERE Location_ID = "+locInt);
resultSet.next();
- return resultSet.getString("Address");
statement.close();
connect.close();
+ return resultSet.getString("Address");
}
// returns ID of new location
- public int addLocation(String state, String address, String town, int zip) throws SQLException, ClassNotFoundException
+ public int addLocation(String name, String state, String address, String town, int zip) throws SQLException, ClassNotFoundException
{
- Class.forName("com.myql.jdbc.Driver");
- Connection connect = DriverManager.getConnection(database,user,password);
- Statement statement = connect.createStatement();
- ResultSet resultSet = statement.executeQuery("SELECT COUNT(Location_ID) FROM location");
- int id = resultSet.getInt("COUNT(Location_ID)")+1; //this will only work if we never delete locations...
- String name = "placeholder";
- String query = "INSERT INTO location(Location_ID, Name, Address, Town, State, Zip_Code)"
- +" VALUES ("+id+", "+name+", "+address+", "+town+", "+state+", "+zip+");";
- statement.executeUpdate(query);
- return id;
- statement.close();
+ return addLocation(new Location(name, address, town, state, ""+zip));
+ }
+
+ // returns ID of new location
+ public int addLocation(Location location) 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();
+ int i = -1;
+ int id=0;
+ while(i <= 0){
+ ResultSet results = stmt.executeQuery("SELECT * from location ORDER BY Location_ID");
+ results.last();
+ //gets largest ID
+ id = results.getInt("Location_ID");
+ id++;
+ //tries this statement, otherwise tries again with a new id
+ i = stmt.executeUpdate("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip()+ "\")");
+ }
+ stmt.close();
connect.close();
+ return id;
}
public Location[] getLocations() throws SQLException, ClassNotFoundException
{
- int userID = 0; //TODO get real ID
- String query = "SELECT * FROM location"; //TODO filter for custom locations (needs db change)
+ return getLocations(0);
+ }
+
+ public Location[] getLocations(int userID) throws SQLException, ClassNotFoundException
+ {
+ String query = "SELECT * FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID; //TODO filter for custom locations (needs db change)
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Statement statement = connect.createStatement();
- ResultSet rs = statement.executeQuery("SELECT COUNT(Location_ID) FROM location");
+ ResultSet rs = statement.executeQuery("SELECT COUNT(Location_ID) FROM location WHERE Employee_Flag = 0 OR Employee_Flag = "+userID);
rs.next();
Location[] locations = new Location[rs.getInt("COUNT(Location_ID)")];
rs = statement.executeQuery(query);
@@ -157,13 +168,13 @@ public Location[] getLocations() throws SQLException, ClassNotFoundException
rs.getString("Address"),
rs.getString("Town"),
rs.getString("State"),
- rs.getInt("Zip_Code")
+ rs.getString("Zip_Code")
);
i++;
}
- return locations;
statement.close();
connect.close();
+ return locations;
}
public void generateTicket(int requester, int location, int device) throws ClassNotFoundException, SQLException
{
diff --git a/src/entities/Location.java b/src/entities/Location.java
index a13147a..91fe562 100644
--- a/src/entities/Location.java
+++ b/src/entities/Location.java
@@ -1,15 +1,27 @@
package entities;
+/**
+ * Representation of locations from database.
+ * @author conno
+ *
+ */
public class Location {
private int id;
private String name;
private String address;
private String town;
private String state;
- private int zip;
-
- public Location(int id, String name, String address, String town, String state, int zip)
- {
+ private String zip;
+
+ /**
+ * Constructor for existing location.
+ * @param name
+ * @param address
+ * @param town
+ * @param state
+ * @param zip
+ */
+ public Location(int id, String name, String address, String town, String state, String zip){
this.id = id;
this.name = name;
this.address = address;
@@ -17,52 +29,79 @@ public Location(int id, String name, String address, String town, String state,
this.state = state;
this.zip = zip;
}
-public int getId()
-{
- return id;
-}
-public void setId(int id)
-{
- this.id = id;
-}
-public String getName()
-{
- return name;
-}
-public void setName(String name)
-{
- this.name = name;
-}
-public String getAddress()
-{
- return address;
-}
-public void setAddress(String address)
-{
- this.address = address;
-}
-public String getTown()
-{
- return town;
-}
-public void setTown(String town)
-{
- this.town = town;
-}
-public String getState()
-{
- return state;
-}
-public void setState(String state)
-{
- this.state = state;
-}
-public int getZip()
-{
- return zip;
-}
-public void setZip(int zip)
-{
- this.zip = zip;
+
+ /**
+ * Constructor for brand new location.
+ * @param name
+ * @param address
+ * @param town
+ * @param state
+ * @param zip
+ */
+ public Location(String name, String address, String town, String state, String zip){
+ this.name = name;
+ this.address = address;
+ this.town = town;
+ this.state = state;
+ this.zip = zip;
+ }
+
+ /**
+ * Make JSON representation of location.
+ */
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ String comma = ", ";
+ sb.append("{\"name\": \"").append(name.replace("\"", """)).append("\"").append(comma);
+ sb.append("\"id\": ").append(id).append(comma);
+ sb.append("\"address\": \"").append(address.replace("\"", """)).append("\"").append(comma);
+ sb.append("\"town\": \"").append(town.replace("\"", """)).append("\"").append(comma);
+ sb.append("\"state\": \"").append(state).append("\"").append(comma);
+ sb.append("\"zip\": \"").append(zip).append("\"");
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * This is a static function which will turn a Location array into its proper string.
+ * @param array
+ * @return
+ */
+ public static String arrayToString(Location[] 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 String getName(){
+ return name;
+ }
+
+ public String getAddress(){
+ return address;
+ }
+
+ public String getTown(){
+ return town;
+ }
+
+ public String getState(){
+ return state;
+ }
+
+ public String getZip(){
+ return zip;
+ }
+
}
-}
\ No newline at end of file