@Override
  public ArrayList<Trago> GetAll() throws Exception {
    ArrayList<Trago> colTragos = new ArrayList<Trago>();
    try {
      Connection con = Conexion.getConexion();

      Statement sql = con.createStatement();
      ResultSet cmd = sql.executeQuery("Select * from tragos;");
      while (cmd.next()) {
        Trago tr = new Trago();
        tr.setDescripcion(cmd.getString("descripcion"));
        tr.setId(cmd.getInt("id"));
        tr.setEstado((cmd.getInt("estado") == 1) ? true : false);
        tr.setGraduacion(cmd.getString("graduacion"));
        tr.setModoPreparacion(cmd.getString("modopreparacion"));
        tr.setNombre(cmd.getString("nombre"));
        tr.setPositivo(cmd.getInt("positivo"));
        tr.setNegativo(cmd.getInt("negativo"));

        colTragos.add(tr);
      }
      cmd.close();
      sql.close();
      con.close();
      for (Trago tr1 : colTragos) {
        tr1.setReceta(ADReceta.getInstancia().GetAllByIdTrago(tr1.getId()));
      }
      return colTragos;

    } catch (Exception ex) {
      throw ex;
    }
  }
  @Override
  public Trago GetById(int id) throws Exception {
    try {
      Connection con = Conexion.getConexion();
      Statement sql = con.createStatement();
      ResultSet cmd = sql.executeQuery("Select * from tragos where id=" + id + ";");
      Trago tr = null;
      while (cmd.next()) {
        tr = new Trago();
        tr.setDescripcion(cmd.getString("descripcion"));
        tr.setId(cmd.getInt("id"));
        tr.setEstado((cmd.getInt("estado") == 1) ? true : false);
        tr.setGraduacion(cmd.getString("graduacion"));
        tr.setModoPreparacion(cmd.getString("modopreparacion"));
        tr.setNombre(cmd.getString("nombre"));
        tr.setPositivo(cmd.getInt("positivo"));
        tr.setNegativo(cmd.getInt("negativo"));
      }
      cmd.close();
      sql.close();
      con.close();
      if (tr != null) {
        tr.setReceta(ADReceta.getInstancia().GetAllByIdTrago(tr.getId()));
      }
      return tr;

    } catch (Exception ex) {
      throw ex;
    }
  }
Exemple #3
0
  @Override
  public List listarPermisosDefecto() throws Exception {
    Connection conn = Conexion.getConexion();

    // ResultSet result = null;
    PreparedStatement statement = null;
    ResultSet result = null;
    List list = new ArrayList();
    String consulta = "";
    int i = 0;
    Permiso permisos;

    consulta =
        "SELECT PermisosDefecto.IdRol, PermisosDefecto.IdPermiso, PermisosDefecto.Activado, Roles.NombreRol, ListaPermisos.Nombre FROM PermisosDefecto, Roles, ListaPermisos WHERE PermisosDefecto.IdRol NOT LIKE 1 AND PermisosDefecto.IdPermiso = ListaPermisos.IdPermiso AND Roles.IdRol=PermisosDefecto.IdRol";
    System.out.println("Consulta: " + consulta);
    // Pido conexion
    try {
      statement = conn.prepareStatement(consulta);
      result = statement.executeQuery();

      while (result.next()) {
        permisos = new Permiso();
        permisos.setIdRol(result.getInt("PermisosDefecto.IdRol"));
        permisos.setIdPermiso(result.getInt("IdPermiso"));
        permisos.setPermiso(result.getString("ListaPermisos.Nombre"));
        permisos.setRol(result.getString("Roles.NombreRol"));
        permisos.setActivado(result.getBoolean("PermisosDefecto.Activado"));
        list.add(permisos);
      }
      return list;

    } catch (SQLException sqle) {
      throw new Exception("Excepcion AgendaDAOImp..." + sqle);
    }
    // cierro la conexion
    finally {
      if (result != null) {
        try {
          result.close();
        } catch (SQLException ignored) {
        }
      }
      if (statement != null)
        try {
          statement.close();
        } catch (SQLException ignored) {
        }
      if (conn != null)
        try {
          conn.close();
        } catch (SQLException ignored) {
        }
    }
  }
