示例#1
0
  @Override
  public ArrayList<Trago> GetAll(boolean Activos) throws Exception {
    ArrayList<Trago> colTragos = new ArrayList<Trago>();
    try {
      Connection con = Conexion.getConexion();

      Statement sql = con.createStatement();
      int i;
      if (Activos) {
        i = 1;
      } else {
        i = 0;
      }

      ResultSet cmd = sql.executeQuery("Select * from tragos where estado=" + i);
      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;
    }
  }
示例#2
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;
    }
  }
示例#3
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;
    }
  }
示例#4
0
  @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;
    }
  }
示例#5
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;
    }
  }