Esempio n. 1
0
  public int cambiarEstado() {
    StringBuilder SQL = new StringBuilder();
    int nAfectados = 0;
    List lCommands = new ArrayList();
    AccesoDatos DAL = null;

    if (this.getId().length() == 0) {
      JOptionPane.showMessageDialog(null, "FALTA INDICAR ID DEl CLIENTE");
    } else {
      try {
        DAL = new AccesoDatos();
        DAL.conectar();

        SQL.append("UPDATE Cliente SET ");
        SQL.append(" bEstado = " + this.getEstado());
        SQL.append(" WHERE sIdCliente = '" + this.getId() + "' ");

        nAfectados = DAL.ejecutarComando(SQL.toString());
        DAL.desconectar();

      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
            null,
            "AH OCURRIDO UN ERROR INESPERADO !",
            "ERROR EN CAMBIAR ESTADO CLIENTE",
            JOptionPane.ERROR_MESSAGE);
      }
    }
    return nAfectados;
  }
Esempio n. 2
0
  public int insertar() {
    int nAfectados = 0;
    StringBuilder SQL = new StringBuilder();
    AccesoDatos DAL = null;

    if (this.getNombre().length() == 0) {
      JOptionPane.showMessageDialog(
          null, " EL NOMBRE NO DEBE ESTAR VACIO", "ERROR", JOptionPane.ERROR_MESSAGE);
    } else {
      SQL.append("INSERT INTO Cliente ");
      SQL.append(
          "( sIdCliente,sNombre,sApellidoPaterno,sApellidoMaterno,sTelefono,sEmail,oFechaRegistro,bEstado ) ");
      SQL.append("VALUES (");
      SQL.append(" '" + this.getId() + "', ");
      SQL.append(" '" + this.getNombre() + "', ");
      SQL.append(" '" + this.getApellidoPaterno() + "', ");
      SQL.append(" '" + this.getApellidoMaterno() + "', ");
      SQL.append(" '" + this.getTelefono() + "', ");
      SQL.append(" '" + this.getEmail() + "', ");
      SQL.append(" '" + this.getFechaRegistro().toString() + "', ");
      SQL.append(" TRUE ) ");

      try {
        DAL = new AccesoDatos();
        DAL.conectar();
        nAfectados = DAL.ejecutarComando(SQL.toString());
        DAL.desconectar();
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null, " ERROR INESPERADO", "ERROR AL INSERTAR CLIENTE", JOptionPane.ERROR_MESSAGE);
      }
    }
    return nAfectados;
  }
Esempio n. 3
0
  public int modificar() {
    int nAfectados = 0;
    StringBuilder SQL = new StringBuilder();
    AccesoDatos DAL = null;

    if (this.getId().length() == 0 || this.getNombre().length() == 0) {
      JOptionPane.showMessageDialog(
          null,
          " EL ID DEL CLIENTE Y EL NOMBRE NO DEBEN ESTAR VACIOS",
          "ERROR",
          JOptionPane.ERROR_MESSAGE);
    } else {
      SQL.append("UPDATE Cliente SET ");
      SQL.append(" sNombre = '" + this.getNombre() + "', ");
      SQL.append(" sApellidoPaterno = '" + this.getApellidoPaterno() + "', ");
      SQL.append(" sApellidoMaterno = '" + this.getApellidoMaterno() + "', ");
      SQL.append(" sTelefono = '" + this.getTelefono() + "', ");
      SQL.append(" sEmail = '" + this.getEmail() + "', ");
      SQL.append(" bEstado = " + this.getEstado());
      SQL.append(" WHERE sIdCliente = '" + this.getId() + "' ");

      try {
        DAL = new AccesoDatos();
        DAL.conectar();
        nAfectados = DAL.ejecutarComando(SQL.toString());
        DAL.desconectar();
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null, " ERROR INESPERADO", "ERROR AL MODIFICAR CLIENTE", JOptionPane.ERROR_MESSAGE);
      }
    }
    return nAfectados;
  }
Esempio n. 4
0
  public boolean buscar() {
    boolean bAnswer = false;
    StringBuilder SQL = new StringBuilder();
    AccesoDatos DAL = null;
    List rst = null;

    if (this.getId().length() == 0) {
      JOptionPane.showMessageDialog(
          null, " EL ID DEL CLIENTE NO DEBE ESTAR VACIO", "ERROR", JOptionPane.ERROR_MESSAGE);
    } else {
      SQL.append(
          "SELECT sNombre,sApellidoPaterno,sApellidoMaterno,sTelefono,sEmail,bEstado,oFechaRegistro ");
      SQL.append(" FROM Cliente");
      SQL.append(" WHERE sIdCliente = '" + this.getId() + "'");

      try {
        DAL = new AccesoDatos();
        DAL.conectar();
        rst = DAL.ejecutarConsulta(SQL.toString());
        DAL.desconectar();

        if (rst.size() == 1) {
          List lRowTemp = (List) rst.get(0);

          this.setNombre((String) lRowTemp.get(0));
          this.setApellidoPaterno((String) lRowTemp.get(1));
          this.setApellidoMaterno((String) lRowTemp.get(2));
          this.setTelefono((String) lRowTemp.get(3));
          this.setEmail((String) lRowTemp.get(4));
          this.setEstado(
              ((lRowTemp.get(5).toString()).equals("t")
                      || lRowTemp.get(5).toString().equals("1")
                      || lRowTemp.get(5).toString().equals("true"))
                  ? true
                  : false);
          this.setFechaRegistro((Date) lRowTemp.get(6));

          bAnswer = true;
        }

      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
            null, " ERROR INESPERADO", "ERROR AL BUSCAR CLIENTE", JOptionPane.ERROR_MESSAGE);
      }
    }

    return bAnswer;
  }