/**
   * 處理學生加選線上選課紀錄之方法
   *
   * @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 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 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 #4
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    WebApplicationContext ctx =
        WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());

    CourseManager manager = (CourseManager) ctx.getBean("courseManager");
    HttpSession session = request.getSession(false);
    boolean b = false;
    if (request.getParameter("count") != null) {
      b = true;
    }

    List students = (List) session.getAttribute("students");

    ByteArrayOutputStream ba = new ByteArrayOutputStream();

    try {
      Document document = new Document(PageSize.A6.rotate(), 5, 5, 5, 5);

      PdfWriter writer = PdfWriter.getInstance(document, ba);
      document.open();
      Image image = null;

      Clazz clazz;
      Student stmd;
      String SchoolName;
      String DeptName;
      StringBuilder StudentNo;

      Map map;
      Map StmdCardNum;

      // writer = PdfWriter.getInstance(document, ba);
      PdfContentByte cb = writer.getDirectContent();
      BaseFont bf = BaseFont.createFont("/kaiu.ttf", "Identity-H", BaseFont.EMBEDDED);

      for (int i = 0; i < students.size(); i++) {

        stmd =
            (Student)
                manager
                    .hqlGetBy(
                        "FROM Student WHERE studentNo='"
                            + ((Map) students.get(i)).get("student_no")
                            + "'")
                    .get(0);
        clazz =
            (Clazz)
                manager.hqlGetBy("FROM Clazz WHERE ClassNo='" + stmd.getDepartClass() + "'").get(0);
        map =
            manager.ezGetMap(
                "SELECT * FROM dept WHERE no='" + clazz.getClassNo().substring(0, 4) + "'");

        try { // 系所名
          DeptName = map.get("fname").toString();
        } catch (Exception e) {
          DeptName = "";
        }
        try { // 部制名
          SchoolName = map.get("school_name").toString();
        } catch (Exception e) {
          SchoolName = "";
        }
        StudentNo = new StringBuilder(stmd.getStudentNo());
        // List list=manager.hqlGetBy("FROM StdImage WHERE studentNo='"+StudentNo+"'");

        /*
        if(b&&manager.testOnlineServer()){//寫入補發記錄
        	try{
        		//真實學號
        		manager.executeSql("INSERT INTO StmdCardNum (student_no, card_num)VALUES('"+stmd.getStudentNo()+"', 1)");
        	}catch(Exception e){
        		manager.executeSql("UPDATE StmdCardNum SET card_num=card_num+1 WHERE student_no='"+stmd.getStudentNo()+"'");
        	}
        	StudentNo.append(manager.ezGetString("SELECT card_num FROM StmdCardNum WHERE student_no='"+stmd.getStudentNo()+"'"));
        	sendMailToLib(stmd, StudentNo.toString(), request);
        }else{
        	//檢查是否已發卡
        	StmdCardNum=manager.ezGetMap("SELECT * FROM StmdCardNum WHERE student_no='"+stmd.getStudentNo()+"'");
        	if(StmdCardNum!=null){
        		StudentNo.append(manager.ezGetString("SELECT card_num FROM StmdCardNum WHERE student_no='"+stmd.getStudentNo()+"'"));
        	}
        }
        */

        StmdCardNum = manager.ezGetMap("SELECT * FROM StmdCardNum WHERE student_no='");

        // 學號不滿8碼補空白, 未來改為9碼時?
        if (StudentNo.length() <= 8) {
          for (int j = StudentNo.length(); j < 8; j++) {
            StudentNo.append(" ");
          }
        }
        // 照片
        try {
          image = getImage(StudentNo.toString());
        } catch (Exception e) {
          continue;
        }
        if (image == null) continue;

        image.scaleAbsolute(54.94f, 74.37f);
        image.setAbsolutePosition(18, 166);

        // 條碼
        Barcode39 code39 = new Barcode39();
        code39.setCode(StudentNo.toString());
        code39.setBarHeight(20);
        code39.setX(0.95f);

        code39.setStartStopText(false);
        code39.setGuardBars(false);
        code39.setExtended(false);
        code39.setChecksumText(false);
        code39.setSize(-1f);
        Image imageCode39 = code39.createImageWithBarcode(cb, null, null);

        imageCode39.setAbsolutePosition(83.15f, 152);

        cb.setColorStroke(Color.white);
        cb.rectangle(18, 150, 54.94f, 9); // 30
        cb.setLineWidth(10);
        cb.stroke();

        cb.closePath();
        cb.closePathEoFillStroke();
        cb.closePathFillStroke();
        cb.closePathStroke();

        // 文字

        cb.beginText(); // 部制
        cb.setFontAndSize(bf, 10);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, SchoolName, 118, 229, 0);
        cb.endText();

        cb.beginText(); // 科系
        cb.setFontAndSize(bf, 10);
        if (DeptName.length() >= 9) {
          cb.setFontAndSize(bf, 8);
        }
        if (DeptName.length() >= 14) {
          cb.setFontAndSize(bf, 6);
        }

        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, DeptName, 118, 215, 0);
        cb.endText();

        cb.beginText(); // 學號
        cb.setFontAndSize(bf, 10);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, stmd.getStudentNo(), 118, 201, 0);
        cb.endText();

        cb.beginText(); // 姓名
        cb.setFontAndSize(bf, 10);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, stmd.getStudentName(), 118, 187, 0);
        cb.endText();

        document.add(image);
        document.add(imageCode39);
        document.newPage();
        // bf=null;
      }

      document.close();
      writer.close();

      response.setHeader(
          "Content-Disposition", "attachment;filename=EmplCard" + Math.random() * 10 + ".pdf");
      response.setContentLength(ba.size());
      response.flushBuffer();
      ServletOutputStream out = response.getOutputStream();
      ba.writeTo(out);
      ba.close();
      out.flush();

    } catch (Exception e) {
      e.printStackTrace();
      try {
        Document document = new Document(PageSize.A6.rotate(), 5, 5, 5, 5);
        PdfWriter writer = PdfWriter.getInstance(document, ba);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont("/kaiu.ttf", "Identity-H", BaseFont.EMBEDDED);
        cb.beginText(); // 部制
        cb.setFontAndSize(bf, 10);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "讀取資料有誤:" + e, 120, 226, 0);
        cb.endText();
        // document.add(cb );
        document.close();
        document = null;
      } catch (DocumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      response.setContentType("text/html; charset=UTF-8");
      response.setContentType("application/pdf");
      response.setHeader("Content-disposition", "attachment;filename=TechTimetable.pdf");
      response.setContentLength(ba.size());
      ServletOutputStream out = response.getOutputStream();
      ba.writeTo(out);
      out.flush();
    }
  }
Example #5
0
  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();
    }
  }