/**
   * 處理確定更新學生選課內容之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward update(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;
    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {
      try {
        Short selectLimit = (Short) aForm.get("selectLimit");
        CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
        cm.txUpdateDtimeSelLimit(aForm.getString("dtimeOid"), selectLimit);
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.ModifySuccessful"));
        saveMessages(request, messages);
        Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
        return mapping.findForward(IConstants.ACTION_SUCCESS_NAME);
      } catch (Exception e) {
        ActionMessages errors = new ActionMessages();
        errors.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Exception.generic", e.getMessage()));
        saveErrors(request, errors);
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }
    }
  }
  /**
   * 處理選擇修改學生選課內容之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward modify(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;
    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {
      String studentNo = aForm.getString("stdNo");
      ScoreManager sm = (ScoreManager) getBean(SCORE_MANAGER_BEAN_NAME);
      Student student = sm.findStudentByStudentNo(studentNo);
      aForm.set("stdName", student.getStudentName());
      aForm.set("stdClassName", Toolket.getClassFullName(student.getDepartClass()));
      SeldDataInfo sdi = getSeldDataInfoByIndex(request);
      if (sdi == null) {
        messages = new ActionMessages();
        messages.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage("Course.onlineAddRemoveCourse.unselected"));
        saveErrors(request, messages);
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }
      request.setAttribute(SELD_DATA_INFO, sdi);
    }

    setContentPage(request.getSession(false), "course/ModifyCourse.jsp");
    return mapping.findForward(IConstants.ACTION_MAIN_NAME);
  }
  /**
   * 處理學生加選線上選課紀錄之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward addCourse(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;
    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {

      String stdNo = aForm.getString("stdNo");
      ScoreManager sm = (ScoreManager) getBean(SCORE_MANAGER_BEAN_NAME);
      Student student = sm.findStudentByStudentNo(stdNo);
      if (student != null) {
        aForm.set("stdName", student.getStudentName());
        aForm.set("stdClassName", Toolket.getClassFullName(student.getDepartClass()));
        aForm.set("sterm", "1");
        aForm.set("classNo", "");
        aForm.set("csCode", "");
      } else {
        messages.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Course.errorN1", "查無此人個人資料"));
        saveErrors(request, messages);
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }
    }

    setContentPage(request.getSession(false), "course/OnlineAddCourse.jsp");
    return mapping.findForward(IConstants.ACTION_MAIN_NAME);
  }
  /**
   * 處理學生退選線上選課紀錄之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward deleteCourse(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;
    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {

      List<SeldDataInfo> aList = getSeldDataListByIndex(request);
      if (!aList.isEmpty()) {

        CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
        // 取得選課欲退選之Oid列表
        StringBuffer seldBuf = new StringBuffer();
        for (SeldDataInfo info : aList) {
          seldBuf.append(info.getSeldOid()).append(",");
        }
        String inSyntax = StringUtils.substringBeforeLast(seldBuf.toString(), ",");
        log.info("Seld Oid SQL IN Syntax : " + inSyntax);
        String studentNo = aForm.getString("stdNo").toUpperCase();
        MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
        String classNo = mm.findStudentByNo(studentNo).getDepartClass();
        // 只有第一階段不會檢查選課人數下限
        cm.txRemoveSelectedSeld(studentNo, classNo, 1, inSyntax, false);
        String idno = getUserCredential(request.getSession(false)).getMember().getIdno();
        for (SeldDataInfo info : aList) {
          cm.txSaveAdcdHistory(info.getDtimeOid(), studentNo.toUpperCase(), idno, "D");
        }
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.DeleteSuccessful"));
        saveMessages(request, messages);
        // aForm.initialize(mapping);
        Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
        setContentPage(request.getSession(false), "course/OnlineAddRemoveCourse.jsp");
      } else {
        messages = new ActionMessages();
        messages.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage("Course.onlineAddRemoveCourse.unselected"));
        saveErrors(request, messages);
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }
    }

    return list(mapping, form, request, response);
  }
  @SuppressWarnings("unchecked")
  private List<SeldDataInfo> getSeldDataListByIndex(HttpServletRequest request) {

    List<SeldDataInfo> aList = new ArrayList<SeldDataInfo>();
    HttpSession session = request.getSession(false);
    String index = Toolket.getSelectedIndexFromCookie(request, SELD_LIST_NAME);
    List<SeldDataInfo> seldDataList = (List<SeldDataInfo>) session.getAttribute(SELD_LIST_NAME);
    for (SeldDataInfo sdi : seldDataList) {
      if (Toolket.isValueInCookie(sdi.getPosition().toString(), index)) {
        aList.add(sdi);
      }
    }

    return aList;
  }
Exemple #6
0
  // Private Method Here ============================>>
  private List getInspectedSelectedList(HttpServletRequest request) {

    HttpSession session = request.getSession(false);
    String oids = Toolket.getSelectedIndexFromCookie(request, "StudInspected");
    List<Keep> keeps = (List<Keep>) session.getAttribute("StudInspectedList");
    List<Keep> selKeeps = new ArrayList<Keep>();
    Keep keep;

    StudAffairDAO dao = (StudAffairDAO) getBean("studAffairDAO");
    for (Iterator<Keep> keepIter = keeps.iterator(); keepIter.hasNext(); ) {
      keep = keepIter.next();
      if (Toolket.isValueInCookie(keep.getOid().toString(), oids)) {
        selKeeps.add(keep);
      }
    }
    return selKeeps;
  }
  /** 執行查詢動作 */
  public ActionForward Query(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    // Toolket.resetCheckboxCookie(response, "FN");
    // Toolket.resetCheckboxCookie(response, "FNList");
    // Toolket.resetCheckboxCookie(response, "FN_List");
    // Toolket.resetCheckboxCookie(response, "FA_List");

    Toolket.resetCheckboxCookie(response, "FNList");
    HttpSession session = request.getSession(false);
    CourseManager manager = (CourseManager) getBean("courseManager");
    DynaActionForm aForm = (DynaActionForm) form;
    // UserCredential user = (UserCredential) session.getAttribute("Credential");

    String SelKeyWords = aForm.getString("Data_name");
    String SelUnit = aForm.getString("FN_Unit");

    String Sel_KW =
        "  And (FD.KeyWords Like '%" + SelKeyWords + "%' or FN.Name Like '%" + SelKeyWords + "%') ";
    String Sel_UT = "  And FN.FN_Unit = '" + SelUnit + "' ";

    if (SelKeyWords.equals("")) {
      Sel_KW = "";
    }
    if (SelUnit.equals("")) {
      Sel_UT = "";
    }

    // List<FileName> FNList = null;
    List FNList =
        manager.ezGetBy(
            "Select FD.Oid, C.name Unit, FD.DocNo, FD.MeetingType, FD.MeetingDate, FN.Name FN_Name "
                + "From File_DataList FD, File_User FU, code5 C, File_Name FN "
                + "Where FD.FN_Oid = FU.FN_Oid "
                + "  And FD.FN_Oid = FN.Oid "
                + "  And FN.FN_Unit = C.Oid "
                + "  And FD.approve = '97' "
                + "  And FN.FN_Type = '550' "
                + "  And FN.OpenLine = '637'"
                + "  And FD.ShareType = '563'"
                + Sel_KW
                + Sel_UT
                + "Group By FN.Name "
                + "Order By C.name, FN.Name DESC ");

    session.setAttribute("FN_List", FNList);
    session.setAttribute("myOpen", "open");
    session.setAttribute("showType", "Query");
    return mapping.findForward("File_OutDownload");
  }
  @SuppressWarnings("unchecked")
  private SeldDataInfo getSeldDataInfoByIndex(HttpServletRequest request) {

    HttpSession session = request.getSession(false);
    String index = Toolket.getSelectedIndexFromCookie(request, SELD_LIST_NAME);
    List seldDataList = (List) session.getAttribute(SELD_LIST_NAME);
    Matcher matcher = pattern.matcher(index);
    SeldDataInfo sdi = null;
    if (matcher.matches())
      sdi = (SeldDataInfo) seldDataList.get(Integer.parseInt(matcher.group(1)));

    return sdi;
  }
  /**
   * 處理確定加選學生低修高選課內容之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward addHigherCourse(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
    ActionMessages messages = new ActionMessages();
    Seld seld = (Seld) request.getSession(false).getAttribute("seldInfoForOnline");

    try {
      Student student = mm.findStudentByNo(seld.getStudentNo());
      cm.txAddSelectedSeld(seld, student, "1", true);
      String idno = getUserCredential(request.getSession(false)).getMember().getIdno();
      cm.txSaveAdcdHistory(seld.getDtimeOid(), student.getStudentNo().toUpperCase(), idno, "A");
      messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.CreateSuccessful"));
      saveMessages(request, messages);
      Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
      return list(mapping, form, request, response);

    } catch (SeldException se) {
      ActionMessages errors = new ActionMessages();
      errors.add(
          ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Course.errorN1", se.getMessage()));
      saveErrors(request, errors);
      if (se.getMessage().indexOf("衝堂") != StringUtils.INDEX_NOT_FOUND) {
        // 目前會拒絕衝堂課程進行加選
        Dtime dtime = cm.findDtimeBy(seld.getDtimeOid());
        Csno csno = cm.findCourseInfoByCscode(dtime.getCscode());
        request.setAttribute("csnoInfo", csno);
        request.setAttribute("classInfo", Toolket.getClassFullName(dtime.getDepartClass()));
        setContentPage(request.getSession(false), "course/ConflictList.jsp");
        return list(mapping, form, request, response);
      } else return list(mapping, form, request, response);
    }
  }
 private Seld processSeldByForm(DynaActionForm form) {
   CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
   Seld seld = new Seld();
   Dtime dtime = cm.findDtimeBy(Integer.valueOf(form.getString("oid")));
   seld.setDtimeOid(Integer.valueOf(form.getString("oid")));
   seld.setStudentNo(form.getString("stdNo").toUpperCase());
   seld.setOpt(form.getString("optId"));
   seld.setCredit((Float) (form.get("credit")));
   seld.setDepartClass(dtime.getDepartClass());
   seld.setDepartClassName(Toolket.getClassFullName(dtime.getDepartClass()));
   seld.setCscode(dtime.getCscode().toUpperCase());
   seld.setCscodeName(cm.findCourseInfoByCscode(dtime.getCscode().toUpperCase()).getChiName());
   return seld;
 }
  private boolean isValidTime(String tTime) {
    String[] sTime = tTime.split(":");

    if (sTime.length != 3) {
      return false;
    }
    if (!Toolket.isNumeric(sTime[0])
        || !Toolket.isNumeric(sTime[1])
        || !Toolket.isNumeric(sTime[2])) {
      return false;
    }

    int t = Integer.parseInt(sTime[0]);
    if (t < 0 || t > 24) return false;

    t = Integer.parseInt(sTime[1]);
    if (t < 0 || t > 59) return false;

    t = Integer.parseInt(sTime[2]);
    if (t < 0 || t > 59) return false;

    return true;
  }
Exemple #12
0
  public ActionForward DelConfirm(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    HttpSession session = request.getSession(false);
    List<Keep> selKeeps = (List<Keep>) session.getAttribute("StudInspectedDelete");
    StudAffairManager sm = (StudAffairManager) getBean("studAffairManager");
    ActionMessages errs =
        sm.delStudInspected(selKeeps, Toolket.getBundle(request, "messages.studaffair"));
    session.removeAttribute("StudInspectedDelete");
    // no undeleteScores will happen even if delete failure
    if (errs.isEmpty()) {
      session.removeAttribute("StudInspectedList");
      setContentPage(session, "studaffair/StudInspected.jsp");
      return mapping.findForward("Main");
    } else {
      saveErrors(request, errs);
      setContentPage(session, "studaffair/StudInspected.jsp");
      return mapping.findForward("Main");
    }
  }
  /**
   * 處理學生課程衝突後確定加選之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward conflictAdd(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // 選課人數上線於前端JavaScript判斷
    // 跨選設定不允許須阻擋並顯示訊息
    Seld seld = (Seld) request.getSession(false).getAttribute("seldInfoForOnline");
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    Student student = mm.findStudentByNo(seld.getStudentNo());
    CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
    // false代表不做衝堂判斷
    cm.txAddSelectedSeld(seld, student, "1", false);
    cm.txAddSeldConflictInfo(
        seld, getUserCredential(request.getSession(false)).getMember(), student, "1");
    ActionMessages messages = new ActionMessages();
    messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.CreateSuccessful"));
    saveMessages(request, messages);
    Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
    return list(mapping, form, request, response);
  }
  /** 初始資料 */
  public ActionForward unspecified(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Toolket.resetCheckboxCookie(response, "FN");
    Toolket.resetCheckboxCookie(response, "FNList");
    // Toolket.resetCheckboxCookie(response, "FN_List");
    // Toolket.resetCheckboxCookie(response, "FA_List");

    HttpSession session = request.getSession(false);
    CourseManager manager = (CourseManager) getBean("courseManager");

    session.setAttribute(
        "FN_Unit",
        manager.ezGetBy( // 排除沒有法規的單位 sequence = 0
            "Select Oid, name From code5 Where category='FileUnit' And sequence <> '0' Order By Oid")); // 取得所屬單位選項
    /*
    List FNList = manager.ezGetBy(
    		"Select FD.Oid, C.name Unit, FD.DocNo, FD.MeetingType, FD.MeetingDate, FN.Name FN_Name " +
    		"From File_DataList FD, File_User FU, code5 C, File_Name FN " +
    		"Where FD.FN_Oid = FU.FN_Oid " +
    		"  And FD.FN_Oid = FN.Oid " +
    		"  And FN.FN_Unit = C.Oid " +
    		"  And FD.approve = '97' " +
    		"  And FN.FN_Type = '550' " +
    		"  And FN.OpenLine = '637'" +
    		"  And FD.ShareType = '563'"+
    		"Group By FN.Name " +
            "Order By C.name, FN.Name DESC ");
    session.setAttribute("FN_List", FNList);	*/

    session.setAttribute("myOpen", "close");
    return mapping.findForward("File_OutDownload");
  }
  private ActionMessages validateInput(DynaActionForm form) {
    ActionMessages msgs = new ActionMessages();

    String level = form.getString("level");
    String levelSel = form.getString("levelSel");
    String depart = form.getString("depart");
    String departSel = form.getString("departSel");
    String beginDate = form.getString("beginDate");
    String beginTime = form.getString("beginTime");
    String endDate = form.getString("endDate");
    String endTime = form.getString("endTime");
    log.debug("depart:" + depart + ", departSel:" + departSel);
    if (!level.equals(levelSel)) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.ScoreUploadLevelErr"));
      return msgs;
    }

    if (!depart.equals(departSel)) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.DepartmentInputErr"));
      return msgs;
    }

    String[] tDate = beginDate.split("/");
    if (tDate.length != 3) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidDateInput"));
      return msgs;
    } else {
      if (!Toolket.isNumeric(tDate[0])
          || !Toolket.isNumeric(tDate[1])
          || !Toolket.isNumeric(tDate[2])) {
        msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidDateInput"));
        return msgs;
      }

      tDate[0] = "" + Integer.parseInt(tDate[0]) + 1911;
    }

    if (!isValidDate(tDate[0], tDate[1], tDate[2])) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidDateInput"));
      return msgs;
    }

    tDate = endDate.split("/");
    if (tDate.length != 3) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidDateInput"));
      return msgs;
    } else {
      if (!Toolket.isNumeric(tDate[0])
          || !Toolket.isNumeric(tDate[1])
          || !Toolket.isNumeric(tDate[2])) {
        msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidDateInput"));
        return msgs;
      }

      tDate[0] = "" + Integer.parseInt(tDate[0]) + 1911;
    }

    if (!isValidDate(tDate[0], tDate[1], tDate[2])) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidDateInput"));
      return msgs;
    }

    if (!isValidTime(beginTime)) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidTimeInput"));
      return msgs;
    }

    if (!isValidTime(endTime)) {
      msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.InvalidTimeInput"));
      return msgs;
    }

    return msgs;
  }
  public ActionForward query(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    Toolket.resetCheckboxCookie(response, "CounselingsL");
    DynaActionForm aForm = (DynaActionForm) form;
    HttpSession session = request.getSession(false);
    StudAffairManager sm = (StudAffairManager) getBean("studAffairManager");
    MemberManager mm = (MemberManager) getBean("memberManager");
    UserCredential credential = (UserCredential) session.getAttribute("Credential");

    String schoolYear = aForm.getString("schoolYear").trim();
    String schoolTerm = aForm.getString("schoolTerm").trim();
    String depart = aForm.getString("department").trim();
    String idenType = aForm.getString("idenType").trim();
    String reportType = aForm.getString("reportType").trim();

    String campusInCharge = "";
    String schoolInCharge = "";
    String deptInCharge = "";
    String departClass = "";
    if (idenType.equalsIgnoreCase("C")) {
      campusInCharge = aForm.getString("campusInChargeC").trim();
      schoolInCharge = aForm.getString("schoolInChargeC").trim();
      deptInCharge = aForm.getString("deptInChargeC").trim();
      departClass = aForm.getString("classInChargeC").trim();
    } else if (idenType.equalsIgnoreCase("A")) {
      campusInCharge = aForm.getString("campusInChargeSAF").trim();
      schoolInCharge = aForm.getString("schoolInChargeSAF").trim();
      deptInCharge = aForm.getString("deptInChargeSAF").trim();
      departClass = aForm.getString("classInChargeSAF").trim();
    } else if (idenType.equalsIgnoreCase("S")) {
      campusInCharge = aForm.getString("campusInCharge").trim();
      schoolInCharge = aForm.getString("schoolInCharge").trim();
      deptInCharge = aForm.getString("deptInCharge").trim();
      departClass = aForm.getString("classInCharge").trim();
    }

    // String studentNo  = aForm.getString("studentNo").trim();

    Map<String, String> CounselingReportInit =
        (Map<String, String>) (session.getAttribute("CounselingReportInit"));
    CounselingReportInit.put("schoolYear", schoolYear);
    CounselingReportInit.put("schoolTerm", schoolTerm);
    CounselingReportInit.put("campusInCharge", campusInCharge);
    CounselingReportInit.put("schoolInCharge", schoolInCharge);
    CounselingReportInit.put("deptInCharge", deptInCharge);
    CounselingReportInit.put("classInCharge", departClass);
    CounselingReportInit.put("reportType", reportType);

    ActionMessages messages = new ActionMessages();

    if (idenType.equalsIgnoreCase("C")
        || idenType.equalsIgnoreCase("A")
        || idenType.equalsIgnoreCase("S")) {
      if (schoolInCharge.equalsIgnoreCase("All")) {
        if (campusInCharge.equalsIgnoreCase("All")) {
          departClass = "";
        } else {
          departClass = campusInCharge;
        }
      } else if (deptInCharge.equalsIgnoreCase("All")) {
        departClass = campusInCharge + schoolInCharge;
      } else if (departClass.equalsIgnoreCase("All")) {
        departClass = campusInCharge + schoolInCharge + deptInCharge;
      }
    }
    if (!depart.equals("")) {
      departClass = "___" + depart + "__";
    }

    if (schoolYear.equals("") || schoolTerm.equals("")) {
      messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("MessageN1", "請輸入學年及學期!"));
      saveMessages(request, messages);
      setContentPage(session, "studaffair/CounselingReport.jsp");
      return mapping.findForward("Main");
    }

    List counselingList = new ArrayList();

    /*
    if(!studentNo.equals("")) {
    	departClass = "";
    }
    */

    /*
    * "1":學習輔導記錄(導師)
      "2":職涯輔導記錄(導師)
      "3":學習輔導記錄(老師)
      "4":學生接受輔導記錄
      "5":輔導次數統計(導師)
      "6":輔導次數統計(老師)

    */
    char iden = idenType.charAt(0);
    if (reportType.equalsIgnoreCase("1")) {
      switch (iden) {
        case 'T':
          counselingList =
              sm.findCounselingByInput(
                  schoolYear,
                  schoolTerm,
                  "U",
                  credential.getMember().getIdno(),
                  "",
                  departClass,
                  null,
                  null);
          break;
        case 'C':
        case 'A':
        case 'S':
          counselingList =
              sm.findCounselingByInput(
                  schoolYear, schoolTerm, "U", "", "", departClass, null, null);
          break;
        case 'L':
      }
    } else if (reportType.equalsIgnoreCase("2")) {
      switch (iden) {
        case 'T':
          counselingList =
              sm.findCounselingByInput(
                  schoolYear,
                  schoolTerm,
                  "T",
                  credential.getMember().getIdno(),
                  "",
                  departClass,
                  null,
                  null);
          break;
        case 'C':
        case 'A':
        case 'S':
          counselingList =
              sm.findCounselingByInput(
                  schoolYear, schoolTerm, "T", "", "", departClass, null, null);
          break;
        case 'L':
      }
    } else if (reportType.equalsIgnoreCase("3")) {
      switch (iden) {
        case 'L':
          counselingList =
              sm.findCounselingByInput(
                  schoolYear,
                  schoolTerm,
                  "L",
                  credential.getMember().getIdno(),
                  "",
                  departClass,
                  null,
                  null);
          break;
        case 'C':
        case 'A':
        case 'S':
          counselingList =
              sm.findCounselingByInput(
                  schoolYear, schoolTerm, "L", "", "", departClass, null, null);
          break;
        case 'T':
      }
    } else if (reportType.equalsIgnoreCase("4")) {
      // 學生接受輔導記錄
      switch (iden) {
        case 'C':
        case 'A':
        case 'S':
          List<StudCounseling> counselsT =
              sm.findCounselingByInput(
                  schoolYear, schoolTerm, "T", "", "", departClass, null, null);
          List<StudCounseling> counselsU =
              sm.findCounselingByInput(
                  schoolYear, schoolTerm, "U", "", "", departClass, null, null);
          List<StudCounseling> counselsL =
              sm.findCounselingByInput(
                  schoolYear, schoolTerm, "L", "", "", departClass, null, null);
          counselingList.addAll(counselsT);
          counselingList.addAll(counselsU);
          counselingList.addAll(counselsL);
          Collections.sort(counselingList, new counselComp());
          break;
        case 'L':
        case 'T':
      }
    } else if (reportType.equalsIgnoreCase("5")) {
      // 輔導次數統計(導師)
      switch (iden) {
        case 'C':
        case 'A':
        case 'S':
          counselingList = sm.findCounselingReport(schoolYear, schoolTerm, "T", departClass, "");
          int countT = 0, countU = 0, countStudent_UT = 0;
          for (Object counsel : counselingList) {
            countT += Integer.parseInt(((Map) counsel).get("countT").toString());
            countU += Integer.parseInt(((Map) counsel).get("countU").toString());
            countStudent_UT += Integer.parseInt(((Map) counsel).get("countStudent_UT").toString());
          }
          CounselingReportInit.put("countT", "" + countT);
          CounselingReportInit.put("countU", "" + countU);
          CounselingReportInit.put("countStudent_UT", "" + countStudent_UT);
          CounselingReportInit.put("total", "" + (countT + countU));

          break;
        case 'L':
        case 'T':
          System.out.println(schoolYear);
          counselingList =
              sm.findCounselingReport(
                  schoolYear, schoolTerm, "T", "", credential.getMember().getIdno());
          int cntT = 0, cntU = 0, countStudentUT = 0;
          for (Object counsel : counselingList) {
            cntT += Integer.parseInt(((Map) counsel).get("countT").toString());
            cntU += Integer.parseInt(((Map) counsel).get("countU").toString());
            countStudentUT += Integer.parseInt(((Map) counsel).get("countStudent_UT").toString());
          }
          CounselingReportInit.put("countT", "" + cntT);
          CounselingReportInit.put("countU", "" + cntU);
          CounselingReportInit.put("countStudent_UT", "" + countStudentUT);
          CounselingReportInit.put("total", "" + (cntT + cntU));

          break;
      }
    } else if (reportType.equalsIgnoreCase("6")) {
      // 輔導次數統計(老師)
      // 依照開課班級,老師,科目排序,一個老師可能教授多個科目
      switch (iden) {
        case 'C':
        case 'A':
        case 'S':
          counselingList = sm.findCounselingReport(schoolYear, schoolTerm, "L", departClass, "");
          int countL = 0, countL_UT = 0;
          for (Object counsel : counselingList) {
            countL += Integer.parseInt(((Map) counsel).get("countL").toString());
            countL_UT += Integer.parseInt(((Map) counsel).get("countL_UT").toString());
          }
          CounselingReportInit.put("countL", "" + countL);
          CounselingReportInit.put("countL_UT", "" + countL_UT);
          break;
        case 'L':
          counselingList =
              sm.findCounselingReport(
                  schoolYear, schoolTerm, "L", "", credential.getMember().getIdno());
          int cntL = 0, countLUT = 0;
          for (Object counsel : counselingList) {
            cntL += Integer.parseInt(((Map) counsel).get("countL").toString());
            countLUT += Integer.parseInt(((Map) counsel).get("countL_UT").toString());
          }
          CounselingReportInit.put("countL", "" + cntL);
          CounselingReportInit.put("countL_UT", "" + countLUT);
          break;
        case 'T':
      }
    }

    // session.setAttribute("StudCounselingInit", StudCounselingInit);
    session.setAttribute("CounselingReportInit", CounselingReportInit);

    session.setAttribute("CounselingReoport", counselingList);
    setContentPage(session, "studaffair/CounselingReport.jsp");
    return mapping.findForward("Main");
  }
  public ActionForward unspecified(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;

    HttpSession session = request.getSession(false);
    UserCredential credential = (UserCredential) session.getAttribute("Credential");
    String classInCharge = credential.getClassInChargeSqlFilterT();
    String idenType = aForm.getString("idenType").trim();

    StudAffairManager sm = (StudAffairManager) getBean("studAffairManager");
    MemberManager mm = (MemberManager) getBean("memberManager");

    Map<String, String> counselType = new HashMap<String, String>();
    counselType.put("L", "學習輔導");
    counselType.put("T", "職涯輔導");

    String schoolYear = Toolket.getSysParameter(IConstants.PARAMETER_SCHOOL_YEAR);
    String schoolTerm = Toolket.getSysParameter(IConstants.PARAMETER_SCHOOL_TERM);
    Map<String, String> CounselingReportInit = new HashMap<String, String>();
    CounselingReportInit.put("idenType", idenType);
    CounselingReportInit.put("schoolYear", schoolYear);
    CounselingReportInit.put("schoolTerm", schoolTerm);

    List<CounselingCode> codesL = sm.findCounselingCode("L");
    List<CounselingCode> codesT = sm.findCounselingCode("T");

    session.setAttribute("StudCounselCodeL", codesL);
    session.setAttribute("StudCounselCodeT", codesT);
    session.setAttribute("StudCounselType", counselType);
    session.setAttribute("CounselingReportInit", CounselingReportInit);

    String[][] repType =
        new String[][] {
          {"1", "學習輔導記錄(導師)"},
          {"2", "職涯輔導記錄(導師)"},
          {"3", "學習輔導記錄(老師)"},
          {"4", "學生接受輔導記錄"},
          {"5", "輔導次數統計(導師)"},
          {"6", "輔導次數統計(老師)"}
        };
    session.setAttribute("CounselReportType", repType);

    List<Map> depts = Toolket.getCollegeDepartment(true);
    session.setAttribute("depts", depts);

    /*
    if(idenType.equals("T")){	//Tutor
    	setContentPage(session, "studaffair/CounselingReportT.jsp");
    }else if(idenType.equals("L")){		//Teacher
    	setContentPage(session, "studaffair/CounselingReportL.jsp");
    }else if(idenType.equals("C")){		//department chief or assistance
    	setContentPage(session, "studaffair/CounselingReportC.jsp");
    }else if(idenType.equals("A")){		//student affair officer
    	setContentPage(session, "studaffair/CounselingReportA.jsp");
    }else if(idenType.equals("S")){		//execution manager
    	//int empOid = credential.getMember().getOid();
    	List<Empl> empls = mm.findEmplByGroup("S1");
    	for(Empl empl:empls){
    		if(empl.getIdno().equalsIgnoreCase(credential.getMember().getIdno())){
    			setContentPage(session, "studaffair/CounselingReportS.jsp");
    			break;
    		}
    	}

    }
    */
    session.removeAttribute("CounselingReoport");
    setContentPage(session, "studaffair/CounselingReport.jsp");
    return mapping.findForward("Main");
  }
  /**
   * 下載
   *
   * @throws IOException
   */
  public ActionForward Download(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException {

    // Toolket.resetCheckboxCookie(response, "FN");
    // Toolket.resetCheckboxCookie(response, "FNList");
    // Toolket.resetCheckboxCookie(response, "FN_List");
    // Toolket.resetCheckboxCookie(response, "FA_List");

    Toolket.resetCheckboxCookie(response, "FNList");
    HttpSession session = request.getSession(false);
    CourseManager manager = (CourseManager) getBean("courseManager");
    // DynaActionForm aForm = (DynaActionForm) form;

    // UserCredential user = (UserCredential) session.getAttribute("Credential");
    // ActionMessages messages = new ActionMessages();

    String ids = Toolket.getSelectedIndexFromCookie(request, "FNList");
    String FL_id = ids.substring(1, ids.length() - 1);
    String FN_id =
        manager.ezGetString("Select FN_Oid From File_DataList Where Oid = '" + FL_id + "'");
    String SelType =
        manager.ezGetString("Select FN_Type From File_Name Where Oid = '" + FN_id + "'");
    String FD_ShareType =
        manager.ezGetString("Select ShareType From File_DataList Where Oid = '" + FL_id + "'");
    String FN_Share =
        manager.ezGetString("Select Share From File_Name Where Oid = '" + FN_id + "'");
    String URL =
        manager.ezGetString("Select Data_URL From File_DataList Where Oid = '" + FL_id + "'");
    String pristineData =
        manager.ezGetString("Select pristineData From File_DataList Where Oid = '" + FL_id + "'");

    manager.DownloadFileFTPServer(
        URL, pristineData, session.getServletContext().getRealPath("/UserFiles/").toString());

    try {
      response.setContentType("application/octet-stream; charset=utf-8");
      String path = session.getServletContext().getRealPath("/UserFiles/") + "/" + pristineData;
      File file = new File(path);

      if (!file.exists()) {
        if (!file.exists()) {
          file = new File(path);
        }
      }

      try {
        String realName = java.net.URLEncoder.encode(file.getName(), "utf-8");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + realName + "\"");
        if (file.exists()) {
          FileInputStream in = new FileInputStream(file);
          OutputStream out = response.getOutputStream();
          byte[] b = new byte[100];
          int len;

          while ((len = in.read(b)) > 0) {
            out.write(b, 0, len);
          }

          if (in != null) {
            in.close();
          }

          if (out != null) {
            out.close();
          }

          file.delete();
        }
      } catch (Exception e) {
        System.out.println(path + " generate errors!");
        e.printStackTrace();
      }

    } catch (Exception e) {

      response.setHeader("Content-Disposition", "attachment;filename=ProjectReport.doc");
      response.setContentType("application/vnd.ms-word; charset=UTF-8");
      PrintWriter out = response.getWriter();

      out.println("<html>");
      out.println("<body>");
      out.println("下載檔案方式不正確!");
      out.println("</body>");
      out.println("</html>");

      out.close();
    }
    Toolket.resetCheckboxCookie(response, "FNList");
    return mapping.findForward("File_OutDownload");
    // return nul
    // System.out.println(session.getServletContext().getRealPath("/UserFiles/")+"/"+pristineData)

  }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    WebApplicationContext wac =
        WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());

    StudAffairManager sm = (StudAffairManager) wac.getBean("studAffairManager");
    ScoreManager scm = (ScoreManager) wac.getBean("scoreManager");

    HttpSession session = request.getSession(false);

    CourseManager manager = (CourseManager) wac.getBean("courseManager");
    // UserCredential credential =
    // (UserCredential)session.getAttribute("Credential");

    // String studentNo = credential.getMember().getAccount();

    String studentNo = request.getParameter("studentno");
    String sterm = Toolket.getSysParameter("School_term");
    /*
     * if(studentNo == null) { studentNo =
     * credential.getStudent().getStudentNo(); } else
     * if(studentNo.trim().equals("")) { studentNo =
     * credential.getStudent().getStudentNo(); }
     */
    response.setContentType("text/xml; charset=UTF-8");
    PrintWriter out = response.getWriter();

    if (!studentNo.trim().equals("")) {
      Student student = scm.findStudentByStudentNo(studentNo);
      if (student != null) {
        String studentName = student.getStudentName();
        String departClass = student.getDepartClass();
        String deptClassName = student.getDepartClass2();
        String daynite = sm.chkStudentDepart(studentNo);

        String mode = request.getParameter("mode");
        if (mode.equals("")) mode = "all";
        log.info("GetTimeOff has been called! and Mode=" + mode);

        // Leo 20120321 將下列79~83行遮蔽,改取85~90行程式執行
        // int elearnSum = 0;
        // List<Seld> elearnList= sm.findDilgByStudentNo(studentNo,"elearn");
        // for (Seld seld : elearnList) {
        //	elearnSum += seld.getElearnDilg();
        // }
        String elcnt;

        elcnt =
            manager.ezGetString(
                "Select SUM(s.`elearn_dilg`) "
                    + "From Seld s, Dtime d "
                    + "Where s.`student_no` like '"
                    + studentNo
                    + "' "
                    + "  And s.`Dtime_oid`=d.`Oid` "
                    + "  And d.`Sterm`='"
                    + sterm
                    + "' ");

        int elearnSum;

        if (elcnt == null) {
          elearnSum = 0;
        } else {
          elearnSum = Integer.parseInt(elcnt);
        }

        List dilgList = sm.getDilgByStudentNo(studentNo, mode);
        Dilg dilg;
        // ===========================Leo
        // Start====================================================================================================
        List desdList = sm.findDesdByStudentNo(studentNo);
        Desd desd;
        // ===========================Leo
        // End======================================================================================================
        String weekday = "";

        // Map result = new HashMap();
        out.println("<dilgPrompt>");
        out.println("<mode>" + mode + "</mode>");
        out.println("<studentNo>" + studentNo + "</studentNo>");
        out.println("<studentName>" + studentName + "</studentName>");
        out.println("<departClass>" + departClass + "</departClass>");
        out.println("<deptClassName>" + deptClassName + "</deptClassName>");
        out.println("<daynite>" + daynite + "</daynite>");
        out.println("<elearnSum>" + elearnSum + "</elearnSum>");

        if (mode.equals("all")) {
          if (dilgList.size() > 0) {
            for (Iterator<Dilg> dilgIter = dilgList.iterator(); dilgIter.hasNext(); ) {
              dilg = dilgIter.next();
              out.println("<dilgInfo>");
              out.println(
                  "<ddate>"
                      + Toolket.printNativeDate(dilg.getDdate())
                      + "("
                      + weekTran(dilg.getWeekDay())
                      + ")"
                      + "</ddate>");
              out.println("<abs0>" + dilg.getAbsName0() + "</abs0>");
              out.println("<abs1>" + dilg.getAbsName1() + "</abs1>");
              out.println("<abs2>" + dilg.getAbsName2() + "</abs2>");
              out.println("<abs3>" + dilg.getAbsName3() + "</abs3>");
              out.println("<abs4>" + dilg.getAbsName4() + "</abs4>");
              out.println("<abs5>" + dilg.getAbsName5() + "</abs5>");
              out.println("<abs6>" + dilg.getAbsName6() + "</abs6>");
              out.println("<abs7>" + dilg.getAbsName7() + "</abs7>");
              out.println("<abs8>" + dilg.getAbsName8() + "</abs8>");
              out.println("<abs9>" + dilg.getAbsName9() + "</abs9>");
              out.println("<abs10>" + dilg.getAbsName10() + "</abs10>");
              out.println("<abs11>" + dilg.getAbsName11() + "</abs11>");
              out.println("<abs12>" + dilg.getAbsName12() + "</abs12>");
              out.println("<abs13>" + dilg.getAbsName13() + "</abs13>");
              out.println("<abs14>" + dilg.getAbsName14() + "</abs14>");
              out.println("<abs15>" + dilg.getAbsName15() + "</abs15>");
              out.println("</dilgInfo>");
            }
          } else {
            out.println("<dilgInfo></dilgInfo>");
          }

        } else if (mode.equals("subject")) {
          if (dilgList.size() > 0) {
            for (Iterator dilgIter = dilgList.iterator(); dilgIter.hasNext(); ) {
              Map dilgMap = (Map) dilgIter.next();
              out.println("<dilgInfo>");
              out.println("<subjectName>" + dilgMap.get("subjectName") + "</subjectName>");
              out.println("<period>" + dilgMap.get("period") + "</period>");
              out.println("<tfLimit>" + dilgMap.get("tfLimit") + "</tfLimit>");
              out.println("<timeOff>" + dilgMap.get("timeOff") + "</timeOff>");
              out.println("<elearnDilg>" + dilgMap.get("elearnDilg") + "</elearnDilg>");
              out.println("<warnning>" + dilgMap.get("warnning") + "</warnning>");
              out.println("<dtimeClass>" + dilgMap.get("dtimeClass") + "</dtimeClass>");
              out.println("<absType>" + dilgMap.get("absType") + "</absType>");
              out.println("</dilgInfo>");
            }
          } else {
            out.println("<dilgInfo></dilgInfo>");
          }

          // ===========================Leo
          // Start====================================================================================================
        } else if (mode.equals("desd")) {
          if (desdList.size() > 0) {
            // System.out.println(desdList.size());

            for (Iterator<Desd> desdIter = desdList.iterator(); desdIter.hasNext(); ) {
              desd = desdIter.next();
              Map Reason =
                  manager.ezGetMap("SELECT name FROM code2 WHERE no='" + desd.getReason() + "'");
              // System.out.println(Reason.get("name"));
              out.println("<dilgInfo>");
              out.println("<ddate>" + desd.getDdate() + "</ddate>");
              out.println("<no>" + desd.getNo() + "</no>");
              out.println("<reason>" + Reason.get("name") + "</reason>");
              out.println("<kind1>" + desd.getKind1() + "</kind1>");
              out.println("<cnt1>" + desd.getCnt1() + "</cnt1>");
              out.println("<kind2>" + desd.getKind2() + "</kind2>");
              out.println("<cnt2>" + desd.getCnt2() + "</cnt2>");
              out.println("</dilgInfo>");
            }
          } else {
            out.println("<dilgInfo></dilgInfo>");
          }
        }
        // ===========================Leo
        // End======================================================================================================

        out.println("</dilgPrompt>");
        out.close();
      } else {
        out.println("<dilgPrompt>");
        out.println("<dilgInfo>");
        out.println("<mode>notfound</mode>");
        out.println("</dilgInfo>");
        out.println("</dilgPrompt>");
        out.close();
      }
    } else {
      out.println("<dilgPrompt>");
      out.println("<dilgInfo>");
      out.println("<mode>notfound</mode>");
      out.println("</dilgInfo>");
      out.println("</dilgPrompt>");
      out.close();
    }
  }
  /**
   * 處理確定加選學生選課內容之方法
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  public ActionForward add(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
    HttpSession session = request.getSession(false);
    DynaActionForm aForm = (DynaActionForm) form;
    Seld seld = processSeldByForm(aForm);
    session.setAttribute("seldInfoForOnline", seld);
    Dtime dtime = cm.findDtimeBy(seld.getDtimeOid());

    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {
      try {
        // 會以紙本作業完成加選,無需考慮衝堂問題
        // 選課人數上線於前端JavaScript判斷
        // 跨選設定不允許須阻擋並顯示訊息
        // 會顯示衝堂訊息
        MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
        ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
        Student student = mm.findStudentByNo(seld.getStudentNo());
        ScoreHist scoreHist = new ScoreHist(student.getStudentNo());
        List<ScoreHist> scoreHistList = sm.findScoreHistBy(scoreHist);
        String[] cscodeHist = new String[0];
        Float[] scoreList = new Float[0];
        float passScore = Toolket.getPassScoreByDepartClass(student.getDepartClass());
        for (ScoreHist hist : scoreHistList) {
          cscodeHist = (String[]) ArrayUtils.add(cscodeHist, hist.getCscode().toUpperCase());
          // 抵免要給分數,不然就會被當做無修課記錄而被加選成功
          if ("6".equals(hist.getEvgrType()))
            scoreList =
                (Float[])
                    ArrayUtils.add(
                        scoreList, hist.getScore() != null ? hist.getScore() : passScore);
          else scoreList = (Float[]) ArrayUtils.add(scoreList, hist.getScore());
        }

        int ind = 0, startIndex = 0;
        boolean isHist = false;
        do {
          ind = ArrayUtils.indexOf(cscodeHist, seld.getCscode().toUpperCase(), startIndex);
          startIndex = ind + 1;
          // 判斷是否選過且及格
          isHist =
              ind != StringUtils.INDEX_NOT_FOUND
                  && scoreList[ind] != null
                  && scoreList[ind] >= passScore;
        } while (!isHist && ind != StringUtils.INDEX_NOT_FOUND);

        // 特殊班級(跨校生等)無條件加選
        String[] specialDepartClass = {"1152A", "1220", "122A", "122B", "2220"};
        String[] addGrade = {"42", "52"}; // 2技學生年級要+2
        int stuGrade =
            ArrayUtils.contains(specialDepartClass, student.getDepartClass())
                ? 9
                : Integer.parseInt(StringUtils.substring(student.getDepartClass(), 4, 5));
        stuGrade =
            ArrayUtils.contains(addGrade, StringUtils.substring(student.getDepartClass(), 1, 3))
                ? stuGrade + 2
                : stuGrade;
        int dtimeGrade = Integer.parseInt(StringUtils.substring(dtime.getDepartClass(), 4, 5));

        if (isHist) {
          messages.add(
              ActionMessages.GLOBAL_MESSAGE,
              new ActionMessage("Course.errorN1", "歷年資料查詢到已修過該科目,請確認,謝謝!!"));
          saveErrors(request, messages);
        } else if (stuGrade >= dtimeGrade) {
          // 判斷學生年級與課程所開班級年級
          cm.txAddSelectedSeld(seld, student, "1", true);
          String idno = getUserCredential(request.getSession(false)).getMember().getIdno();
          cm.txSaveAdcdHistory(seld.getDtimeOid(), student.getStudentNo().toUpperCase(), idno, "A");
          if (ind != StringUtils.INDEX_NOT_FOUND)
            messages.add(
                ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("Course.errorN1", "該科目於歷年資料有查詢到,但該科目未及格,所以加選成功。"));
          else
            messages.add(
                ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.CreateSuccessful"));
          saveMessages(request, messages);
        } else {
          messages.add(
              ActionMessages.GLOBAL_MESSAGE,
              new ActionMessage(
                  "Course.messageN1",
                  "注意:學生低修高年級課程,加選作業尚未完成!<br/>"
                      + "&nbsp;&nbsp;&nbsp;&nbsp;按下[再次確定]鍵後課程才會加入學生選課資料中。"));
          saveErrors(request, messages);
          setContentPage(request.getSession(false), "course/OnlineAddHigherCourse.jsp");
          return mapping.findForward(IConstants.ACTION_MAIN_NAME);
        }

        Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
        return list(mapping, form, request, response);
      } catch (SeldException se) {
        ActionMessages errors = new ActionMessages();
        errors.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Course.errorN1", se.getMessage()));
        saveErrors(request, errors);
        if (se.getMessage().indexOf("衝堂") != StringUtils.INDEX_NOT_FOUND) {
          // 目前會拒絕衝堂課程進行加選
          dtime = cm.findDtimeBy(seld.getDtimeOid());
          Csno csno = cm.findCourseInfoByCscode(dtime.getCscode());
          request.setAttribute("csnoInfo", csno);
          request.setAttribute("classInfo", Toolket.getClassFullName(dtime.getDepartClass()));
          setContentPage(request.getSession(false), "course/ConflictList.jsp");
          return list(mapping, form, request, response);
        } else return list(mapping, form, request, response);
      }
    }
  }
  public ActionForward save(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;
    HttpSession session = request.getSession(false);
    Map initMap = (Map) session.getAttribute("TchScoreUploadInfo");

    String scoretype = aForm.getString("scoretype");
    String departClass = initMap.get("departClass").toString();
    String cscode = initMap.get("cscode").toString();
    String teacherId = initMap.get("teacherId").toString();
    int dtimeoid = 0;

    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));

    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      // request.removeAttribute("ScoreInputInit");
      // log.debug("=======> Teacher Input score ValidateError='");

      session.setAttribute("TchScoreUploadFormMap", aForm.getMap());
      // session.setAttribute("ScoreInput", aForm.getStrings("scrinput"));
      return mapping.findForward("Main");
    } else {
      ActionMessages errors = new ActionMessages();
      try {
        List<Regs> regs = (List<Regs>) session.getAttribute("TchScoreInEdit");
        ScoreManager sm = (ScoreManager) getBean("scoreManager");
        dtimeoid = regs.get(0).getDtimeOid();

        Map calscore = new HashMap();
        // log.debug("ScoreMidTermEdit1Action->scr19f.size():" + scr19f.length);
        calscore.put("scr23f", scr23f);

        // errors = sm.updateScoreInput(aForm.getMap(), scores);
        errors = sm.updateTchScoreInput(aForm.getMap(), regs, calscore);
        if (!errors.isEmpty()) {

          saveErrors(request, errors);
          // request.removeAttribute("ScoreInputInit");

          session.setAttribute("TchScoreUploadFormMap", aForm.getMap());
          // session.setAttribute("ScoreInput", aForm.getStrings("scrinput"));
          return mapping.findForward("Main");
        }
        Calendar now = Calendar.getInstance();
        String nows =
            ""
                + (now.get(Calendar.YEAR) - 1911)
                + "/"
                + (now.get(Calendar.MONTH) + 1)
                + "/"
                + now.get(Calendar.DATE)
                + " "
                + now.get(Calendar.HOUR_OF_DAY)
                + ":"
                + now.get(Calendar.MINUTE)
                + ":"
                + now.get(Calendar.SECOND);

        errors = sm.updateRegsTime(dtimeoid, departClass, cscode, teacherId, scoretype, nows);
        if (!errors.isEmpty()) {

          saveErrors(request, errors);
        }

        int count = 0;
        String[] studentNames = new String[regs.size()];
        Regs myregs;
        String[] score = (String[]) aForm.getMap().get("scr23");
        String[] studentNos = (String[]) aForm.getMap().get("studentNo");
        int scoresint = 0;
        int totalscore = 0;
        int totalstu = score.length;
        int nopass = 0;

        for (Iterator regsIter = regs.iterator(); regsIter.hasNext(); ) {
          myregs = (Regs) regsIter.next();
          studentNames[count++] = myregs.getStudentName();
        }

        for (int i = 0; i < score.length; i++) {
          scoresint = Integer.parseInt(score[i]);
          totalscore = totalscore + scoresint;
          if (scoresint < 60) {
            nopass++;
            score[i] = score[i] + "*";
          }
        }

        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Message.CreateSuccessful"));
        saveMessages(request, messages);
        aForm.initialize(mapping);
        Map pmap = new HashMap();
        pmap.put("scoretype", scoretype);
        pmap.put("opmode", "Print");
        pmap.put("schoolYear", Toolket.getSysParameter("School_year"));
        pmap.put("schoolTerm", Toolket.getSysParameter("School_term"));
        pmap.put("departClass", departClass);
        pmap.put("depClassName", initMap.get("depClassName").toString());
        pmap.put("teacherName", initMap.get("teacherName").toString());
        pmap.put("cscode", cscode);
        pmap.put("cscodeName", initMap.get("cscodeName").toString());
        pmap.put("studentNo", studentNos);
        pmap.put("studentName", studentNames);
        pmap.put("score", score);
        pmap.put("totalstu", totalstu);
        pmap.put("totalscore", totalscore);
        pmap.put("avgscore", Math.round(totalscore / totalstu));
        pmap.put("nopass", nopass);
        pmap.put("pass", (totalstu - nopass));
        pmap.put("now", nows);
        session.setAttribute("TchScoreUploadPrint", pmap);

        // session.removeAttribute("TchScoreMidInfo");
        session.removeAttribute("TchScoreInEdit");
        session.removeAttribute("TchScoreUploadFormMap");
        setContentPage(session, "teacher/TeachClassChoose.jsp");
        return mapping.findForward("Main");
      } catch (Exception e) {
        e.printStackTrace();
        errors.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Exception.generic", e.getMessage()));
        saveErrors(request, errors);
        session.setAttribute("TchScoreUploadFormMap", aForm.getMap());
        return mapping.findForward("Main");
      }
    }
  }
  /**
   * 處理以學號查詢學生選課清單
   *
   * @param mapping org.apache.struts.action.ActionMapping object
   * @param form org.apache.struts.action.ActionForm object
   * @param request javax.servlet.http.HttpServletRequest object
   * @param response javax.servlet.http.HttpServletResponse object
   * @return org.apache.struts.action.ActionForward object
   * @exception java.lang.Exception
   */
  @SuppressWarnings("unchecked")
  public ActionForward list(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    DynaActionForm aForm = (DynaActionForm) form;
    HttpSession session = request.getSession(false);
    Toolket.resetCheckboxCookie(response, SELD_LIST_NAME);
    // 確實清除變數"seldList"內所存資料,因學生可能無選課資料
    session.removeAttribute(SELD_LIST_NAME);
    ActionMessages messages = validateInputForUpdate(aForm, Toolket.getBundle(request));
    if (!messages.isEmpty()) {
      saveErrors(request, messages);
      return mapping.findForward(IConstants.ACTION_MAIN_NAME);
    } else {
      try {
        CourseManager cm = (CourseManager) getBean(COURSE_MANAGER_BEAN_NAME);
        log.info("Student NO : " + aForm.getString("stdNo"));
        List<Map> seldList =
            doForDuplicate(cm.getSeldDataByStudentNo(aForm.getString("stdNo"), "1"));
        if (!seldList.isEmpty()) {
          session.setAttribute("NO", aForm.getString("stdNo").toUpperCase());
          int hours = 0, position = 0;
          float credit = 0.0F;
          List<SeldDataInfo> result = new ArrayList<SeldDataInfo>();
          SeldDataInfo info = null;
          for (Map content : seldList) {
            info = new SeldDataInfo();
            Integer dtimeOid = (Integer) content.get("oid");
            info.setClassNo((String) content.get("classNo"));
            info.setClassName((String) content.get("className"));
            info.setCsCode((String) content.get("cscode"));
            info.setCsName((String) content.get("chi_Name"));
            info.setStuSelect(String.valueOf(cm.findSeldCountByDtimeOid(dtimeOid)));
            info.setSelectLimit(((Integer) content.get("select_Limit")).toString());
            info.setHour(Short.valueOf(((Integer) content.get("thour")).toString()));
            info.setCredit((Float) content.get("credit"));
            info.setSeldOid((Integer) content.get("soid")); // Seld Oid
            String opt = (String) content.get("opt");
            info.setOpt(opt);
            info.setOptName(Toolket.getCourseOpt(opt));
            info.setDtimeOid(dtimeOid); // Dtime Oid
            info.setPosition(Integer.valueOf(position++));
            info.setTerm((String) content.get("sterm"));
            hours += ((Integer) content.get("thour")).intValue();
            credit += ((Float) content.get("credit")).floatValue();
            result.add(info);
          }
          session.setAttribute(SELD_LIST_COUNT, Integer.valueOf(seldList.size()));
          session.setAttribute(SELD_LIST_HOURS, Integer.valueOf(hours));
          session.setAttribute(
              SELD_LIST_CREDITS, Float.valueOf(new DecimalFormat("0.0").format(credit)));
          session.setAttribute(SELD_LIST_NAME, result);
          session.setAttribute("mode", "ALL");
        } else {
          // 查無資料則回傳空白List
          session.setAttribute(SELD_LIST_NAME, Collections.EMPTY_LIST);
          session.setAttribute("mode", "NONE");
          ActionMessages msg = new ActionMessages();
          msg.add(
              ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Course.messageN1", "查無任何選課資料!!"));
          saveMessages(request, msg);
        }

      } catch (Exception e) {
        ActionMessages errors = new ActionMessages();
        errors.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Exception.generic", e.getMessage()));
        saveErrors(request, errors);
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }
    }

    setContentPage(request.getSession(false), "course/OnlineAddRemoveCourse.jsp");
    return mapping.findForward(IConstants.ACTION_MAIN_NAME);
  }
Exemple #23
0
  public ActionForward print(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws JRException, IOException, ServletException {
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    StudAffairManager sm = (StudAffairManager) getBean("studAffairManager");
    StudAffairDAO dao = (StudAffairDAO) getBean("studAffairDAO");
    HttpSession session = request.getSession(false);
    DynaActionForm aForm = (DynaActionForm) form;
    UserCredential user = (UserCredential) session.getAttribute("Credential");

    String qty = aForm.getString("qty").trim();
    boolean setupPrinter = false;
    boolean isPrint = false;

    ActionMessages messages = new ActionMessages();

    if (!qty.equals("")) {
      String idno = user.getMember().getIdno();
      String prefix = idno.substring(idno.length() - 5);
      int q = Integer.parseInt(qty);
      String[] codes = new String[q];
      String rano = prefix + this.getRandom(4);
      String hql = "From AssessPaper Where serviceNo='" + rano + "' And idno='" + idno + "'";

      // 建立服務編號
      boolean isUniq = false;
      for (int j = 0; j < q; j++) {
        while (true) {
          rano = prefix + this.getRandom(4);
          isUniq = true;
          if (dao.submitQuery(hql).isEmpty()) {
            // 檢查服務編號是否重複
            for (int k = 0; k < j; k++) {
              if (rano == codes[k]) {
                isUniq = false;
                break;
              }
            }
            if (isUniq) {
              codes[j] = rano;
              break;
            }
          }
        }
      }
      // Insert into DB
      ActionMessages msg = mm.addNewAssessPaper(idno, codes);
      if (!msg.isEmpty()) {
        messages.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("MessageN1", "滿意度調查列印資料新增失敗:" + msg));
        saveErrors(request, messages);
        setContentPage(request, "personnel/AssessPaperPrint.jsp");
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }

      // TODO: print the paper in pdf format
      String reportSourceFile = "/WEB-INF/reports/AssessPaper.jrxml";
      String reportCompiledFile = "/WEB-INF/reports/AssessPaper.jasper";
      List<Object> printData = new ArrayList<Object>();
      ServletContext context = request.getSession().getServletContext();
      JasperReportUtils.initJasperReportsClasspath(request);

      printData = fillPrintData(codes);

      DecimalFormat df = new DecimalFormat(",##0.0");
      File reportFile = null;
      reportFile = new File(context.getRealPath(reportCompiledFile));
      // 需要時再編譯即可
      // if (!reportFile.exists()) {
      JasperReportUtils.compileJasperReports(context.getRealPath(reportSourceFile));
      reportFile = new File(context.getRealPath(reportCompiledFile));
      if (!reportFile.exists())
        throw new JRRuntimeException("查無\"AssessPaper.jasper\"檔案,請電洽電算中心,謝謝!!");
      // }

      Map<String, String> parameters = new HashMap<String, String>();

      JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath());

      parameters.put("idno", idno);
      parameters.put("userName", user.getMember().getName());
      parameters.put("PrintDate", Toolket.Date2Str(new Date())); // 列印日期

      String[] fields = {
        "serviceNo0",
        "serviceNo1",
        "serviceNo2",
        "serviceNo3",
        "serviceNo4",
        "serviceNo5",
        "serviceNo6",
        "serviceNo7",
        "serviceNo8",
        "serviceNo9"
      };

      JasperPrint jasperPrint =
          JasperFillManager.fillReport(
              jasperReport, parameters, new HibernateQueryResultDataSource(printData, fields));
      // jasperPrint.
      // 列印或預覽
      if (isPrint) {
        JasperPrintManager.printReport(jasperPrint, setupPrinter);
      } else {
        byte[] bytes =
            JasperRunManager.runReportToPdf(
                jasperReport, parameters, new HibernateQueryResultDataSource(printData, fields));

        Calendar td = Calendar.getInstance();
        String ran =
            ""
                + (td.get(Calendar.MINUTE))
                + (td.get(Calendar.SECOND))
                + (td.get(Calendar.MILLISECOND));
        String ranDir = "/WEB-INF/reports/temp/" + ran;

        File tempdir = new File(context.getRealPath(ranDir));
        if (!tempdir.exists()) tempdir.mkdirs();

        OutputStream os =
            new BufferedOutputStream(
                new FileOutputStream(new File(context.getRealPath(ranDir + "/AssessPaper.pdf"))));
        JasperExportManager.exportReportToPdfStream(jasperPrint, os);
        JasperReportUtils.printPdfToFrontEnd(response, bytes);
        os.close();
        Toolket.deleteDIR(tempdir);
        return null;
      }

    } else {
      messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("MessageN1", "請輸入欲列印張數!"));
      saveErrors(request, messages);
    }
    setContentPage(request, "personnel/AssessPaperPrint.jsp");
    return unspecified(mapping, form, request, response);
  }