UsergroupAddAction.java~34~
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. package officeol.mc.actions;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.Action;
  8. import officeol.mc.tools.*;
  9. public class UsergroupAddAction extends Action {
  10.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  11.                                  HttpServletRequest request,
  12.                                  HttpServletResponse response) {
  13.        try{
  14.            request.setCharacterEncoding("GBK");
  15.            String ugname = request.getParameter("ugname");
  16.            String dep = request.getParameter("dep");
  17.            int ulen = Integer.parseInt(request.getParameter("ulen"));
  18.            String[] uid = new String[ulen];
  19.            for(int i = 0; i < ulen; i++){
  20.                uid[i] = request.getParameter("user"+i);
  21.            }
  22.            DBConn dbc = new DBConn();
  23.            Tool tl = new Tool();
  24.            if(ugname!=null&&!ugname.equals("")){
  25.                String ugcheck =
  26.                        "select usergroup from usergroup where usergroup='"+ugname+"'";
  27.                String[][] ugc = dbc.getArray(ugcheck);
  28.                String ugmd5 = tl.hash(ugname);
  29.                if(ugc==null){
  30.                    if(uid!=null){
  31.                        for (int i = 0; i < ulen; i++) {
  32.                            if (uid[i] != null) {
  33.                                String asql =
  34.                                        "insert into usergroup (usergroup,userid,depid,ugmd5) values('" +
  35.                                        ugname + "'," + uid[i] + ",'" + dep +
  36.                                        "','" + ugmd5 + "')";
  37.                                System.out.println(asql);
  38.                                dbc.executeUpdate(asql);
  39.                            }
  40.                        }
  41.                    }else{
  42.                        System.out.println(asql);
  43.                        request.setAttribute("msg", "没有选择需要添加的用户!");
  44.                        return mapping.findForward("err");
  45.                    }
  46.                    request.setAttribute("msg", "用户组"+ugname+"添加成功!");
  47.                    return mapping.findForward("succ");
  48.                }else{
  49.                    request.setAttribute("msg", "用户名已经存在!");
  50.                    return mapping.findForward("err");
  51.                }
  52.            }else{
  53.                request.setAttribute("msg", "用户组名不能为空!");
  54.                return mapping.findForward("err");
  55.            }
  56.        }catch(Exception ex){
  57.            request.setAttribute("msg","用户组添加出现异常,请重试!");
  58.        }
  59.         return mapping.findForward("err");
  60.     }
  61. }