/* SphereTech v0.2 by Kenny Mann //===================================================================== // Goals - General //==================================================================== - Track Software Licenses - Track Users, their hardware, software and accounts/passwords - Generate Reports - Events (Future) - Journal / Service Events (Logs for incidents, and needtodo) //===================================================================== // Goals - Users //==================================================================== - Store name - Department - Phone Extention - Direct Supervisor - Job Title - Installed Software - Hardware Specs - Passwords for different servers and account names - Network Switch ID //===================================================================== // Notes //==================================================================== - For Windows you must run like this (no quotes): "javac -deprecation spheretech.java" <-- Compile "java -cp . spheretech" <-- Run This assumes that 'java' and 'javac' is in your path. You can find your path by typing "PATH" in a comand prompt. - Releases for this program should *ALWAYS* compile. They may not be complete, but should compile and run. //===================================================================== // Food for thought //===================================================================== - Sort after entering data - Sort Software, Accounts, and Users - Job Title - Tab order - "login" button is default, such that when enter is pressed it is launched - Sync with Zaurus with the spread sheet program? MySQL database? //===================================================================== // SQL Structure //===================================================================== // Users Tab //===================================================================== ------------------+-------------+-----------+ Name | Field Name | Data type | ------------------+-------------+-----------+ ID | id | tinytext | User | username | tinytext | Department | dep | tinytext | Phone Extention | phext | tinytext | Supervisor | super | tinytext | Network ID | netid | tinytext | Motherboard | cpu-mobo | tinytext | Processor | cpu-proc | tinytext | RAM | cpu-ram | tinytext | Video | cpu-vid | tinytext | Audio | cpu-aud | tinytext | Network | cpu-nic | tinytext | CD-ROM | cpu-cdrom | tinytext | Harddrive | cpu-hd | tinytext | Misc. Devices | cpu-miscdev | tinytext | Software | soft | text | Accounts | accts | text | ------------------+-------------+-----------+ //===================================================================== // Software tab //===================================================================== ------------------+-------------+-----------+ Name | Field Name | Data type | ------------------+-------------+-----------+ ID | id | tinytext | Title | title | tinytext | Make | make | tinytext | Code Key | codekey | tinytext | Serial Number | sernum | tinytext | Price | price | tinytext | DateOfPurchase | dop | tinytext | Seller | seller | tinytext | Buyer | buyer | tinytext | MS Number | msnum | tinytext | UPC | upc | tinytext | CD Set | cdset | tinytext | ISBN | isbn | tinytext | Operating Sys | os | tinytext | Media | media | tinytext | Misc | misc | text | ------------------+-------------+-----------+ */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.tree.*; import java.sql.*; import javax.swing.plaf.metal.*; import java.util.*; import java.text.Collator; public class spheretech { //JTextField private static JTextField txt_main_accname; private static JTextField txt_main_server; private static JTextField txt_main_database; private static JTextField txt_user_acc; private static JTextField txt_user_dbase; private static JTextField txt_user_server; private static JTextField txt_user_username; private static JTextField txt_user_department; private static JTextField txt_user_phext; private static JTextField txt_user_super; private static JTextField txt_user_netsw; private static JTextField txt_user_mobo; private static JTextField txt_user_proc; private static JTextField txt_user_ram; private static JTextField txt_user_video; private static JTextField txt_user_audio; private static JTextField txt_user_network; private static JTextField txt_user_cdrom; private static JTextField txt_user_harddrive; private static JTextField txt_user_softname; private static JTextField txt_user_softmake; private static JTextField txt_user_service; private static JTextField txt_user_accname; private static JTextField txt_user_pass; private static JTextField txt_soft_title; private static JTextField txt_soft_make; private static JTextField txt_soft_codekey; private static JTextField txt_soft_sernum; private static JTextField txt_soft_price; private static JTextField txt_soft_dop; private static JTextField txt_soft_seller; private static JTextField txt_soft_buyer; private static JTextField txt_soft_msnum; private static JTextField txt_soft_upc; private static JTextField txt_soft_cdset; private static JTextField txt_soft_isbn; private static JTextField txt_soft_os; private static JTextField txt_soft_media; private static JTextField txt_soft_misc; //JTextArea private static JTextArea txt_user_miscdev; //JPasswordField private static JPasswordField txt_main_password; //JLabel private static JLabel lbl_main_accname; private static JLabel lbl_main_password; private static JLabel lbl_main_server; private static JLabel lbl_main_database; private static JLabel lbl_user_service; private static JLabel lbl_user_accname; private static JLabel lbl_user_pass; private static JLabel lbl_user_acc; private static JLabel lbl_user_accts; private static JLabel lbl_user_soft; private static JLabel lbl_user_pword; private static JLabel lbl_user_dbase; private static JLabel lbl_user_server; private static JLabel lbl_user_username; private static JLabel lbl_user_department; private static JLabel lbl_user_phext; private static JLabel lbl_user_super; private static JLabel lbl_user_netsw; private static JLabel lbl_user_mobo; private static JLabel lbl_user_proc; private static JLabel lbl_user_ram; private static JLabel lbl_user_video; private static JLabel lbl_user_audio; private static JLabel lbl_user_network; private static JLabel lbl_user_cdrom; private static JLabel lbl_user_harddrive; private static JLabel lbl_user_miscdev; private static JLabel lbl_user_softname; private static JLabel lbl_user_softmake; private static JLabel lbl_soft_software; private static JLabel lbl_soft_title; private static JLabel lbl_soft_make; private static JLabel lbl_soft_codekey; private static JLabel lbl_soft_sernum; private static JLabel lbl_soft_price; private static JLabel lbl_soft_dop; private static JLabel lbl_soft_seller; private static JLabel lbl_soft_buyer; private static JLabel lbl_soft_msnum; private static JLabel lbl_soft_upc; private static JLabel lbl_soft_cdset; private static JLabel lbl_soft_isbn; private static JLabel lbl_soft_os; private static JLabel lbl_soft_media; private static JLabel lbl_soft_misc; //JList private static JList lst_user_users; private static JList lst_user_soft; private static JList lst_user_accts; private static JList lst_soft_software; //DefaultListModel private static DefaultListModel itms_user_users; private static DefaultListModel itms_user_soft; private static DefaultListModel itms_user_accts; private static DefaultListModel itms_soft_software; public static void main (String[] args) { JFrame f = new JFrame ("SphereTech v0.2"); f.addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent we) { System.exit (0); } }); f.setSize ( 450, 600); f.setLocation (50, 50); JTabbedPane tabs = new JTabbedPane (); tabs = buildPage (); f.getContentPane ().add (tabs); f.setVisible (true); } //============================================================ // ---------------------- Build Panels ----------------------- //============================================================ public static JTabbedPane buildPage () { JTabbedPane tabs = new JTabbedPane (); JPanel main = buildMainPanel (); JPanel users = buildUsersPanel (); JPanel software = buildSoftwarePanel (); tabs.addTab ( "Main", null, main ); tabs.addTab ( "Users", null, users ); tabs.addTab ( "Software", null, software ); return tabs; } //============================================================ // -------------------- Build Main Panel --------------------- //============================================================ public static JPanel buildMainPanel () { JPanel myPanel = new JPanel (); myPanel.setLayout ( null ); //======================= // Labels //======================= lbl_main_accname = new JLabel ( "Account:" ); lbl_main_password = new JLabel ( "Password:" ); lbl_main_server = new JLabel ( "Server:" ); lbl_main_database = new JLabel ( "Database:" ); lbl_main_accname.setBounds ( 20,20,150,20 ); lbl_main_password.setBounds ( 20,45,150,20 ); lbl_main_server.setBounds ( 20,70,150,20 ); lbl_main_database.setBounds ( 20,95,150,20 ); myPanel.add ( lbl_main_accname ); myPanel.add ( lbl_main_password ); myPanel.add ( lbl_main_server ); myPanel.add ( lbl_main_database ); //======================= // Text Boxes //======================= txt_main_accname = new JTextField (); txt_main_server = new JTextField (); txt_main_database = new JTextField (); txt_main_accname.setBounds ( 90,20,150,20 ); txt_main_server.setBounds ( 90,70,150,20 ); txt_main_database.setBounds ( 90,95, 150,20 ); myPanel.add (txt_main_accname); myPanel.add (txt_main_server); myPanel.add (txt_main_database); //======================= // Password Fields //======================= txt_main_password = new JPasswordField (); txt_main_password.setBounds ( 90,45,150,20 ); myPanel.add (txt_main_password); //======================= // Buttons //======================= JButton makesql = new JButton("Gen DBase"); JButton testuser = new JButton("Test User"); makesql.setBounds(275,25,130,20); testuser.setBounds(275,50,130,20); myPanel.add(makesql); myPanel.add(testuser); makesql.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { RecreateSQLDatabase(); }}); testuser.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { TestUser(); }}); //======================= // Panels //======================= JPanel panelAcc = new JPanel (); JPanel panelDbase = new JPanel (); panelAcc.setLayout ( null ); panelDbase.setLayout ( null ); panelAcc.setBounds ( 10,0,240,120 ); panelDbase.setBounds ( 260,0,160,120 ); panelDbase.setBorder ( new TitledBorder ( "Action" ) ); panelAcc.setBorder ( new TitledBorder ( "Sign on" ) ); myPanel.add ( panelDbase ); myPanel.add ( panelAcc ); //======================= // Preset Values //======================= txt_main_accname.setText("kmann"); txt_main_password.setText("test"); txt_main_server.setText("127.0.0.1"); txt_main_database.setText("cdrobot"); return myPanel; } //============================================================ // -------------------- Build Users Panel -------------------- //============================================================ private static JPanel buildUsersPanel (){ JPanel myPanel = new JPanel (); myPanel.setLayout ( null ); //======================= // Items //======================= itms_user_users = new DefaultListModel(); itms_user_soft = new DefaultListModel(); itms_user_accts = new DefaultListModel(); //======================= // Lists //======================= lst_user_users = new JList ( itms_user_users ); lst_user_soft = new JList ( itms_user_soft); lst_user_accts = new JList ( itms_user_accts); JScrollPane scroll = new JScrollPane(lst_user_users); JScrollPane scroll2 = new JScrollPane(lst_user_soft); JScrollPane scroll3 = new JScrollPane(lst_user_accts); scroll.setMinimumSize(new java.awt.Dimension(50,50)); scroll2.setMinimumSize(new java.awt.Dimension(50,50)); scroll3.setMinimumSize(new java.awt.Dimension(50,50)); scroll.setPreferredSize(new java.awt.Dimension(450,300)); scroll2.setPreferredSize(new java.awt.Dimension(450,300)); scroll3.setPreferredSize(new java.awt.Dimension(450,300)); scroll.setAutoscrolls(true); scroll2.setAutoscrolls(true); scroll3.setAutoscrolls(true); scroll.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll2.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll3.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll2.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll3.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll.getViewport().setView(lst_user_users); scroll2.getViewport().setView(lst_user_soft); scroll3.getViewport().setView(lst_user_accts); scroll.setBounds (10,10,300,150); scroll2.setBounds (10,350,190,100); scroll3.setBounds (205,350,210,100); myPanel.add (scroll); myPanel.add (scroll2); myPanel.add (scroll3); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int index = lst_user_users.locationToIndex(e.getPoint()); String stringValue = (String)lst_user_users.getSelectedValue(); User_LoadUser(stringValue); } }}; lst_user_users.addMouseListener(mouseListener); //======================= // Labels //======================= lbl_user_service = new JLabel ("Service:"); lbl_user_accname = new JLabel ("Account Name:"); lbl_user_pass = new JLabel ("Password:"); lbl_user_username = new JLabel ("User:"); lbl_user_soft = new JLabel ("Software"); lbl_user_accts = new JLabel ("Accounts"); lbl_user_department = new JLabel ("Department:"); lbl_user_phext = new JLabel ("Phone Extention:"); lbl_user_super = new JLabel ("Supervisor:"); lbl_user_netsw = new JLabel ("Network ID:"); lbl_user_mobo = new JLabel ("Motherboard:"); lbl_user_proc = new JLabel ("Processor:"); lbl_user_ram = new JLabel ("RAM:"); lbl_user_video = new JLabel ("Video:"); lbl_user_audio = new JLabel ("Audio:"); lbl_user_network = new JLabel ("Network:"); lbl_user_cdrom = new JLabel ("CD-ROM:"); lbl_user_harddrive = new JLabel ("Harddrive:"); lbl_user_miscdev = new JLabel ("Misc. Devices:"); lbl_user_softname = new JLabel ("Name:"); lbl_user_softmake = new JLabel ("Maker:"); lbl_user_service.setBounds (200,450,100,15); lbl_user_accname.setBounds (200,465,100,15); lbl_user_pass.setBounds (200,480,100,15); lbl_user_username.setBounds (10,190,100,15); lbl_user_soft.setBounds (10,330,100,15); lbl_user_accts.setBounds (210,330,100,15); lbl_user_department.setBounds (10,205,100,15); lbl_user_phext.setBounds (10,220,100,15); lbl_user_super.setBounds (10,235,100,15); lbl_user_netsw.setBounds (10,250,100,15); lbl_user_mobo.setBounds (240,175,100,15); lbl_user_proc.setBounds (240,190,100,15); lbl_user_ram.setBounds (240,205,100,15); lbl_user_video.setBounds (240,220,100,15); lbl_user_audio.setBounds (240,235,100,15); lbl_user_network.setBounds (240,250,100,15); lbl_user_cdrom.setBounds (240,265,100,15); lbl_user_harddrive.setBounds (240,280,100,15); lbl_user_miscdev.setBounds (240,295,100,15); lbl_user_softname.setBounds (10,450,100,15); lbl_user_softmake.setBounds (10,465,100,15); myPanel.add (lbl_user_service); myPanel.add (lbl_user_accname); myPanel.add (lbl_user_pass); myPanel.add (lbl_user_username); myPanel.add (lbl_user_soft); myPanel.add (lbl_user_accts); myPanel.add (lbl_user_department); myPanel.add (lbl_user_phext); myPanel.add (lbl_user_super); myPanel.add (lbl_user_netsw); myPanel.add (lbl_user_mobo); myPanel.add (lbl_user_proc); myPanel.add (lbl_user_ram); myPanel.add (lbl_user_video); myPanel.add (lbl_user_audio); myPanel.add (lbl_user_network); myPanel.add (lbl_user_cdrom); myPanel.add (lbl_user_harddrive); myPanel.add (lbl_user_miscdev); myPanel.add (lbl_user_softname); myPanel.add (lbl_user_softmake); //======================= // Text Fields //======================= txt_user_username = new JTextField (); txt_user_department = new JTextField (); txt_user_phext = new JTextField (); txt_user_super = new JTextField (); txt_user_netsw = new JTextField (); txt_user_mobo = new JTextField (); txt_user_proc = new JTextField (); txt_user_ram = new JTextField (); txt_user_video = new JTextField (); txt_user_audio = new JTextField (); txt_user_network = new JTextField (); txt_user_cdrom = new JTextField (); txt_user_harddrive = new JTextField (); txt_user_softname = new JTextField (); txt_user_softmake = new JTextField (); txt_user_service = new JTextField (); txt_user_accname = new JTextField (); txt_user_pass = new JTextField (); txt_user_username.setBounds (110,190,125,15); txt_user_department.setBounds (110,205,125,15); txt_user_phext.setBounds (110,220,125,15); txt_user_super.setBounds (110,235,125,15); txt_user_netsw.setBounds (110,250,125,15); txt_user_mobo.setBounds (320,175,95,15); txt_user_proc.setBounds (320,190,95,15); txt_user_ram.setBounds (320,205,95,15); txt_user_video.setBounds (320,220,95,15); txt_user_audio.setBounds (320,235,95,15); txt_user_network.setBounds (320,250,95,15); txt_user_cdrom.setBounds (320,265,95,15); txt_user_harddrive.setBounds (320,280,95,15); txt_user_softname.setBounds (60,450,110,15); txt_user_softmake.setBounds (60,465,110,15); txt_user_service.setBounds (290,450,110,15); txt_user_accname.setBounds (290,465,110,15); txt_user_pass.setBounds (290,480,110,15); myPanel.add (txt_user_username); myPanel.add (txt_user_department); myPanel.add (txt_user_phext); myPanel.add (txt_user_super); myPanel.add (txt_user_netsw); myPanel.add (txt_user_mobo); myPanel.add (txt_user_proc); myPanel.add (txt_user_ram); myPanel.add (txt_user_video); myPanel.add (txt_user_audio); myPanel.add (txt_user_network); myPanel.add (txt_user_cdrom); myPanel.add (txt_user_harddrive); myPanel.add (txt_user_softname); myPanel.add (txt_user_softmake); myPanel.add (txt_user_accname); myPanel.add (txt_user_pass); myPanel.add (txt_user_service); //======================= // Text Area //======================= txt_user_miscdev = new JTextArea (); txt_user_miscdev.setBounds (320,295,95,50); txt_user_miscdev.setBorder (new EtchedBorder ()); txt_user_miscdev.setLineWrap(true); txt_user_miscdev.setWrapStyleWord(true); myPanel.add (txt_user_miscdev); //======================= // Buttons //======================= JButton addsoft = new JButton ( "Add" ); JButton adduser = new JButton ( "Add" ); JButton moduser = new JButton ( "Update User" ); JButton deluser = new JButton ( "Delete" ); JButton delsoft = new JButton ( "Delete" ); JButton addacc = new JButton ( "Add" ); JButton delacc = new JButton ( "Delete" ); JButton popusers = new JButton ( "Refresh List" ); JButton clear = new JButton ( "New/Clear" ); JButton sortuser = new JButton ( "Sort Users" ); addsoft.setBounds( 10,510,95,15 ); adduser.setBounds( 325,25,105,15 ); moduser.setBounds( 325,45,105,15 ); deluser.setBounds( 325,65,105,15 ); popusers.setBounds( 325,85,105,15 ); sortuser.setBounds( 325,105,105,15 ); clear.setBounds( 325,125,105,15 ); delsoft.setBounds( 100,510,80,15 ); addacc.setBounds( 200,510,80,15 ); delacc.setBounds( 290,510,80,15 ); myPanel.add(addsoft); myPanel.add(adduser); myPanel.add(moduser); myPanel.add(deluser); myPanel.add(delsoft); myPanel.add(addacc); myPanel.add(delacc); myPanel.add(popusers); myPanel.add(clear); myPanel.add(sortuser); clear.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_ClearEverything (); }}); addsoft.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_AddSoftware (); }}); delsoft.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_DelSoftware (); }}); addacc.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_AddAccount (); }}); delacc.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_DelAccount (); }}); adduser.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_AddUser (); }}); moduser.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_ModUser (); }}); deluser.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_DelUser (); }}); popusers.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_PopulateUsers (); }}); sortuser.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { User_SortUsers(); }}); //======================= // Panels //======================= JPanel panelUserInfo = new JPanel (); JPanel panelAction = new JPanel (); panelUserInfo.setLayout ( null ); panelAction.setLayout ( null ); panelUserInfo.setBounds ( 0, 160, 420, 380 ); panelAction.setBounds ( 315, 0, 120, 160 ); panelUserInfo.setBorder ( new TitledBorder ( "User Information" ) ); panelAction.setBorder ( new TitledBorder ( "Perform Action" ) ); myPanel.add ( panelUserInfo ); myPanel.add ( panelAction ); //======================= // Tab Focus //======================= txt_user_username.setNextFocusableComponent(txt_user_department); txt_user_department.setNextFocusableComponent(txt_user_phext); txt_user_phext.setNextFocusableComponent(txt_user_super); txt_user_super.setNextFocusableComponent(txt_user_netsw); txt_user_netsw.setNextFocusableComponent(txt_user_mobo); txt_user_mobo.setNextFocusableComponent(txt_user_proc); txt_user_proc.setNextFocusableComponent(txt_user_ram); txt_user_ram.setNextFocusableComponent(txt_user_video); txt_user_video.setNextFocusableComponent(txt_user_audio); txt_user_audio.setNextFocusableComponent(txt_user_network); txt_user_network.setNextFocusableComponent(txt_user_cdrom); txt_user_cdrom.setNextFocusableComponent(txt_user_harddrive); txt_user_harddrive.setNextFocusableComponent(txt_user_softname); txt_user_softname.setNextFocusableComponent(txt_user_softmake); txt_user_softmake.setNextFocusableComponent(addsoft); txt_user_service.setNextFocusableComponent(txt_user_accname); txt_user_accname.setNextFocusableComponent(txt_user_pass); txt_user_pass.setNextFocusableComponent(addacc); return myPanel; } //============================================================ // ------------------Build Software Panel -------------------- //============================================================ public static JPanel buildSoftwarePanel () { JPanel myPanel = new JPanel (); myPanel.setLayout ( null ); itms_soft_software = new DefaultListModel(); //======================= // Lists //======================= lst_soft_software = new JList ( itms_soft_software ); JScrollPane scroll = new JScrollPane(lst_soft_software); scroll.setMinimumSize(new java.awt.Dimension(50,50)); scroll.setPreferredSize(new java.awt.Dimension(450,300)); scroll.setAutoscrolls(true); scroll.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll.getViewport().setView(lst_soft_software); scroll.setBounds (10,25,200,340); myPanel.add (scroll); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int index = lst_soft_software.locationToIndex(e.getPoint()); String stringValue = (String)lst_soft_software.getSelectedValue(); Soft_LoadSoftware(stringValue); } }}; lst_soft_software.addMouseListener(mouseListener); //======================= // Labels //======================= lbl_soft_software = new JLabel ("Software:"); lbl_soft_title = new JLabel ("Title:"); lbl_soft_make = new JLabel ("Make:"); lbl_soft_codekey = new JLabel ("Code Key:"); lbl_soft_sernum = new JLabel ("Serial Number:"); lbl_soft_price = new JLabel ("Price:"); lbl_soft_dop = new JLabel ("Date of Purchase:"); lbl_soft_seller = new JLabel ("Seller:"); lbl_soft_buyer = new JLabel ("Buyer:"); lbl_soft_msnum = new JLabel ("MS #:"); lbl_soft_upc = new JLabel ("UPC:"); lbl_soft_cdset = new JLabel ("CD Set:"); lbl_soft_isbn = new JLabel ("ISBN #:"); lbl_soft_os = new JLabel ("OS:"); lbl_soft_media = new JLabel ("Media:"); lbl_soft_misc = new JLabel ("Misc:"); lbl_soft_software.setBounds (10,10,150,15); lbl_soft_title.setBounds (220,60,150,15); lbl_soft_make.setBounds (220,75,150,15); lbl_soft_codekey.setBounds (220,90,150,15); lbl_soft_sernum.setBounds (220,105,150,15); lbl_soft_price.setBounds (220,120,150,15); lbl_soft_dop.setBounds (220,135,150,15); lbl_soft_seller.setBounds (220,150,150,15); lbl_soft_buyer.setBounds (220,165,150,15); lbl_soft_msnum.setBounds (220,180,150,15); lbl_soft_upc.setBounds (220,195,150,15); lbl_soft_cdset.setBounds (220,210,150,15); lbl_soft_isbn.setBounds (220,225,150,15); lbl_soft_os.setBounds (220,240,150,15); lbl_soft_media.setBounds (220,255,150,15); lbl_soft_misc.setBounds (220,270,150,15); myPanel.add (lbl_soft_software); myPanel.add (lbl_soft_title); myPanel.add (lbl_soft_make); myPanel.add (lbl_soft_codekey); myPanel.add (lbl_soft_sernum); myPanel.add (lbl_soft_price); myPanel.add (lbl_soft_dop); myPanel.add (lbl_soft_seller); myPanel.add (lbl_soft_buyer); myPanel.add (lbl_soft_msnum); myPanel.add (lbl_soft_upc); myPanel.add (lbl_soft_cdset); myPanel.add (lbl_soft_isbn); myPanel.add (lbl_soft_os); myPanel.add (lbl_soft_media); myPanel.add (lbl_soft_misc); //======================= // Text Fields //======================= txt_soft_title = new JTextField (); txt_soft_make = new JTextField (); txt_soft_codekey = new JTextField (); txt_soft_sernum = new JTextField (); txt_soft_price = new JTextField (); txt_soft_dop = new JTextField (); txt_soft_seller = new JTextField (); txt_soft_buyer = new JTextField (); txt_soft_msnum = new JTextField (); txt_soft_upc = new JTextField (); txt_soft_cdset = new JTextField (); txt_soft_isbn = new JTextField (); txt_soft_os = new JTextField (); txt_soft_media = new JTextField (); txt_soft_misc = new JTextField (); txt_soft_title.setBounds (325,60,100,15); txt_soft_make.setBounds (325,75,100,15); txt_soft_codekey.setBounds (325,90,100,15); txt_soft_sernum.setBounds (325,105,100,15); txt_soft_price.setBounds (325,120,100,15); txt_soft_dop.setBounds (325,135,100,15); txt_soft_seller.setBounds (325,150,100,15); txt_soft_buyer.setBounds (325,165,100,15); txt_soft_msnum.setBounds (325,180,100,15); txt_soft_upc.setBounds (325,195,100,15); txt_soft_cdset.setBounds (325,210,100,15); txt_soft_isbn.setBounds (325,225,100,15); txt_soft_os.setBounds (325,240,100,15); txt_soft_media.setBounds (325,255,100,15); txt_soft_misc.setBounds (325,270,100,15); myPanel.add (txt_soft_title); myPanel.add (txt_soft_make); myPanel.add (txt_soft_codekey); myPanel.add (txt_soft_sernum); myPanel.add (txt_soft_price); myPanel.add (txt_soft_dop); myPanel.add (txt_soft_seller); myPanel.add (txt_soft_buyer); myPanel.add (txt_soft_msnum); myPanel.add (txt_soft_upc); myPanel.add (txt_soft_cdset); myPanel.add (txt_soft_isbn); myPanel.add (txt_soft_os); myPanel.add (txt_soft_media); myPanel.add (txt_soft_misc); //======================= // Buttons //======================= JButton addsoft = new JButton ( "Add" ); JButton modsoft = new JButton ( "Modify" ); JButton delsoft = new JButton ( "Delete" ); JButton popsoft = new JButton ( "Update List" ); JButton clear = new JButton ( "New/Clear" ); addsoft.setBounds( 25,390,105,15 ); modsoft.setBounds( 25,415,105,15 ); delsoft.setBounds( 25,440,105,15 ); popsoft.setBounds( 25,465,105,15 ); clear.setBounds( 25,490,105,15 ); myPanel.add(addsoft); myPanel.add(modsoft); myPanel.add(delsoft); myPanel.add(popsoft); myPanel.add(clear); addsoft.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { Soft_AddSoft (); }}); modsoft.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { Soft_ModSoft (); }}); delsoft.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { Soft_DelSoft (); }}); popsoft.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { Soft_PopulateSoftware (); }}); clear.addActionListener (new ActionListener (){ public void actionPerformed (ActionEvent ae) { Soft_ClearEverything (); }}); //======================= // Panels //======================= JPanel panelAction = new JPanel (); panelAction.setLayout ( null ); panelAction.setBounds ( 10, 370, 135, 160 ); panelAction.setBorder ( new TitledBorder ( "Perform Action" ) ); myPanel.add ( panelAction ); return myPanel; } //============================================================ // --Main-------------- Recreate SQL DBase ------------------- //============================================================ private static void RecreateSQLDatabase(){ String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver String url = ""; Object[] options = { "OK", "CANCEL" }; int op = JOptionPane.showOptionDialog(null, "All data contained in that database will be GONE!\nPress OK to continue.", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if ( op != 0 ) return; //No? Then lets not do anything. //Drop main database try { url = "jdbc:mysql://" + txt_main_server.getText() + "/"; Class.forName(driverName); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf (txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute = "drop database " + txt_main_database.getText();; stmt.executeUpdate(execute); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); System.err.println("Most likely the database doesn't exist... that's OK! We make that next :-"); } //Create new database try { Class.forName(driverName); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf (txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute = "create database " + txt_main_database.getText();; stmt.executeUpdate(execute); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } //Create users table try { url = "jdbc:mysql://" + txt_main_server.getText () + "/" + txt_main_database.getText(); Class.forName(driverName); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf (txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute = "create table users ( username tinytext, dep tinytext, phext tinytext, super tinytext, netid tinytext, cpu_mobo tinytext, cpu_proc tinytext, cpu_ram tinytext, cpu_vid tinytext, cpu_aud tinytext, cpu_nic tinytext, cpu_cdrom tinytext, cpu_hd tinytext, cpu_miscdev text, software text, accounts text)"; stmt.executeUpdate(execute); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } //Create software table try { url = "jdbc:mysql://" + txt_main_server.getText () + "/" + txt_main_database.getText(); Class.forName(driverName); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf (txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute = "create table software ( title tinytext, make tinytext, codekey tinytext, sernum tinytext, price tinytext, dop tinytext, seller tinytext, buyer tinytext, msnum tinytext, upc tinytext, cdset tinytext, isbn tinytext, os tinytext, media tinytext, misc text)"; stmt.executeUpdate(execute); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Main---------------- Test User -------------------------- //============================================================ private static void TestUser(){ String outcome="Something Bad Here"; try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver String url = "jdbc:mysql://" + txt_main_server.getText () + "/" + txt_main_database.getText(); Class.forName(driverName); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf (txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute = "select * from users"; ResultSet rs = stmt.executeQuery(execute); conn.close(); outcome="User OK!\nDatabase Exist!"; } catch (Exception e) { outcome=e.getMessage(); } JOptionPane.showMessageDialog(null, outcome); } //============================================================ // ---------------------- Sort Users ------------------------- //============================================================ private static void User_SortUsers(){ int itm_count = itms_user_users.size(); if ( itm_count <= 0 ) return; String[] UserItems = new String[itm_count]; for ( int i=0; i= 0 ){ itms_user_soft.removeElementAt( selection ); if( selection >= itms_user_soft.size() ) selection = itms_user_soft.size() - 1; lst_user_soft.setSelectedIndex( selection ); } } //============================================================ // --Main-------------------- Add Account ------------------------ //============================================================ private static void User_AddAccount(){ boolean addMe = true; String addItem = ""; String tempString1 = txt_user_service.getText(); String tempString2 = txt_user_accname.getText(); String tempString3 = txt_user_pass.getText(); if ( (tempString1.length() == 0) || (tempString2.length() == 0) ){ JOptionPane.showMessageDialog(null, "Account not completed."); return; } addItem = "Serv: `" + txt_user_service.getText() + "` Acc: `" + txt_user_accname.getText() + "` Pass: `" + txt_user_pass.getText() + "`"; itms_user_accts.addElement (addItem); SortAccList(); txt_user_service.setText (""); txt_user_accname.setText (""); txt_user_pass.setText (""); txt_user_service.requestFocus (); } //============================================================ // --Main------------------Delete Account ------------------------ //============================================================ private static void User_DelAccount(){ int selection = lst_user_accts.getSelectedIndex(); if( selection >= 0 ){ itms_user_accts.removeElementAt( selection ); if( selection >= itms_user_accts.size() ) selection = itms_user_accts.size() - 1; lst_user_accts.setSelectedIndex( selection ); } } //============================================================ // --Main-------------------- Add User --------------------------- //============================================================ private static void User_AddUser(){ String tmp_username=txt_user_username.getText(), tmp_department=txt_user_department.getText(), tmp_phext=txt_user_phext.getText(), tmp_super=txt_user_super.getText(), tmp_netsw=txt_user_netsw.getText(), tmp_mobo=txt_user_mobo.getText(), tmp_proc=txt_user_proc.getText(), tmp_ram=txt_user_ram.getText(); String tmp_video=txt_user_video.getText(), tmp_audio=txt_user_audio.getText(), tmp_network=txt_user_network.getText(), tmp_cdrom=txt_user_cdrom.getText(), tmp_harddrive=txt_user_harddrive.getText(), tmp_miscdev=txt_user_miscdev.getText(); String tmp_software=getSoftware(), tmp_accounts=getAccounts(); if ( tmp_username.length() == 0 ) { JOptionPane.showMessageDialog(null, "I need at least a username"); return; } try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://127.0.0.1/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="Insert into users(username,dep,phext,super,netid,cpu_mobo,cpu_proc,cpu_ram,cpu_vid,cpu_aud,cpu_nic,cpu_cdrom,cpu_hd,cpu_miscdev,software,accounts) values (\"" + tmp_username + "\",\"" + tmp_department + "\",\"" + tmp_phext + "\",\"" + tmp_super + "\",\"" + tmp_netsw + "\",\"" + tmp_mobo + "\",\"" + tmp_proc + "\",\"" + tmp_ram + "\",\"" + tmp_video + "\",\"" + tmp_audio + "\",\"" + tmp_network + "\",\"" + tmp_cdrom + "\",\"" + tmp_harddrive + "\",\"" + tmp_miscdev + "\",\"" + tmp_software + "\",\"" + tmp_accounts + "\")"; stmt.executeUpdate(execute); conn.close(); User_ClearEverything(); User_PopulateUsers(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Main-------------------- Mod User --------------------------- //============================================================ private static void User_ModUser(){ String username = txt_user_username.getText(); if ( username.length() == 0 ){ JOptionPane.showMessageDialog(null, "Please load a user."); return; } try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://127.0.0.1/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="Update users Set dep=\"" + txt_user_department.getText() + "\", phext=\"" + txt_user_phext.getText() + "\", super=\"" + txt_user_super.getText() + "\", netid=\"" + txt_user_netsw.getText() + "\", cpu_mobo=\"" + txt_user_mobo.getText() + "\", cpu_proc=\"" + txt_user_proc.getText() + "\", cpu_ram=\"" + txt_user_ram.getText() + "\", cpu_vid=\"" + txt_user_video.getText() + "\", cpu_aud=\"" + txt_user_audio.getText() + "\", cpu_nic=\"" + txt_user_network.getText() + "\", cpu_cdrom=\"" + txt_user_cdrom.getText() + "\", cpu_hd=\"" + txt_user_harddrive.getText() + "\", cpu_miscdev=\"" + txt_user_miscdev.getText() + "\", software=\"" + getSoftware() + "\", accounts=\"" + getAccounts() + "\" where username=\"" + username + "\""; stmt.executeUpdate(execute); conn.close(); JOptionPane.showMessageDialog(null, username + " updated."); } catch (Exception e) { System.err.println(e.getMessage()); } User_PopulateUsers(); } //============================================================ // --Main-------------------- DelUser ---------------------------- //============================================================ private static void User_DelUser(){ try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://127.0.0.1/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="delete from users where username=" + (String)lst_user_users.getSelectedValue(); stmt.executeUpdate(execute); User_PopulateUsers(); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Main-------------------Populate Users List ------------------ //============================================================ private static void User_PopulateUsers(){ try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://" + txt_main_server.getText () + "/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="select username from users"; ResultSet rs=stmt.executeQuery(execute); itms_user_users.removeAllElements(); while( rs.next()){ itms_user_users.addElement(rs.getString(1)); } conn.close(); User_SortUsers(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Main-------------------Get Software ------------------------- //============================================================ private static String getSoftware (){ String software=""; int size = lst_user_soft.getModel ().getSize(); if ( size > 0 ){ for (int x=0;x 0 ){ for (int x=0;x 0 ){ String[] AccItems = new String[itm_count]; for ( int i=0; i 0 ){ String[] SoftItems = new String[itm_count]; for ( int i=0; i 0 ) { tmp = strArray[i]; strArray[i] = strArray[j]; strArray[j] = tmp; } } } } //============================================================ // --Software------- Add Software ---------------------------- //============================================================ private static void Soft_AddSoft() { String tmp_title=txt_soft_title.getText(); if ( tmp_title.length() == 0 ) { JOptionPane.showMessageDialog(null, "I need at least a title"); return; } try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://127.0.0.1/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="Insert into software(title,make,codekey,sernum,price,dop,seller,buyer,msnum,upc,cdset,isbn,os,media,misc) values (\"" + txt_soft_title.getText() + "\", \"" + txt_soft_make.getText() + "\", \"" + txt_soft_codekey.getText() + "\", \"" + txt_soft_sernum.getText() + "\", \"" + txt_soft_price.getText() + "\", \"" + txt_soft_dop.getText() + "\", \"" + txt_soft_seller.getText() + "\", \"" + txt_soft_buyer.getText() + "\", \"" + txt_soft_msnum.getText() + "\", \"" + txt_soft_upc.getText() + "\", \"" + txt_soft_cdset.getText() + "\", \"" + txt_soft_isbn.getText() + "\", \"" + txt_soft_os.getText() + "\", \"" + txt_soft_media.getText() + "\", \"" + txt_soft_misc.getText() + "\")"; stmt.executeUpdate(execute); conn.close(); Soft_ClearEverything(); Soft_PopulateSoftware(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Software------- Mod Software ---------------------------- //============================================================ private static void Soft_ModSoft() { String title=txt_soft_title.getText(); if ( title.length() == 0 ){ JOptionPane.showMessageDialog(null, "Please load a title."); return; } try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://127.0.0.1/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="Update Software Set make=\"" + txt_soft_make.getText() + "\", codekey=\"" + txt_soft_codekey.getText() + "\", sernum=\"" + txt_soft_sernum.getText() + "\", price=\"" + txt_soft_price.getText() + "\", dop=\"" + txt_soft_dop.getText() + "\", seller=\"" + txt_soft_seller.getText() + "\", buyer=\"" + txt_soft_buyer.getText() + "\", msnum=\"" + txt_soft_msnum.getText() + "\", upc=\"" + txt_soft_upc.getText() + "\", cdset=\"" + txt_soft_cdset.getText() + "\", isbn=\"" + txt_soft_isbn.getText() + "\", os=\"" + txt_soft_os.getText() + "\", media=\"" + txt_soft_media.getText() + "\", misc=\"" + txt_soft_misc.getText() + "\" where title=\"" + title + "\""; stmt.executeUpdate(execute); conn.close(); JOptionPane.showMessageDialog(null, title + " updated."); } catch (Exception e) { System.err.println(e.getMessage()); } Soft_PopulateSoftware(); } //============================================================ // --Software------- Del Software ---------------------------- //============================================================ private static void Soft_DelSoft() { try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://127.0.0.1/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(), String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="delete from software where title=" + (String)lst_soft_software.getSelectedValue(); stmt.executeUpdate(execute); Soft_PopulateSoftware(); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Software------- Populate Software ----------------------- //============================================================ private static void Soft_PopulateSoftware() { try { String execute, tmp_make; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://" + txt_main_server.getText () + "/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="select title from software"; ResultSet rs=stmt.executeQuery(execute); itms_soft_software.removeAllElements(); while( rs.next()){ itms_soft_software.addElement(rs.getString(1)); } conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } //============================================================ // --Software------- Clear Everything ------------------------ //============================================================ private static void Soft_ClearEverything() { txt_soft_title.setText(""); txt_soft_make.setText(""); txt_soft_codekey.setText(""); txt_soft_sernum.setText(""); txt_soft_price.setText(""); txt_soft_dop.setText(""); txt_soft_seller.setText(""); txt_soft_buyer.setText(""); txt_soft_msnum.setText(""); txt_soft_upc.setText(""); txt_soft_cdset.setText(""); txt_soft_isbn.setText(""); txt_soft_os.setText(""); txt_soft_media.setText(""); txt_soft_misc.setText(""); } private static void Soft_LoadSoftware(String loaded) { try { String execute; String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver Class.forName(driverName); String url = "jdbc:mysql://" + txt_main_server.getText () + "/" + txt_main_database.getText(); Connection conn = DriverManager.getConnection(url,txt_main_accname.getText(),String.valueOf(txt_main_password.getPassword())); Statement stmt = conn.createStatement(); execute="select * from software where title=\"" + loaded + "\""; System.out.println(loaded); ResultSet rs=stmt.executeQuery(execute); rs.next(); txt_soft_title.setText(rs.getString(1)); txt_soft_make.setText(rs.getString(2)); txt_soft_codekey.setText(rs.getString(3)); txt_soft_sernum.setText(rs.getString(4)); txt_soft_price.setText(rs.getString(5)); txt_soft_dop.setText(rs.getString(6)); txt_soft_seller.setText(rs.getString(7)); txt_soft_buyer.setText(rs.getString(8)); txt_soft_msnum.setText(rs.getString(9)); txt_soft_upc.setText(rs.getString(10)); txt_soft_cdset.setText(rs.getString(11)); txt_soft_isbn.setText(rs.getString(12)); txt_soft_os.setText(rs.getString(13)); txt_soft_media.setText(rs.getString(14)); txt_soft_misc.setText(rs.getString(15)); conn.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } }