Exemple #1
0
  /**
   * Luo paramatrien pohjalta uusi tai tallenna vanha koe tietorakenteeseen.
   *
   * @param unit Yksikkö, joka tallennetaan.
   * @param date Pvm.
   * @param subject Aine.
   * @return True, jos tallennettiin, muute false.
   */
  public boolean saveExam(Exam unit, String date, String subject) {
    boolean replace = false;
    if (unit.getRef() != null) {
      if (!confirmSave()) {
        return false;
      }
      replace = true;
    }
    Exam edit = unit;
    if (replace) {
      edit = getEditable(edit);
    }
    try {
      edit.parseField(FN.EXAM_DATE, date);

      if (subject != null) {
        List<Subject> match = manager.getSubjects(subject, FN.SUBJECT_NAME);
        Subject s;
        if (match.size() < 1) {
          s = new Subject();
          s.parseField(FN.SUBJECT_NAME, subject);
          manager.add(s);
        } else {
          s = match.get(0);
        }
        Ref subjectRef = s.getRef();

        edit.setField(FN.EXAM_SUBJECT_REF, subjectRef);
      }
    } catch (ParseException e) {
      showParseError(e);
      return false;
    }
    if (replace) {
      manager.remove(unit);
    }
    manager.add(edit);

    finishSave();

    return true;
  }
Exemple #2
0
 /**
  * @param selectedSubject Haluttu aine.
  * @param date Haluttu pvm.
  * @return Koe-taulukon malli, jossa on kaikki tietorakenteen parametreja osittain vastaavat
  *     yksiköt.
  */
 public DataTableModel<CombinedUnit> getExamTableModel(Subject selectedSubject, String date) {
   FN[] fields = {FN.SUBJECT_NAME, FN.EXAM_DATE};
   String[] fieldNames = {"aine", "päivämäärä"};
   String subjectId;
   if (selectedSubject == null) {
     subjectId = "";
   } else {
     subjectId = String.valueOf(selectedSubject.getRef());
   }
   String[] search = {subjectId, date};
   List<Exam> exams = manager.searchExams(search, new FN[] {FN.EXAM_SUBJECT_REF, FN.EXAM_DATE});
   List<CombinedUnit> data = manager.joinRefs(exams, FN.EXAM_SUBJECT_REF);
   DataTableModel<CombinedUnit> model = new DataTableModel<>(data, fields, fieldNames);
   return model;
 }