Example #1
0
  public void create(Answersheet answersheet) {
    String name = answersheet.getAnswersheetName();
    int paperId = answersheet.getPaper().getPaperId();
    int bpId = answersheet.getBpartner().getBpartnerId();
    Date date = answersheet.getDate();
    Date start = answersheet.getStartTime();
    Date finish = answersheet.getFinishTime();

    int id = dao.insert(name, paperId, bpId, date, start, finish);
    answersheet.setAnswersheetId(id);

    List<Integer> auditorIds = answersheet.getAuditorIds();
    answersheetAuditorDao.delete(id);
    answersheetAuditorDao.insert(id, auditorIds);

    List<String> attendances = answersheet.getAttendances();
    answersheetAttendanceDao.delete(id);
    answersheetAttendanceDao.insert(id, attendances);

    // create answer list of this answersheet
    Log.i(tag, "Create list of answers for Answersheet id " + id);
    Cursor cursor = paperQuestionDao.fetchByPaperId(paperId);
    while (cursor.moveToNext()) {
      int questionId = cursor.getInt(cursor.getColumnIndex(PaperQuestionDao.COLUMN_QUESTION_ID));
      Answer answer = new Answer(answersheet.getAnswersheetId(), questionId);
      answerBo.save(answer);
    }
    cursor.close();
  }
Example #2
0
  public void save(Answersheet answersheet) {

    int answersheetId = answersheet.getAnswersheetId();
    String name = answersheet.getAnswersheetName();
    int paperId = answersheet.getPaper().getPaperId();
    int bpId = answersheet.getBpartner().getBpartnerId();
    Date date = answersheet.getDate();
    Date start = answersheet.getStartTime();
    Date finish = answersheet.getFinishTime();

    if (answersheetId != 0) {
      dao.update(answersheetId, name, paperId, bpId, date, start, finish);

      List<Integer> auditorIds = answersheet.getAuditorIds();
      answersheetAuditorDao.delete(answersheetId);
      answersheetAuditorDao.insert(answersheetId, auditorIds);

      List<String> attendances = answersheet.getAttendances();
      answersheetAttendanceDao.delete(answersheetId);
      answersheetAttendanceDao.insert(answersheetId, attendances);

    } else {

      create(answersheet);
    }
  }