Пример #1
0
  /**
   * @param examId
   * @return
   */
  public Resources getExamResources(Exam exam) {
    Resources resources = new Resources();

    String query = "SELECT * FROM " + HLPResources.TABLE_NAME;
    query +=
        " LEFT JOIN "
            + HLPRelations.TABLE_NAME
            + "  ON ("
            + HLPResources.TABLE_NAME
            + "."
            + HLPResources.COL_ID
            + " = "
            + HLPRelations.COL_RES_ID
            + ")";
    query += " WHERE " + HLPRelations.COL_EXAM_ID + " = " + exam.getId();
    query += " AND " + HLPRelations.COL_SRCTABLE + " = '" + HLPExams.TABLE_NAME + "';";

    Log.i(DBsettings.LOG_TAG_TASKS, query);

    Cursor cursor = this.hlpExams.openCon().rawQuery(query, null);
    if (cursor != null) {
      resources.cursorToResourceList(cursor);
    } else {
      Log.w(DBsettings.LOG_TAG_EXAMS, "Cursor is NULL!!");
    }

    this.hlpExams.closeCon();

    return resources;
  }
Пример #2
0
  /**
   * @param id
   * @return
   */
  public Exam getExamById(long id) {
    Exam exam = new Exam();

    String query = "SELECT * FROM " + HLPExams.TABLE_NAME + " WHERE _id = '" + id + "'";

    Cursor cursor = this.hlpExams.openCon().rawQuery(query, null);
    if (cursor != null) {
      if (cursor.getCount() < 1) {
        this.hlpExams.closeCon();
        return null;
      }

      if (cursor.moveToFirst()) {
        exam.cursorToExam(cursor);
      }
    } else {
      Log.w(DBsettings.LOG_TAG_LECTURES, "Cursor is NULL!!");
    }
    this.hlpExams.closeCon();

    return exam;
  }
Пример #3
0
  /**
   * @param exam
   * @return
   */
  public long addExam(Exam exam) {
    long id = this.addExam(exam.getTitle(), exam.getComment(), exam.getLecture_id());
    exam.setId(id);

    if (exam.getDate() != null) {
      this.setExamDate(exam, exam.getDate());
    }

    return id;
  }
Пример #4
0
  /**
   * @param examId
   * @param date
   * @return
   */
  public boolean setExamDate(Exam exam, Date date) {
    boolean worked = false;

    Relation relation = this.dblRelations.getRelationByExamWithDateSet(exam);
    if (relation != null) {
      this.dblDates.deleteDate(relation.getDateId());
      this.dblRelations.deleteRelation(relation);
    }

    long dateId = this.dblDates.addDate(date);
    long relId =
        this.dblRelations.addRelation(
            new Relation(0, HLPExams.TABLE_NAME, 0, exam.getId(), 0, dateId, 0));

    if (dateId != -1 && relId != -1) worked = true;

    return worked;
  }
Пример #5
0
  /**
   * @param exam
   * @return
   */
  public int updateExam(Exam exam) {
    ContentValues values = new ContentValues();

    if (!exam.getTitle().isEmpty()) {
      values.put(HLPExams.COL_TITLE, exam.getTitle());
    }

    if (!exam.getComment().isEmpty()) {
      values.put(HLPExams.COL_COMMENT, exam.getComment());
    }

    if (exam.getLecture_id() > 0) {
      values.put(HLPExams.COL_LECTURE_ID, exam.getLecture_id());
    }

    int ret =
        this.hlpExams.openCon().update(HLPExams.TABLE_NAME, values, "_id = " + exam.getId(), null);

    Log.i(DBsettings.LOG_TAG_EXAMS, "Update res.: " + ret);

    return ret;
  }
Пример #6
0
 /**
  * @param exam
  * @return
  */
 public int deleteExam(Exam exam) {
   return this.deleteExam(exam.getId());
 }