UserAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:12k
源码类别:
Jsp/Servlet
开发平台:
Java
- //Created by MyEclipse Struts
- // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl
- //czp
- package com.oa.module.office.user;
- 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 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 com.oa.module.folder.Forder;
- import com.oa.module.hints.Thints;
- import com.oa.util.PubUtil;
- import com.oa.util.XPage;
- /**
- * MyEclipse Struts
- * Creation date: 01-17-2008
- *
- * XDoclet definition:
- * @struts.action path="/user" name="userForm" input="/Jsp_file/user/user.jsp" parameter="method" scope="request" validate="true"
- */
- public class UserAction extends DispatchAction {
- private InUserDAO userdao;
- private Forder forderdao;
- public Forder getForderdao() {
- return forderdao;
- }
- public void setForderdao(Forder forderdao) {
- this.forderdao = forderdao;
- }
- public ActionForward query(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- int currentPage = 1;
- try {
- currentPage = Integer.parseInt(request.getParameter("currentPage"));
- } catch (Exception e) {
- currentPage = 1;
- }
- int count = 10;
- Tuser info = new Tuser();
- // 拷贝查询参数(后面拷到前面){前面是目的地,后面是源}
- try {
- BeanUtils.copyProperties(info, userForm);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- XPage userpage = userdao.getUserlist(currentPage, count, info);
- List deptlist = null;
- deptlist = userdao.getDept();
- request.setAttribute("deptlist", deptlist);
- request.setAttribute("userpage", userpage);
- return mapping.findForward("userlist");
- }
- public ActionForward add(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- userForm.setMethod("addlist");
- List deptlist = null;
- List worklist = null;
- List rolelist = null;
- deptlist = userdao.getDept();
- worklist = userdao.getWork();
- rolelist = userdao.getRole();
- request.setAttribute("deptlist",deptlist);
- request.setAttribute("worklist",worklist);
- request.setAttribute("rolelist", rolelist);
- return mapping.getInputForward();
- }
- public ActionForward addlist(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String[] role1 = request.getParameterValues("role1");
- UserForm userForm = (UserForm) form;
- userForm.setUislocked("0");
- userForm.setUisonline("0");
- userForm.setUpwd("888888");
- userForm.setUaddtime(PubUtil.getNowDate());
- Tuser info = new Tuser();
- int num = role1.length;
- Tuserrole[] urole = new Tuserrole[num];
- Thints hint = new Thints();
- hint.setHshowtype("1");
- hint.setHshowtime("10");
- hint.setHaffair("1");
- hint.setHmeeting("1");
- hint.setHemail("1");
- hint.setHmemo("贴士备注");
- hint.setUser(info);
- info.setHint(hint);
- for(int i=0;i<num;i++){
- urole[i] = new Tuserrole();
- urole[i].setRid(Integer.parseInt(role1[i]));
- urole[i].setUser(info);
- info.getUserrole().add(urole[i]);
- }
- try {
- //info目的地 userForm 源
- BeanUtils.copyProperties(info,userForm);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- boolean flag = userdao.addList(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- Tuser user = userdao.getUserForName(info.getUname());
- String path = this.getServlet().getServletContext().getRealPath("/");
- path = path.replace('\', '/');
- path += "forder";
- System.out.println(forderdao);
- forderdao.buildSystemForder(user.getUno(),user.getUname(),path);
- request.setAttribute("msg", "添加用户成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "添加用户失败");
- return mapping.getInputForward();
- }
- }
- public ActionForward update(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- if(!(userForm.getUno().toString()==null)&&userForm.getUno().toString()=="1"){
- request.setAttribute("msg", "超级管理员不能修改");
- return mapping.getInputForward();
- }else{
- Tuser info = userdao.getUserById(userForm.getUno());
- try {
- BeanUtils.copyProperties(userForm,info);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- List deptlist = null;
- List worklist = null;
- List rolelist = null;
- List rlist = null;
- deptlist = userdao.getDept();
- worklist = userdao.getWork();
- rolelist = userdao.getRole();
- rlist = userdao.getRList(userForm.getUno());
- request.setAttribute("deptlist",deptlist);
- request.setAttribute("worklist",worklist);
- request.setAttribute("rolelist", rolelist);
- request.setAttribute("rlist",rlist);
- userForm.setMethod("edit");
- return mapping.getInputForward();
- }
- }
- public ActionForward edit(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String[] role1 = request.getParameterValues("role1");
- UserForm userForm = (UserForm) form;
- Tuser info = new Tuser();
- try {
- BeanUtils.copyProperties(info,userForm);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- int num = role1.length;
- Tuserrole[] urole = new Tuserrole[num];
- for(int i=0;i<num;i++){
- urole[i] = new Tuserrole();
- urole[i].setRid(Integer.parseInt(role1[i]));
- urole[i].setUser(info);
- info.getUserrole().add(urole[i]);
- }
- boolean flag = userdao.editList(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "修改用户成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "修改用户失败");
- return mapping.getInputForward();
- }
- }
- public ActionForward open(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- Tuser info = userdao.getUserById(userForm.getUno());
- info.setUislocked("0");
- boolean flag = userdao.openUser(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "恢复用户成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "恢复用户失败");
- return mapping.findForward("query");
- }
- }
- public ActionForward close(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- if(!(userForm.getUno()==null)&&!userForm.getUno().equals("1")){
- Tuser info = userdao.getUserById(userForm.getUno());
- info.setUislocked("1");
- System.out.println(userForm.getUno()+"aaaaaaa");
- System.out.println(userForm);
- System.out.println("aaaaa");
- boolean flag = userdao.closeUser(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "冻结用户成功");
- return mapping.findForward("query");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "冻结用户失败");
- return mapping.findForward("query");
- }
- }else{
- request.setAttribute("msg", "超级管理员不能冻结");
- return mapping.findForward("query");
- }
- }
- public ActionForward updatepwd(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- userForm.setMethod("editPwd");
- HttpSession session = request.getSession();
- Tuser info = (Tuser)session.getAttribute("user");
- System.out.println(info.getUno());
- try {
- BeanUtils.copyProperties(userForm,info);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return mapping.findForward("updatepwd");
- }
- public ActionForward editPwd(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- String pwd = request.getParameter("newpwd");
- UserForm userForm = (UserForm) form;
- boolean flag = userdao.updatePwd(userForm.getUno(),pwd);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "修改密码成功");
- return mapping.findForward("updatepwd");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "修改密码失败");
- return mapping.findForward("updatepwd");
- }
- }
- public ActionForward updateuser(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- userForm.setMethod("edituser");
- // Tuser info = userdao.getUserById(userForm.getUno());
- HttpSession session = request.getSession();
- Tuser info = (Tuser)session.getAttribute("user");
- try {
- BeanUtils.copyProperties(userForm,info);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- List deptlist = null;
- List worklist = null;
- deptlist = userdao.getDept();
- worklist = userdao.getWork();
- request.setAttribute("deptlist",deptlist);
- request.setAttribute("worklist",worklist);
- return mapping.findForward("updateuser");
- }
- public ActionForward edituser(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- UserForm userForm = (UserForm) form;
- Tuser info = new Tuser();
- try {
- BeanUtils.copyProperties(info,userForm);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
- boolean flag = userdao.editList(info);
- if (flag) {
- // 去列表页面,并显示成功信息
- request.setAttribute("msg", "修改用户资料成功");
- return mapping.findForward("updateuser");
- } else {
- // 去添加页面,并显示失败信息
- request.setAttribute("msg", "修改用户资料失败");
- return mapping.getInputForward();
- }
- }
- public ActionForward checkName(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) throws IOException {
- PrintWriter out = response.getWriter();
- UserForm userForm = (UserForm) form;
- if(!(userForm.getUname()==null)&&!userForm.getUname().equals("")){
- boolean flag = userdao.getUserByName(userForm.getUname());
- if (flag) {
- // 去列表页面,并显示成功信息
- out.print("此用户已存在,请更换!");
- } else {
- out.print("可以使用!");
- }
- } else {
- out.print("用户名不能为空!");
- }
- return null;
- }
- public InUserDAO getUserdao() {
- return userdao;
- }
- public void setUserdao(InUserDAO userdao) {
- this.userdao = userdao;
- }
- }