/** Initialize the contents of the frame. */
  private void initialize() {
    frame = new JFrame();
    frame.getContentPane().setBackground(new Color(153, 50, 204));
    frame.setBounds(100, 100, 725, 547);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JLabel lblNewLabel = new JLabel("Username");
    lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
    lblNewLabel.setBounds(119, 113, 146, 36);
    frame.getContentPane().add(lblNewLabel);

    textField = new JTextField();
    textField.setBounds(355, 122, 153, 22);
    frame.getContentPane().add(textField);
    textField.setColumns(10);

    JLabel lblNewLabel_1 = new JLabel("Password");
    lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
    lblNewLabel_1.setBounds(119, 213, 87, 22);
    frame.getContentPane().add(lblNewLabel_1);

    JButton btnNewButton = new JButton("Back");
    btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 22));
    btnNewButton.setBounds(124, 313, 121, 36);
    frame.getContentPane().add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Login");
    btnNewButton_1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            try {
              String query = "select * from logindetails where UserName=? and Password=?";
              PreparedStatement pst = connect.prepareStatement(query);
              pst.setString(1, textField.getText());
              pst.setString(2, passwordField.getText());
              ResultSet rs = pst.executeQuery();
              if (rs.next()) {
                // JOptionPane.showMessageDialog(null, "connection successfull");
                ah.setVisible(true);
                frame.dispose();
              } else {
                JOptionPane.showMessageDialog(
                    null, "user credentials are wrong.Try again with correct credentials");
              }
            } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e);
            }
          }
        });
    btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 22));
    btnNewButton_1.setBounds(424, 314, 97, 35);
    frame.getContentPane().add(btnNewButton_1);

    passwordField = new JPasswordField();
    passwordField.setBounds(355, 215, 166, 22);
    frame.getContentPane().add(passwordField);

    JLabel lblNewLabel_2 = new JLabel("Administrator Login");
    lblNewLabel_2.setForeground(new Color(128, 128, 128));
    lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 28));
    lblNewLabel_2.setBounds(199, 48, 309, 34);
    frame.getContentPane().add(lblNewLabel_2);
  }
  /** Initialize the contents of the frame. */
  private void initialize() {

    JPanel mainPanel = new JPanel();

    JButton book = new JButton("Book");
    mainPanel.add(book);
    book.setPreferredSize(new Dimension(200, 80));

    JTextField enterFlightNum = new JTextField("Enter Flight Number");
    enterFlightNum.setColumns(10);
    enterFlightNum.setBounds(227, 251, 286, 42);
    mainPanel.add(enterFlightNum);

    JButton mainMenu = new JButton("Main Menu");
    mainPanel.add(mainMenu);
    mainMenu.setPreferredSize(new Dimension(200, 80));
    mainMenu.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            fFrame.setVisible(false);
            new MainUI(c1);
          }
        });

    book.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            try {
              c1.bookFlight(Integer.parseInt(enterFlightNum.getText()));
              ;
            } catch (Exception ex) {

              ex.printStackTrace();
            }
          }
        });

    JPanel mainPanel2 = new JPanel();
    JLabel listFlights = new JLabel();
    mainPanel2.add(listFlights);

    Connection connection;
    String labelText = "<html>";
    try {
      Class.forName("com.mysql.jdbc.Driver");
      System.out.println("Driver loaded");

      connection = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "CIS3270", "Cis3270");

      System.out.println("Connection complete");

      Statement statement;

      statement = connection.createStatement();

      String queryString = "select * from flight";

      ResultSet rs = statement.executeQuery(queryString);

      while (rs.next()) {

        labelText =
            labelText
                + rs.getString(1)
                + " "
                + rs.getString(3)
                + " "
                + rs.getString(4)
                + " "
                + rs.getString(5)
                + " "
                + rs.getString(6)
                + "<br>";
      }

    } catch (Exception e) {

    }

    listFlights.setText(labelText);
    System.out.println(labelText);

    JPanel mainCombine = new JPanel();
    mainCombine.add(mainPanel, BorderLayout.NORTH);
    mainCombine.add(mainPanel2, BorderLayout.SOUTH);

    fFrame = new JFrame();
    fFrame.setSize(1000, 800);
    fFrame.add(mainCombine);
    fFrame.setVisible(true);
    fFrame.setResizable(false);
    fFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fFrame.getContentPane().setLayout(null);
  }
  /** Create the frame. */
  public SotrudnikDialog() {
    setTitle(
        "\u041D\u043E\u0432\u044B\u0439 \u0441\u043E\u0442\u0440\u0443\u0434\u043D\u0438\u043A");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setBounds(100, 100, 450, 330);
    contentPane = new JPanel();
    contentPane.setBackground(new Color(255, 204, 255));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel label_familiya = new JLabel("\u0424\u0430\u043C\u0438\u043B\u0438\u044F");
    label_familiya.setBounds(10, 37, 110, 14);
    contentPane.add(label_familiya);

    JLabel label_imya = new JLabel("\u0418\u043C\u044F");
    label_imya.setBounds(10, 62, 110, 14);
    contentPane.add(label_imya);

    JLabel label_otchestvo = new JLabel("\u041E\u0442\u0447\u0435\u0441\u0442\u0432\u043E");
    label_otchestvo.setBounds(10, 87, 110, 14);
    contentPane.add(label_otchestvo);

    textField_otchestvo = new JTextField();
    textField_otchestvo.setBounds(167, 84, 186, 20);
    contentPane.add(textField_otchestvo);
    textField_otchestvo.setColumns(10);

    textField_imya = new JTextField();
    textField_imya.setBounds(167, 58, 186, 20);
    contentPane.add(textField_imya);
    textField_imya.setColumns(10);

    textField_familiya = new JTextField();
    textField_familiya.setBounds(167, 33, 186, 20);
    contentPane.add(textField_familiya);
    textField_familiya.setColumns(10);

    JLabel label_data_priema =
        new JLabel(
            "\u0414\u0430\u0442\u0430 \u043F\u0440\u0438\u0435\u043C\u0430 \u043D\u0430 \u0440\u0430\u0431\u043E\u0442\u0443");
    label_data_priema.setBounds(10, 112, 147, 14);
    contentPane.add(label_data_priema);

    JLabel label_phone = new JLabel("\u0422\u0435\u043B\u0435\u0444\u043E\u043D");
    label_phone.setBounds(10, 137, 134, 14);
    contentPane.add(label_phone);

    JLabel label_doljnost = new JLabel("\u0414\u043E\u043B\u0436\u043D\u043E\u0441\u0442\u044C");
    label_doljnost.setBounds(10, 162, 140, 14);
    contentPane.add(label_doljnost);

    JLabel label_kvalification =
        new JLabel("\u041A\u0432\u0430\u043B\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u044F");
    label_kvalification.setBounds(10, 190, 147, 14);
    contentPane.add(label_kvalification);

    textField_phone = new JTextField();
    textField_phone.setBounds(167, 134, 186, 20);
    contentPane.add(textField_phone);
    textField_phone.setColumns(10);

    textField_date.setBounds(167, 109, 186, 20);
    contentPane.add(textField_date);

    label_id_hidden.setFont(new Font("Tahoma", Font.BOLD, 12));
    label_id_hidden.setBounds(143, 11, 122, 14);
    contentPane.add(label_id_hidden);

    button_insert.setBounds(83, 230, 160, 23);
    contentPane.add(button_insert);

    button_cancel.setBounds(264, 230, 104, 23);
    contentPane.add(button_cancel);

    button_update.setBounds(83, 230, 160, 23);
    contentPane.add(button_update);

    JButton button_plus_doljnost = new JButton("+");
    button_plus_doljnost.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent arg0) {
            DoljnostDialog d = new DoljnostDialog();
            d.setTitle("Добавление должности");
            d.show();
          }
        });
    button_plus_doljnost.setBounds(359, 159, 41, 23);
    contentPane.add(button_plus_doljnost);

    JButton button_plus_kvalification = new JButton("+");
    button_plus_kvalification.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent arg0) {
            KvalificationDialog d = new KvalificationDialog();
            d.setTitle("Добавление квалификации");
            d.show();
          }
        });
    button_plus_kvalification.setBounds(359, 184, 41, 23);
    contentPane.add(button_plus_kvalification);

    JLabel label =
        new JLabel(
            "\u041F\u043E\u043B\u044F, \u043E\u0442\u043C\u0435\u0447\u0435\u043D\u043D\u044B\u0435 ");
    label.setBounds(60, 264, 122, 14);
    contentPane.add(label);

    JLabel label_3 = new JLabel("*");
    label_3.setForeground(Color.RED);
    label_3.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_3.setBounds(186, 264, 12, 14);
    contentPane.add(label_3);

    JLabel label_4 =
        new JLabel(
            "\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B  \u0434\u043B\u044F \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F!");
    label_4.setBounds(197, 264, 203, 14);
    contentPane.add(label_4);

    JLabel label_5 = new JLabel("*");
    label_5.setForeground(Color.RED);
    label_5.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_5.setBounds(356, 37, 12, 14);
    contentPane.add(label_5);

    JLabel label_1 = new JLabel("*");
    label_1.setForeground(Color.RED);
    label_1.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_1.setBounds(356, 62, 12, 14);
    contentPane.add(label_1);

    comboBox_doljnost.setBounds(167, 159, 186, 20);
    contentPane.add(comboBox_doljnost);

    comboBox_kvalification.setBounds(167, 187, 186, 20);
    contentPane.add(comboBox_kvalification);

    // Actions for button "Добавить"
    button_insert.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!textField_familiya.getText().equals("") && !textField_imya.getText().equals("")) {
              try {
                Sotrudnik s = new Sotrudnik();
                s.setFamiliya(textField_familiya.getText());
                s.setImya(textField_imya.getText());
                s.setOtchestvo(textField_otchestvo.getText());
                s.setData_priema(Date.valueOf(textField_date.getText()));
                s.setPhone(textField_phone.getText());
                Doljnost d = (Doljnost) comboBox_doljnost.getSelectedItem();
                s.setId_doljnosti(d.getId_doljnosti());
                Kvalification k = (Kvalification) comboBox_kvalification.getSelectedItem();
                s.setId_kvalification(k.getId_kvalification());

                DBClass db = new DBClass();
                db.sotrudnikUpsert(s, "INSERT");
                MyFrame.updateList();
                ZakazDialog.updateSotrudnik();
              } catch (SQLException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(panelException, e.getMessage());
              } catch (ClassNotFoundException ee) {
                ee.printStackTrace();
                JOptionPane.showMessageDialog(panelException, ee.getMessage());
              } finally {
                dispose();
              }
            } else JOptionPane.showMessageDialog(null, "Введите обязательные параметры!");
          }
        });

    // Actions for button "Отмена"
    button_cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            dispose();
          }
        });

    // Actions for button "Сохранить изменения"
    button_update.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!textField_familiya.getText().equals("")
                && !textField_imya.getText().equals("")
                && !textField_date.getText().equals("")) {
              if (textField_date.getText().length() == 10) {
                try {
                  Integer.parseInt((textField_date.getText().substring(0, 3)));
                  Integer.parseInt((textField_date.getText().substring(5, 6)));
                  Integer.parseInt((textField_date.getText().substring(8, 9)));

                  Sotrudnik s = new Sotrudnik();
                  s.setId_sotrudnika(Integer.parseInt(label_id_hidden.getText()));
                  s.setFamiliya(textField_familiya.getText());
                  s.setImya(textField_imya.getText());
                  s.setOtchestvo(textField_otchestvo.getText());
                  s.setPhone(textField_phone.getText());

                  Doljnost d = (Doljnost) comboBox_doljnost.getSelectedItem();
                  s.setId_doljnosti(d.getId_doljnosti());

                  Kvalification k = (Kvalification) comboBox_kvalification.getSelectedItem();
                  s.setId_kvalification(k.getId_kvalification());

                  DBClass db = new DBClass();
                  db.sotrudnikUpsert(s, "UPDATE");
                  MyFrame.updateList();
                  dispose();
                } catch (NumberFormatException e) {
                  JOptionPane.showMessageDialog(panelException, e.getMessage());
                } catch (SQLException e) {
                  // e.printStackTrace();
                  JOptionPane.showMessageDialog(panelException, e.getMessage());
                } catch (ClassNotFoundException ee) {
                  // ee.printStackTrace();
                  JOptionPane.showMessageDialog(panelException, ee.getMessage());
                }
              } else JOptionPane.showMessageDialog(null, "Введите дату в правильном формате!");
            } else JOptionPane.showMessageDialog(null, "Введите обязательные параметры!");
          }
        });
  }