Exemple #4
0
  @Override
  public boolean insertarPermisosUsuario(Permiso permiso) throws Exception {
    Connection conn = Conexion.getConexion();

    boolean insertado;
    ResultSet result = null;
    PreparedStatement statement = null;

    // Pido conexion
    try {
      String consulta =
          "INSERT INTO `SiluBd`.`Permisos` (`IdUsuario`, `IdPermiso`, `Permiso`, `Activado`)VALUES ("
              + permiso.getIdUsuario()
              + ", "
              + permiso.getIdPermiso()
              + ", '"
              + permiso.getPermiso()
              + "', "
              + permiso.getActivado()
              + ");";
      statement = conn.prepareStatement(consulta);
      System.out.println(consulta);
      insertado = statement.execute(consulta);
      result = statement.getResultSet();
      if (!insertado) {
        return true;
      } else {
        System.out.println("No se ha insertado el permiso");
        return false;
      }
    } catch (SQLException sqle) {
      throw new Exception("Excepcion PermisosDAOImp..." + sqle);
    }
    // cierro la conexion
    finally {
      if (result != null) {
        try {
          result.close();
        } catch (SQLException ignored) {
        }
      }
      if (statement != null)
        try {
          statement.close();
        } catch (SQLException ignored) {
        }
      if (conn != null)
        try {
          conn.close();
        } catch (SQLException ignored) {
        }
    }
  }
  public void guardarSinRecetas(Trago variable) throws Exception {
    try {
      Connection con = Conexion.getConexion();
      Statement sql = con.createStatement();
      if (variable.getId() == 0) {
        sql.executeUpdate(
            "insert into tragos (nombre,descripcion,modopreparacion,estado,graduacion,positivo,negativo) values('"
                + variable.getNombre()
                + "', "
                + " '"
                + variable.getDescripcion()
                + "','"
                + variable.getModoPreparacion()
                + "',"
                + variable.getEstadomysql()
                + ",'"
                + variable.getGraduacion()
                + "', "
                + " "
                + variable.getPositivo()
                + ", "
                + variable.getNegativo()
                + "  )");
      } else {
        sql.executeUpdate(
            "update tragos set nombre='"
                + variable.getNombre()
                + "', descripcion='"
                + variable.getDescripcion()
                + "',modopreparacion='"
                + variable.getModoPreparacion()
                + "',"
                + " estado="
                + variable.getEstadomysql()
                + ",graduacion='"
                + variable.getGraduacion()
                + "',  "
                + " positivo="
                + variable.getPositivo()
                + ", negativo="
                + variable.getNegativo()
                + " where id="
                + variable.getId()
                + " ");
      }

      sql.close();
      con.close();
    } catch (Exception ex) {
      throw ex;
    }
  }
Exemple #6
0
  @Override
  public List listarRoles() throws Exception {
    Connection conn = Conexion.getConexion();

    // ResultSet result = null;
    PreparedStatement statement = null;
    ResultSet result = null;
    List list = new ArrayList();
    String consulta = "";
    Permiso permisos;

    consulta = "SELECT IdRol, NombreRol FROM `SiluBd`.`Roles` WHERE IdRol NOT LIKE 1;";
    System.out.println("Consulta: " + consulta);
    // Pido conexion
    try {
      // statement = conn.prepareStatement("SELECT * FROM `SiluBd`.`Clientes` WHERE
      // Dni='"+Dni+"';"); //, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY
      statement = conn.prepareStatement(consulta);
      result = statement.executeQuery();

      while (result.next()) {
        permisos = new Permiso();
        permisos.setIdRol(result.getInt("IdRol"));
        permisos.setRol(result.getString("NombreRol"));

        list.add(permisos);
      }
      return list;

    } catch (SQLException sqle) {
      throw new Exception("Excepcion AgendaDAOImp..." + sqle);
    }
    // cierro la conexion
    finally {
      if (result != null)
        try {
          result.close();
        } catch (SQLException ignored) {
        }
      if (statement != null)
        try {
          statement.close();
        } catch (SQLException ignored) {
        }
      if (conn != null)
        try {
          conn.close();
        } catch (SQLException ignored) {
        }
    }
  }
