diff --git a/WebContent/WEB-INF/lib/mysql-connector-java-5.1.40-bin.jar b/WebContent/WEB-INF/lib/mysql-connector-java-5.1.40-bin.jar new file mode 100644 index 0000000..60bef5c Binary files /dev/null and b/WebContent/WEB-INF/lib/mysql-connector-java-5.1.40-bin.jar differ diff --git a/WebContent/html/javascript/listing.js b/WebContent/html/javascript/listing.js index 6275ffe..f67c432 100644 --- a/WebContent/html/javascript/listing.js +++ b/WebContent/html/javascript/listing.js @@ -1,49 +1,56 @@ //get all the option buttons var options = document.getElementsByClassName('option'); +var dev0 = { +name: window.myname, +description: window.mydesc, +hardware: window.myhard, +software:"potato" +}; + var dev1 = { - name:"George", - description:"George is probably the coolest iPhone to exist. Ever. Point blank, period.", - hardware:"iphone", - software:"apple" + name:"George", + description:"George is probably the coolest iPhone to exist. Ever. Point blank, period.", + hardware:"iphone", + software:"apple" }; var dev2 = { - name:"Greyson", - description:"Greyson is pretty cool.. I guess.", - hardware:"iphone", - software:"apple" + name:"Greyson", + description:"Greyson is pretty cool.. I guess.", + hardware:"iphone", + software:"apple" }; var dev3 = { - name:"Linkin Park", - description:'"The hardest part of ending is starting again."', - hardware:"ipad", - software:"apple" + name:"Linkin Park", + description:'"The hardest part of ending is starting again."', + hardware:"ipad", + software:"apple" }; var dev4 = { - name:"Abercrombie", - description:"To all the people that hated me in high school, I have the prettiest clothes you all wear now!!", - hardware:"ipad", - software:"apple" + name:"Abercrombie", + description:"To all the people that hated me in high school, I have the prettiest clothes you all wear now!!", + hardware:"ipad", + software:"apple" }; var dev5 = { - name:"Hulk", - description:"Go ahead and HULK SMASH! this awesome computer stick into your USB.", - hardware:"computerStick", - software:"intel" + name:"Hulk", + description:"Go ahead and HULK SMASH! this awesome computer stick into your USB.", + hardware:"computerStick", + software:"intel" }; var dev6 = { - name:"Captain America", - description:'"Make America Great Again. Wait, thats someone else.."', - hardware:"computerStick", - software:"intel" + name:"Captain America", + description:'"Make America Great Again. Wait, thats someone else.."', + hardware:"computerStick", + software:"intel" }; -var devices = [dev1, dev2, dev3, dev4, dev5, dev6]; +var devices = [dev0, dev1, dev2, dev3, dev4, dev5, dev6]; options[0].addEventListener('click', showAll); for(var a = 1; a < options.length; a++){ options[a].addEventListener('click', show); @@ -53,11 +60,11 @@ showAll(); function showAll(){ var html = ''; - + for(var i = 0; i < devices.length; i++){ html += '
' + devices[i].name + '

' + devices[i].description + '



'; } - + document.getElementById('devContainer').innerHTML = html; var unavailable = getUnavailableItems(); @@ -81,13 +88,13 @@ function showAll(){ function show(){ var type = this.getAttribute('data-type'); var html = ''; - + for(var i = 0; i < devices.length; i++){ if(type.localeCompare(devices[i].hardware) == 0 || type.localeCompare(devices[i].software) == 0){ html += '
' + devices[i].name + '

' + devices[i].description + '



