Пример #1
0
 public HashMap<String, String> getGeneralInfo(long projectId, String date) {
   ActivityDataSource activityDataSource = new ActivityDataSource(context);
   List<ActivityStructure> activities = activityDataSource.getAllActivities();
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   List<TaskStructure> tasks = null;
   HashMap<String, String> info = new HashMap<String, String>();
   try {
     for (ActivityStructure activity : activities) {
       tasks = new ArrayList<TaskStructure>();
       String whereSequence =
           ("project_id = " + projectId)
               + " and "
               + ("activity_id = " + activity.getId())
               + " and "
               + ("date = date('" + date + "')");
       Cursor cursor =
           database.query(
               TaskStructure.TABLE_NAME, allColumns, whereSequence, null, null, null, null);
       cursor.moveToFirst();
       while (!cursor.isAfterLast()) {
         TaskStructure task = cursorToTask(cursor);
         tasks.add(task);
         cursor.moveToNext();
       }
       cursor.close();
       info.put(activity.getName(), totalTime(tasks));
     }
     return info;
   } finally {
     database.close();
   }
 }
Пример #2
0
  public TaskStructure createTask(
      String name, String description, String date, int time, long activityId, long projectId) {
    SQLiteDatabase database = dbHelper.getWritableDatabase();
    try {
      ContentValues values = new ContentValues();

      values.put(TaskStructure.COLUMN_NAME, name);
      values.put(TaskStructure.COLUMN_DESCRIPTION, description);
      values.put(TaskStructure.COLUMN_DATE, date);
      values.put(TaskStructure.COLUMN_TIME, time);
      values.put(TaskStructure.ACTIVITY_ID, activityId);
      values.put(TaskStructure.PROJECT_ID, projectId);
      long insertId = database.insert(TaskStructure.TABLE_NAME, null, values);
      Cursor cursor =
          database.query(
              TaskStructure.TABLE_NAME,
              allColumns,
              TaskStructure.COLUMN_ID + " = " + insertId,
              null,
              null,
              null,
              null);
      cursor.moveToFirst();
      TaskStructure task = cursorToTask(cursor);
      return task;
    } finally {
      database.close();
    }
  }
Пример #3
0
 public void deleteTask(long id) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   try {
     database.delete(TaskStructure.TABLE_NAME, TaskStructure.COLUMN_ID + " = " + id, null);
   } finally {
     database.close();
   }
 }
Пример #4
0
 public void deleteTasks(long projectId) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   try {
     int status = database.delete(TaskStructure.TABLE_NAME, "project_id = " + projectId, null);
     if (status != 1) {
       Log.e(ProjectStructure.class.getName(), "Can`t delete tasks for project id: " + projectId);
     }
   } finally {
     database.close();
   }
 }
Пример #5
0
 public int updateTask(String nameTask, String descriptionTask, int time, long taskId) {
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   try {
     ContentValues values = new ContentValues();
     values.put(TaskStructure.COLUMN_NAME, nameTask);
     values.put(TaskStructure.COLUMN_DESCRIPTION, descriptionTask);
     values.put(TaskStructure.COLUMN_TIME, time);
     String whereClause = ("_id = " + taskId);
     return database.update(TaskStructure.TABLE_NAME, values, whereClause, null);
   } finally {
     database.close();
   }
 }
Пример #6
0
 public TaskStructure getTask(long taskId) {
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   try {
     Cursor cursor =
         database.query(
             TaskStructure.TABLE_NAME, allColumns, ("_id = " + taskId), null, null, null, null);
     cursor.moveToFirst();
     TaskStructure task = cursorToTask(cursor);
     cursor.close();
     return task;
   } finally {
     database.close();
   }
 }
Пример #7
0
  public List<TaskStructure> getAllTasks(long projectId, String date) {
    SQLiteDatabase database = dbHelper.getWritableDatabase();
    List<TaskStructure> tasks = null;

    String whereSequence =
        ("project_id = " + projectId) + " and " + ("date = date('" + date + "')");
    try {
      tasks = new ArrayList<TaskStructure>();
      Cursor cursor =
          database.query(
              TaskStructure.TABLE_NAME, allColumns, whereSequence, null, null, null, null);
      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {
        TaskStructure task = cursorToTask(cursor);
        tasks.add(task);
        cursor.moveToNext();
      }
      cursor.close();
    } finally {
      database.close();
    }
    return tasks;
  }
Пример #8
0
  public boolean taskExists(String name, Session session) {
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    try {
      String whereSequence =
          ("name = '" + name + "'")
              + " and "
              + ("project_id = " + session.getProjectId())
              + " and "
              + ("date = date('" + session.getDate(Session.RELEVANT) + "')");
      Cursor cursor =
          database.query(
              TaskStructure.TABLE_NAME, allColumns, whereSequence, null, null, null, null);

      TaskStructure task = null;
      if (cursor.moveToFirst()) {
        task = cursorToTask(cursor);
      }

      return task != null;
    } finally {
      database.close();
    }
  }