Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.51 KB | None | 0 0
  1. package system;
  2.  
  3. import java.io.Console;
  4. import java.security.MessageDigest;
  5. import java.security.NoSuchAlgorithmException;
  6. import java.sql.Connection;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import java.util.Locale;
  12. import java.util.Scanner;
  13.  
  14. import javax.xml.bind.DatatypeConverter;
  15.  
  16. import oracle.jdbc.pool.OracleDataSource;
  17.  
  18. public class Aplikacja {
  19.  
  20. String typUzytkownika ="klient";
  21. static String pesel = "92022565434";
  22.  
  23. public void menu() throws SQLException, NoSuchAlgorithmException
  24. {
  25. String message ="";
  26. Connection conn = connect();
  27. do
  28. {
  29. message = login(conn);
  30. System.out.println(message);
  31. }
  32. while(message.equals("Niepoprawny pesel lub haslo"));
  33.  
  34. if(typUzytkownika.equals("klient"))
  35. {
  36. menuCustomer(conn);
  37. }
  38. else if(typUzytkownika.equals("pracownik"))
  39. {
  40. menuWorker(conn);
  41. }
  42. }
  43.  
  44. public void menuCustomer(Connection conn) throws SQLException
  45. {
  46. int action = 0;
  47. boolean end = false;
  48. Scanner scanner = new Scanner(System.in);
  49.  
  50. while(!end)
  51. {
  52. System.out.println("MENU \n1.Wypisz produkty \n2.Zamow produkty \n3.Zobacz zamowienia \n4.Zakoncz");
  53. action = scanner.nextInt();
  54.  
  55. switch(action)
  56. {
  57. case 1:
  58. showProducts(conn);
  59. break;
  60. case 2:
  61. String res = order(conn);
  62. System.out.println(res);
  63. break;
  64. case 3:
  65. PreparedStatement stmt1 = conn.prepareStatement("SELECT * FROM zamowienia WHERE pesel_klienta like " + pesel );
  66. ResultSet rslt1 = stmt1.executeQuery();
  67.  
  68. while (rslt1.next())
  69. {
  70. System.out.println(rslt1.getString(1) +" "+ rslt1.getString(2)+ " "+rslt1.getString(3)+ " "+rslt1.getString(4)+ " "+rslt1.getString(5));
  71. }
  72. break;
  73. case 4:
  74. end = true;
  75. break;
  76. default:
  77. System.out.println("Wprowadzono niewlasciwa liczbe");
  78. break;
  79. }
  80. }
  81. }
  82.  
  83.  
  84. public void menuWorker(Connection conn) throws SQLException
  85. {
  86. int action;
  87. boolean end = false;
  88. Scanner scanner = new Scanner(System.in);
  89. while(!end) {
  90. System.out.println("MENU "
  91. + "\n1.Wypisz produkty "
  92. + "\n2.Dodaj produkt do katalogu"
  93. + "\n3.Usun produkt z katalogu"
  94. + "\n4.Edytuj dane produktu "
  95. + "\n5.Zobacz zamowienia "
  96. + "\n6.Zrealizuj zamowienie"
  97. + "\n7 Wyswietl klientow"
  98. + "\n8.Dodaj klienta "
  99. + "\n9.Usun klienta "
  100. + "\n10. Zakoncz");
  101.  
  102. System.out.println("Wybor: ");
  103. while(!scanner.hasNextInt()) {
  104. System.out.println("Podaj liczbe calkowita z zakresu 1-10: ");
  105. scanner.next();
  106. }
  107. action = scanner.nextInt();
  108. scanner.nextLine();
  109.  
  110.  
  111. switch(action)
  112. {
  113. case 1:
  114. showProducts(conn);
  115. break;
  116. case 2:
  117. insertProduct(conn);
  118. break;
  119. case 3:
  120. deleteProduct(conn);
  121. break;
  122. case 4:
  123. updateProduct(conn);
  124. break;
  125. case 5:
  126. showOrders(conn);
  127. break;
  128. case 6:
  129. executeOrder(conn);
  130. break;
  131. case 7:
  132. showClients(conn);
  133. break;
  134. case 8:
  135. addClient(conn);
  136. break;
  137. case 9:
  138. deleteClient(conn);
  139. break;
  140. case 10:
  141. end = true;
  142. break;
  143. default:
  144. System.out.println("Wprowadzono niewlasciwa liczbe");
  145. break;
  146. }
  147. }
  148. }
  149.  
  150. public static Connection connect() throws SQLException
  151. {
  152. OracleDataSource ods = new OracleDataSource();
  153. ods.setURL("jdbc:oracle:thin:@localhost:1521/xe"); // jdbc:oracle:thin:@//[hostname]:[port]/[DB service name]
  154. ods.setUser("wasik"); // [username]
  155. ods.setPassword("121212as"); // [password]
  156. Connection conn = ods.getConnection();
  157.  
  158. return conn;
  159.  
  160. // Connection con = DriverManager.getConnection(
  161. //"jdbc:oracle:thin:@localhost:1521:xe","wasik","121212as");
  162.  
  163. // return con;
  164. }
  165.  
  166. public void disconect()
  167. {
  168.  
  169. }
  170.  
  171. public String login(Connection conn) throws SQLException, NoSuchAlgorithmException
  172. {
  173. String password;
  174. Scanner scanner = new Scanner(System.in);
  175. System.out.println("Login: ");
  176. pesel = scanner.nextLine();
  177. System.out.println("haslo: ");
  178. password = scanner.nextLine();
  179.  
  180. if(checkPassword(pesel, password, conn))
  181. {
  182. PreparedStatement stmt = conn.prepareStatement("SELECT pesel FROM klienci WHERE pesel like " + pesel );
  183. ResultSet rslt = stmt.executeQuery();
  184. if(rslt.next())
  185. {
  186. typUzytkownika = "klient";
  187.  
  188. }
  189. else
  190. {
  191. typUzytkownika = "pracownik";
  192. }
  193.  
  194. Statement stmt2 = conn.createStatement();
  195. String update = "UPDATE LOGOWANIE SET status = 'online' WHERE PESEL = '" + pesel +"'";
  196. stmt2.executeUpdate(update);
  197. return "Udane logowanie";
  198. }
  199. else
  200. return "Niepoprawny pesel lub haslo";
  201. }
  202.  
  203. public boolean checkPassword(String pesel, String password, Connection conn) throws SQLException, NoSuchAlgorithmException
  204. {
  205. MessageDigest md = MessageDigest.getInstance("MD5");
  206. md.update(password.getBytes());
  207. byte[] digest = md.digest();
  208. String passwordHash = DatatypeConverter.printHexBinary(digest).toUpperCase();
  209.  
  210. PreparedStatement stmt = conn.prepareStatement("SELECT haslo FROM logowanie WHERE pesel like " + pesel );
  211. ResultSet rslt = stmt.executeQuery();
  212. if(rslt.next())
  213. {
  214. if(rslt.getString(1).equals(passwordHash))
  215. return true;
  216. else
  217. return false;
  218. }
  219. else
  220. return false;
  221. }
  222.  
  223. public static String order(Connection conn) throws SQLException
  224. {
  225. int product = 0;
  226. int action = 0;
  227. String order = "";
  228. boolean end = false;
  229. Scanner scanner = new Scanner(System.in);
  230.  
  231. while(!end)
  232. {
  233. System.out.println("MENU ZAMOWIEN \n1.Dodaj produkt do zamowienia \n2.Zloz zamowienie \n3.Anuluj");
  234. action = scanner.nextInt();
  235.  
  236. switch(action)
  237. {
  238. case 1:
  239. System.out.println("Id produktu");
  240. product = scanner.nextInt();
  241.  
  242. PreparedStatement stmt = conn.prepareStatement("SELECT * FROM katalog WHERE LICZBA_SZTUK > 0 AND PRODUKT_ID = " + Integer.toString(product) );
  243. ResultSet rslt = stmt.executeQuery();
  244. if(rslt.next())
  245. {
  246. order +=" INSERT INTO KATALOG_ZAMOWIENIE_RELACJA" +
  247. " VALUES ( RELACJA_ID_SEQ.nextval,"+ Integer.toString(product)+", ZAMOWIENIE_ID_SEQ.currval);" +
  248. " UPDATE KATALOG" +
  249. " SET LICZBA_SZTUK = LICZBA_SZTUK -1" +
  250. " WHERE PRODUKT_ID like "+ Integer.toString(product)+";";
  251. System.out.println(order);
  252. System.out.println("Produkt "+ rslt.getString(2) + " dodany");
  253. }
  254. else
  255. {
  256. System.out.println("Nie ma produktu o tym indeksie");
  257. }
  258. break;
  259. case 2:
  260. if(!order.equals(""))
  261. {
  262. PreparedStatement stmt1 = conn.prepareStatement("BEGIN" +
  263. " INSERT INTO ZAMOWIENIA" +
  264. " VALUES ( ZAMOWIENIE_ID_SEQ.nextval, "+pesel+", TO_DATE('20-11-2018', 'DD-MM-YYYY'), 'Założono', 0);"+
  265. order+
  266. " EXCEPTION" +
  267. " WHEN OTHERS THEN" +
  268. " ROLLBACK;" +
  269. " END;");
  270.  
  271. ResultSet rslt1 = stmt1.executeQuery();
  272. return "Zamowienie zlozone";
  273. }
  274. else
  275. {
  276. return "Zamowienie niemozliwe";
  277. }
  278. case 3:
  279. end = true;
  280. return "Zamowienie anulowane";
  281. default:
  282. System.out.println("Wprowadzono niewlasciwa liczbe");
  283. break;
  284. }
  285. }
  286. //
  287. //return "Zamowienie niemozliwe";
  288. return"";
  289. }
  290.  
  291. public static void showProducts(Connection conn) throws SQLException {
  292.  
  293. PreparedStatement stmt = conn.prepareStatement("SELECT * FROM katalog WHERE LICZBA_SZTUK > 0" );
  294. ResultSet rslt = stmt.executeQuery();
  295. int counter = 0;
  296. while (rslt.next())
  297. {
  298. counter++;
  299. System.out.println(counter + ". " + rslt.getString(1) +" "+ rslt.getString(2)+ " "+rslt.getString(3)+ " "+rslt.getString(4)+ " "+rslt.getString(5)+ " "+rslt.getString(6));
  300.  
  301. }
  302. }
  303.  
  304. public void showClients(Connection conn) throws SQLException {
  305.  
  306. PreparedStatement stmt = conn.prepareStatement("SELECT * FROM KLIENCI" );
  307. ResultSet rslt = stmt.executeQuery();
  308. int licznik = 0;
  309. while (rslt.next())
  310. {
  311. int dane_id = Integer.parseInt(rslt.getString(2));
  312. licznik++;
  313. String pesel = rslt.getString(1);
  314. System.out.println(licznik + ". Klient:\n\nPesel: " + pesel );
  315.  
  316. //drukowanie danych
  317. PreparedStatement stmt1 = conn.prepareStatement("SELECT imie,nazwisko,adres,email"
  318. + ",numer_telefonu FROM DANE_OSOBOWE WHERE DANE_ID = " + dane_id);
  319. ResultSet rslt1 = stmt1.executeQuery();
  320. String imie = "";
  321. String nazwisko = "";
  322. String email = "";
  323. String nr_tel = "";
  324. int adres_id = 0;
  325. while(rslt1.next()) {
  326. imie = rslt1.getString(1);
  327. nazwisko = rslt1.getString(2);
  328. adres_id = Integer.parseInt(rslt1.getString(3));
  329. email = rslt1.getString(4);
  330. nr_tel = rslt1.getString(5);
  331. }
  332. System.out.println("Imie: " + imie + "\nNazwisko: " + nazwisko + "\nE-mail: " +
  333. email + "\nNumer telefonu: " + nr_tel);
  334.  
  335. //drukowanie adresu
  336. PreparedStatement stmt2 = conn.prepareStatement("SELECT miasto,ulica,numer_domu"
  337. + " FROM ADRES WHERE ADRES_ID = " + adres_id );
  338. ResultSet rslt2 = stmt2.executeQuery();
  339. String miasto = "";
  340. String ulica = "";
  341. int nr_domu = 0;
  342.  
  343. while(rslt2.next()) {
  344. miasto = rslt2.getString(1);
  345. ulica = rslt2.getString(2);
  346. nr_domu = Integer.parseInt(rslt2.getString(3));
  347. }
  348. System.out.println("Miasto: " + miasto + "\nUlica: " + ulica + "\nNumer domu: " + nr_domu + "\n\n");
  349. }
  350.  
  351. }
  352.  
  353. public boolean insertProduct(Connection conn) throws SQLException {
  354. Scanner scanner = new Scanner(System.in);
  355. scanner.useLocale(Locale.US);
  356. try {
  357. String nazwa = "";
  358. System.out.println("\nPodaj nazwe produktu: ");
  359. nazwa = scanner.nextLine();
  360.  
  361. String producent = "";
  362. System.out.println("\nPodaj producenta produktu: ");
  363. producent = scanner.nextLine();
  364.  
  365. int ilosc = 0;
  366. System.out.println("\nPodaj ilosc sztuk produktu: ");
  367. while(!scanner.hasNextInt()) {
  368. System.out.println("Podaj liczbe calkowita: ");
  369. scanner.next();
  370. }
  371. ilosc = scanner.nextInt();
  372. scanner.nextLine();
  373.  
  374. //int ilosc = 0;
  375. //System.out.println("\nPodaj ilosc sztuk produktu: ");
  376. //ilosc = scanner.nextInt();
  377.  
  378. String typ = "";
  379. System.out.println("\nPodaj typ produktu: ");
  380. typ = scanner.nextLine();
  381.  
  382.  
  383. float cena = 0;
  384. System.out.println("\nPodaj cene produktu: ");
  385. while(!scanner.hasNextFloat()) {
  386. System.out.println("Podaj liczbe zmiennoprzecinkowa: ");
  387. scanner.next();
  388. }
  389. cena = scanner.nextFloat();
  390. scanner.nextLine();
  391.  
  392. //float cena = 0;
  393. //System.out.println("\nPodaj cene produktu: ");
  394. //cena = scanner.nextFloat();
  395.  
  396. Statement stmt = conn.createStatement();
  397. String update = "INSERT INTO KATALOG VALUES( PRODUKT_ID_SEQ.nextval,'" + nazwa +
  398. "','" + producent + "'," + ilosc + ",'" + typ + "'," + cena + ")";
  399.  
  400. System.out.println(update);
  401. stmt.executeUpdate(update);
  402. }
  403.  
  404. catch (SQLException e) {
  405. e.printStackTrace();
  406. return false;
  407. }
  408.  
  409. return true;
  410.  
  411.  
  412. }
  413.  
  414. public boolean updateProduct(Connection conn) throws SQLException {
  415. Scanner scanner = new Scanner(System.in);
  416. scanner.useLocale(Locale.US);
  417. try {
  418. showProducts(conn);
  419.  
  420. int id = 0;
  421. System.out.println("\nPodaj id produktu, ktory chcesz edytowac: ");
  422. while(!scanner.hasNextInt()) {
  423. System.out.println("Podaj liczbe calkowita: ");
  424. scanner.next();
  425. }
  426. id = scanner.nextInt();
  427. scanner.nextLine();
  428.  
  429. //System.out.println("\nPodaj id produktu, ktory chcesz edytowac: ");
  430. //id = scanner.nextInt();
  431.  
  432. String nazwa = "";
  433. System.out.println("\nPodaj nazwe produktu: ");
  434. nazwa = scanner.nextLine();
  435.  
  436. String producent = "";
  437. System.out.println("\nPodaj producenta produktu: ");
  438. producent = scanner.nextLine();
  439.  
  440. int ilosc = 0;
  441. System.out.println("\nPodaj ilosc sztuk produktu: ");
  442. while(!scanner.hasNextInt()) {
  443. System.out.println("Podaj liczbe calkowita: ");
  444. scanner.next();
  445. }
  446. ilosc = scanner.nextInt();
  447. scanner.nextLine();
  448.  
  449. //int ilosc = 0;
  450. //System.out.println("\nPodaj ilosc sztuk produktu: ");
  451. //ilosc = scanner.nextInt();
  452.  
  453. String typ = "";
  454. System.out.println("\nPodaj typ produktu: ");
  455. typ = scanner.nextLine();
  456.  
  457. float cena = 0;
  458. System.out.println("\nPodaj cene produktu: ");
  459. while(!scanner.hasNextFloat()) {
  460. System.out.println("Podaj liczbe zmiennoprzecinkowa: ");
  461. scanner.next();
  462. }
  463. cena = scanner.nextFloat();
  464. scanner.nextLine();
  465.  
  466. //float cena = 0;
  467. //System.out.println("\nPodaj cene produktu: ");
  468. //cena = scanner.nextFloat();
  469.  
  470. Statement stmt = conn.createStatement();
  471. String update = "UPDATE KATALOG SET nazwa = '" + nazwa +
  472. "', producent = '" + producent + "', liczba_sztuk = " + ilosc +
  473. ", typ_produktu = '" + typ + "', cena = " + cena + " WHERE produkt_id = " + id + "";
  474. System.out.println(update);
  475. stmt.executeUpdate(update);
  476. }
  477.  
  478. catch(SQLException e) {
  479. e.printStackTrace();
  480. return false;
  481. }
  482.  
  483. return true;
  484. }
  485.  
  486. public boolean addClient(Connection conn) throws SQLException {
  487.  
  488. Scanner scanner = new Scanner(System.in);
  489. try {
  490. //dodawanie danych logowania
  491. String pesel = "";
  492. System.out.println("\nPodaj pesel klienta: ");
  493. pesel = scanner.nextLine();
  494.  
  495. String haslo = "";
  496. System.out.println("\nPodaj haslo klienta: ");
  497. haslo = scanner.nextLine();
  498.  
  499. Statement stmt = conn.createStatement();
  500. String update = "INSERT INTO LOGOWANIE VALUES('" + pesel + "', STANDARD_HASH('" + haslo + "','MD5'),'offline')";
  501. stmt.executeUpdate(update);
  502.  
  503.  
  504. //dodawanie adresu
  505. String miasto = "";
  506. System.out.println("\nPodaj dane zamieszkania\n\n Podaj miasto: ");
  507. miasto = scanner.nextLine();
  508.  
  509. String ulica = "";
  510. System.out.println("\nPodaj ulice: ");
  511. ulica = scanner.nextLine();
  512.  
  513. int nr_domu = 0;
  514. System.out.println("\nPodaj numer domu: ");
  515. while(!scanner.hasNextInt()) {
  516. System.out.println("Podaj liczbe calkowita: ");
  517. scanner.next();
  518. }
  519. nr_domu = scanner.nextInt();
  520. scanner.nextLine();
  521.  
  522. //int nr_domu = 0;
  523. // System.out.println("\nPodaj numer domu: ");
  524. //nr_domu = scanner.nextInt();
  525.  
  526. Statement stmt1 = conn.createStatement();
  527. String update1 = "INSERT INTO ADRES VALUES(ADRES_ID_SEQ.nextval,'" + miasto + "','" + ulica + "'," + nr_domu + ")";
  528. stmt1.executeUpdate(update1);
  529.  
  530.  
  531. //dodawanie danych osobowych
  532. String imie = "";
  533. System.out.println("\nPodaj dane klienta\n\n Podaj imie: ");
  534. imie = scanner.nextLine();
  535.  
  536. String nazwisko = "";
  537. System.out.println("\nPodaj nazwisko: ");
  538. nazwisko = scanner.nextLine();
  539.  
  540. String email = "";
  541. System.out.println("\nPodaj email: ");
  542. email = scanner.nextLine();
  543.  
  544. String nr_tel = "";
  545. System.out.println("\nPodaj numer telefonu: ");
  546. nr_tel = scanner.nextLine();
  547.  
  548. Statement stmt2 = conn.createStatement();
  549. String update2 = "INSERT INTO DANE_OSOBOWE VALUES(DANE_OSOBOWE_ID_SEQ.nextval,'" +
  550. imie + "','" + nazwisko + "',ADRES_ID_SEQ.currval,'" + email +
  551. "','" + nr_tel + "')";
  552. stmt2.executeUpdate(update2);
  553.  
  554. //dodawanie klienta
  555. Statement stmt3 = conn.createStatement();
  556. String update3 = "INSERT INTO KLIENCI VALUES('" + pesel + "', DANE_OSOBOWE_ID_SEQ.currval)";
  557. stmt3.executeUpdate(update3);
  558.  
  559.  
  560. }
  561.  
  562. catch (SQLException e){
  563. e.printStackTrace();
  564. return false;
  565. }
  566.  
  567. return true;
  568.  
  569. }
  570.  
  571. public boolean deleteClient(Connection conn) throws SQLException {
  572. Scanner scanner = new Scanner(System.in);
  573. try {
  574.  
  575. showClients(conn);
  576. System.out.println("Podaj pesel klienta, ktorego chcesz usunac: ");
  577. String pesel;
  578. pesel = scanner.nextLine();
  579.  
  580. int dane_id = 0;
  581. PreparedStatement stmt = conn.prepareStatement("SELECT DANE FROM KLIENCI WHERE PESEL = '" + pesel + "'");
  582. ResultSet rslt = stmt.executeQuery();
  583. if(!rslt.next())
  584. return false;
  585. else
  586. dane_id = Integer.parseInt(rslt.getString(1));
  587.  
  588. int adres_id = 0;
  589. PreparedStatement stmt3 = conn.prepareStatement("SELECT ADRES FROM DANE_OSOBOWE WHERE DANE_ID =" + dane_id);
  590. ResultSet rslt3 = stmt3.executeQuery();
  591.  
  592. if(rslt3.next())
  593. adres_id = Integer.parseInt(rslt3.getString(1));
  594.  
  595. PreparedStatement stmt1 = conn.prepareStatement("BEGIN DELETE KLIENCI WHERE PESEL = '" + pesel
  596. + "';DELETE DANE_OSOBOWE WHERE DANE_ID = " + dane_id
  597. + ";DELETE ADRES WHERE ADRES_ID = " + adres_id
  598. + ";DELETE LOGOWANIE WHERE PESEL = '" + pesel + "'; EXCEPTION" +
  599. " WHEN OTHERS THEN" +
  600. " ROLLBACK;COMMIT;END;");
  601. stmt1.executeUpdate();
  602.  
  603. //PreparedStatement stmt2 = conn.prepareStatement(";DELETE DANE WHERE DANE_ID = " + dane_id);
  604. //stmt2.executeUpdate();
  605.  
  606. //PreparedStatement stmt4 = conn.prepareStatement(";DELETE ADRES WHERE ADRES_ID = " + adres_id);
  607. //stmt4.executeUpdate();
  608.  
  609. //PreparedStatement stmt5 = conn.prepareStatement(";DELETE LOGOWANIE WHERE PESEL = '" + pesel + "'");
  610. //stmt5.executeUpdate();
  611.  
  612. } catch(SQLException e) {
  613. e.printStackTrace();
  614. return false;
  615. }
  616.  
  617. return true;
  618.  
  619.  
  620. }
  621.  
  622. public void showOrders(Connection conn) throws SQLException {
  623.  
  624. int action;
  625. boolean end = false;
  626. Scanner scanner = new Scanner(System.in);
  627. while(!end)
  628. {
  629. System.out.println("MENU "
  630. + "\n1.Zlozone"
  631. + "\n2.Zrealizowane"
  632. + "\n3. Wroc");
  633.  
  634. System.out.println("\nWybor: ");
  635. while(!scanner.hasNextInt()) {
  636. System.out.println("Podaj liczbe calkowita: ");
  637. scanner.next();
  638. }
  639. action = scanner.nextInt();
  640. scanner.nextLine();
  641.  
  642.  
  643. switch(action) {
  644. case 1:
  645. showUnrealisedOrders(conn);
  646. break;
  647.  
  648. case 2:
  649. showRealisedOrders(conn);
  650. break;
  651.  
  652. case 3:
  653. end = true;
  654. break;
  655. default:
  656. System.out.println("Wprowadzono niewlasciwa liczbe");
  657. break;
  658.  
  659. }
  660. }
  661.  
  662.  
  663. }
  664.  
  665. public boolean executeOrder(Connection conn) throws SQLException {
  666.  
  667. Scanner scanner = new Scanner(System.in);
  668.  
  669. try {
  670.  
  671. showOrders(conn);
  672.  
  673. int wybor;
  674. System.out.println("Podaj id zamowienia, ktore chcesz zrealizowac");
  675. while(!scanner.hasNextInt()) {
  676. System.out.println("Podaj liczbe calkowita: ");
  677. scanner.next();
  678. }
  679. wybor = scanner.nextInt();
  680. scanner.nextLine();
  681.  
  682. //System.out.println("Podaj id zamowienia, ktore chcesz zrealizowac");
  683. //int wybor;
  684. //wybor = scanner.nextInt();
  685.  
  686. Statement stmt = conn.createStatement();
  687. String update = "UPDATE ZAMOWIENIA SET status = 'Zrealizowane' WHERE ZAMOWIENIE_ID = " + wybor;
  688. stmt.executeUpdate(update);
  689.  
  690. } catch(SQLException e) {
  691. return false;
  692. }
  693.  
  694. return true;
  695.  
  696.  
  697. }
  698.  
  699. public boolean deleteProduct(Connection conn) throws SQLException {
  700.  
  701. Scanner scanner = new Scanner(System.in);
  702. try {
  703.  
  704. showProducts(conn);
  705.  
  706. int prod_id;
  707. System.out.println("Podaj id produktu, ktory chcesz usunac: ");
  708. while(!scanner.hasNextInt()) {
  709. System.out.println("Podaj liczbe calkowita: ");
  710. scanner.next();
  711. }
  712. prod_id = scanner.nextInt();
  713. scanner.nextLine();
  714.  
  715. //System.out.println("Podaj id produktu, ktory chcesz usunac: ");
  716. //int prod_id;
  717. //prod_id = scanner.nextInt();
  718.  
  719.  
  720. PreparedStatement stmt1 = conn.prepareStatement("DELETE KATALOG WHERE PRODUKT_ID = " + prod_id);
  721. stmt1.executeUpdate();
  722.  
  723.  
  724. } catch(SQLException e) {
  725. e.printStackTrace();
  726. return false;
  727. }
  728.  
  729. return true;
  730. }
  731.  
  732. public void showRealisedOrders(Connection conn) throws SQLException {
  733. PreparedStatement stmt1 = conn.prepareStatement("SELECT * FROM zamowienia WHERE status = 'Zrealizowane'");
  734. ResultSet rslt1 = stmt1.executeQuery();
  735. int licznik = 0;
  736.  
  737. String id = "";
  738. String pesel = "";
  739. String data = "";
  740. String status = "";
  741. float cena = 0;
  742.  
  743. //while (rslt1.next())
  744. //{
  745. // licznik++;
  746. // System.out.println(licznik + ". " + rslt1.getString(1) +" "+ rslt1.getString(2)+ " "+rslt1.getString(3)+ " "+rslt1.getString(4)+ " "+rslt1.getString(5));
  747. //}
  748.  
  749. while(rslt1.next()) {
  750. id = rslt1.getString(1);
  751. pesel = rslt1.getString(2);
  752. data = rslt1.getString(3);
  753. status = rslt1.getString(4);
  754. cena = Float.parseFloat(rslt1.getString(5));
  755.  
  756. licznik++;
  757. System.out.println("Zamowienie " + licznik + "\nZamowienie ID: " + id +
  758. "\nPesel klienta: " + pesel + "\nData zlozenia: " + data + "\nStatus: " + status +
  759. "\nCena: " + cena);
  760.  
  761. String nazwa;
  762. String producent;
  763. String typ;
  764. String prod_id;
  765.  
  766. PreparedStatement stmt2 = conn.prepareStatement("SELECT produkt_id FROM katalog_zamowienie_relacja WHERE zamowienie_id = " + id);
  767. ResultSet rslt2 = stmt2.executeQuery();
  768. int licznik2 = 0;
  769.  
  770. while(rslt2.next()) {
  771. licznik2++;
  772. prod_id = rslt2.getString(1);
  773. System.out.println("\n" + licznik2 +". ID produktu: " + prod_id);
  774. PreparedStatement stmt3 = conn.prepareStatement("SELECT nazwa,producent,typ_produktu FROM katalog WHERE produkt_id = " + prod_id);
  775. ResultSet rslt3 = stmt3.executeQuery();
  776. while(rslt3.next()) {
  777. nazwa = rslt3.getString(1);
  778. producent = rslt3.getString(2);
  779. typ = rslt3.getString(3);
  780. System.out.println(" " + nazwa + " " + producent + " " + typ);
  781. }
  782.  
  783. }
  784.  
  785.  
  786. }
  787.  
  788. }
  789.  
  790. public void showUnrealisedOrders(Connection conn) throws SQLException {
  791. //PreparedStatement stmt = conn.prepareStatement("SELECT * FROM zamowienia WHERE status = 'Założono'");
  792. //ResultSet rslt = stmt.executeQuery();
  793. // int licznik = 0;
  794.  
  795. //while (rslt1.next())
  796. //{
  797. // licznik++;
  798. // System.out.println(licznik + ". " + rslt1.getString(1) +" "+ rslt1.getString(2)+ " "+rslt1.getString(3)+ " "+rslt1.getString(4)+ " "+rslt1.getString(5));
  799. //}
  800.  
  801.  
  802. PreparedStatement stmt1 = conn.prepareStatement("SELECT * FROM zamowienia WHERE status = 'Założono'");
  803. ResultSet rslt1 = stmt1.executeQuery();
  804. int licznik1 = 0;
  805.  
  806. String id = "";
  807. String pesel = "";
  808. String data = "";
  809. String status = "";
  810. float cena = 0;
  811.  
  812. //while (rslt1.next())
  813. //{
  814. // licznik++;
  815. // System.out.println(licznik + ". " + rslt1.getString(1) +" "+ rslt1.getString(2)+ " "+rslt1.getString(3)+ " "+rslt1.getString(4)+ " "+rslt1.getString(5));
  816. //}
  817.  
  818. while(rslt1.next()) {
  819. id = rslt1.getString(1);
  820. pesel = rslt1.getString(2);
  821. data = rslt1.getString(3);
  822. status = rslt1.getString(4);
  823. cena = Float.parseFloat(rslt1.getString(5));
  824.  
  825. licznik1++;
  826. System.out.println("Zamowienie " + licznik1 + "\nZamowienie ID: " + id +
  827. "\nPesel klienta: " + pesel + "\nData zlozenia: " + data + "\nStatus: " + status +
  828. "\nCena: " + cena);
  829.  
  830. String nazwa;
  831. String producent;
  832. String typ;
  833. String prod_id;
  834.  
  835. PreparedStatement stmt2 = conn.prepareStatement("SELECT produkt_id FROM katalog_zamowienie_relacja WHERE zamowienie_id = " + id);
  836. ResultSet rslt2 = stmt2.executeQuery();
  837. int licznik2 = 0;
  838.  
  839. while(rslt2.next()) {
  840. licznik2++;
  841. prod_id = rslt2.getString(1);
  842. System.out.println("\n" + licznik2 +". ID produktu: " + prod_id);
  843. PreparedStatement stmt3 = conn.prepareStatement("SELECT nazwa,producent,typ_produktu FROM katalog WHERE produkt_id = " + prod_id);
  844. ResultSet rslt3 = stmt3.executeQuery();
  845. while(rslt3.next()) {
  846. nazwa = rslt3.getString(1);
  847. producent = rslt3.getString(2);
  848. typ = rslt3.getString(3);
  849. System.out.println(" " + nazwa + " " + producent + " " + typ);
  850. }
  851.  
  852. }
  853.  
  854.  
  855. }
  856.  
  857. }
  858.  
  859. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement