Skip to content

Commit

Permalink
Shopping cart locations properly make use of employee flags when read…
Browse files Browse the repository at this point in the history
…ing from and writing to db
  • Loading branch information
arc12012 committed Mar 30, 2017
1 parent 9bcea10 commit 1e34125
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion WebContent/html/webpages/orderFormHandler.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ if(Integer.parseInt(request.getParameter("location_dropdown"))==0)
request.getParameter("state"),
request.getParameter("address"),
request.getParameter("town"),
Integer.parseInt(request.getParameter("zip"))
request.getParameter("zip"),
sso
);
}
Expand Down
5 changes: 2 additions & 3 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function forceDropdownCustomLocation() {
function getLocations() {
<%
Location[] loci = access.getLocations( );
Location[] loci = access.getLocations(sso);
for(int i=0; i<loci.length; i++)
{
System.out.println(loci[i].getName());
Expand Down Expand Up @@ -431,8 +431,7 @@ function getLocations() {
function submitOrderForm() {
// This is called just before order form is submitted. In order for any database activity to occur,
// we must first append the employees ID as well as the ids of whatever devices are selected.
// If nothing is checked then nust don't bother submitting form
if(checked.length == 0) break;
// First, employee id
userID=getUserID();
document.orderForm.userID.value=userID;
Expand Down
9 changes: 5 additions & 4 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MySQLAccess {
String user = "b372dfe7409692";
String password = "74f6e317";
String[][] result = new String[20][3];

public Statement connectDB() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database, user, password);
Expand Down Expand Up @@ -101,9 +101,9 @@ public String locationIntToString(int locInt) throws ClassNotFoundException, SQL
}

// returns ID of new location
public int addLocation(String name, String state, String address, String town, int zip) throws SQLException, ClassNotFoundException
public int addLocation(String name, String state, String address, String town, String zip, int userID) throws SQLException, ClassNotFoundException
{
return addLocation(new Location(name, address, town, state, ""+zip));
return addLocation(new Location(name, address, town, state, zip, userID));
}

// returns ID of new location
Expand All @@ -122,7 +122,8 @@ public int addLocation(Location location) throws SQLException, ClassNotFoundExce
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()+ "\")");
System.out.println("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code,Employee_Flag) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip()+"\","+location.getEmployeeFlag() + ")");
i = stmt.executeUpdate("INSERT INTO location (Location_ID,Name,Address,Town,State,Zip_Code,Employee_Flag) VALUES (" + id +",\"" + location.getName() + "\",\"" + location.getAddress()+ "\",\"" + location.getTown() + "\",\"" + location.getState() + "\",\"" + location.getZip()+"\","+location.getEmployeeFlag() + ")");
}
stmt.close();
connect.close();
Expand Down
18 changes: 18 additions & 0 deletions src/entities/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Location {
private String town;
private String state;
private String zip;
private int employee_flag;

/**
* Constructor for existing location.
Expand Down Expand Up @@ -46,6 +47,15 @@ public Location(String name, String address, String town, String state, String z
this.zip = zip;
}

public Location(String name, String address, String town, String state, String zip, int employee_flag) {
this.name = name;
this.address = address;
this.town = town;
this.state = state;
this.zip = zip;
this.employee_flag = employee_flag;
}

/**
* Make JSON representation of location.
*/
Expand Down Expand Up @@ -103,5 +113,13 @@ public String getState(){
public String getZip(){
return zip;
}
public void setEmployeeFlag(int ID)
{
employee_flag=ID;
}
public int getEmployeeFlag()
{
return employee_flag;
}

}

0 comments on commit 1e34125

Please sign in to comment.