Skip to content

Commit

Permalink
New location from order form now 'works'
Browse files Browse the repository at this point in the history
I haven't included a way to name the new location, yet. But the feature does work. Also ordering multiple devices works
  • Loading branch information
Adam Claxton authored and Adam Claxton committed Mar 23, 2017
1 parent 2b31f6a commit 14a49ee
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 142 deletions.
21 changes: 0 additions & 21 deletions WebContent/html/webpages/orderForm.html

This file was deleted.

4 changes: 4 additions & 0 deletions WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 7 additions & 11 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="<option id = 0>New Location...</option>";
document.orderForm.location_dropdown.innerHTML="<option value = 0>New Location...</option>";
for (var i = locations.length - 1; i >= 0; i--) {
document.orderForm.location_dropdown.innerHTML+=
("<option value = "+locations[i].id
Expand Down Expand Up @@ -323,20 +323,20 @@ function forceUpdateLocationMetadata() {
}
function forceDropdownCustomLocation() {
$("#dropdown option[id='0']").attr("selected",true);
$("#dropdown option[value='0']").attr("selected",true);
}
function getLocations() {
<%
Location[] loci = access.getLocations();
Location[] loci = access.getLocations(9); //TODO get real ID
%>
var loci = new Array(<%=loci.length%>);
<%
for(int i = 0; i<loci.length; i++)
{
%>
loci[<%=i%>]={
id:<%=loci[i].getId()%>,
id:<%=loci[i].getID()%>,
name:"<%=loci[i].getName()%>",
address:"<%=loci[i].getAddress()%>",
town:"<%=loci[i].getTown()%>",
Expand Down Expand Up @@ -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));
}
</script>
Expand Down
47 changes: 14 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,32 @@
<groupId>2017-CSE-Senior-Project-Team-2</groupId>
<artifactId>2017-CSE-Senior-Project-Team-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>2017-CSE-Senior-Project-Team-2</name>
<description>our senior design project in maven, a test</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
</dependencies>

<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</pluginRepository>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>testPivotal</id>
<name>test repository for pivotal</name>
<url>repo.spring.io</url>
</pluginRepository>
</pluginRepositories>

<packaging>war</packaging>
</project>
61 changes: 36 additions & 25 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -42,8 +39,6 @@ public void connectDB() throws SQLException, ClassNotFoundException {

public String[][] getResult(){
return result;
statement.close();
connect.close();
}


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
{
Expand Down
Loading

0 comments on commit 14a49ee

Please sign in to comment.