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