Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.19 KB | None | 0 0
  1. import DAO.SotrudnikiDAO;
  2. import DAO.SpecialnostiDAO;
  3. import Entity.Sotrudniki;
  4. import Entity.Specialnosti;
  5.  
  6. import javax.swing.*;
  7. import java.awt.*;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.sql.Connection;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.util.Arrays;
  15. import java.util.List;
  16.  
  17. public final class GUI extends JFrame {
  18.  
  19. GUI(){
  20. setTitle("kurse work");
  21. Connection connection = ConnectDataBase.connDataBase();
  22. setDefaultCloseOperation(EXIT_ON_CLOSE);
  23.  
  24. JPanel jPanel = new JPanel();
  25. jPanel.setLayout(new FlowLayout());
  26.  
  27. JButton VSTU = new JButton("ВГТУ");
  28. JButton VSU = new JButton("ВГУ");
  29. JButton VSUET = new JButton("ВГУИТ");
  30. JButton Search = new JButton("Поиск");
  31. jPanel.add(VSTU);
  32. jPanel.add(VSU);
  33. jPanel.add(VSUET);
  34. jPanel.add(Search);
  35. VSTU.addActionListener(new ActionListener() {
  36. @Override
  37. public void actionPerformed(ActionEvent e) {
  38. setTitle("ВГТУ");
  39. jPanel.setVisible(false);
  40. JPanel jPanel1 = new JPanel();
  41. jPanel1.setLayout(new FlowLayout());
  42. setContentPane(jPanel1);
  43. try {
  44. Statement statement = connection.createStatement();
  45. ResultSet resultSet = statement.executeQuery("select adres from vus where id='1'");
  46. while (resultSet.next()){
  47. JLabel jLabel = new JLabel("Адрес: ");
  48. JLabel jLabel2 = new JLabel(resultSet.getString("adres"));
  49. jPanel1.add(jLabel);
  50. jPanel1.add(jLabel2);
  51. }
  52. }
  53. catch (SQLException ex) {
  54. ex.printStackTrace();
  55. }
  56. JButton getSotr = new JButton("Сотрудники");
  57. JButton getSpec = new JButton("Специальности");
  58. JButton BACK = new JButton("Назад");
  59. jPanel1.add(getSotr);
  60. getSotr.addActionListener(new ActionListener() {
  61. @Override
  62. public void actionPerformed(ActionEvent e) {
  63. jPanel1.setVisible(false);
  64. JPanel jPanel2 = new JPanel();
  65. setContentPane(jPanel2);
  66. JButton addSotr = new JButton("Добавить");
  67. JButton change = new JButton("Изменить");
  68. JButton BACK1 = new JButton("Назад");
  69. jPanel2.add(addSotr);
  70. addSotr.addActionListener(new ActionListener() {
  71. @Override
  72. public void actionPerformed(ActionEvent e) {
  73. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  74. try {
  75. Sotrudniki sotrudniki = sotrudnikiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),1,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
  76. } catch (SQLException ex) {
  77. ex.printStackTrace();
  78. }
  79. }
  80. });
  81. jPanel2.add(change);
  82. change.addActionListener(new ActionListener() {
  83. @Override
  84. public void actionPerformed(ActionEvent e) {
  85. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  86. try {
  87. Sotrudniki sotrudniki = new Sotrudniki(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите новый телефон сотрудника"));
  88. sotrudnikiDAO.update(connection,sotrudniki);
  89. } catch (SQLException ex) {
  90. ex.printStackTrace();
  91. }
  92. }
  93. });
  94. jPanel2.add(BACK1);
  95. BACK1.addActionListener(new ActionListener() {
  96. @Override
  97. public void actionPerformed(ActionEvent e) {
  98. jPanel2.setVisible(false);
  99. jPanel1.setVisible(true);
  100. setContentPane(jPanel1);
  101. }
  102. });
  103. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  104. try{
  105. List<Sotrudniki> list = sotrudnikiDAO.all(connection,1);
  106. JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
  107. } catch (SQLException ex) {
  108. ex.printStackTrace();
  109. }
  110. }
  111. });
  112. jPanel1.add(getSpec);
  113. getSpec.addActionListener(new ActionListener() {
  114. @Override
  115. public void actionPerformed(ActionEvent e) {
  116. jPanel1.setVisible(false);
  117. JPanel jPanel2 = new JPanel();
  118. setContentPane(jPanel2);
  119. JButton addSpec = new JButton("Добавить");
  120. JButton change = new JButton("Изменить");
  121. JButton BACK1 = new JButton("Назад");
  122. jPanel2.add(addSpec);
  123. addSpec.addActionListener(new ActionListener() {
  124. @Override
  125. public void actionPerformed(ActionEvent e) {
  126. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  127. try {
  128. Specialnosti specialnosti = specialnostiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),1,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
  129. } catch (SQLException ex) {
  130. ex.printStackTrace();
  131. }
  132. }
  133. });
  134. jPanel2.add(change);
  135. change.addActionListener(new ActionListener() {
  136. @Override
  137. public void actionPerformed(ActionEvent e) {
  138. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  139. try {
  140. Specialnosti specialnosti = new Specialnosti(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя специальности"),JOptionPane.showInputDialog(jPanel1,"Введите новую информацию специальности"));
  141. specialnostiDAO.update(connection,specialnosti);
  142. } catch (SQLException ex) {
  143. ex.printStackTrace();
  144. }
  145. }
  146. });
  147. jPanel2.add(BACK1);
  148. BACK1.addActionListener(new ActionListener() {
  149. @Override
  150. public void actionPerformed(ActionEvent e) {
  151. jPanel2.setVisible(false);
  152. jPanel1.setVisible(true);
  153. setContentPane(jPanel1);
  154. }
  155. });
  156. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  157. try{
  158. List<Specialnosti> list = specialnostiDAO.all(connection,1);
  159. JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
  160. } catch (SQLException ex) {
  161. ex.printStackTrace();
  162. }
  163. }
  164. });
  165. jPanel1.add(BACK);
  166. BACK.addActionListener(new ActionListener() {
  167. @Override
  168. public void actionPerformed(ActionEvent e) {
  169. jPanel1.setVisible(false);
  170. jPanel.setVisible(true);
  171. setContentPane(jPanel);
  172. setTitle("kurse work");
  173. }
  174. });
  175. }
  176. });
  177. VSU.addActionListener(new ActionListener() {
  178. @Override
  179. public void actionPerformed(ActionEvent e) {
  180. setTitle("ВГУ");
  181. jPanel.setVisible(false);
  182. JPanel jPanel1 = new JPanel();
  183. jPanel1.setLayout(new FlowLayout());
  184. setContentPane(jPanel1);
  185. try {
  186. Statement statement = connection.createStatement();
  187. ResultSet resultSet = statement.executeQuery("select adres from vus where id='2'");
  188. while (resultSet.next()){
  189. JLabel jLabel = new JLabel("Адрес: ");
  190. JLabel jLabel2 = new JLabel(resultSet.getString("adres"));
  191. jPanel1.add(jLabel);
  192. jPanel1.add(jLabel2);
  193. }
  194. }
  195. catch (SQLException ex) {
  196. ex.printStackTrace();
  197. }
  198. JButton getSotr = new JButton("Сотрудники");
  199. JButton getSpec = new JButton("Специальности");
  200. JButton BACK = new JButton("Назад");
  201. jPanel1.add(getSotr);
  202. getSotr.addActionListener(new ActionListener() {
  203. @Override
  204. public void actionPerformed(ActionEvent e) {
  205. jPanel1.setVisible(false);
  206. JPanel jPanel2 = new JPanel();
  207. setContentPane(jPanel2);
  208. JButton addSotr = new JButton("Добавить");
  209. JButton change = new JButton("Изменить");
  210. JButton BACK1 = new JButton("Назад");
  211. jPanel2.add(addSotr);
  212. addSotr.addActionListener(new ActionListener() {
  213. @Override
  214. public void actionPerformed(ActionEvent e) {
  215. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  216. try {
  217. Sotrudniki sotrudniki = sotrudnikiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),2,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
  218. } catch (SQLException ex) {
  219. ex.printStackTrace();
  220. }
  221. }
  222. });
  223. jPanel2.add(change);
  224. change.addActionListener(new ActionListener() {
  225. @Override
  226. public void actionPerformed(ActionEvent e) {
  227. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  228. try {
  229. Sotrudniki sotrudniki = new Sotrudniki(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите новый телефон сотрудника"));
  230. sotrudnikiDAO.update(connection,sotrudniki);
  231. } catch (SQLException ex) {
  232. ex.printStackTrace();
  233. }
  234. }
  235. });
  236. jPanel2.add(BACK1);
  237. BACK1.addActionListener(new ActionListener() {
  238. @Override
  239. public void actionPerformed(ActionEvent e) {
  240. jPanel2.setVisible(false);
  241. jPanel1.setVisible(true);
  242. setContentPane(jPanel1);
  243. }
  244. });
  245. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  246. try{
  247. List<Sotrudniki> list = sotrudnikiDAO.all(connection,2);
  248. JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
  249. } catch (SQLException ex) {
  250. ex.printStackTrace();
  251. }
  252. }
  253. });
  254. jPanel1.add(getSpec);
  255. getSpec.addActionListener(new ActionListener() {
  256. @Override
  257. public void actionPerformed(ActionEvent e) {
  258. jPanel1.setVisible(false);
  259. JPanel jPanel2 = new JPanel();
  260. setContentPane(jPanel2);
  261. JButton addSpec = new JButton("Добавить");
  262. JButton change = new JButton("Изменить");
  263. JButton BACK1 = new JButton("Назад");
  264. jPanel2.add(addSpec);
  265. addSpec.addActionListener(new ActionListener() {
  266. @Override
  267. public void actionPerformed(ActionEvent e) {
  268. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  269. try {
  270. Specialnosti specialnosti = specialnostiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),2,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
  271. } catch (SQLException ex) {
  272. ex.printStackTrace();
  273. }
  274. }
  275. });
  276. jPanel2.add(change);
  277. change.addActionListener(new ActionListener() {
  278. @Override
  279. public void actionPerformed(ActionEvent e) {
  280. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  281. try {
  282. Specialnosti specialnosti = new Specialnosti(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя специальности"),JOptionPane.showInputDialog(jPanel1,"Введите новую информацию специальности"));
  283. specialnostiDAO.update(connection,specialnosti);
  284. } catch (SQLException ex) {
  285. ex.printStackTrace();
  286. }
  287. }
  288. });
  289. jPanel2.add(BACK1);
  290. BACK1.addActionListener(new ActionListener() {
  291. @Override
  292. public void actionPerformed(ActionEvent e) {
  293. jPanel2.setVisible(false);
  294. jPanel1.setVisible(true);
  295. setContentPane(jPanel1);
  296. }
  297. });
  298. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  299. try{
  300. List<Specialnosti> list = specialnostiDAO.all(connection,2);
  301. JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
  302. } catch (SQLException ex) {
  303. ex.printStackTrace();
  304. }
  305. }
  306. });
  307. jPanel1.add(BACK);
  308. BACK.addActionListener(new ActionListener() {
  309. @Override
  310. public void actionPerformed(ActionEvent e) {
  311. jPanel1.setVisible(false);
  312. jPanel.setVisible(true);
  313. setContentPane(jPanel);
  314. setTitle("kurse work");
  315. }
  316. });
  317. }
  318. });
  319.  
  320. VSUET.addActionListener(new ActionListener() {
  321. @Override
  322. public void actionPerformed(ActionEvent e) {
  323. setTitle("ВГУИТ");
  324. jPanel.setVisible(false);
  325. JPanel jPanel1 = new JPanel();
  326. jPanel1.setLayout(new FlowLayout());
  327. setContentPane(jPanel1);
  328. try {
  329. Statement statement = connection.createStatement();
  330. ResultSet resultSet = statement.executeQuery("select adres from vus where id='3'");
  331. while (resultSet.next()){
  332. JLabel jLabel = new JLabel("Адрес: ");
  333. JLabel jLabel2 = new JLabel(resultSet.getString("adres"));
  334. jPanel1.add(jLabel);
  335. jPanel1.add(jLabel2);
  336. }
  337. }
  338. catch (SQLException ex) {
  339. ex.printStackTrace();
  340. }
  341. JButton getSotr = new JButton("Сотрудники");
  342. JButton getSpec = new JButton("Специальности");
  343. JButton BACK = new JButton("Назад");
  344. jPanel1.add(getSotr);
  345. getSotr.addActionListener(new ActionListener() {
  346. @Override
  347. public void actionPerformed(ActionEvent e) {
  348. jPanel1.setVisible(false);
  349. JPanel jPanel2 = new JPanel();
  350. setContentPane(jPanel2);
  351. JButton addSotr = new JButton("Добавить");
  352. JButton change = new JButton("Изменить");
  353. JButton BACK1 = new JButton("Назад");
  354. jPanel2.add(addSotr);
  355. addSotr.addActionListener(new ActionListener() {
  356. @Override
  357. public void actionPerformed(ActionEvent e) {
  358. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  359. try {
  360. Sotrudniki sotrudniki = sotrudnikiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),3,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
  361. } catch (SQLException ex) {
  362. ex.printStackTrace();
  363. }
  364. }
  365. });
  366. jPanel2.add(change);
  367. change.addActionListener(new ActionListener() {
  368. @Override
  369. public void actionPerformed(ActionEvent e) {
  370. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  371. try {
  372. Sotrudniki sotrudniki = new Sotrudniki(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите новый телефон сотрудника"));
  373. sotrudnikiDAO.update(connection,sotrudniki);
  374. } catch (SQLException ex) {
  375. ex.printStackTrace();
  376. }
  377. }
  378. });
  379. jPanel2.add(BACK1);
  380. BACK1.addActionListener(new ActionListener() {
  381. @Override
  382. public void actionPerformed(ActionEvent e) {
  383. jPanel2.setVisible(false);
  384. jPanel1.setVisible(true);
  385. setContentPane(jPanel1);
  386. }
  387. });
  388. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  389. try{
  390. List<Sotrudniki> list = sotrudnikiDAO.all(connection,3);
  391. JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
  392. } catch (SQLException ex) {
  393. ex.printStackTrace();
  394. }
  395. }
  396. });
  397. jPanel1.add(getSpec);
  398. getSpec.addActionListener(new ActionListener() {
  399. @Override
  400. public void actionPerformed(ActionEvent e) {
  401. jPanel1.setVisible(false);
  402. JPanel jPanel2 = new JPanel();
  403. setContentPane(jPanel2);
  404. JButton addSpec = new JButton("Добавить");
  405. JButton change = new JButton("Изменить");
  406. JButton BACK1 = new JButton("Назад");
  407. jPanel2.add(addSpec);
  408. addSpec.addActionListener(new ActionListener() {
  409. @Override
  410. public void actionPerformed(ActionEvent e) {
  411. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  412. try {
  413. Specialnosti specialnosti = specialnostiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),3,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
  414. } catch (SQLException ex) {
  415. ex.printStackTrace();
  416. }
  417. }
  418. });
  419. jPanel2.add(change);
  420. change.addActionListener(new ActionListener() {
  421. @Override
  422. public void actionPerformed(ActionEvent e) {
  423. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  424. try {
  425. Specialnosti specialnosti = new Specialnosti(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя специальности"),JOptionPane.showInputDialog(jPanel1,"Введите новую информацию специальности"));
  426. specialnostiDAO.update(connection,specialnosti);
  427. } catch (SQLException ex) {
  428. ex.printStackTrace();
  429. }
  430. }
  431. });
  432. jPanel2.add(BACK1);
  433. BACK1.addActionListener(new ActionListener() {
  434. @Override
  435. public void actionPerformed(ActionEvent e) {
  436. jPanel2.setVisible(false);
  437. jPanel1.setVisible(true);
  438. setContentPane(jPanel1);
  439. }
  440. });
  441. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  442. try{
  443. List<Specialnosti> list = specialnostiDAO.all(connection,3);
  444. JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
  445. } catch (SQLException ex) {
  446. ex.printStackTrace();
  447. }
  448. }
  449. });
  450. jPanel1.add(BACK);
  451. BACK.addActionListener(new ActionListener() {
  452. @Override
  453. public void actionPerformed(ActionEvent e) {
  454. jPanel1.setVisible(false);
  455. jPanel.setVisible(true);
  456. setContentPane(jPanel);
  457. setTitle("kurse work");
  458. }
  459. });
  460. }
  461. });
  462.  
  463. Search.addActionListener(new ActionListener() {
  464. @Override
  465. public void actionPerformed(ActionEvent e) {
  466. setTitle("Поиск");
  467. jPanel.setVisible(false);
  468. JPanel jPanel1 = new JPanel();
  469. jPanel1.setLayout(new FlowLayout());
  470. setContentPane(jPanel1);
  471.  
  472. JButton searchSotr = new JButton("Сотрудники");
  473. searchSotr.addActionListener(new ActionListener() {
  474. @Override
  475. public void actionPerformed(ActionEvent e) {
  476. SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
  477. try {
  478. Sotrudniki sotrudniki = sotrudnikiDAO.getById(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")));
  479. if (sotrudniki != null) {
  480. JOptionPane.showMessageDialog(jPanel, sotrudniki.getName() + ": " + sotrudniki.getFone());
  481. } else {
  482. JOptionPane.showMessageDialog(jPanel1, "Нет такого сотрудника!");
  483. }
  484. } catch (SQLException ex) {
  485. ex.printStackTrace();
  486. }
  487. }
  488. });
  489. JButton searchSpec = new JButton("Специальности");
  490. searchSpec.addActionListener(new ActionListener() {
  491. @Override
  492. public void actionPerformed(ActionEvent e) {
  493. SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
  494. try {
  495. Specialnosti specialnosti = specialnostiDAO.getById(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")));
  496. if (specialnosti != null) {
  497. JOptionPane.showMessageDialog(jPanel, specialnosti.getName() + ": " + specialnosti.getInfo());
  498. } else {
  499. JOptionPane.showMessageDialog(jPanel1, "Нет такой специальности!");
  500. }
  501. } catch (SQLException ex) {
  502. ex.printStackTrace();
  503. }
  504. }
  505. });
  506. JButton BACK1 = new JButton("Назад");
  507. BACK1.addActionListener(new ActionListener() {
  508. @Override
  509. public void actionPerformed(ActionEvent e) {
  510. jPanel1.setVisible(false);
  511. jPanel.setVisible(true);
  512. setContentPane(jPanel);
  513. setTitle("kurse work");
  514. }
  515. });
  516. jPanel1.add(searchSotr);
  517. jPanel1.add(searchSpec);
  518. jPanel1.add(BACK1);
  519. }
  520. });
  521.  
  522. setSize(500, 500);
  523. setContentPane(jPanel);
  524. setLocationRelativeTo(null);
  525. setVisible(true);
  526. }
  527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement