UsergroupAddAction.java~40~
上传用户: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.             String a = "a";
  20.             for (int i = 0; i < ulen; i++) {
  21.                 uid[i] = request.getParameter("user" + i);
  22.                 if(uid[i]!=null){
  23.                     a = "b";
  24.                 }
  25.             }
  26.             DBConn dbc = new DBConn();
  27.             Tool tl = new Tool();
  28.             if (ugname != null && !ugname.equals("")) {
  29.                 String ugcheck =
  30.                         "select usergroup from usergroup where usergroup='" +
  31.                         ugname + "'";
  32.                 String[][] ugc = dbc.getArray(ugcheck);
  33.                 String ugmd5 = tl.hash(ugname);
  34.                 if (ugc == null) {
  35.                     if (a.equals("b")) {
  36.                         for (int i = 0; i < ulen; i++) {
  37.                             if (uid[i] != null) {
  38.                                 String asql =
  39.                                         "insert into usergroup (usergroup,userid,depid,ugmd5) values('" +
  40.                                         ugname + "'," + uid[i] + ",'" + dep +
  41.                                         "','" + ugmd5 + "')";
  42.                                // System.out.println(asql);
  43.                                 dbc.executeUpdate(asql);
  44.                             }
  45.                         }
  46.                         request.setAttribute("msg", "用户组" + ugname + "添加成功!");
  47.                         return mapping.findForward("succ");
  48.                     } else {
  49.                         //System.out.println("uid is null");
  50.                         request.setAttribute("msg", "没有选择需要添加的用户!");
  51.                         return mapping.findForward("err");
  52.                     }
  53.                 } else {
  54.                     request.setAttribute("msg", "用户名已经存在!");
  55.                     return mapping.findForward("err");
  56.                 }
  57.             } else {
  58.                 request.setAttribute("msg", "用户组名不能为空!");
  59.                 return mapping.findForward("err");
  60.             }
  61.         } catch (Exception ex) {
  62.             request.setAttribute("msg", "用户组添加出现异常,请重试!");
  63.         }
  64.         return mapping.findForward("err");
  65.     }
  66. }