コード例 #1
0
  // Update
  public int updateAssignment(Assignment assignment) {
    int update;
    Log.d("Went into updateAssignment", "yes");
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(TITLE, assignment.gettitle());
    values.put(TYPE, assignment.gettype());
    values.put(MONTH, assignment.getmonth());
    values.put(DAY, assignment.getday());
    values.put(YEAR, assignment.getyear());
    values.put(PRIORITY, assignment.getpriority());
    if (assignment.getCourse() != null) values.put(C_ID, assignment.getCourse().getcid());
    if (assignment.getinstructor() != null) values.put(I_ID, assignment.getinstructor().getiid());
    values.put(NOTES, assignment.getnotes());
    values.put(COMPLETED, assignment.getcompleted());

    update =
        db.update(
            TABLE_ASSIGNMENT,
            values,
            A_ID + "= ?",
            new String[] {String.valueOf(assignment.getaid())});
    if (assignment.getpartners() != null) updatePartner(assignment.getpartners());
    if (assignment.getgrade() != null) updateGrade(assignment.getgrade());
    return update;
  }
コード例 #2
0
  // Setters
  // Adding new Assignment
  public void addAssignment(Assignment assignment) {
    Log.d("cane into addAssignment", "yes");
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(TITLE, assignment.gettitle());
    values.put(TYPE, assignment.gettype());
    values.put(MONTH, assignment.getmonth());
    values.put(DAY, assignment.getday());
    values.put(YEAR, assignment.getyear());
    values.put(PRIORITY, assignment.getpriority());
    Log.d("set priority", "yes");
    if (assignment.getCourse() != null) values.put(C_ID, assignment.getCourse().getcid());
    else values.put(C_ID, 0);
    if (assignment.getinstructor() != null) values.put(I_ID, assignment.getinstructor().getiid());
    else values.put(I_ID, 0);
    values.put(NOTES, assignment.getnotes());
    values.put(COMPLETED, assignment.getcompleted());
    Log.d("ContentValues:", values.toString());
    Log.d("Am about to input values to database", "yes");
    long aid = db.insert(TABLE_ASSIGNMENT, null, values);
    assignment.setaid((int) aid);
    db.close(); // Closing database connection

    if (assignment.getpartners().size() > 0) {
      for (int count = 0; count < assignment.getpartners().size(); count++) {
        assignment.getpartners().get(count).setaid(assignment.getaid());
      }
      addPartner(assignment.getpartners());
    }
    if (assignment.getgrade() != null) {
      assignment.getgrade().setaid(assignment.getaid());
      addGrade(assignment.getgrade());
    }
  }