/** * 處理進入課務列印畫面 * * @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 */ @Override public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(false); MemberDAO dao = (MemberDAO) getBean("memberDAO"); UserCredential user = getUserCredential(session); List<Module> modules = dao.findModulesByParentNameMember("Course/ReportPrintList", user.getMember().getOid()); session.setAttribute("ModuleList", modules); session.setAttribute("DirectoryBanner", " 課 務 列 印 "); setContentPage(session, "Directory1.jsp"); return mapping.findForward(IConstants.ACTION_MAIN_NAME); }
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"); }
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); }
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"); }