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