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