@Override
 public void actionPerformed(ActionEvent e) {
   try {
     if (!((String) tableNames.getSelectedItem()).equals("INCIDENT")) {
       JOptionPane.showMessageDialog(
           null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
       return;
     }
     if (table.getSelectedRow() == -1) {
       JOptionPane.showMessageDialog(
           null, "Запись не выбрана.", "Message", JOptionPane.INFORMATION_MESSAGE);
       return;
     }
     int key = Integer.parseInt(table.getValueAt(table.getSelectedRow(), 0).toString());
     BaseUpdater updater = new BaseUpdater();
     boolean result = updater.deleteIncident(connection, key);
     if (result) {
       JOptionPane.showMessageDialog(
           null, "Происшествие было удалено", "Message", JOptionPane.INFORMATION_MESSAGE);
       tableNames.setSelectedItem("INCIDENT");
     } else {
       JOptionPane.showMessageDialog(
           null, "Происшествие не было удалено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
     }
   } catch (SQLException ex) {
     ex.printStackTrace();
     JOptionPane.showMessageDialog(
         null, "Ошибка при работе с базой.", "Ошибка", JOptionPane.ERROR_MESSAGE);
   }
 }
    @Override
    public void actionPerformed(ActionEvent e) {
      try {
        if (!((String) tableNames.getSelectedItem()).equals("PERSON")) {
          JOptionPane.showMessageDialog(
              null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        if (table.getSelectedRow() == -1) {
          JOptionPane.showMessageDialog(
              null, "Запись не выбрана.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        AddPersonDialog addPerson = new AddPersonDialog(thisFrame);
        addPerson.setFirstName((String) table.getValueAt(table.getSelectedRow(), 1));
        addPerson.setLastName((String) table.getValueAt(table.getSelectedRow(), 2));
        addPerson.setPassportNumber((Integer) table.getValueAt(table.getSelectedRow(), 3));
        addPerson.setAddress((String) table.getValueAt(table.getSelectedRow(), 4));
        addPerson.setBurnDate((Date) table.getValueAt(table.getSelectedRow(), 5));
        addPerson.setCourtRate((Integer) table.getValueAt(table.getSelectedRow(), 6));
        addPerson.setVisible(true);
        if (!addPerson.getOk()) {
          return;
        }
        BaseUpdater updater = new BaseUpdater();
        boolean result =
            updater.updatePerson(
                connection,
                (Integer) table.getValueAt(table.getSelectedRow(), 0),
                addPerson.getFirstName(),
                addPerson.getLastName(),
                addPerson.getAddress(),
                addPerson.getPassportNumber(),
                addPerson.getCourtRate(),
                addPerson.getBurnDate());

        if (result) {
          JOptionPane.showMessageDialog(
              null, "Информация была обновлена", "Message", JOptionPane.INFORMATION_MESSAGE);
          tableNames.setSelectedItem("PERSON");
        } else {
          JOptionPane.showMessageDialog(
              null, "Информация не была обновлена.", "Ошибка", JOptionPane.ERROR_MESSAGE);
        }
      } catch (ParseException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Неверный формат даты.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      } catch (SQLException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Ошибка. Информация не была обновлена.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      try {
        if (!((String) tableNames.getSelectedItem()).equals("INCIDENT")) {
          JOptionPane.showMessageDialog(
              null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        if (table.getSelectedRow() == -1) {
          JOptionPane.showMessageDialog(
              null, "Запись не выбрана.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }

        AddIncidentDialog addIncident = new AddIncidentDialog(thisFrame);
        addIncident.setDecision((String) table.getValueAt(table.getSelectedRow(), 3));
        addIncident.setDescription((String) table.getValueAt(table.getSelectedRow(), 2));
        addIncident.setDate((Date) table.getValueAt(table.getSelectedRow(), 1));
        addIncident.setVisible(true);
        if (!addIncident.getOk()) {
          return;
        }
        BaseUpdater updater = new BaseUpdater();

        boolean result =
            updater.updateIncident(
                connection,
                (Integer) table.getValueAt(table.getSelectedRow(), 0),
                addIncident.getDecision(),
                addIncident.getDescription(),
                addIncident.getDate());

        if (result) {
          JOptionPane.showMessageDialog(
              null, "Информация была обновлена", "Message", JOptionPane.INFORMATION_MESSAGE);
          tableNames.setSelectedItem("INCIDENT");
        } else {
          JOptionPane.showMessageDialog(
              null, "Информация не была обновлена", "Ошибка", JOptionPane.ERROR_MESSAGE);
        }
      } catch (ParseException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Неверный формат даты.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      } catch (SQLException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Ошибка. Информация не была обновлена.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      try {
        if (!((String) tableNames.getSelectedItem()).equals("PERSON")) {
          JOptionPane.showMessageDialog(
              null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        AddPersonDialog addPerson = new AddPersonDialog(thisFrame);
        addPerson.setVisible(true);
        if (!addPerson.getOk()) {
          return;
        }
        BaseUpdater updater = new BaseUpdater();
        boolean result =
            updater.addPerson(
                connection,
                addPerson.getFirstName(),
                addPerson.getLastName(),
                addPerson.getAddress(),
                addPerson.getPassportNumber(),
                addPerson.getCourtRate(),
                addPerson.getBurnDate());

        if (result) {
          JOptionPane.showMessageDialog(
              null, "Лицо было добавлено", "Message", JOptionPane.INFORMATION_MESSAGE);
          tableNames.setSelectedItem("PERSON");
        } else {
          JOptionPane.showMessageDialog(
              null, "Лицо не было добавлено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
        }
      } catch (ParseException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Неверный формат даты.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      } catch (SQLException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Ошибка. Лицо не было добавлено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      }
    }
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     if (!((String) tableNames.getSelectedItem()).equals("INCIDENT")) {
       JOptionPane.showMessageDialog(
           null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
       return;
     }
     AddIncidentDialog addIncident = new AddIncidentDialog(thisFrame);
     addIncident.setVisible(true);
     if (!addIncident.getOk()) {
       return;
     }
     BaseUpdater updater = new BaseUpdater();
     boolean result =
         updater.addIncedent(
             connection,
             addIncident.getDecision(),
             addIncident.getDescription(),
             addIncident.getDate());
     if (result) {
       JOptionPane.showMessageDialog(
           null, "Происшествие было добавлено", "Message", JOptionPane.INFORMATION_MESSAGE);
       tableNames.setSelectedItem("INCIDENT");
     } else {
       JOptionPane.showMessageDialog(
           null, "Происшествие не было добавлено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
     }
   } catch (ParseException ex) {
     ex.printStackTrace();
     JOptionPane.showMessageDialog(
         null, "Неверный формат даты.", "Ошибка", JOptionPane.ERROR_MESSAGE);
   } catch (SQLException ex) {
     ex.printStackTrace();
     JOptionPane.showMessageDialog(
         null, "Ошибка. Происшествие не было добавлено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
   }
 }
    @Override
    public void actionPerformed(ActionEvent e) {
      try {
        if (!((String) tableNames.getSelectedItem()).equals("ARTICLE")) {
          JOptionPane.showMessageDialog(
              null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        AddArticleDialog addArticle = new AddArticleDialog(thisFrame);
        addArticle.setVisible(true);
        if (!addArticle.getOk()) {
          return;
        }

        BaseUpdater updater = new BaseUpdater();
        boolean result =
            updater.addArticle(
                connection,
                addArticle.getArticleNumber(),
                addArticle.getArticleName(),
                addArticle.getArticleDescription());

        if (result) {
          JOptionPane.showMessageDialog(
              null, "Статья была добавлена", "Message", JOptionPane.INFORMATION_MESSAGE);
          tableNames.setSelectedItem("ARTICLE");
        } else {
          JOptionPane.showMessageDialog(
              null, "Статья не была добавлена.", "Ошибка", JOptionPane.ERROR_MESSAGE);
        }
      } catch (SQLException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(
            null, "Ошибка. Статья не была добавлена.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      try {
        if (!((String) tableNames.getSelectedItem()).equals("INCIDENT")) {
          JOptionPane.showMessageDialog(
              null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        if (table.getSelectedRow() == -1) {
          JOptionPane.showMessageDialog(
              null, "Запись не выбрана.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        int selectedRow = table.getSelectedRow();
        int incidentNumber = Integer.parseInt(table.getValueAt(selectedRow, 0).toString());

        String query =
            "select personnumber, firstName, lastName, passportnumber from " + "alex.person";
        PreparedStatement pStatment = connection.prepareStatement(query);
        ResultSet result = pStatment.executeQuery();
        Map<String, Integer> persons = new HashMap<String, Integer>();
        while (result.next()) {
          persons.put(
              result.getString("firstname")
                  + " "
                  + result.getString("lastname")
                  + ": "
                  + result.getString("passportnumber"),
              Integer.valueOf(result.getInt("personnumber")));
        }

        query = "select * from alex.status";
        pStatment = connection.prepareStatement(query);
        result = pStatment.executeQuery();
        Map<String, Integer> status = new HashMap<String, Integer>();
        while (result.next()) {
          status.put(
              result.getString("statusname"), Integer.valueOf(result.getInt("statusnumber")));
        }

        ConnectWithPersonDialog dialog = new ConnectWithPersonDialog(thisFrame, persons, status);
        dialog.setVisible(rootPaneCheckingEnabled);
        if (!dialog.getOk()) {
          return;
        }

        BaseUpdater updater = new BaseUpdater();
        boolean resultBool =
            updater.addPersonToIncident(
                connection, dialog.getPersonKey(), incidentNumber, dialog.getStatusKey());

        if (resultBool) {
          JOptionPane.showMessageDialog(
              null,
              "Лицо было добавлено к происшествию.",
              "Message",
              JOptionPane.INFORMATION_MESSAGE);
        } else {
          JOptionPane.showMessageDialog(
              null, "Лицо не было добавлено к происшествию", "Ошибка", JOptionPane.ERROR_MESSAGE);
        }

      } catch (SQLException ex) {
        JOptionPane.showMessageDialog(
            null,
            "Ошибка. Лицо не было добавлено к происшествию",
            "Ошибка",
            JOptionPane.ERROR_MESSAGE);
      }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      try {
        if (!((String) tableNames.getSelectedItem()).equals("INCIDENT")) {
          JOptionPane.showMessageDialog(
              null, "Не выбрана необходимая таблица.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        if (table.getSelectedRow() == -1) {
          JOptionPane.showMessageDialog(
              null, "Запись не выбрана.", "Message", JOptionPane.INFORMATION_MESSAGE);
          return;
        }
        int selectedRow = table.getSelectedRow();
        int incidentNumber = Integer.parseInt(table.getValueAt(selectedRow, 0).toString());

        // Selecte all having articles
        String query = "select articlenumber, articlename from alex.article";
        PreparedStatement pStatment = connection.prepareStatement(query);
        ResultSet result = pStatment.executeQuery();

        Map<String, Integer> articles = new HashMap<String, Integer>();
        while (result.next()) {
          articles.put(
              result.getString("articlenumber") + ": " + result.getString("articlename"),
              Integer.valueOf(result.getInt("articlenumber")));
        }

        // Getting nessesary information
        AddCriminalCaseDialog dialog = new AddCriminalCaseDialog(thisFrame, articles);
        dialog.setVisible(rootPaneCheckingEnabled);
        if (!dialog.getOk()) {
          return;
        }

        // Execute operation
        BaseUpdater updater = new BaseUpdater();
        boolean resultBool =
            updater.addCriminalCase(
                connection,
                dialog.getCriminalDate(),
                dialog.getArticleKeys(),
                dialog.getCriminalNote(),
                incidentNumber);

        if (resultBool) {
          JOptionPane.showMessageDialog(
              null, "Уголовное дело было добавлено.", "Message", JOptionPane.INFORMATION_MESSAGE);
          tableNames.setSelectedItem("INCIDENT");
        } else {
          JOptionPane.showMessageDialog(
              null, "Уголовное дело не было добавлено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
        }

      } catch (ParseException ex) {
        JOptionPane.showMessageDialog(
            null, "Неверный формат даты.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      } catch (SQLException ex) {
        JOptionPane.showMessageDialog(
            null, "Ошибка. Уголовное дело не было добавлено.", "Ошибка", JOptionPane.ERROR_MESSAGE);
      }
    }