Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import DAO.SotrudnikiDAO;
- import DAO.SpecialnostiDAO;
- import Entity.Sotrudniki;
- import Entity.Specialnosti;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Arrays;
- import java.util.List;
- public final class GUI extends JFrame {
- GUI(){
- setTitle("kurse work");
- Connection connection = ConnectDataBase.connDataBase();
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- JPanel jPanel = new JPanel();
- jPanel.setLayout(new FlowLayout());
- JButton VSTU = new JButton("ВГТУ");
- JButton VSU = new JButton("ВГУ");
- JButton VSUET = new JButton("ВГУИТ");
- JButton Search = new JButton("Поиск");
- jPanel.add(VSTU);
- jPanel.add(VSU);
- jPanel.add(VSUET);
- jPanel.add(Search);
- VSTU.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- setTitle("ВГТУ");
- jPanel.setVisible(false);
- JPanel jPanel1 = new JPanel();
- jPanel1.setLayout(new FlowLayout());
- setContentPane(jPanel1);
- try {
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("select adres from vus where id='1'");
- while (resultSet.next()){
- JLabel jLabel = new JLabel("Адрес: ");
- JLabel jLabel2 = new JLabel(resultSet.getString("adres"));
- jPanel1.add(jLabel);
- jPanel1.add(jLabel2);
- }
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- JButton getSotr = new JButton("Сотрудники");
- JButton getSpec = new JButton("Специальности");
- JButton BACK = new JButton("Назад");
- jPanel1.add(getSotr);
- getSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- JPanel jPanel2 = new JPanel();
- setContentPane(jPanel2);
- JButton addSotr = new JButton("Добавить");
- JButton change = new JButton("Изменить");
- JButton BACK1 = new JButton("Назад");
- jPanel2.add(addSotr);
- addSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = sotrudnikiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),1,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(change);
- change.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = new Sotrudniki(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите новый телефон сотрудника"));
- sotrudnikiDAO.update(connection,sotrudniki);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(BACK1);
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.setVisible(false);
- jPanel1.setVisible(true);
- setContentPane(jPanel1);
- }
- });
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try{
- List<Sotrudniki> list = sotrudnikiDAO.all(connection,1);
- JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel1.add(getSpec);
- getSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- JPanel jPanel2 = new JPanel();
- setContentPane(jPanel2);
- JButton addSpec = new JButton("Добавить");
- JButton change = new JButton("Изменить");
- JButton BACK1 = new JButton("Назад");
- jPanel2.add(addSpec);
- addSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = specialnostiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),1,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(change);
- change.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = new Specialnosti(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя специальности"),JOptionPane.showInputDialog(jPanel1,"Введите новую информацию специальности"));
- specialnostiDAO.update(connection,specialnosti);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(BACK1);
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.setVisible(false);
- jPanel1.setVisible(true);
- setContentPane(jPanel1);
- }
- });
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try{
- List<Specialnosti> list = specialnostiDAO.all(connection,1);
- JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel1.add(BACK);
- BACK.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- jPanel.setVisible(true);
- setContentPane(jPanel);
- setTitle("kurse work");
- }
- });
- }
- });
- VSU.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- setTitle("ВГУ");
- jPanel.setVisible(false);
- JPanel jPanel1 = new JPanel();
- jPanel1.setLayout(new FlowLayout());
- setContentPane(jPanel1);
- try {
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("select adres from vus where id='2'");
- while (resultSet.next()){
- JLabel jLabel = new JLabel("Адрес: ");
- JLabel jLabel2 = new JLabel(resultSet.getString("adres"));
- jPanel1.add(jLabel);
- jPanel1.add(jLabel2);
- }
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- JButton getSotr = new JButton("Сотрудники");
- JButton getSpec = new JButton("Специальности");
- JButton BACK = new JButton("Назад");
- jPanel1.add(getSotr);
- getSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- JPanel jPanel2 = new JPanel();
- setContentPane(jPanel2);
- JButton addSotr = new JButton("Добавить");
- JButton change = new JButton("Изменить");
- JButton BACK1 = new JButton("Назад");
- jPanel2.add(addSotr);
- addSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = sotrudnikiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),2,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(change);
- change.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = new Sotrudniki(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите новый телефон сотрудника"));
- sotrudnikiDAO.update(connection,sotrudniki);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(BACK1);
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.setVisible(false);
- jPanel1.setVisible(true);
- setContentPane(jPanel1);
- }
- });
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try{
- List<Sotrudniki> list = sotrudnikiDAO.all(connection,2);
- JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel1.add(getSpec);
- getSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- JPanel jPanel2 = new JPanel();
- setContentPane(jPanel2);
- JButton addSpec = new JButton("Добавить");
- JButton change = new JButton("Изменить");
- JButton BACK1 = new JButton("Назад");
- jPanel2.add(addSpec);
- addSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = specialnostiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),2,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(change);
- change.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = new Specialnosti(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя специальности"),JOptionPane.showInputDialog(jPanel1,"Введите новую информацию специальности"));
- specialnostiDAO.update(connection,specialnosti);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(BACK1);
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.setVisible(false);
- jPanel1.setVisible(true);
- setContentPane(jPanel1);
- }
- });
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try{
- List<Specialnosti> list = specialnostiDAO.all(connection,2);
- JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel1.add(BACK);
- BACK.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- jPanel.setVisible(true);
- setContentPane(jPanel);
- setTitle("kurse work");
- }
- });
- }
- });
- VSUET.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- setTitle("ВГУИТ");
- jPanel.setVisible(false);
- JPanel jPanel1 = new JPanel();
- jPanel1.setLayout(new FlowLayout());
- setContentPane(jPanel1);
- try {
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("select adres from vus where id='3'");
- while (resultSet.next()){
- JLabel jLabel = new JLabel("Адрес: ");
- JLabel jLabel2 = new JLabel(resultSet.getString("adres"));
- jPanel1.add(jLabel);
- jPanel1.add(jLabel2);
- }
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- JButton getSotr = new JButton("Сотрудники");
- JButton getSpec = new JButton("Специальности");
- JButton BACK = new JButton("Назад");
- jPanel1.add(getSotr);
- getSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- JPanel jPanel2 = new JPanel();
- setContentPane(jPanel2);
- JButton addSotr = new JButton("Добавить");
- JButton change = new JButton("Изменить");
- JButton BACK1 = new JButton("Назад");
- jPanel2.add(addSotr);
- addSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = sotrudnikiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),3,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(change);
- change.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = new Sotrudniki(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите новый телефон сотрудника"));
- sotrudnikiDAO.update(connection,sotrudniki);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(BACK1);
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.setVisible(false);
- jPanel1.setVisible(true);
- setContentPane(jPanel1);
- }
- });
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try{
- List<Sotrudniki> list = sotrudnikiDAO.all(connection,3);
- JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel1.add(getSpec);
- getSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- JPanel jPanel2 = new JPanel();
- setContentPane(jPanel2);
- JButton addSpec = new JButton("Добавить");
- JButton change = new JButton("Изменить");
- JButton BACK1 = new JButton("Назад");
- jPanel2.add(addSpec);
- addSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = specialnostiDAO.add(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),3,JOptionPane.showInputDialog(jPanel1,"Введите имя сотрудника"),JOptionPane.showInputDialog(jPanel1,"Введите телефон сотрудника"));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(change);
- change.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = new Specialnosti(Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")),Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите новое id вуза")),JOptionPane.showInputDialog(jPanel1,"Введите новое имя специальности"),JOptionPane.showInputDialog(jPanel1,"Введите новую информацию специальности"));
- specialnostiDAO.update(connection,specialnosti);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel2.add(BACK1);
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel2.setVisible(false);
- jPanel1.setVisible(true);
- setContentPane(jPanel1);
- }
- });
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try{
- List<Specialnosti> list = specialnostiDAO.all(connection,3);
- JOptionPane.showMessageDialog(jPanel1,Arrays.toString(list.toArray()));
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- jPanel1.add(BACK);
- BACK.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- jPanel.setVisible(true);
- setContentPane(jPanel);
- setTitle("kurse work");
- }
- });
- }
- });
- Search.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- setTitle("Поиск");
- jPanel.setVisible(false);
- JPanel jPanel1 = new JPanel();
- jPanel1.setLayout(new FlowLayout());
- setContentPane(jPanel1);
- JButton searchSotr = new JButton("Сотрудники");
- searchSotr.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SotrudnikiDAO sotrudnikiDAO = new SotrudnikiDAO();
- try {
- Sotrudniki sotrudniki = sotrudnikiDAO.getById(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id сотрудника")));
- if (sotrudniki != null) {
- JOptionPane.showMessageDialog(jPanel, sotrudniki.getName() + ": " + sotrudniki.getFone());
- } else {
- JOptionPane.showMessageDialog(jPanel1, "Нет такого сотрудника!");
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- JButton searchSpec = new JButton("Специальности");
- searchSpec.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- SpecialnostiDAO specialnostiDAO = new SpecialnostiDAO();
- try {
- Specialnosti specialnosti = specialnostiDAO.getById(connection,Integer.parseInt(JOptionPane.showInputDialog(jPanel1,"Введите id специальности")));
- if (specialnosti != null) {
- JOptionPane.showMessageDialog(jPanel, specialnosti.getName() + ": " + specialnosti.getInfo());
- } else {
- JOptionPane.showMessageDialog(jPanel1, "Нет такой специальности!");
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- });
- JButton BACK1 = new JButton("Назад");
- BACK1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- jPanel1.setVisible(false);
- jPanel.setVisible(true);
- setContentPane(jPanel);
- setTitle("kurse work");
- }
- });
- jPanel1.add(searchSotr);
- jPanel1.add(searchSpec);
- jPanel1.add(BACK1);
- }
- });
- setSize(500, 500);
- setContentPane(jPanel);
- setLocationRelativeTo(null);
- setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement