Skip to content

Commit

Permalink
Switching Branch
Browse files Browse the repository at this point in the history
Still need to do work
  • Loading branch information
clj13001 committed Mar 31, 2017
1 parent e8e507c commit 3dc05cc
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 160 deletions.
4 changes: 4 additions & 0 deletions WebContent/html/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ input[type=number]{
width: 60%;
}

textarea{
margin: 0 auto;
}

select{
margin:0 auto;
width: 65%;
Expand Down
279 changes: 127 additions & 152 deletions WebContent/html/webpages/adminDeviceSettings.jsp

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions WebContent/html/webpages/adminLocation.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@
<div class = "form-group">
<label for="addName">Location Name *</label>
<input style = "width: 150px;" name = "name" class="form-control" id="addName" placeholder="Location Name" required = "true">
<span class = "help-block"></span>
</div>
<div class = "form-group">
<label for="addAddress">Address *</label>
<input style = "width: 200px;" name = "address" class="form-control" id="addAddress" placeholder="Address" required = "true">
<span class = "help-block"></span>
</div>
<div class = "form-group">
<label for="addTown">City/Town *</label>
Expand Down
70 changes: 70 additions & 0 deletions WebContent/html/webpages/deviceRedirect.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<%@ page import = "database.MySQLAccess,entities.Device" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>Synchrony Financial</title>

<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel = "stylesheet" type = "text/css" href = "../css/stylesheet.css">
<link rel = "shortcut icon" href = "../imgs/synchrony-financial-logo-dlpx_1.ico">
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
</nav>
</head>
<body>
<h2>Redirect Page</h2>
<p>You shouldn't be seeing this page :)</p>

<%
//make instance
MySQLAccess myaccess = new MySQLAccess();
String name = request.getParameter("name").replace("\"","\\\"");
String description = request.getParameter("description").replace("\"","\\\"");
String mac = request.getParameter("MAC");
String manufacturer = request.getParameter("manu").replace("\"","\\\"");
String hardware = request.getParameter("hardware").replace("\"","\\\"");
String model = request.getParameter("model").replace("\"","\\\"");
String serial = request.getParameter("serial");
String nfc = request.getParameter("NFC");
//add form was submitted
if(request.getParameter("add") != null){
Device device = new Device(name,description,mac,manufacturer,hardware,model,serial,nfc);
myaccess.addDevice(device);
}
/*
//modify form was submitted
if(request.getParameter("modify") != null){
//getParameter() always returns string
String strID = request.getParameter("id");
//turn to int for constructor
int id = Integer.parseInt(strID);
Location location = new Location(id,name,address,town,state,zip);
myaccess.modifyLocation(location);
}
//delete form was submitted
if(request.getParameter("delete") != null){
String strID = request.getParameter("id");
int id = Integer.parseInt(strID);
myaccess.deleteLocation(id);
}
*/
%>
<script>
window.location.replace("adminLocation.jsp");
</script>
<!-- Navbar generation. -->
<script src = "../javascript/navbar.js"></script>
</body>
</html>
25 changes: 23 additions & 2 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public int addLocation(Location location) throws SQLException, ClassNotFoundExce
id = results.getInt("Location_ID");
id++;
//tries this statement, otherwise tries again with a new id
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();
Expand Down Expand Up @@ -258,7 +257,7 @@ public Device[] getAllDevices() throws SQLException, ClassNotFoundException{

//iterate result set
while(resultSet.next()){
devices[counter] = new Device(resultSet.getString("Device_Name"),resultSet.getString("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"), resultSet.getString("Model"), resultSet.getString("Manufacturer"), resultSet.getString("Status"));
devices[counter] = new Device(resultSet.getString("Device_Name"),resultSet.getInt("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"),resultSet.getString("Model"),resultSet.getString("Manufacturer"),resultSet.getString("Status"),resultSet.getString("MAC_Address"),resultSet.getString("Serial_Num"),resultSet.getInt("NFC_ID"));
counter++;
}

Expand Down Expand Up @@ -322,4 +321,26 @@ public void deleteLocation(int id) throws ClassNotFoundException, SQLException{
stmt.close();
connect.close();
}

public void addDevice(Device device) 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 devices ORDER BY Device_ID");
results.last();
//gets largest ID
id = results.getInt("Device_ID");
id++;
//tries this statement, otherwise tries again with a new id
String command = "INSERT INTO devices (Device_ID,Device_Name,Device_Description,MAC_Address,Manufacturer,Hardware,Model,Serial_Num,Added_By,NFC_ID) " + "VALUES (" + id +",\"" + device.getName() + "\",\"" + device.getDesc()+ "\",\"" + device.getMAC() + "\",\"" + device.getManufacturer() + "\",\""+device.getHardware()+ "\",\"" + device.getModel() + "\",\"" + device.getSerial() + "\",30," + device.getNFC() + ");"; //TODO update the Added_By to include cookies
System.out.println(command);
i = stmt.executeUpdate(command);
}
stmt.close();
connect.close();
}
}
55 changes: 51 additions & 4 deletions src/entities/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,49 @@
*/
public class Device {
private String Device_Name;
private String Device_ID;
private int Device_ID;
private String Device_Description;
private String Hardware;
private String Model;
private String Manu;
private String Status;
private String MAC;
private String Serial;
private int NFC;

public Device(String name, String id, String desc, String hardware, String model, String manufacturer, String available) {
public Device(String name, int id, String desc, String hardware, String model, String manufacturer, String available, String mac, String serial, int nfc) {
Device_ID = id;
Device_Name = name;
Device_Description = desc;
Hardware = hardware;
Model = model;
Manu = manufacturer;
Status = available;
MAC = mac;
Serial = serial;
NFC = nfc;
}

/**
* Constructor for newly created devices (so we omit the ID)
* @param name
* @param description
* @param mac
* @param manufacturer
* @param hardware
* @param model
* @param serial
* @param nfc
*/
public Device(String name, String description, String mac, String manufacturer, String hardware, String model, String serial, String nfc){
Device_Name = name;
Device_Description = description;
MAC = mac;
Manu = manufacturer;
Hardware = hardware;
Model = model;
Serial = serial;
NFC = Integer.parseInt(nfc);
}
/**
* Formatting the device to fit a JSON object.
Expand All @@ -35,7 +63,10 @@ public String toString(){
sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma);
sb.append("\"status\": \"").append(Status).append("\"").append(comma);
sb.append("\"model\": \"").append(Model).append("\"").append(comma);
sb.append("\"manufacturer\": \"").append(Manu).append("\"");
sb.append("\"manufacturer\": \"").append(Manu).append("\"").append(comma);
sb.append("\"mac\": \"").append(MAC).append("\"").append(comma);
sb.append("\"serial\": \"").append(Serial).append("\"").append(comma);
sb.append("\"nfc\": ").append(NFC);
sb.append("}");
return sb.toString();
}
Expand All @@ -58,7 +89,7 @@ public static String arrayToString(Device[] array){
return sb.toString();
}

public String getID(){
public int getID(){
return Device_ID;
}

Expand All @@ -77,4 +108,20 @@ public String getModel(){
public String getHardware(){
return Hardware;
}

public String getMAC(){
return MAC;
}

public String getManufacturer(){
return Manu;
}

public String getSerial(){
return Serial;
}

public int getNFC() {
return NFC;
}
}

0 comments on commit 3dc05cc

Please sign in to comment.