' } } - + document.getElementById('devContainer').innerHTML = html; var unavailable = getUnavailableItems(); diff --git a/WebContent/html/javascript/request.js b/WebContent/html/javascript/request.js index 41018f2..1330a49 100644 --- a/WebContent/html/javascript/request.js +++ b/WebContent/html/javascript/request.js @@ -1,6 +1,35 @@ //get all the option buttons var options = document.getElementsByClassName('option'); +function ajaxFunction(){ + var request; + try { + request = new XMLHttpRequest(); + } + catch(e){ + try { + request = new ActiveXObject("Msxml2.XMLHTTP"); + } + catch(e){ + try { + request = new ActiveXObject(Microsoft.XMLHTTP); + } catch(e) { + alert("Something is wrong with your browser"); + return false; + } + + } + } + + + request.onreadystatechange = function(){ + if(request.readyState == 4){ + var display = document.getElementById('ajaxDiv'); + display.innerHTML = request.responseText; + } + } + +} var dev1 = { id: 1, name:"George", diff --git a/WebContent/index.jsp b/WebContent/index.jsp index 7908735..0467f72 100644 --- a/WebContent/index.jsp +++ b/WebContent/index.jsp @@ -1,3 +1,4 @@ +<%@ page import = "database.MySQLAccess" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> @@ -7,6 +8,22 @@ Insert title here - +<% +MySQLAccess myaccess = new MySQLAccess(); +myaccess.connectDB(); +String name = myaccess.getResult()[0][0]; +String description = myaccess.getResult()[0][1]; +String hardware = myaccess.getResult()[0][2]; +out.println(name); +out.println(description); +out.println(hardware); +%> + \ No newline at end of file diff --git a/db/Workbench Schema.mwb b/db/Workbench Schema.mwb index 25df763..03d6ed6 100644 Binary files a/db/Workbench Schema.mwb and b/db/Workbench Schema.mwb differ diff --git a/db/Workbench Schema.mwb.bak b/db/Workbench Schema.mwb.bak index 8683818..25df763 100644 Binary files a/db/Workbench Schema.mwb.bak and b/db/Workbench Schema.mwb.bak differ diff --git a/db/seniordesign.mwb b/db/seniordesign.mwb new file mode 100644 index 0000000..3106b1c Binary files /dev/null and b/db/seniordesign.mwb differ diff --git a/db/seniordesign.sql b/db/seniordesign.sql new file mode 100644 index 0000000..2e28052 --- /dev/null +++ b/db/seniordesign.sql @@ -0,0 +1,224 @@ +-- MySQL Script generated by MySQL Workbench +-- 12/03/16 22:12:11 +-- Model: New Model Version: 1.0 +-- MySQL Workbench Forward Engineering + +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +-- ----------------------------------------------------- +-- Schema seniordesign +-- ----------------------------------------------------- + +-- ----------------------------------------------------- +-- Schema seniordesign +-- ----------------------------------------------------- +CREATE SCHEMA IF NOT EXISTS `seniordesign` DEFAULT CHARACTER SET utf8 ; +USE `seniordesign` ; + +-- ----------------------------------------------------- +-- Table `seniordesign`.`location` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`location` ( + `Location_ID` INT(11) NOT NULL COMMENT 'Identification key for a location.', + `Name` VARCHAR(45) NOT NULL COMMENT 'Name of the location, not necessarily unique.', + `Address` VARCHAR(45) NOT NULL COMMENT 'Address for shipping.', + `Zip_Code` INT(11) NOT NULL COMMENT 'Zip Code for shipping', + PRIMARY KEY (`Location_ID`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`employee` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`employee` ( + `Employee_ID` INT(11) NOT NULL COMMENT 'Employee ID number.', + `Location_ID` INT(11) NOT NULL COMMENT 'Where the employee is registered to work at.', + `Name` VARCHAR(45) NOT NULL COMMENT 'Actual name, might not be unique', + PRIMARY KEY (`Employee_ID`), + INDEX `LOCATION_ID_idx` (`Location_ID` ASC), + CONSTRAINT `Employee_Location_ID` + FOREIGN KEY (`Location_ID`) + REFERENCES `seniordesign`.`location` (`Location_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`fingerprint` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`fingerprint` ( + `Finger_ID` INT(11) NOT NULL, + `Finger_Data` INT(11) NOT NULL, + PRIMARY KEY (`Finger_ID`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`admin` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`admin` ( + `Admin_ID` INT(11) NOT NULL, + `Finger_ID` INT(11) NULL DEFAULT NULL, + `Finger_Registered_Flag` INT(11) NULL DEFAULT NULL, + `Employee_ID` INT(11) NULL DEFAULT NULL, + PRIMARY KEY (`Admin_ID`), + INDEX `EMPLOYEE_ID_idx` (`Employee_ID` ASC), + INDEX `Finger_ID_idx` (`Finger_ID` ASC), + CONSTRAINT `Admin_Employee_ID` + FOREIGN KEY (`Employee_ID`) + REFERENCES `seniordesign`.`employee` (`Employee_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `Admin_Finger_ID` + FOREIGN KEY (`Finger_ID`) + REFERENCES `seniordesign`.`fingerprint` (`Finger_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`ticket` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`ticket` ( + `Ticket_ID` INT(11) NOT NULL COMMENT 'Identification piece of a ticket.', + `Requestor` INT(11) NOT NULL COMMENT 'Whoever initiated the request. Will use their employee ID.', + `Item_Amt` INT(11) NOT NULL COMMENT 'However many items are on a request. Must be at least 1.', + `Begin_Date` DATE NOT NULL COMMENT 'The date that the request was initiated.', + PRIMARY KEY (`Ticket_ID`), + INDEX `Requestor_idx` (`Requestor` ASC), + CONSTRAINT `Ticket_Requestor` + FOREIGN KEY (`Requestor`) + REFERENCES `seniordesign`.`employee` (`Employee_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`devices` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`devices` ( + `Device_ID` INT(11) NOT NULL COMMENT 'How devices will be individually identified. ', + `Device_Name` VARCHAR(45) NOT NULL, + `Device_Description` VARCHAR(200) NOT NULL, + `Ticket_ID` INT(11) NULL DEFAULT NULL COMMENT 'The ticket this device is currently ordered on. Can be null if not ordered out. Foreign key to the ticket table’s primary key.', + `Renter` INT(11) NULL DEFAULT NULL COMMENT 'Employee ID of whoever is renting out the device currently – can be null if nobody is renting it.', + `Location` INT(11) NOT NULL COMMENT 'Storage if not rented, if rented the location COULD be different from the location listed under an employee’s records.', + `Manufacturer` VARCHAR(45) NOT NULL, + `Hardware_Type` VARCHAR(45) NOT NULL COMMENT 'What brand of device it is, such as iPad, iPhone, etc.', + `Model` VARCHAR(45) NOT NULL, + `Serial_Num` VARCHAR(45) NOT NULL, + `Available` INT(11) NOT NULL COMMENT 'Describes if the device is available to rent out yet or not.', + `Return_Date` DATE NULL DEFAULT NULL COMMENT 'Describes how much time is left from the requested amount of time – will cooperate with sending automatic reminders about returning the device. Can be null if the device isn’t rented out.', + `NFC_ID` INT(11) NULL DEFAULT NULL, + PRIMARY KEY (`Device_ID`), + INDEX `Device_Renter_idx` (`Renter` ASC), + INDEX `Device_Location_idx` (`Location` ASC), + INDEX `Device_Ticket_ID_idx` (`Ticket_ID` ASC), + INDEX `Device_Item_Num_idx` (`Ticket_ID` ASC), + CONSTRAINT `Device_Location` + FOREIGN KEY (`Location`) + REFERENCES `seniordesign`.`location` (`Location_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `Device_Renter` + FOREIGN KEY (`Renter`) + REFERENCES `seniordesign`.`employee` (`Employee_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `Device_Ticket_ID` + FOREIGN KEY (`Ticket_ID`) + REFERENCES `seniordesign`.`ticket` (`Ticket_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`item` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`item` ( + `Ticket_ID` INT(11) NOT NULL COMMENT 'The ticket this item is on. This will be both part of the composite key and a foreign key.', + `Item_Num` INT(11) NOT NULL COMMENT 'This is the index the item has on the ticket. This is part of the composite key and the foreign key.', + `Renter` INT(11) NOT NULL COMMENT 'Employee ID of whoever is responsible for this item.', + `Location` INT(11) NOT NULL COMMENT 'Employee ID of whoever is responsible for this item.', + `Device_ID` INT(11) NULL DEFAULT NULL COMMENT 'The ID of the device that is associated to this item. This is null until the administrator assigns a device to an item.', + `Status` VARCHAR(45) NOT NULL COMMENT 'Whatever the current status is of the item.', + `Status_Date_Fields_(Start&End)` DATE NULL DEFAULT NULL COMMENT 'We will include fields for all the start/end times of a status. We haven’t determined all the statuses yet. It is null if that status hasn’t been reached yet.', + `Request_Date` DATE NOT NULL COMMENT 'Includes the date that the device might be able to be returned by. Will incorporate into the automated email notification system.', + PRIMARY KEY (`Ticket_ID`, `Item_Num`), + INDEX `Item_Renter_idx` (`Renter` ASC), + INDEX `Item_Location_idx` (`Location` ASC), + INDEX `Item_Device_ID_idx` (`Device_ID` ASC), + CONSTRAINT `Item_Device_ID` + FOREIGN KEY (`Device_ID`) + REFERENCES `seniordesign`.`devices` (`Device_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `Item_Location` + FOREIGN KEY (`Location`) + REFERENCES `seniordesign`.`location` (`Location_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `Item_Renter` + FOREIGN KEY (`Renter`) + REFERENCES `seniordesign`.`employee` (`Employee_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `Item_Ticket_ID` + FOREIGN KEY (`Ticket_ID`) + REFERENCES `seniordesign`.`ticket` (`Ticket_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`sadmin` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`sadmin` ( + `Sadmin_ID` INT(11) NOT NULL, + `Password` VARCHAR(45) NULL DEFAULT NULL, + `Employee_ID` INT(11) NULL DEFAULT NULL, + PRIMARY KEY (`Sadmin_ID`), + INDEX `EMPLOYEE_ID_idx` (`Employee_ID` ASC), + CONSTRAINT `Sadmin_Employee_ID` + FOREIGN KEY (`Employee_ID`) + REFERENCES `seniordesign`.`employee` (`Employee_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `seniordesign`.`waitlist` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `seniordesign`.`waitlist` ( + `Waitlist_ID` INT(11) NOT NULL, + `Ticket_ID` INT(11) NOT NULL, + PRIMARY KEY (`Waitlist_ID`), + INDEX `TICKET_ID_idx` (`Ticket_ID` ASC), + CONSTRAINT `Waitlist_Ticket_ID` + FOREIGN KEY (`Ticket_ID`) + REFERENCES `seniordesign`.`ticket` (`Ticket_ID`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index fc4c4b8..2b62b32 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -3,8 +3,30 @@ import java.sql.*; public class MySQLAccess { - private Connection connect = null; - private Statement statement = null; - private PreparedStatement preparedStatement = null; - private ResultSet resultSet = null; + + String[][] result = new String[20][3]; + + public void connectDB() throws SQLException, ClassNotFoundException { + Class.forName("com.mysql.jdbc.Driver"); + Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/seniordesign", "root", "password"); + Statement statement = connect.createStatement(); + //PreparedStatement preparedStatement = null; + ResultSet resultSet = statement.executeQuery("SELECT * FROM devices"); + + while(resultSet.next()){ + String deviceName = resultSet.getString("Device_Name"); + String deviceDescription = resultSet.getString("Device_Description"); + String hardwareType = resultSet.getString("Hardware_Type"); + + for(int i = 0; i<1; i++){ + result[i][0] = deviceName; + result[i][1] = deviceDescription; + result[i][2] = hardwareType; + } + } + } + + public String[][] getResult(){ + return result; + } }