DeptAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:7k
源码类别:
Jsp/Servlet
开发平台:
Java
- //Created by MyEclipse Struts
- // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
- package com.oa.module.office.dept;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.lang.reflect.InvocationTargetException;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- 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 com.oa.util.XPage;
- /**
- * MyEclipse Struts
- * Creation date: 01-21-2008
- *
- * 部门的Action处理JSP过来的请求
- *
- * XDoclet definition:
- * @struts.action path="/dept" name="deptForm" input="/Jsp_file/department/department.jsp" parameter="method" scope="request" validate="true"
- */
- public class DeptAction extends DispatchAction {
- private InDeptDAO deptdao;
- /**
- * 默认查询方法
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return 去页面
- */
- public ActionForward query(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- int currentPage = 1;
- try {
- currentPage = Integer.parseInt(request.getParameter("currentPage"));
- } catch (Exception e) {
- currentPage = 1;
- }
- int count = 6;
- Tdept info = new Tdept();
- // 拷贝查询参数(后面拷到前面){前面是目的地,后面是源}
- try {
- BeanUtils.copyProperties(info, deptForm);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- XPage deptpage = deptdao.getDeptlist(currentPage, count, info);
- request.setAttribute("deptpage", deptpage);
- return mapping.findForward("deptlist");
- }
- /**
- * 添加请求,到添加页面
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward add(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- deptForm.setMethod("addlist");
- List userlist =null;
- userlist = deptdao.getUser();
- request.setAttribute("userlist",userlist);
- return mapping.getInputForward();
- }
- /**
- * 添加到数据库
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward addlist(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- Tdept info = new Tdept();
- try {
- BeanUtils.copyProperties(info,deptForm);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- boolean flag = deptdao.addList(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "添加部门成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "添加部门失败");
- return mapping.getInputForward();
- }
- }
- /**
- * 接受修改请求,到修改页面
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward update(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- Tdept info = deptdao.getDeptById(deptForm.getDid());
- try {
- BeanUtils.copyProperties(deptForm,info);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- List userlist =null;
- userlist = deptdao.getUser();
- request.setAttribute("userlist",userlist);
- deptForm.setMethod("edit");
- return mapping.getInputForward();
- }
- /**
- * 处理修改
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward edit(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- Tdept info = new Tdept();
- try {
- BeanUtils.copyProperties(info,deptForm);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- boolean flag = deptdao.editList(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "修改部门成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "修改部门失败");
- return mapping.getInputForward();
- }
- }
- /**
- * 部门恢复正常方法
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward open(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- Tdept info = deptdao.getDeptById(deptForm.getDid());
- info.setDflag("0");
- boolean flag = deptdao.openDept(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "恢复部门成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "恢复部门失败");
- return mapping.findForward("query");
- }
- }
- /**
- * 部门删除方法
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward close(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- DeptForm deptForm = (DeptForm) form;
- Tdept info = deptdao.getDeptById(deptForm.getDid());
- info.setDflag("1");
- boolean flag1 = deptdao.getUserForDid(deptForm.getDid());
- if(flag1){//返回TRUE就是有...
- request.setAttribute("msg", "该部门还有用户,不能删除!");
- return mapping.findForward("query");
- } else {
- boolean flag = deptdao.closeDept(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "删除部门成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "删除部门失败");
- return mapping.findForward("query");
- }
- }
- }
- /**
- * AJAX验证是否重名方法
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws IOException
- */
- public ActionForward checkName(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) throws IOException {
- PrintWriter out = response.getWriter();
- DeptForm deptForm = (DeptForm) form;
- if(!(deptForm.getDname()==null)&&!deptForm.getDname().equals("")){
- boolean flag = deptdao.getDeptByName(deptForm.getDname());
- if (flag) {
- // 去列表页面,并显示成功信息
- out.print("此部门已存在,请更换!");
- } else {
- out.print("可以使用!");
- }
- } else {
- out.print("部门名称不能为空!");
- }
- return null;
- }
- public InDeptDAO getDeptdao() {
- return deptdao;
- }
- public void setDeptdao(InDeptDAO deptdao) {
- this.deptdao = deptdao;
- }
- }