Skip to content

Commit

Permalink
BETA IS READY
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Apr 7, 2017
1 parent 86a6a38 commit 7b2f796
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
11 changes: 9 additions & 2 deletions WebContent/html/javascript/request.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<%
Device[] mydevices = DeviceQueries.getAllDevices();
Device[] mydevices = DeviceQueries.getAvailableDevices();
//string representation of array.
String deviceString = Device.arrayToString(mydevices);
//out.println(description);
Expand Down Expand Up @@ -150,7 +150,8 @@ function addToCart(){
if(!inCart(id)){ //if not in the cart
var cart = getCartItems(); //this is an array
id = parseInt(id,10); //this gets just the numerical value from the id!
cart.push(devices[id - 1]); //push to bottom of cart
var device = getDevice(id);
cart.push(device); //push to bottom of cart
localStorage.setItem('cart', JSON.stringify(cart));
$('#added').fadeIn(1000);
$('#added').fadeIn(1000);
Expand Down Expand Up @@ -189,6 +190,12 @@ function makeDeviceArray(){
window.json = '<%=deviceString%>';
return JSON.parse(window.json);
}
function getDevice(id){
for(var i = 0; i < devices.length; i++){
if(id == devices[i].id)
return devices[i];
}
}
//this code allows a message to appear that indicates that the item was successfully placed in the shopping cart.
</script>
<script src="../javascript/lib/fuzzy.js"></script>
Expand Down
26 changes: 26 additions & 0 deletions src/database/DeviceQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ public static Device[] getAllDevices() throws SQLException, ClassNotFoundExcepti
return devices;
}

public static Device[] getAvailableDevices() throws SQLException, ClassNotFoundException{
//database connect
System.getenv("VCAP_SERVICES");
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(database, user, password);
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices WHERE Status = \"Available\"");
int counter = 0;

resultSet.last();
int rows = resultSet.getRow();
resultSet.beforeFirst();

//Covers amount of rows, and 6 attributes (indices 0-5)
Device[] devices = new Device[rows];

//iterate result set
while(resultSet.next()){
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++;
}
stmt.close();
connection.close();
return devices;
}

/**
* This function will take devices as input and return them.
* More specifically, the input will be a string that looks like an array.
Expand Down

0 comments on commit 7b2f796

Please sign in to comment.