コード例 #1
0
ファイル: vtnCategorias.java プロジェクト: Reycod/Inventarios
  private void jButton4ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:

    String estado = "";
    if (radioActivo.isSelected()) {
      estado = "Activo";
    } else if (RadioInactivo.isSelected()) {
      estado = "Inactivo";
    }

    try {
      List<String> validar = new ArrayList<>();
      validar.add(txtCateNombre.getText());
      validar.add(txtDesCate.getText());
      validar.add(estado);
      if (Validaciones.validarCampos(validar)) {
        Categoria cate = this.getObjCategoria(); // recuperando el objeto recuperado desde la tabla
        cate.setNombre(txtCateNombre.getText());
        cate.setDescripcion(txtDesCate.getText());
        cate.setEstado(estado);

        CategoriaDao catDao = new CategoriaDao();
        if (catDao.actualizarCategoria(cate)) {
          JOptionPane.showMessageDialog(
              this, "Actualización correcta", null, JOptionPane.INFORMATION_MESSAGE);
          limpiarCamposCategoria();
          bloquearCamposCategoria();
          listarDatos();
        }
      } else {
        JOptionPane.showMessageDialog(
            this, "Faltan campos por llenar..!!", null, JOptionPane.WARNING_MESSAGE);
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, "Error" + e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jButton4ActionPerformed
コード例 #2
0
ファイル: vtnCategorias.java プロジェクト: Reycod/Inventarios
 private void tablaCategoriaMousePressed(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_tablaCategoriaMousePressed
   // TODO add your handling code here:
   DefaultTableModel tm = (DefaultTableModel) tablaCategoria.getModel();
   String dato = String.valueOf(tm.getValueAt(tablaCategoria.getSelectedRow(), 0));
   CategoriaDao catDao = new CategoriaDao();
   try {
     Categoria cat = catDao.buscarCategoria(Integer.parseInt(dato));
     this.setObjCategoria(cat); // insertando el
     txtCateNombre.setText(cat.getNombre());
     txtDesCate.setText(cat.getDescripcion());
     if (cat.getEstado().equals("Activo")) {
       radioActivo.setSelected(true);
     } else if (cat.getEstado().equals("Inactivo")) {
       RadioInactivo.setSelected(true);
     }
     // JOptionPane.showMessageDialog(null, "Precionado" + cat.getNombre());
   } catch (Exception ex) {
     JOptionPane.showMessageDialog(
         this, "Error" + ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
   }
 } // GEN-LAST:event_tablaCategoriaMousePressed