예제 #1
0
  private boolean isEmptyFields() {
    boolean state = false;
    javax.swing.text.JTextComponent textField;
    javax.swing.JComboBox combo;
    String date;

    for (int i = 0; i <= manageEdit.getPnFields().getComponentCount(); i++) {
      try {
        textField = (javax.swing.text.JTextComponent) manageEdit.getPnFields().getComponent(i);
        if (textField.getText().equals("")) {
          state = true;
          textField.requestFocus();
        } else if (textField.getText().indexOf("-") != -1) {
          String special = textField.getText().trim();
          if ((special.length() < 12) && (special.length() != 10)) {
            state = true;
            textField.requestFocus();
          }
        }
      } catch (Exception e) {
      }
    }
    return state;
  }
예제 #2
0
  @Override
  public void actionPerformed(ActionEvent e) {

    String command = e.getActionCommand();
    if (command.equals("add")) {
      this.manageEdit = new ManageBreedEdit(null, true, this);
      this.manageEdit.setComboBoxModel(model);
      this.manageEdit.showFrame();
      temp = null;

    } else if (command.equals("remove")) {
      if (temp != null) {
        int i =
            JOptionPane.showConfirmDialog(
                null, "En Realidad Desea Eliminar El Registro", "Atencion", JOptionPane.OK_OPTION);
        if (i == 0) {
          this.modelBreeds.deleteObject(temp);
          id = 0;
          JOptionPane.showMessageDialog(null, "Registro Eliminado");
          temp = null;
        } else {
          JOptionPane.showMessageDialog(null, "Transaccion Cancelada");
        }
      } else {
        JOptionPane.showMessageDialog(null, "No Se Ha Seleccionado Ningun Registro");
      }

    } else if (command.equals("save")) {

      if (isEmptyFields()) {
        JOptionPane.showMessageDialog(
            null,
            "Existen Campos En Blancos Por Favor Completar",
            "Error",
            JOptionPane.ERROR_MESSAGE);
        return;
      } else {
        if (temp == null) {
          if (this.manageEdit.getBreedHeigth() != 0 && this.manageEdit.getBreedWidth() != 0) {
            this.species = modelSpecies.getSpeciesByName(this.manageEdit.getSpecieName());
            this.breed =
                new Breeds(
                    manageEdit.getBreedName(),
                    species,
                    manageEdit.getBreedHeigth(),
                    manageEdit.getBreedWidth());
            modelBreeds.insertObject(this.breed);
            JOptionPane.showMessageDialog(null, "Registro Agregado ");
            this.manageEdit.dispose();
          } else {
            JOptionPane.showMessageDialog(
                null,
                "Existen Malas Entradas En Campos Favor Corrregir",
                "Error",
                JOptionPane.ERROR_MESSAGE);
          }
        } else {
          int i =
              JOptionPane.showConfirmDialog(
                  null,
                  "Seguro De Querer Alterar La Informacion De Este Registro",
                  "Atencion",
                  JOptionPane.OK_OPTION);
          if (i == 0) {
            Species es = this.modelSpecies.getSpeciesByName(this.manageEdit.getSpecieName());
            temp.setBreedsName(this.manageEdit.getBreedName());
            temp.setSpecie(es);
            temp.setHeight(this.manageEdit.getBreedHeigth());
            temp.setWidth(this.manageEdit.getBreedWidth());

            modelBreeds.updateObject(temp);
            this.manageEdit.dispose();
          } else {
            JOptionPane.showMessageDialog(null, "Tansaccion Cancelada");
          }
        }
        temp = null;
      }

    } else if (command.equals("cancel")) {
      int i =
          JOptionPane.showConfirmDialog(
              null,
              " En Realidad Desea Cancelar El registro",
              "Atencion",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE);
      if (i == 0) {
        manageEdit.dispose();
        temp = null;
      }

    } else if (command.equals("update")) {

      if (id != 0) {
        this.manageEdit = new ManageBreedEdit(null, true, this);
        this.manageEdit.setComboBoxModel(model);
        this.manageEdit.setAllFields(
            temp.getBreedsName(),
            temp.getSpecie().getSpeciesName(),
            temp.getWidth(),
            temp.getHeight());
        this.manageEdit.showFrame();
      } else {
        JOptionPane.showMessageDialog(
            null, "No Existe Un Registro Seleccionado", "Error", JOptionPane.ERROR_MESSAGE);
      }

    } else if (command.equals("exit")) {
      this.manageBreeds.closeFrame();
    }
  }