Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
0
  public Answersheet getAnswersheet(int answersheetId) {
    // TODO Auto-generated method stub
    Answersheet answersheet = null;

    Cursor cursor = dao.fetchById(answersheetId);
    if (cursor.moveToNext()) {
      int id = cursor.getInt(cursor.getColumnIndex(AnswersheetDao.COLUMN_ID));
      String answersheetName = cursor.getString(cursor.getColumnIndex(AnswersheetDao.COLUMN_NAME));
      int paperId = cursor.getInt(cursor.getColumnIndex(AnswersheetDao.COLUMN_PAPER_ID));
      int bpartnerId = cursor.getInt(cursor.getColumnIndex(AnswersheetDao.COLUMN_BP_ID));
      String startTime = cursor.getString(cursor.getColumnIndex(AnswersheetDao.COLUMN_START));
      String finishTime = cursor.getString(cursor.getColumnIndex(AnswersheetDao.COLUMN_FINISH));

      List<Integer> auditorIds = new ArrayList<Integer>();
      Cursor cursorX = answersheetAuditorDao.fetchById(answersheetId);
      while (cursorX.moveToNext()) {
        int auditorId =
            cursorX.getInt(cursorX.getColumnIndex(AnswersheetAuditorDao.COLUMN_AUDITOR_ID));
        auditorIds.add(auditorId);
      }
      cursorX.close();

      List<String> attendances = new ArrayList<String>();
      Cursor cursorY = answersheetAttendanceDao.fetchById(answersheetId);
      while (cursorY.moveToNext()) {
        String attendance =
            cursorY.getString(
                cursorY.getColumnIndex(AnswersheetAttendanceDao.COLUMN_ATTENDANCE_NAME));
        attendances.add(attendance);
      }
      cursorY.close();

      answersheet = new Answersheet();
      answersheet.setAnswersheetId(id);
      answersheet.setAnswersheetName(answersheetName);
      answersheet.setPaper(paperBo.getPaper(paperId));
      answersheet.setBpartner(bpartnerBo.getBPartner(bpartnerId));
      answersheet.setStartTime(new Date(startTime));
      answersheet.setFinishTime(new Date(finishTime));
      answersheet.setAuditorIds(auditorIds);
      answersheet.setAttendances(attendances);
    }
    cursor.close();
    return answersheet;
  }