Skip to content

Commit

Permalink
Autofill correctly parses phone number and location
Browse files Browse the repository at this point in the history
  • Loading branch information
arc12012 committed Feb 27, 2017
1 parent 0a35b90 commit 8a971dd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
8 changes: 4 additions & 4 deletions WebContent/html/webpages/shoppingCart.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ function autoFillFields() {
<%
MySQLAccess access = new MySQLAccess();
User employee = access.getEmployeeByID(9); //replace with real ID
int location = employee.getLocation();
String location = employee.getLocationName();
String name = employee.getName();
int phone = employee.getPhone();
String phone = employee.getPhone();
%>
employee.location = "<%=location%>";
employee.locationName = "<%=location%>";
employee.name = "<%=name%>";
employee.phone = "<%=phone%>";
document.orderForm.name.value=employee.name;
document.orderForm.location.value=employee.location;
document.orderForm.location.value=employee.locationName;
document.orderForm.phone.value=employee.phone;
}
Expand Down
10 changes: 6 additions & 4 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void connectDB() throws SQLException, ClassNotFoundException {
while(resultSet.next()){
String deviceName = resultSet.getString("Device_Name");
String deviceDescription = resultSet.getString("Device_Description");
String hardwareType = resultSet.getString("Hardware_Type");
String hardwareType = resultSet.getString("Hardware_Model");

for(int i = 0; i<1; i++){
result[i][0] = deviceName;
Expand All @@ -44,7 +44,7 @@ public void initializeEmployee(int id) throws ClassNotFoundException, SQLExcepti
statement.executeQuery("INSERT INTO employee (Employee_ID) VALUES ("+id+");");
}

public void updateEmployee(int id, String name, int phone, int location) throws ClassNotFoundException, SQLException
public void updateEmployee(int id, String name, String phone, int location) throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(database,user,password);
Expand All @@ -69,9 +69,11 @@ public User getEmployeeByID(int id) throws ClassNotFoundException, SQLException
id,
resultSet.getInt("Location_ID"),
resultSet.getString("Name"),
resultSet.getInt("Phone_Number")
resultSet.getString("Phone_Number")
);

resultSet = statement.executeQuery("SELECT Address FROM location WHERE Location_ID = "+employee.getLocation());
resultSet.next();
employee.setLocationName(resultSet.getString("Address"));
return employee;
}

Expand Down
2 changes: 1 addition & 1 deletion src/entities/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
public class Admin extends User {

public Admin(int id, int location, String name, int phone) {
public Admin(int id, int location, String name, String phone) {
super(id, location, name, phone);
}

Expand Down
31 changes: 28 additions & 3 deletions src/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
public class User {
private int id;
private int location;
private String locationName;
private String name;
private int phone;
private String phone;

public User(int id, int location, String name, int phone){
public User(int id, int location, String name, String phone){
this.id = id;
this.location = location;
this.name = name; //later will do table lookup to determine by id
Expand All @@ -16,16 +17,40 @@ public int getID()
{
return id;
}
public void setID(int id)
{
this.id=id;
}
public int getLocation()
{
return location;
}
public void setLocation(int location)
{
this.location=location;
}
public String getName()
{
return name;
}
public int getPhone()
public void setName(String name)
{
this.name=name;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone=phone;
}
public String getLocationName()
{
return locationName;
}
public void setLocationName(String locationName)
{
this.locationName=locationName;
}
}

0 comments on commit 8a971dd

Please sign in to comment.