Exemple #1
0
  public long inserir(Tarefa Tarefa) {
    // criar um "container" dos valores para cada campo da tabela
    ContentValues valores = new ContentValues();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    valores.put("descricao", Tarefa.getDescricao());
    valores.put("dataLimite", sdf.format(Tarefa.getDataLimite()).replace("/", ""));
    valores.put("dataLembrete", sdf.format(Tarefa.getDataLembrete()).replace("/", ""));
    Tarefa.setStatus("P");
    valores.put("status", Tarefa.getStatus());
    valores.put("username", Tarefa.getUsername());
    valores.put("idCategoria", String.valueOf(Tarefa.getIdCategoria()));

    // abrir o banco de dados para escrita
    db = helper.getWritableDatabase();
    // inserir o registro
    long rowID = db.insert("tarefa", null, valores);
    // fechar os objetos
    db.close();
    helper.close();

    return rowID;
  }
Exemple #2
0
  public boolean update(Tarefa tarefa) {
    // se a tarefa não foi realizada atualizar true senão return false
    if (this.checarTarefaRealizada(tarefa)) {
      ContentValues valores = new ContentValues();
      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

      valores.put("descricao", tarefa.getDescricao());
      valores.put("dataLimite", sdf.format(tarefa.getDataLimite()).replace("/", ""));
      valores.put("dataLembrete", sdf.format(tarefa.getDataLembrete()).replace("/", ""));
      if (tarefa.getDataRealizacao() != null)
        valores.put("dataRealizacao", sdf.format(tarefa.getDataRealizacao()).replace("/", ""));
      valores.put("status", tarefa.getStatus());
      valores.put("username", tarefa.getUsername());
      valores.put("idCategoria", String.valueOf(tarefa.getIdCategoria()));

      // abrir o banco de dados para escrita
      db = helper.getWritableDatabase();
      db.update("tarefa", valores, "id = ?", new String[] {Integer.toString(tarefa.getId())});
      db.close();
      helper.close();
      return true;
    } else return false;
  }