Exemple #7
0
  @Override
  public List listarPermisosUsuario(int idUsuario) throws Exception {
    Connection conn = Conexion.getConexion();

    // ResultSet result = null;
    PreparedStatement statement = null;
    ResultSet result = null;
    List list = new ArrayList();
    String consulta = "";
    int i = 0;
    Permiso permisos;

    consulta =
        "SELECT Nombre, Activado FROM `SiluBd`.`Permisos` WHERE IdUsuario=" + idUsuario + ";";
    System.out.println("Consulta: " + consulta);
    // Pido conexion
    try {
      statement = conn.prepareStatement(consulta);
      result = statement.executeQuery();

      while (result.next()) {
        permisos = new Permiso();
        permisos.setRol(result.getString("Nombre"));
        permisos.setActivado(result.getBoolean("Activado"));
        list.add(permisos);
      }
      return list;

    } catch (SQLException sqle) {
      throw new Exception("Excepcion AgendaDAOImp..." + sqle);
    }
    // cierro la conexion
    finally {
      if (result != null) {
        try {
          result.close();
        } catch (SQLException ignored) {
        }
      }
      if (statement != null)
        try {
          statement.close();
        } catch (SQLException ignored) {
        }
      if (conn != null)
        try {
          conn.close();
        } catch (SQLException ignored) {
        }
    }
  }
  public ArrayList<Trago> GetAll(String filtro) throws Exception {
    ArrayList<Trago> colTragos = new ArrayList<Trago>();
    try {
      Connection con = Conexion.getConexion();

      Statement sql = con.createStatement();

      ResultSet cmd =
          sql.executeQuery(
              "select tr.* from "
                  + " tragos tr inner join ingrediente_trago it on tr.id=it.idtrago"
                  + " inner join ingrediente i on it.idingrediente=i.id"
                  + " where tr.estado=1 and (tr.nombre like '%"
                  + filtro
                  + "%' or i.nombre like '%"
                  + filtro
                  + "%')");
      while (cmd.next()) {
        Trago tr = new Trago();
        tr.setDescripcion(cmd.getString("descripcion"));
        tr.setId(cmd.getInt("id"));
        tr.setEstado((cmd.getInt("estado") == 1) ? true : false);
        tr.setGraduacion(cmd.getString("graduacion"));
        tr.setModoPreparacion(cmd.getString("modopreparacion"));
        tr.setNombre(cmd.getString("nombre"));
        tr.setPositivo(cmd.getInt("positivo"));
        tr.setNegativo(cmd.getInt("negativo"));
        // tr.setReceta(ADReceta.getInstancia().GetAllByIdTrago(tr.getId()));
        colTragos.add(tr);
      }
      cmd.close();
      sql.close();
      con.close();
      for (Trago tr1 : colTragos) {
        tr1.setReceta(ADReceta.getInstancia().GetAllByIdTrago(tr1.getId()));
      }
      return colTragos;

    } catch (Exception ex) {
      throw ex;
    }
  }
  @Override
  public void Guardar(Trago variable) throws Exception {
    Connection con = null;
    try {
      ADReceta adRec = ADReceta.getInstancia();
      con = Conexion.getConexion();
      con.setAutoCommit(false);
      String sql;
      PreparedStatement statement;
      if ((variable.getId()) == 0) {
        sql =
            "insert into tragos (nombre,descripcion,modopreparacion,estado,graduacion,positivo,negativo) values('"
                + variable.getNombre()
                + "', "
                + " '"
                + variable.getDescripcion()
                + "','"
                + variable.getModoPreparacion()
                + "',"
                + variable.getEstadomysql()
                + ",'"
                + variable.getGraduacion()
                + "', "
                + " "
                + variable.getPositivo()
                + ", "
                + variable.getNegativo()
                + "  )";
        statement = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        statement.executeUpdate();
        int id = 0;
        ResultSet rs = statement.getGeneratedKeys();
        if (rs.next()) {
          id = rs.getInt(1);
        }
        if (variable.getReceta().size() > 0) {
          for (Receta re : variable.getReceta()) {
            re.setIdtrago(id);
          }
        }

      } else {
        sql =
            "update tragos set nombre='"
                + variable.getNombre()
                + "', descripcion='"
                + variable.getDescripcion()
                + "',modopreparacion='"
                + variable.getModoPreparacion()
                + "',"
                + " estado="
                + variable.getEstadomysql()
                + ",graduacion='"
                + variable.getGraduacion()
                + "',  "
                + " positivo="
                + variable.getPositivo()
                + ", negativo="
                + variable.getNegativo()
                + " where id="
                + variable.getId()
                + " ";
        statement = con.prepareStatement(sql);
        statement.executeUpdate();
        adRec.eliminarByIdTrago(variable.getId(), con);
      }

      for (Receta re : variable.getReceta()) {
        adRec.Guardar(re, con);
      }

      con.commit();
      statement.close();
      con.close();

    } catch (Exception ex) {
      if (con != null) {
        con.rollback();
      }
      throw ex;
    }
  }