/**
   * 處理學生退選線上選課紀錄之方法
   *
   * @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);
  }
Example #2
0
  public ActionForward unspecified(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    StudAffairManager sm = (StudAffairManager) getBean("studAffairManager");
    HttpSession session = request.getSession(false);
    DynaActionForm aForm = (DynaActionForm) form;
    aForm.initialize(mapping);
    UserCredential user = (UserCredential) session.getAttribute("Credential");

    String idno = user.getMember().getIdno();
    Map papers = mm.getAssessPaperByIdno(idno);

    session.setAttribute("AssessPaperList", papers.get("papers"));
    session.setAttribute("AssessPaperTotal", papers.get("total"));
    session.setAttribute("AssessPaperAvg", papers.get("avgScore"));

    setContentPage(session, "personnel/AssessPaperPrint.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 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);
    }
  }
  /**
   * 處理學生課程衝突後確定加選之方法
   *
   * @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);
  }
  /**
   * 處理確定加選學生選課內容之方法
   *
   * @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);
      }
    }
  }
Example #6
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);
  }
Example #7
0
  /** 取得成績未上傳老師名單並寄發e-mail, cc給學務單位 */
  @SuppressWarnings("unchecked")
  @Override
  public void run() {

    StudAffairManager sm =
        (StudAffairManager) Global.context.getBean(IConstants.STUD_AFFAIR_MANAGER_BEAN_NAME);
    StudAffairDAO dao = (StudAffairDAO) Global.context.getBean("studAffairDAO");
    ScoreManager scm = (ScoreManager) Global.context.getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) Global.context.getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);

    String email = "";

    Calendar start = null;
    Calendar end = null;

    List<String> depts = sm.findCampusDepartment();
    String hql = "";
    String err = "";

    // Send email for Department that Teacher not upload score data which will expire
    start = Calendar.getInstance();
    start.add(Calendar.DATE, -8);

    List<Map> notUpload = new ArrayList<Map>();
    // Send email for Teacher not upload score data will expired
    try {
      notUpload = scm.findScoreNotUpload(depart, level, scope);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    String teachedId = "";
    Empl empl = new Empl();
    DEmpl dempl = new DEmpl();
    int cnt = 0;
    for (Map notupMap : notUpload) {
      teachedId = notupMap.get("teacherID").toString();
      empl = mm.findEmplByIdno(teachedId);
      if (empl != null) {
        if (empl.getEmail() != null) {
          email = empl.getEmail();
        } else {
          email = "";
        }
      } else {
        dempl = mm.findDEmplByIdno(teachedId);
        if (dempl.getEmail() != null) {
          email = dempl.getEmail();
        } else {
          email = "";
        }
      }
      if (!email.equals("")) {
        // if(notupMap.get("teacherId").toString().equalsIgnoreCase("D120148934")||
        // notupMap.get("teacherId").toString().equalsIgnoreCase("F120603503")){
        // log.debug("email:" + email + ",is valid: " +
        // Toolket.isValidEmail(email));
        if (Toolket.isValidEmail(email)) {
          // TODO:test only

          if (cnt == 0) {
            err = this.sendEmail(notupMap, "*****@*****.**");
            cnt++;
            // break;
          }

          err = this.sendEmail(notupMap, email);
          err += err;
        }
        // }
      }
    }
    if (!err.equals("")) {
      sendDeptEmail("SysAdmin", err);
    }
  }