Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package itinventory;
- import java.sql.Statement;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.ResultSet;
- import javax.swing.JOptionPane;
- //CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE(null,'WATTS','C:\Users\JacobIT\Desktop\WattsPrinters.csv',null,null,null,0);
- //Above is used to import a CSV into the appropriate table. Replace the file lo
- //cation with the CSV and the "WATTS" with the corresponding table name
- /**
- * Millikin Information Technology
- * Inventory System
- *
- * @author jacobit
- */
- public class ITInventory {
- public static void main(String[] args) throws SQLException {
- int LoopEnter = 1;
- while(LoopEnter==1){
- /*The following block of code is contained inside of a try/catch statement due
- *to issues putting the connection code elsewhere. Inside, the first chunk
- *of code estalishes a connection to a netbeans derby database.
- */
- try{
- String host,username,password;
- host = "jdbc:derby://localhost:1527/Inventory";
- username = "ITUser";
- password = "penguin";
- Connection Con = DriverManager.getConnection(host, username, password);
- Statement stmt = Con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- //Below simply asks which functionality the user would like to utilize.
- int ActionChoice = Integer.parseInt(JOptionPane.showInputDialog("Welcome to the Millikin IT Inventory Program, or MIIP for short."
- + "\nBelow are 4 different actions you can perform with devices."
- + "\nPlease enter in the line below, the number corresponding to your choice."
- + "\n1. Search for a machine via Serial."
- + "\n2. Search a machine via IP."
- + "\n3. Delete a machine from the database."
- + "\n4. Add a machine to the database"));
- //User chose "Search for Machine via IP"
- if(ActionChoice==1){//User chooses to Search for Machine via the serial
- int DeviceType = Integer.parseInt(JOptionPane.showInputDialog("What is the type of device that you wish to look-up."
- + "\nEnter the corresponding number:"
- + "\n1: Non Watts Printer"
- + "\n2: Watts Printer"
- + "\n3: Desktop"));
- if(DeviceType==2){
- String UserInput = JOptionPane.showInputDialog("Please scan the device you wish to look-up.");
- String SQL = "SELECT * FROM ITUSER.WATTS WHERE SERIAL LIKE '"+UserInput+"%'";
- ResultSet rs = stmt.executeQuery(SQL);
- while(rs.next()){
- String Serial = rs.getString("Serial");
- String Printername = rs.getString("PrinterName");
- String Location = rs.getString("Location");
- String IP = rs.getString("IP");
- String Out = ("Serial Number: "+Serial+"\nPrinter Name: "+Printername+"\nPrinter Location: "+Location+"\nPrinter IP Address: "+IP);
- JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
- }
- }
- if(DeviceType==1){
- String UserInput = JOptionPane.showInputDialog("Please scan the device you wish to look-up.");
- String SQL = "SELECT * FROM ITUSER.NON_WATTS_PRINTERS WHERE SERIAL LIKE '"+UserInput+"%'";
- ResultSet rs = stmt.executeQuery(SQL);
- while(rs.next()){
- String Serial = rs.getString("Serial");
- String Printername = rs.getString("PrinterName");
- String Location = rs.getString("Location");
- String IP = rs.getString("IP");
- String Out = ("Serial Number: "+Serial+"\nPrinter Name: "+Printername+"\nPrinter Location: "+Location+"\nPrinter IP Address: "+IP);
- JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
- }
- }
- if(DeviceType==3){
- String UserInput = JOptionPane.showInputDialog("Please scan the device you wish to look-up.");
- String SQL = "SELECT * FROM ITUSER.DESKTOPS WHERE SERIAL LIKE '"+UserInput+"%'";
- ResultSet rs = stmt.executeQuery(SQL);
- while(rs.next()){
- String Serial = rs.getString("Serial");
- String Printername = rs.getString("DeviceName");
- String Location = rs.getString("Location");
- String IP = rs.getString("IP");
- String Out = ("Serial Number: "+Serial+"\nDevice Name: "+Printername+"\nDevice Location: "+Location+"\nDevice IP Address: "+IP);
- JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
- }
- }
- }
- if(ActionChoice==2){//The user chooses to search for a device via IP
- int DeviceType = Integer.parseInt(JOptionPane.showInputDialog("What is the type of device that you wish to look-up."
- + "\nEnter the corresponding number:"
- + "\n1: Non Watts Printer"
- + "\n2: Watts Printer"
- + "\n3: Desktop"));
- if(DeviceType==2){
- String UserInput = JOptionPane.showInputDialog("Please enter the IP of the device you wish to look-up.");
- String SQL = "SELECT * FROM ITUSER.WATTS WHERE IP LIKE '"+UserInput+"%'";
- ResultSet rs = stmt.executeQuery(SQL);
- while(rs.next()){
- String Serial = rs.getString("Serial");
- String Printername = rs.getString("PrinterName");
- String Location = rs.getString("Location");
- String IP = rs.getString("IP");
- String Out = ("Serial Number: "+Serial+"\nPrinter Name: "+Printername+"\nPrinter Location: "+Location+"\nPrinter IP Address: "+IP);
- JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
- }
- }
- if(DeviceType==1){
- String UserInput = JOptionPane.showInputDialog("Please enter the IP of the device you wish to look-up.");
- String SQL = "SELECT * FROM ITUSER.NON_WATTS_PRINTERS WHERE IP LIKE '"+UserInput+"%'";
- ResultSet rs = stmt.executeQuery(SQL);
- while(rs.next()){
- String Serial = rs.getString("Serial");
- String Printername = rs.getString("PrinterName");
- String Location = rs.getString("Location");
- String IP = rs.getString("IP");
- String Out = ("Serial Number: "+Serial+"\nPrinter Name: "+Printername+"\nPrinter Location: "+Location+"\nPrinter IP Address: "+IP);
- JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
- }
- }
- if(DeviceType==3){
- String UserInput = JOptionPane.showInputDialog("Please enter the IP of the device you wish to look-up.");
- String SQL = "SELECT * FROM ITUSER.DESKTOPS WHERE IP LIKE '"+UserInput+"%'";
- ResultSet rs = stmt.executeQuery(SQL);
- while(rs.next()){
- String Serial = rs.getString("Serial");
- String Printername = rs.getString("DeviceName");
- String Location = rs.getString("Location");
- String IP = rs.getString("IP");
- String Out = ("Serial Number: "+Serial+"\nDevice Name: "+Printername+"\nDevice Location: "+Location+"\nDevice IP Address: "+IP);
- JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
- }
- }
- }
- //Cant figure out how to properly implement the delete funstionality just yet. Soon.
- if(ActionChoice==3){//The user chooses to delete a device from the database.
- }
- if(ActionChoice==4){//The User chooses to add a device to the database.
- String DeviceType = JOptionPane.showInputDialog("Welcome to the device addition wizard."
- + "\nPlease have the following information ready to input."
- + "\n1. Device Type"
- + "\n2. Device Serial Number"
- + "\n3. Device Name"
- + "\n4. Device Location"
- + "\n5. Device IP Address"
- + "\n"
- + "\nNow, Please enter one of the corresponding numbers to the device type below."
- + "\n1. Watts Printer"
- + "\n2. Non-Watts Printer"
- + "\n3. Desktop");
- //The following code allows you to add a device using the InsertAndDelete class.
- //It does not insert fully into the database just yet, as I am having issues with the SQL side of things.
- if(DeviceType.equalsIgnoreCase("1")){
- String UserInput = JOptionPane.showInputDialog("You have chosen to enter a new Watts printer into the database."
- + "\nPlease enter the desired device's serial number below.");
- InsertAndDelete InsertNew = new InsertAndDelete();
- InsertNew.SerialNumber = (UserInput);
- UserInput = JOptionPane.showInputDialog("Please enter the desired device's name below.");
- InsertNew.NameOfMachine = UserInput;
- UserInput = JOptionPane.showInputDialog("Please enter the desired device's location below. "
- + "\nPlease refrain from using more than 45 characters.");
- InsertNew.DeviceLocation = UserInput;
- UserInput = JOptionPane.showInputDialog("Please enter the current IP Address of the device below.");
- InsertNew.IPAddress = UserInput;
- String DeviceInfo[];
- DeviceInfo = new String[4];
- DeviceInfo[0] = InsertNew.getSerial();
- DeviceInfo[1] = InsertNew.getName();
- DeviceInfo[2] = InsertNew.getDeviceLocation();
- DeviceInfo[3] = InsertNew.getIP();
- }
- if(DeviceType.equalsIgnoreCase("2")){
- String UserInput = JOptionPane.showInputDialog("You have chosen to enter a new Watts printer into the database."
- + "\nPlease enter the desired device's serial number below.");
- InsertAndDelete InsertNew = new InsertAndDelete();
- InsertNew.SerialNumber = (UserInput);
- UserInput = JOptionPane.showInputDialog("Please enter the desired device's name below.");
- InsertNew.NameOfMachine = UserInput;
- UserInput = JOptionPane.showInputDialog("Please enter the desired device's location below. "
- + "\nPlease refrain from using more than 45 characters.");
- InsertNew.DeviceLocation = UserInput;
- UserInput = JOptionPane.showInputDialog("Please enter the current IP Address of the device below.");
- InsertNew.IPAddress = UserInput;
- String DeviceInfo[];
- DeviceInfo = new String[4];
- DeviceInfo[0] = InsertNew.getSerial();
- DeviceInfo[1] = InsertNew.getName();
- DeviceInfo[2] = InsertNew.getDeviceLocation();
- DeviceInfo[3] = InsertNew.getIP();
- }
- if(DeviceType.equalsIgnoreCase("3")){
- String UserInput = JOptionPane.showInputDialog("You have chosen to enter a new Watts printer into the database."
- + "\nPlease enter the desired device's serial number below.");
- InsertAndDelete InsertNew = new InsertAndDelete();
- InsertNew.SerialNumber = (UserInput);
- UserInput = JOptionPane.showInputDialog("Please enter the desired device's name below.");
- InsertNew.NameOfMachine = UserInput;
- UserInput = JOptionPane.showInputDialog("Please enter the desired device's location below. "
- + "\nPlease refrain from using more than 45 characters.");
- InsertNew.DeviceLocation = UserInput;
- UserInput = JOptionPane.showInputDialog("Please enter the current IP Address of the device below.");
- InsertNew.IPAddress = UserInput;
- String DeviceInfo[];
- DeviceInfo = new String[4];
- DeviceInfo[0] = InsertNew.getSerial();
- DeviceInfo[1] = InsertNew.getName();
- DeviceInfo[2] = InsertNew.getDeviceLocation();
- DeviceInfo[3] = InsertNew.getIP();
- }
- }
- }
- //Catches a failed connection error, so that the program will retry.
- catch (SQLException err){
- System.out.println(err.getMessage());
- }
- //Replays the program if desired.s
- String LoopExitOrContinue = JOptionPane.showInputDialog("Would you like to perform another action?\nEnter 'Yes' or 'No'.");
- if(LoopExitOrContinue.equalsIgnoreCase("no")){
- LoopEnter=0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement