Advertisement
JakeFromNotStateFarm

Untitled

Dec 12th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.44 KB | None | 0 0
  1.  
  2. package itinventory;
  3. import java.sql.Statement;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7. import java.sql.ResultSet;
  8. import javax.swing.JOptionPane;
  9.  
  10.  
  11. //CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE(null,'WATTS','C:\Users\JacobIT\Desktop\WattsPrinters.csv',null,null,null,0);
  12. //Above is used to import a CSV into the appropriate table. Replace the file lo
  13. //cation with the CSV and the "WATTS" with the corresponding table name
  14. /**
  15.  * Millikin Information Technology
  16.  * Inventory System
  17.  *
  18.  * @author jacobit
  19.  */
  20. public class ITInventory {
  21.     public static void main(String[] args) throws SQLException {
  22.     int LoopEnter = 1;
  23.     while(LoopEnter==1){
  24.         /*The following block of code is contained inside of a try/catch statement due
  25.         *to issues putting the connection code elsewhere. Inside, the first chunk
  26.         *of code estalishes a connection to a netbeans derby database.
  27.         */
  28.         try{
  29.             String host,username,password;
  30.             host = "jdbc:derby://localhost:1527/Inventory";
  31.             username = "ITUser";
  32.             password = "penguin";
  33.             Connection Con = DriverManager.getConnection(host, username, password);
  34.             Statement stmt = Con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  35.             //Below simply asks which functionality the user would like to utilize.
  36.             int ActionChoice = Integer.parseInt(JOptionPane.showInputDialog("Welcome to the Millikin IT Inventory Program, or MIIP for short."
  37.                     + "\nBelow are 4 different actions you can perform with devices."
  38.                     + "\nPlease enter in the line below, the number corresponding to your choice."
  39.                     + "\n1. Search for a machine via Serial."
  40.                     + "\n2. Search a machine via IP."
  41.                     + "\n3. Delete a machine from the database."
  42.                     + "\n4. Add a machine to the database"));
  43.             //User chose "Search for Machine via IP"
  44.             if(ActionChoice==1){//User chooses to Search for Machine via the serial
  45.            
  46.                         int DeviceType = Integer.parseInt(JOptionPane.showInputDialog("What is the type of device that you wish to look-up."
  47.                             + "\nEnter the corresponding number:"
  48.                             + "\n1: Non Watts Printer"
  49.                             + "\n2: Watts Printer"
  50.                             + "\n3: Desktop"));
  51.  
  52.                         if(DeviceType==2){
  53.                             String UserInput = JOptionPane.showInputDialog("Please scan the device you wish to look-up.");
  54.                             String SQL = "SELECT * FROM ITUSER.WATTS WHERE SERIAL LIKE '"+UserInput+"%'";
  55.                             ResultSet rs = stmt.executeQuery(SQL);
  56.  
  57.                             while(rs.next()){
  58.                                 String Serial = rs.getString("Serial");
  59.                                 String Printername = rs.getString("PrinterName");
  60.                                 String Location = rs.getString("Location");
  61.                                 String IP = rs.getString("IP");
  62.  
  63.                                 String Out = ("Serial Number:         "+Serial+"\nPrinter Name:           "+Printername+"\nPrinter Location:      "+Location+"\nPrinter IP Address:  "+IP);
  64.                                 JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
  65.  
  66.                             }
  67.                         }
  68.                         if(DeviceType==1){
  69.                             String UserInput = JOptionPane.showInputDialog("Please scan the device you wish to look-up.");
  70.                             String SQL = "SELECT * FROM ITUSER.NON_WATTS_PRINTERS WHERE SERIAL LIKE '"+UserInput+"%'";
  71.                             ResultSet rs = stmt.executeQuery(SQL);
  72.  
  73.                             while(rs.next()){
  74.                                 String Serial = rs.getString("Serial");
  75.                                 String Printername = rs.getString("PrinterName");
  76.                                 String Location = rs.getString("Location");
  77.                                 String IP = rs.getString("IP");
  78.  
  79.                                 String Out = ("Serial Number:         "+Serial+"\nPrinter Name:           "+Printername+"\nPrinter Location:      "+Location+"\nPrinter IP Address:  "+IP);
  80.                                 JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
  81.  
  82.                             }
  83.                         }
  84.                         if(DeviceType==3){
  85.                             String UserInput = JOptionPane.showInputDialog("Please scan the device you wish to look-up.");
  86.                             String SQL = "SELECT * FROM ITUSER.DESKTOPS WHERE SERIAL LIKE '"+UserInput+"%'";
  87.                             ResultSet rs = stmt.executeQuery(SQL);
  88.  
  89.                             while(rs.next()){
  90.                                 String Serial = rs.getString("Serial");
  91.                                 String Printername = rs.getString("DeviceName");
  92.                                 String Location = rs.getString("Location");
  93.                                 String IP = rs.getString("IP");
  94.  
  95.                                 String Out = ("Serial Number:         "+Serial+"\nDevice Name:            "+Printername+"\nDevice Location:      "+Location+"\nDevice IP Address:  "+IP);
  96.                                 JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
  97.                             }
  98.                         }
  99.             }
  100.             if(ActionChoice==2){//The user chooses to search for a device via IP
  101.                         int DeviceType = Integer.parseInt(JOptionPane.showInputDialog("What is the type of device that you wish to look-up."
  102.                             + "\nEnter the corresponding number:"
  103.                             + "\n1: Non Watts Printer"
  104.                             + "\n2: Watts Printer"
  105.                             + "\n3: Desktop"));
  106.  
  107.                         if(DeviceType==2){
  108.                             String UserInput = JOptionPane.showInputDialog("Please enter the IP of the device you wish to look-up.");
  109.                             String SQL = "SELECT * FROM ITUSER.WATTS WHERE IP LIKE '"+UserInput+"%'";
  110.                             ResultSet rs = stmt.executeQuery(SQL);
  111.  
  112.                             while(rs.next()){
  113.                                 String Serial = rs.getString("Serial");
  114.                                 String Printername = rs.getString("PrinterName");
  115.                                 String Location = rs.getString("Location");
  116.                                 String IP = rs.getString("IP");
  117.  
  118.                                 String Out = ("Serial Number:         "+Serial+"\nPrinter Name:           "+Printername+"\nPrinter Location:      "+Location+"\nPrinter IP Address:  "+IP);
  119.                                 JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
  120.  
  121.                             }
  122.                         }
  123.                         if(DeviceType==1){
  124.                             String UserInput = JOptionPane.showInputDialog("Please enter the IP of the device you wish to look-up.");
  125.                             String SQL = "SELECT * FROM ITUSER.NON_WATTS_PRINTERS WHERE IP LIKE '"+UserInput+"%'";
  126.                             ResultSet rs = stmt.executeQuery(SQL);
  127.  
  128.                             while(rs.next()){
  129.                                 String Serial = rs.getString("Serial");
  130.                                 String Printername = rs.getString("PrinterName");
  131.                                 String Location = rs.getString("Location");
  132.                                 String IP = rs.getString("IP");
  133.  
  134.                                 String Out = ("Serial Number:         "+Serial+"\nPrinter Name:           "+Printername+"\nPrinter Location:      "+Location+"\nPrinter IP Address:  "+IP);
  135.                                 JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
  136.  
  137.                             }
  138.                         }
  139.                         if(DeviceType==3){
  140.                             String UserInput = JOptionPane.showInputDialog("Please enter the IP of the device you wish to look-up.");
  141.                             String SQL = "SELECT * FROM ITUSER.DESKTOPS WHERE IP LIKE '"+UserInput+"%'";
  142.                             ResultSet rs = stmt.executeQuery(SQL);
  143.  
  144.                             while(rs.next()){
  145.                                 String Serial = rs.getString("Serial");
  146.                                 String Printername = rs.getString("DeviceName");
  147.                                 String Location = rs.getString("Location");
  148.                                 String IP = rs.getString("IP");
  149.  
  150.                                 String Out = ("Serial Number:         "+Serial+"\nDevice Name:            "+Printername+"\nDevice Location:      "+Location+"\nDevice IP Address:  "+IP);
  151.                                 JOptionPane.showMessageDialog(null, Out+"\n-----------------------------------------------------");
  152.                             }
  153.                         }
  154.             }
  155.             //Cant figure out how to properly implement the delete funstionality just yet. Soon.
  156.             if(ActionChoice==3){//The user chooses to delete a device from the database.
  157.                
  158.             }
  159.             if(ActionChoice==4){//The User chooses to add a device to the database.
  160.                 String DeviceType = JOptionPane.showInputDialog("Welcome to the device addition wizard."
  161.                         + "\nPlease have the following information ready to input."
  162.                         + "\n1. Device Type"
  163.                         + "\n2. Device Serial Number"
  164.                         + "\n3. Device Name"
  165.                         + "\n4. Device Location"
  166.                         + "\n5. Device IP Address"
  167.                         + "\n"
  168.                         + "\nNow, Please enter one of the corresponding numbers to the device type below."
  169.                         + "\n1. Watts Printer"
  170.                         + "\n2. Non-Watts Printer"
  171.                         + "\n3. Desktop");
  172.                 //The following code allows you to add a device using the InsertAndDelete class.
  173.                 //It does not insert fully into the database just yet, as I am having issues with the SQL side of things.
  174.                 if(DeviceType.equalsIgnoreCase("1")){
  175.                     String UserInput = JOptionPane.showInputDialog("You have chosen to enter a new Watts printer into the database."
  176.                             + "\nPlease enter the desired device's serial number below.");
  177.                     InsertAndDelete InsertNew = new InsertAndDelete();
  178.                     InsertNew.SerialNumber = (UserInput);
  179.                    
  180.                     UserInput = JOptionPane.showInputDialog("Please enter the desired device's name below.");
  181.                     InsertNew.NameOfMachine = UserInput;
  182.                    
  183.                     UserInput = JOptionPane.showInputDialog("Please enter the desired device's location below. "
  184.                             + "\nPlease refrain from using more than 45 characters.");
  185.                     InsertNew.DeviceLocation = UserInput;
  186.                    
  187.                     UserInput = JOptionPane.showInputDialog("Please enter the current IP Address of the device below.");
  188.                     InsertNew.IPAddress = UserInput;
  189.                                        
  190.                     String DeviceInfo[];
  191.                     DeviceInfo = new String[4];
  192.                    
  193.                     DeviceInfo[0] = InsertNew.getSerial();
  194.                     DeviceInfo[1] = InsertNew.getName();
  195.                     DeviceInfo[2] = InsertNew.getDeviceLocation();
  196.                     DeviceInfo[3] = InsertNew.getIP();
  197.                 }
  198.                 if(DeviceType.equalsIgnoreCase("2")){
  199.                     String UserInput = JOptionPane.showInputDialog("You have chosen to enter a new Watts printer into the database."
  200.                             + "\nPlease enter the desired device's serial number below.");
  201.                     InsertAndDelete InsertNew = new InsertAndDelete();
  202.                     InsertNew.SerialNumber = (UserInput);
  203.                    
  204.                     UserInput = JOptionPane.showInputDialog("Please enter the desired device's name below.");
  205.                     InsertNew.NameOfMachine = UserInput;
  206.                    
  207.                     UserInput = JOptionPane.showInputDialog("Please enter the desired device's location below. "
  208.                             + "\nPlease refrain from using more than 45 characters.");
  209.                     InsertNew.DeviceLocation = UserInput;
  210.                    
  211.                     UserInput = JOptionPane.showInputDialog("Please enter the current IP Address of the device below.");
  212.                     InsertNew.IPAddress = UserInput;
  213.                                        
  214.                     String DeviceInfo[];
  215.                     DeviceInfo = new String[4];
  216.                    
  217.                     DeviceInfo[0] = InsertNew.getSerial();
  218.                     DeviceInfo[1] = InsertNew.getName();
  219.                     DeviceInfo[2] = InsertNew.getDeviceLocation();
  220.                     DeviceInfo[3] = InsertNew.getIP();
  221.                 }
  222.                 if(DeviceType.equalsIgnoreCase("3")){
  223.                     String UserInput = JOptionPane.showInputDialog("You have chosen to enter a new Watts printer into the database."
  224.                             + "\nPlease enter the desired device's serial number below.");
  225.                     InsertAndDelete InsertNew = new InsertAndDelete();
  226.                     InsertNew.SerialNumber = (UserInput);
  227.                    
  228.                     UserInput = JOptionPane.showInputDialog("Please enter the desired device's name below.");
  229.                     InsertNew.NameOfMachine = UserInput;
  230.                    
  231.                     UserInput = JOptionPane.showInputDialog("Please enter the desired device's location below. "
  232.                             + "\nPlease refrain from using more than 45 characters.");
  233.                     InsertNew.DeviceLocation = UserInput;
  234.                    
  235.                     UserInput = JOptionPane.showInputDialog("Please enter the current IP Address of the device below.");
  236.                     InsertNew.IPAddress = UserInput;
  237.                                        
  238.                     String DeviceInfo[];
  239.                     DeviceInfo = new String[4];
  240.                    
  241.                     DeviceInfo[0] = InsertNew.getSerial();
  242.                     DeviceInfo[1] = InsertNew.getName();
  243.                     DeviceInfo[2] = InsertNew.getDeviceLocation();
  244.                     DeviceInfo[3] = InsertNew.getIP();
  245.                 }
  246.             }
  247.                
  248.         }
  249.        
  250.        
  251.         //Catches a failed connection error, so that the program will retry.
  252.         catch (SQLException err){
  253.             System.out.println(err.getMessage());
  254.        
  255.         }
  256.         //Replays the program if desired.s
  257.         String LoopExitOrContinue = JOptionPane.showInputDialog("Would you like to perform another action?\nEnter 'Yes' or 'No'.");
  258.         if(LoopExitOrContinue.equalsIgnoreCase("no")){
  259.             LoopEnter=0;
  260.         }
  261.        
  262.     }
  263.        
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement