Esempio n. 1
0
    @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);
      }
    }
Esempio n. 2
0
 @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);
   }
 }