Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.72 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.sql.*;
  4. import java.awt.event.*;
  5.  
  6. public class CycleBusinessGUI extends JFrame implements ActionListener {
  7. //Employee
  8. JLabel ID = new JLabel("Employee ID");
  9. JTextField jtfID = new JTextField(20);
  10. JLabel firstName = new JLabel("First Name");
  11. JLabel lastName = new JLabel("Last Name");
  12. JLabel expertise = new JLabel("Expertise");
  13. JLabel yearHired = new JLabel("Year Hired");
  14. JLabel supervisor = new JLabel("Supervisor");
  15. JLabel phone = new JLabel("Phone Number");
  16. JLabel email = new JLabel("Email Address");
  17. JLabel relation = new JLabel("Relationship Status");
  18. JTextField firstN = new JTextField(20);
  19. JTextField lastN = new JTextField(20);
  20. JTextField exper = new JTextField(20);
  21. JTextField yearH = new JTextField(20);
  22. JTextField superV = new JTextField(20);
  23. JTextField phoneN = new JTextField(20);
  24. JTextField emailA = new JTextField(20);
  25. JTextField relaS = new JTextField(20);
  26. JTextArea descript = new JTextArea(5,40);
  27. JTextArea descript2 = new JTextArea(5,40);
  28. JScrollPane jspDescript = new JScrollPane(descript);
  29. JScrollPane jspDescript2 = new JScrollPane(descript2);
  30. JButton find = new JButton("Find");
  31. JButton add = new JButton("Add");
  32. JButton update = new JButton("Update");
  33. JButton clear = new JButton("Clear");
  34. JButton delete = new JButton("Delete");
  35. JButton audit = new JButton("Audit");
  36.  
  37. //Customer
  38. JTextField creditR = new JTextField(20);
  39. JTextField addressN = new JTextField(20);
  40. JTextField cityW = new JTextField(20);
  41. JTextField stateW = new JTextField(20);
  42. JTextField zipC = new JTextField(20);
  43. JTextField n = new JTextField(20);
  44. JTextField cPhoneN = new JTextField(20);
  45. JTextField cusIDI = new JTextField(20);
  46. JTextArea cusArea = new JTextArea(5,40);
  47. JTextArea cusArea2 = new JTextArea(5,40);
  48. JButton cFind = new JButton("Find");
  49. JButton cAdd = new JButton("Add");
  50. JButton cUpdate = new JButton("Update");
  51. JButton cClear = new JButton("Clear");
  52. JButton cDelete = new JButton("Delete");
  53. JButton cAudit = new JButton("Audit");
  54. JLabel creditRating = new JLabel("Credit Rating");
  55. JLabel address = new JLabel("Address");
  56. JLabel city = new JLabel("City");
  57. JLabel state = new JLabel("State");
  58. JLabel zip = new JLabel("Zip Code");
  59. JLabel name = new JLabel("Name");
  60. JLabel cPhone = new JLabel("Phone");
  61. JLabel cusID = new JLabel("Customer ID");
  62. JTabbedPane jtpComplete = new JTabbedPane();
  63. //MotoCycle
  64.  
  65. JLabel motoID = new JLabel("Moto ID");
  66. JLabel info = new JLabel("Description");
  67. JLabel manu = new JLabel("Manufacturer");
  68. JLabel msrp = new JLabel("MSRP");
  69. JLabel cate = new JLabel("Category");
  70. JTextField jtfmoto = new JTextField(20);
  71. JTextField jtfInfo = new JTextField(20);
  72. JTextField jtfManu = new JTextField(20);
  73. JTextField jtfMsrp = new JTextField(20);
  74. JTextField jtfCate = new JTextField(20);
  75. JTextArea motoArea = new JTextArea(5,40);
  76. JTextArea motoArea2 = new JTextArea(5,40);
  77. JButton mFind = new JButton("Find");
  78. JButton mAdd = new JButton("Add");
  79. JButton mUpdate = new JButton("Update");
  80. JButton mClear = new JButton("Clear");
  81. JButton mDelete = new JButton("Delete");
  82. JButton mAudit = new JButton("Audit");
  83.  
  84. //Invoice
  85. JLabel employeeId = new JLabel("Employee ID");
  86. JLabel customerId = new JLabel("Customer ID");
  87. JLabel invoiceDate = new JLabel("Invoice Date");
  88. JLabel total = new JLabel("Total");
  89. JTextField jtfEmployeeId = new JTextField(20);
  90. JTextField jtfCustomerId = new JTextField(20);
  91. JTextField jtfInvoiceDate = new JTextField(20);
  92. JTextField jtfTotal = new JTextField(20);
  93. JButton iFind = new JButton("Find");
  94. JButton iAdd = new JButton("Add");
  95. JButton iUpdate = new JButton("Update");
  96. JButton iClear = new JButton("Clear");
  97. JButton iDelete = new JButton("Delete");
  98. JButton iAudit = new JButton("Audit");
  99. JTextArea invArea = new JTextArea(5,40);
  100. JTextArea invArea2 = new JTextArea(5,40);
  101. //Moto-Cust
  102. JLabel mcusID = new JLabel("Customer ID");
  103. JLabel mID = new JLabel("Moto ID");
  104. JTextField jtfCusId = new JTextField(20);
  105. JTextField jtfMID = new JTextField(20);
  106. JButton mcAdd = new JButton("Add");
  107. JButton mcDelete = new JButton("Delete");
  108. JTextArea mcArea = new JTextArea(5, 40);
  109. JTextArea mcArea2 = new JTextArea(5, 40);
  110.  
  111. public CycleBusinessGUI(){
  112. //Employee Panel
  113. JPanel employ = new JPanel(new GridLayout(9,2));
  114. employ.add(ID);
  115. employ.add(jtfID);
  116. employ.add(firstName);
  117. employ.add(firstN);
  118. employ.add(lastName);
  119. employ.add(lastN);
  120. employ.add(expertise);
  121. employ.add(exper);
  122. employ.add(yearHired);
  123. employ.add(yearH);
  124. employ.add(supervisor);
  125. employ.add(superV);
  126. employ.add(phone);
  127. employ.add(phoneN);
  128. employ.add(email);
  129. employ.add(emailA);
  130. employ.add(relation);
  131. employ.add(relaS);
  132. JPanel ebuttonPanel = new JPanel(new GridLayout(1,6));
  133. ebuttonPanel.add(find);
  134. ebuttonPanel.add(update);
  135. ebuttonPanel.add(add);
  136. ebuttonPanel.add(clear);
  137. ebuttonPanel.add(delete);
  138. ebuttonPanel.add(audit);
  139. find.addActionListener(this);
  140. add.addActionListener(this);
  141. delete.addActionListener(this);
  142. clear.addActionListener(this);
  143. update.addActionListener(this);
  144. audit.addActionListener(this);
  145. JPanel area = new JPanel(new FlowLayout());
  146. area.add(jspDescript);
  147. JPanel area2 = new JPanel(new FlowLayout());
  148. area2.add(jspDescript2);
  149. JPanel eComplete = new JPanel(new FlowLayout());
  150. eComplete.add(employ);
  151. eComplete.add(area);
  152. eComplete.add(ebuttonPanel);
  153. eComplete.add(area2);
  154.  
  155. //Customer Panel
  156. JPanel customer = new JPanel(new GridLayout(8,2));
  157. customer.add(cusID);
  158. customer.add(cusIDI);
  159. customer.add(name);
  160. customer.add(n);
  161. customer.add(creditRating);
  162. customer.add(creditR);
  163. //NOTE: Make new phone. Caused code confusion//
  164. customer.add(cPhone);
  165. customer.add(cPhoneN);
  166. customer.add(address);
  167. customer.add(addressN);
  168. customer.add(city);
  169. customer.add(cityW);
  170. customer.add(state);
  171. customer.add(stateW);
  172. customer.add(zip);
  173. customer.add(zipC);
  174. JPanel cbuttonPanel = new JPanel(new GridLayout(1,6));
  175. cbuttonPanel.add(cFind);
  176. cbuttonPanel.add(cUpdate);
  177. cbuttonPanel.add(cAdd);
  178. cbuttonPanel.add(cClear);
  179. cbuttonPanel.add(cDelete);
  180. //cbuttonPanel.add(cAudit);
  181. cFind.addActionListener(this);
  182. cUpdate.addActionListener(this);
  183. cAdd.addActionListener(this);
  184. cClear.addActionListener(this);
  185. cDelete.addActionListener(this);
  186.  
  187. JPanel cComplete = new JPanel(new FlowLayout());
  188. cComplete.add(customer);
  189. cComplete.add(cusArea);
  190. cComplete.add(cbuttonPanel);
  191. cComplete.add(cusArea2);
  192.  
  193.  
  194. //Motorcycle//////////////////////////////////////////////
  195. JPanel motorcycle = new JPanel(new GridLayout(5,2));
  196. motorcycle.add(motoID);
  197. motorcycle.add(jtfmoto);
  198. motorcycle.add(info);
  199. motorcycle.add(jtfInfo);
  200. motorcycle.add(manu);
  201. motorcycle.add(jtfManu);
  202. motorcycle.add(msrp);
  203. motorcycle.add(jtfMsrp);
  204. motorcycle.add(cate);
  205. motorcycle.add(jtfCate);
  206. JPanel mbuttonPanel = new JPanel(new GridLayout(1,6));
  207. mbuttonPanel.add(mFind);
  208. mbuttonPanel.add(mUpdate);
  209. mbuttonPanel.add(mAdd);
  210. mbuttonPanel.add(mClear);
  211. mbuttonPanel.add(mDelete);
  212. mFind.addActionListener(this);
  213. mAdd.addActionListener(this);
  214. mUpdate.addActionListener(this);
  215. mClear.addActionListener(this);
  216. mDelete.addActionListener(this);
  217.  
  218. JPanel mComplete = new JPanel(new FlowLayout());
  219. mComplete.add(motorcycle);
  220. mComplete.add(motoArea);
  221. mComplete.add(mbuttonPanel);
  222. mComplete.add(motoArea2);
  223.  
  224.  
  225. //Invoice
  226. JPanel invoice = new JPanel(new GridLayout(4,2));
  227. invoice.add(employeeId);
  228. invoice.add(jtfEmployeeId);
  229. invoice.add(customerId);
  230. invoice.add(jtfCustomerId);
  231. invoice.add(invoiceDate);
  232. invoice.add(jtfInvoiceDate);
  233. invoice.add(total);
  234. invoice.add(jtfTotal);
  235.  
  236. JPanel ibuttonPanel = new JPanel(new GridLayout(1,6));
  237. ibuttonPanel.add(iFind);
  238. ibuttonPanel.add(iUpdate);
  239. ibuttonPanel.add(iAdd);
  240. ibuttonPanel.add(iClear);
  241. ibuttonPanel.add(iDelete);
  242. iFind.addActionListener(this);
  243. iClear.addActionListener(this);
  244.  
  245. JPanel iComplete = new JPanel(new FlowLayout());
  246. iComplete.add(invoice);
  247. iComplete.add(invArea);
  248. iComplete.add(ibuttonPanel);
  249. iComplete.add(invArea2);
  250.  
  251. JPanel motocust = new JPanel(new GridLayout(2,2));
  252. motocust.add(mcusID);
  253. motocust.add(jtfCusId);
  254. motocust.add(mID);
  255. motocust.add(jtfMID);
  256.  
  257. JPanel mcbuttonPanel = new JPanel (new GridLayout(1, 2));
  258. mcbuttonPanel.add(mcAdd);
  259. mcbuttonPanel.add(mcDelete);
  260. mcAdd.addActionListener(this);
  261. mcDelete.addActionListener(this);
  262.  
  263. JPanel mcComplete = new JPanel(new FlowLayout());
  264. mcComplete.add(motocust);
  265. mcComplete.add(mcArea);
  266. mcComplete.add(mcbuttonPanel);
  267. mcComplete.add(mcArea2);
  268.  
  269. jtpComplete.add(eComplete, "Employee");
  270. jtpComplete.add(cComplete,"Customer");
  271. jtpComplete.add(mComplete,"Motorcycle");
  272. jtpComplete.add(iComplete,"Invoice");
  273. jtpComplete.add(mcComplete, "Moto-Cust");
  274.  
  275. jtpComplete.setToolTipTextAt(0,"Eploy");
  276. jtpComplete.setToolTipTextAt(1,"Cus");
  277. jtpComplete.setToolTipTextAt(2,"Moto");
  278. jtpComplete.setToolTipTextAt(3,"Invo");
  279. jtpComplete.setToolTipTextAt(4, "MoCust");
  280. add(jtpComplete);
  281. }
  282.  
  283. public static void main(String args[]) throws SQLException,ClassNotFoundException{
  284. JFrame frame = new CycleBusinessGUI();
  285. frame.setTitle(" ");
  286. frame.setLocationRelativeTo(null);
  287. frame.setSize(550, 550);
  288. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  289. frame.setLocationRelativeTo(null);
  290. frame.setVisible(true);
  291.  
  292.  
  293.  
  294. }
  295. public void actionPerformed(ActionEvent e){
  296. if (e.getSource() == cFind){
  297. System.out.println("Customer Find Button Clicked");
  298.  
  299. try{
  300. // Load the JDBC driver
  301. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  302. System.out.println("Driver loaded");
  303.  
  304.  
  305. // Establish a connection
  306. Connection connection = DriverManager.getConnection
  307. ("jdbc:odbc:CycleBusiness");
  308. System.out.println("Database connected");
  309. //if statements for strings
  310.  
  311.  
  312. // Create a statement
  313. Statement stmt = connection.createStatement();
  314.  
  315. String myString = "SELECT * FROM Customer WHERE(CustomerID LIKE '"
  316. + cusIDI.getText()+ "%') AND (Name LIKE '"
  317. + n.getText() + "%') AND (CreditRating LIKE '"
  318. + creditR.getText() + "%') AND (Phone LIKE '"
  319. + cPhoneN.getText() + "%') AND (Address LIKE '"
  320. + addressN.getText() + "%') AND (City LIKE '"
  321. + cityW.getText() + "%') AND (State LIKE '"
  322. + stateW.getText() + "%') AND (ZipCode LIKE '"
  323. + zipC.getText() + "%')";
  324.  
  325. System.out.println(myString);
  326. // Select the columns from the Student table
  327. ResultSet rset = stmt.executeQuery(myString);
  328.  
  329.  
  330. // Iterate through the result and print the student names
  331. while (rset.next())
  332. cusArea2.append(rset.getString(1) + " " + rset.getString(2)
  333. + " " + rset.getString(3)+ " " + rset.getString(4)
  334. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  335.  
  336.  
  337. // close the connection
  338. connection.close();
  339. }
  340. catch(ClassNotFoundException ex){
  341. }
  342.  
  343.  
  344. catch(SQLException ex){
  345.  
  346. }
  347. }
  348. if (e.getSource() == find){
  349. try{
  350. // Load the JDBC driver
  351. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  352. System.out.println("Driver loaded");
  353.  
  354.  
  355. // Establish a connection
  356. Connection connection = DriverManager.getConnection
  357. ("jdbc:odbc:CycleBusiness");
  358. System.out.println("Database connected");
  359. //if statements for strings
  360.  
  361.  
  362. // Create a statement
  363. Statement stmt = connection.createStatement();
  364.  
  365. String myString = "SELECT * FROM Employee WHERE(EmployeeID LIKE '"
  366. + jtfID.getText()+ "%') AND (FirstName LIKE '"
  367. + firstN.getText() + "%') AND (LastName LIKE '"
  368. + lastN.getText() + "%') AND (Expertise LIKE '"
  369. + exper.getText() + "%') AND (YearHired LIKE '"
  370. + yearH.getText() + "%') AND (Supervisor LIKE '"
  371. + superV.getText() + "%') AND (PhoneNumber LIKE '"
  372. + phoneN.getText() + "%') AND (Email LIKE '"
  373. + emailA.getText() + "%') AND (RStatus LIKE '"
  374. + relaS.getText() + "%')";
  375.  
  376. System.out.println(myString);
  377. // Select the columns from the Student table
  378. ResultSet rset = stmt.executeQuery(myString);
  379.  
  380.  
  381. // Iterate through the result and print the student names
  382. while (rset.next())
  383. descript2.append(rset.getString(1) + " " + rset.getString(2)
  384. + " " + rset.getString(3)+ " " + rset.getString(4)
  385. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  386.  
  387.  
  388. // close the connection
  389. connection.close();
  390. }
  391. catch(ClassNotFoundException ex){
  392. }
  393.  
  394.  
  395. catch(SQLException ex){
  396.  
  397. }
  398. }
  399. if (e.getSource() == mFind){
  400. try{
  401. // Load the JDBC driver
  402. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  403. System.out.println("Driver loaded");
  404.  
  405.  
  406. // Establish a connection
  407. Connection connection = DriverManager.getConnection
  408. ("jdbc:odbc:CycleBusiness");
  409. System.out.println("Database connected");
  410. //if statements for strings
  411.  
  412.  
  413. // Create a statement
  414. Statement stmt = connection.createStatement();
  415.  
  416. String myString = "SELECT * FROM Motorcycle WHERE(MotoID LIKE '"
  417. + jtfmoto.getText()+ "%') AND (Description LIKE '"
  418. + jtfInfo.getText() + "%') AND (Manufacturer LIKE '"
  419. + jtfManu.getText() + "%') AND (MSRP LIKE '"
  420. + jtfMsrp.getText() + "%') AND (Category LIKE '"
  421. + jtfCate.getText() + "%')";
  422.  
  423. System.out.println(myString);
  424. // Select the columns from the Student table
  425. ResultSet rset = stmt.executeQuery(myString);
  426.  
  427.  
  428. // Iterate through the result and print the student names
  429. while (rset.next())
  430. motoArea2.append(rset.getString(1) + " " + rset.getString(2)
  431. + " " + rset.getString(3)+ " " + rset.getString(4)
  432. + " " + rset.getString(5) + "\n");
  433.  
  434.  
  435. // close the connection
  436. connection.close();
  437. }
  438. catch(ClassNotFoundException ex){
  439. System.out.println("ClassNotFoundException Error");
  440. }
  441.  
  442.  
  443. catch(SQLException ex){
  444. System.out.println("SQLException Error");
  445. }
  446. }
  447.  
  448. if (e.getSource() == iFind){
  449. try{
  450. // Load the JDBC driver
  451. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  452. System.out.println("Driver loaded");
  453.  
  454.  
  455. // Establish a connection
  456. Connection connection = DriverManager.getConnection
  457. ("jdbc:odbc:CycleBusiness");
  458. System.out.println("Database connected");
  459. //if statements for strings
  460.  
  461.  
  462. // Create a statement
  463. Statement stmt = connection.createStatement();
  464.  
  465. String myString = "SELECT * FROM Invoice WHERE(EmployeeID LIKE '"
  466. + jtfEmployeeId.getText()+ "%') AND (CustomerID LIKE '"
  467. + jtfCustomerId.getText() + "%') AND (InvDate LIKE '"
  468. + jtfInvoiceDate.getText() + "%') AND (Total LIKE '"
  469. + jtfTotal.getText() + "%')";
  470.  
  471. System.out.println(myString);
  472. // Select the columns from the Student table
  473. ResultSet rset = stmt.executeQuery(myString);
  474.  
  475.  
  476. // Iterate through the result and print the student names
  477. while (rset.next())
  478. invArea2.append(rset.getString(1) + " " + rset.getString(2)
  479. + " " + rset.getString(3)+ " " + rset.getString(4)
  480. + "\n");
  481.  
  482.  
  483. // close the connection
  484. connection.close();
  485. }
  486. catch(ClassNotFoundException ex){
  487. System.out.println("ClassNotFoundException Error");
  488. }
  489.  
  490.  
  491. catch(SQLException ex){
  492. System.out.println("SQLException Error");
  493. }
  494. }
  495. if (e.getSource() == add){
  496. System.out.println("Employee Add Clicked");
  497. try{
  498. // Load the JDBC driver
  499. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  500. System.out.println("Driver loaded");
  501.  
  502.  
  503. // Establish a connection
  504. Connection connection = DriverManager.getConnection
  505. ("jdbc:odbc:CycleBusiness");
  506. System.out.println("Database connected");
  507. //if statements for strings
  508.  
  509.  
  510. // Create a statement
  511. Statement stmt = connection.createStatement();
  512.  
  513. String myString = "Insert INTO Employee(EmployeeID,FirstName,LastName,Expertise ,YearHired,Supervisor,"
  514. + "PhoneNumber,Email ,RStatus)VALUES( '" + jtfID.getText() + "','" + firstN.getText() + "','"
  515. + lastN.getText() + "','" + exper.getText() + "','"
  516. + yearH.getText() + "','" + superV.getText() + "','"
  517. + phoneN.getText() + "','" + emailA.getText() + "','" + relaS.getText() + "')";
  518.  
  519. System.out.println(myString);
  520. // Select the columns from the Student table
  521. ResultSet rset = stmt.executeQuery(myString);
  522.  
  523.  
  524. // Iterate through the result and print the student names
  525. while (rset.next())
  526. descript2.append(rset.getString(1) + " " + rset.getString(2)
  527. + " " + rset.getString(3)+ " " + rset.getString(4)
  528. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  529.  
  530.  
  531. // close the connection
  532. connection.close();
  533. }
  534. catch(ClassNotFoundException ex){
  535. }
  536.  
  537.  
  538. catch(SQLException ex){
  539.  
  540. }
  541. }
  542. if (e.getSource() == cAdd){
  543. System.out.println("Customer Add Clicked");
  544. try{
  545. // Load the JDBC driver
  546. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  547. System.out.println("Driver loaded");
  548.  
  549.  
  550. // Establish a connection
  551. Connection connection = DriverManager.getConnection
  552. ("jdbc:odbc:CycleBusiness");
  553. System.out.println("Database connected");
  554. //if statements for strings
  555.  
  556.  
  557. // Create a statement
  558. Statement stmt = connection.createStatement();
  559.  
  560. String myString = "Insert INTO Customer(CustomerID,Name,CreditRating,Phone ,Address,City,"
  561. + "State,ZipCode)VALUES( '" + cusIDI.getText() + "','" + n.getText() + "','"
  562. + creditR.getText() + "','" + cPhoneN.getText() + "','"
  563. + addressN.getText() + "','" + cityW.getText() + "','"
  564. + stateW.getText() + "','" + zipC.getText() + "')";
  565.  
  566. System.out.println(myString);
  567. // Select the columns from the Student table
  568. ResultSet rset = stmt.executeQuery(myString);
  569.  
  570.  
  571. // Iterate through the result and print the student names
  572. while (rset.next())
  573. descript2.append(rset.getString(1) + " " + rset.getString(2)
  574. + " " + rset.getString(3)+ " " + rset.getString(4)
  575. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  576.  
  577.  
  578. // close the connection
  579. connection.close();
  580. }
  581. catch(ClassNotFoundException ex){
  582. }
  583.  
  584.  
  585. catch(SQLException ex){
  586.  
  587. }
  588. }
  589.  
  590. if (e.getSource() == delete){
  591. System.out.println("Employee Delete Clicked");
  592. try{
  593. // Load the JDBC driver
  594. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  595. System.out.println("Driver loaded");
  596.  
  597.  
  598. // Establish a connection
  599. Connection connection = DriverManager.getConnection
  600. ("jdbc:odbc:CycleBusiness");
  601. System.out.println("Database connected");
  602. //if statements for strings
  603.  
  604.  
  605. // Create a statement
  606. Statement stmt = connection.createStatement();
  607.  
  608. String myString = "DELETE * FROM Employee WHERE(EmployeeID LIKE '"
  609. + jtfID.getText()+ "%') AND (FirstName LIKE '"
  610. + firstN.getText() + "%') AND (LastName LIKE '"
  611. + lastN.getText() + "%') AND (Expertise LIKE '"
  612. + exper.getText() + "%') AND (YearHired LIKE '"
  613. + yearH.getText() + "%') AND (Supervisor LIKE '"
  614. + superV.getText() + "%') AND (PhoneNumber LIKE '"
  615. + phoneN.getText() + "%') AND (Email LIKE '"
  616. + emailA.getText() + "%') AND (RStatus LIKE '"
  617. + relaS.getText() + "%')";
  618.  
  619. System.out.println(myString);
  620. // Select the columns from the Student table
  621. ResultSet rset = stmt.executeQuery(myString);
  622.  
  623.  
  624. // Iterate through the result and print the student names
  625. while (rset.next())
  626. descript2.append(rset.getString(1) + " " + rset.getString(2)
  627. + " " + rset.getString(3)+ " " + rset.getString(4)
  628. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  629.  
  630.  
  631. // close the connection
  632. connection.close();
  633. }
  634. catch(ClassNotFoundException ex){
  635. }
  636.  
  637.  
  638. catch(SQLException ex){
  639.  
  640. }
  641.  
  642.  
  643. }
  644. if (e.getSource() == cDelete){
  645. System.out.println("Customer Delete Clicked");
  646. try{
  647. // Load the JDBC driver
  648. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  649. System.out.println("Driver loaded");
  650.  
  651.  
  652. // Establish a connection
  653. Connection connection = DriverManager.getConnection
  654. ("jdbc:odbc:CycleBusiness");
  655. System.out.println("Database connected");
  656. //if statements for strings
  657.  
  658.  
  659. // Create a statement
  660. Statement stmt = connection.createStatement();
  661.  
  662. String myString = "DELETE * FROM Customer WHERE(CustomerID LIKE '"
  663. + cusIDI.getText()+ "%') AND (Name LIKE '"
  664. + n.getText() + "%') AND (CreditRating LIKE '"
  665. + creditR.getText() + "%') AND (Phone LIKE '"
  666. + cPhoneN.getText() + "%') AND (Address LIKE '"
  667. + addressN.getText() + "%') AND (City LIKE '"
  668. + cityW.getText() + "%') AND (State LIKE '"
  669. + stateW.getText() + "%') AND (ZipCode LIKE '"
  670. + zipC.getText() + "%')";
  671.  
  672. System.out.println(myString);
  673. // Select the columns from the Student table
  674. ResultSet rset = stmt.executeQuery(myString);
  675.  
  676.  
  677. // Iterate through the result and print the student names
  678. while (rset.next())
  679. descript2.append(rset.getString(1) + " " + rset.getString(2)
  680. + " " + rset.getString(3)+ " " + rset.getString(4)
  681. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  682.  
  683.  
  684. // close the connection
  685. connection.close();
  686. }
  687. catch(ClassNotFoundException ex){
  688. }
  689.  
  690.  
  691. catch(SQLException ex){
  692.  
  693. }
  694. if (e.getSource() == mcDelete){
  695. System.out.println("Moto-Cust Delete Clicked");
  696. try{
  697. // Load the JDBC driver
  698. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  699. System.out.println("Driver loaded");
  700.  
  701.  
  702. // Establish a connection
  703. Connection connection = DriverManager.getConnection
  704. ("jdbc:odbc:CycleBusiness");
  705. System.out.println("Database connected");
  706. //if statements for strings
  707.  
  708.  
  709. // Create a statement
  710. Statement stmt = connection.createStatement();
  711.  
  712. String myString = "DELETE * FROM MotoCust WHERE(CustomerID LIKE '"
  713. + mcusID.getText()+ "%') AND (MotoID LIKE '"
  714. + motoID.getText() + "%')";
  715. System.out.println(myString);
  716. // Select the columns from the Student table
  717. ResultSet rset = stmt.executeQuery(myString);
  718.  
  719.  
  720. // Iterate through the result and print the student names
  721. while (rset.next())
  722. mcArea2.append(rset.getString(1) + " " + rset.getString(2)+"\n");
  723.  
  724.  
  725. // close the connection
  726. connection.close();
  727. }
  728. catch(ClassNotFoundException ex){
  729. }
  730.  
  731.  
  732. catch(SQLException ex){
  733.  
  734. }
  735.  
  736.  
  737.  
  738.  
  739. }
  740.  
  741. if (e.getSource() == mcAdd){
  742. System.out.println("Moto-Cust Add Clicked");
  743. try{
  744. // Load the JDBC driver
  745. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  746. System.out.println("Driver loaded");
  747. System.out.println("Moto - Cust Add Clicked");
  748.  
  749. // Establish a connection
  750. Connection connection = DriverManager.getConnection
  751. ("jdbc:odbc:CycleBusiness");
  752. System.out.println("Database connected");
  753. //if statements for strings
  754.  
  755.  
  756. // Create a statement
  757. Statement stmt = connection.createStatement();
  758.  
  759. String myString = "Insert INTO Moto-Cust(CustomerID,MotoID) VALUES ( '" + mcusID.getText() + "','" + mID.getText() + "')";
  760.  
  761.  
  762.  
  763. System.out.println(myString);
  764. // Select the columns from the Student table
  765. ResultSet rset = stmt.executeQuery(myString);
  766.  
  767.  
  768. // Iterate through the result and print the student names
  769. while (rset.next())
  770. mcArea2.append(rset.getString(1) + " " + rset.getString(2)+"\n");
  771.  
  772.  
  773.  
  774. // close the connection
  775. connection.close();
  776. }
  777. catch(ClassNotFoundException ex){
  778. }
  779.  
  780.  
  781. catch(SQLException ex){
  782.  
  783. }
  784. }
  785.  
  786.  
  787.  
  788.  
  789. if(e.getSource() == clear){
  790. System.out.println("Employee Clear Clicked");
  791. descript2.setText(null);
  792.  
  793. }
  794. if(e.getSource() == cClear){
  795. System.out.println("Customer Clear Clicked");
  796. cusArea2.setText(null);
  797.  
  798. }
  799. if(e.getSource() == mClear){
  800. System.out.println("Motorcycle Clear Clicked");
  801. motoArea2.setText(null);
  802.  
  803. }
  804. if(e.getSource() == iClear){
  805. System.out.println("Invoice Clear Clicked");
  806. invArea2.setText(null);
  807.  
  808. }
  809.  
  810.  
  811. if(e.getSource() == cUpdate){
  812. System.out.println("Customer Update Clicked");
  813. try{
  814. // Load the JDBC driver
  815. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  816. System.out.println("Driver loaded");
  817.  
  818.  
  819. // Establish a connection
  820. Connection connection = DriverManager.getConnection
  821. ("jdbc:odbc:CycleBusiness");
  822. System.out.println("Database connected");
  823. //if statements for strings
  824.  
  825.  
  826. // Create a statement
  827. Statement stmt = connection.createStatement();
  828.  
  829. String myString = "UPDATE Customer SET CustomerID ="
  830. + cusIDI.getText()+ "WHERE TITLE = CustomerID AND SET Name ="
  831. + n.getText() + "WHERE TITLE = NAME AND AND SET CreditRating ="
  832. + creditR.getText() + "WHERE TITLE = CreditRating AND SET Phone ="
  833. + cPhoneN.getText() + "WHERE TITLE = Phone AND SET AND SET Name = AND SET Name ="
  834. + addressN.getText() + "%') AND (City LIKE '"
  835. + cityW.getText() + "%') AND (State LIKE '"
  836. + stateW.getText() + "%') AND (ZipCode LIKE '"
  837. + zipC.getText() + "%')";
  838.  
  839. System.out.println(myString);
  840. // Select the columns from the Student table
  841. ResultSet rset = stmt.executeQuery(myString);
  842.  
  843.  
  844. // Iterate through the result and print the student names
  845. while (rset.next())
  846. descript2.append(rset.getString(1) + " " + rset.getString(2)
  847. + " " + rset.getString(3)+ " " + rset.getString(4)
  848. + " " + rset.getString(5) + " " + rset.getString(6) + " " + rset.getString(7) + " " + rset.getString(8)+"\n");
  849.  
  850.  
  851. // close the connection
  852. connection.close();
  853. }
  854. catch(ClassNotFoundException ex){
  855. }
  856.  
  857.  
  858. catch(SQLException ex){
  859.  
  860. }
  861.  
  862.  
  863. }
  864.  
  865.  
  866.  
  867. }
  868.  
  869.  
  870.  
  871. }
  872. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement