📄 affairtypeaction.java
字号:
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xslpackage com.oa.module.affair.affairtype;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.io.PrintWriter;import java.io.UnsupportedEncodingException;import java.lang.reflect.InvocationTargetException;import java.util.List;import java.util.Map;import com.oa.module.affair.affairdao.IAffair;import com.oa.module.affair.affairdao.TAffair;import com.oa.module.affair.affairpower.Transpower;import com.oa.module.affair.affairtype.AffairTypeForm;import com.oa.module.office.role.RoleDAO;import com.oa.module.office.user.Tuser;import com.oa.module.office.user.UserDAO;import com.oa.util.ToolUtil;import com.oa.util.XPage;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.commons.beanutils.BeanUtils;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction;import org.apache.xalan.lib.Redirect;import org.jdom.Document;import org.jdom.Element;import org.jdom.output.Format;import org.jdom.output.XMLOutputter;import org.springframework.web.servlet.view.RedirectView;/** * 事务类别Action * MyEclipse Struts * Creation date: 01-20-2008 * * XDoclet definition: * @struts.action path="/affairType" name="AffairTypeForm" input="/Jsp_file/affair/addtranstype.jsp" parameter="task" scope="request" validate="true" */public class AffairTypeAction extends DispatchAction { // --------------------------------------------------------- Instance Variables private IAffair affairdao ; private UserDAO userdao; private RoleDAO roledao; // --------------------------------------------------------- Methods public ActionForward getlist( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{ AffairTypeForm affairTypeForm = (AffairTypeForm) form; HttpSession httpsession = request.getSession(); Tuser user = (Tuser)httpsession.getAttribute("user"); PrintWriter out = null; try { out = response.getWriter(); } catch (IOException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } if (user != null) { int currentPage = 1; try { currentPage = Integer.parseInt(request.getParameter("currentPage")); } catch (Exception e) { currentPage = 1; } int count = 10; Transtype typebean = new Transtype(); try { BeanUtils.copyProperties(typebean, affairTypeForm); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } XPage typepage = affairdao.gettypelist(currentPage, count, typebean); request.setAttribute("typepage", typepage); return mapping.findForward("getlist"); }else { out.print("<script>alert('登录时间过期,请重新登录');" + "window.top.location.href='" + request.getContextPath() + "/Jsp_file/login/login.jsp';"); out.print("</script>"); } return null; } /** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward * @throws InvocationTargetException * @throws IllegalAccessException * @throws IOException */ public ActionForward addtype( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{ AffairTypeForm affairTypeForm = (AffairTypeForm) form; // TODO Auto-generated method stub String date = ToolUtil.getDate(); String filename = System.currentTimeMillis() + ".xml"; affairTypeForm.setTxmlpath(filename); affairTypeForm.setTtime(date); HttpSession httpsession = request.getSession(); Tuser user = (Tuser)httpsession.getAttribute("user"); affairTypeForm.setUno(user.getUno()); String tstep = request.getParameter("tstep"); int count = 0; if(tstep!=null){ count = Integer.parseInt(tstep); } Transtype type = new Transtype(); type.setTrid(request.getParameter("transroleid0")); BeanUtils.copyProperties(type, affairTypeForm); for (int i = 0; i < count; i++) { Transpower power = new Transpower(); power.setTranstype(type); power.setTpid(i+1); power.setRqid(request.getParameter("roleid"+i)); power.setUno(request.getParameter("userid"+i)); type.getTranspower().add(power); } boolean flag = this.affairdao.addAffairType(type,request); ; String[] transroleid = request.getParameter("transroleid0").split(","); this.affairdao.addtyperole(type.getRtid(),transroleid); if (flag == true) { //把事务环节写到XML文件 Document doc = new Document(); Element root = new Element("steps"); int stepCount = Integer.valueOf(request.getParameter("tstep")).intValue(); for (int i = 0; i < stepCount; i++) { Element step = new Element("step"); Element id = new Element("id"); id.setText("" + (i + 1)); Element userid = new Element("userid"); userid.setText(request.getParameter("userid" + i)); Element roleid = new Element("roleid"); roleid.setText(request.getParameter("roleid" + i)); step.addContent(id); step.addContent(userid); step.addContent(roleid); root.addContent(step); } doc.addContent(root); Format format = Format.getCompactFormat(); format.setIndent(" "); format.setEncoding("gb2312"); XMLOutputter out = new XMLOutputter(format); OutputStream fileout = null; String path = servlet.getServletContext().getRealPath("upload")+"/affairXml/" + File.separator + filename; try { fileout = new FileOutputStream(path); out.output(doc, fileout); response.getWriter().println("<script>alert('添加成功');"); response.getWriter().println("</script>"); affairTypeForm.setTask("getlist"); return mapping.findForward("getlist"); } catch (FileNotFoundException e) { try { response.getWriter().print("<script>alert('添加失败');window.history.back();</script>"); } catch (IOException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } // TODO 自动生成 catch 块 e.printStackTrace(); } catch (IOException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } return null; } public ActionForward edittype( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{ AffairTypeForm affairTypeForm = (AffairTypeForm) form; String transID = request.getParameter("rtid"); boolean flag = this.affairdao.isused(transID); if (flag == true) { request.setAttribute("msg","该事务正在使用中,不能进行修改"); return new ActionForward("/Jsp_file/msg.jsp"); } else { Map transrole = affairdao.getrole(transID); Map affair = affairdao.getaffair(transID); int count = Integer.valueOf(affair.get("tstep").toString()).intValue(); String dir = servlet.getServletContext().getRealPath("upload")+ "\\affairXml" + File.separator+ affair.get("txmlpath").toString(); List translist= affairdao.getSteps(dir, count); if(translist==null){ request.setAttribute("msg","找不到该XML文件"); return new ActionForward("/Jsp_file/msg.jsp"); }else{ request.setAttribute("translist", translist); affairTypeForm.setTname(affair.get("tname").toString()); affairTypeForm.setRtid(Integer.parseInt(transID)); request.setAttribute("transrole", transrole); request.setAttribute("rtid",transID); affairTypeForm.setTask("editedtype"); } return mapping.findForward("edit");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -