/**
   * 處理學生加選線上選課紀錄之方法
   *
   * @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);
  }
Esempio n. 3
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();
    }
  }
Esempio n. 4
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();
    }
  }