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

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 DeparuserAddAction extends Action {
  10.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  11.                                  HttpServletRequest request,
  12.                                  HttpServletResponse response) {
  13.         try {
  14.             request.setCharacterEncoding("GBK");
  15.             DBConn dbc = new DBConn();
  16.             String dep = request.getParameter("dep");
  17.             int jj = Integer.parseInt(request.getParameter("j"));
  18.             String[] uids = new String[jj];
  19.             for (int i = 0; i < uids.length; i++) {
  20.                 uids[i] = request.getParameter("un" + i);
  21.             }
  22.             String[] sql = new String[jj];
  23.             String checksql =
  24.                     "select userid from userdepar where deparid =" + dep;
  25.             String udsql1 = "update [user] set deparment = 1 where id = ";
  26.             String udsql0 = "update [user] set deparment = 0 where id = ";
  27.             String temping = "";
  28.             String[][] checkInfo = dbc.getArray(checksql);
  29.             if(checkInfo!=null){
  30.                 int type = 0; //修改类型0不变,1添加,2删除
  31.                 int len = 0;
  32.                 if (uids.length <= checkInfo.length) {
  33.                     len = checkInfo.length;
  34.                 } else {
  35.                     len = uids.length;
  36.                 }
  37.                 String[] same = new String[len];
  38.                 int j = 0;
  39.                 //得出相同的,不用修改的权限ID
  40.                 for (int x = 0; x < checkInfo.length; x++) {
  41.                     for (int i = 0; i < uids.length; i++) {
  42.                         String tempsql1 = "";
  43.                         if (uids[i] != null) {
  44.                             if (checkInfo[x][0].equals(uids[i])) {
  45.                                 same[j] = checkInfo[x][0];
  46.                                 j++;
  47.                                 //System.out.println(checkInfo[x][0]);
  48.                                 continue;
  49.                             }
  50.                         }
  51.                     }
  52.                 }
  53.                 int l = 0;
  54.                 int h = 0;
  55.                 for (int i = 0; i < uids.length; i++) {
  56.                     //得出应该向数据库添加的
  57.                     String tempsql1 = "";
  58.                     String temp = "a";
  59.                     for (int k = l; k < same.length; k++) {
  60.                         h = l;
  61.                         if (same[k] != null && uids[i] != null) {
  62.                             if (same[k].equals(uids[i])) {
  63.                                 l++;
  64.                                 break;
  65.                             } else {
  66.                                 temp = "b";
  67.                                 tempsql1 =
  68.                                         "insert into userdepar (userid,deparid) values (" +
  69.                                         uids[i] + ",'" + dep + "')";
  70.                                 //System.out.println(tempsql1);
  71.                                 dbc.executeUpdate(tempsql1);
  72.                                 temping = "";
  73.                                 temping = udsql1 + "'"+uids[i]+"'";
  74.                                 dbc.executeUpdate(udsql1);
  75.                                 //System.out.println("dd" + ids[i]);
  76.                                 break;
  77.                             }
  78.                         }
  79.                     }
  80.                     if (l <= i && l == h) {
  81.                         if (uids[i] != null) {
  82.                             if (temp.equals("a")) {
  83.                                 tempsql1 =
  84.                                         "insert into userdepar (userid,deparid) values (" +
  85.                                         uids[i] + ",'" + dep + "')";
  86.                                 //System.out.println(tempsql1);
  87.                                 dbc.executeUpdate(tempsql1);
  88.                                 udsql1 = udsql1 + "'"+uids[i]+"'";
  89.                                 dbc.executeUpdate(udsql1);
  90.                                 //System.out.println("dd" + ids[i]);
  91.                             }
  92.                         }
  93.                     }
  94.                 }
  95.                 l = 0;
  96.                 h = 0;
  97.                 for (int i = 0; i < checkInfo.length; i++) {
  98.                     //得出应该删除的
  99.                     String temp = "a";
  100.                     String tempsql2 = "";
  101.                     for (int k = l; k < same.length; k++) {
  102.                         h = l;
  103.                         if (same[k] != null && checkInfo[i][0] != null) {
  104.                             if (same[k].equals(checkInfo[i][0])) {
  105.                                 l++;
  106.                                 break;
  107.                             } else {
  108.                                 temp = "b";
  109.                                 tempsql2 =
  110.                                         "delete from userdepar where deparid = " +
  111.                                         dep + " and userid =" + checkInfo[i][0];
  112.                                 //System.out.println(tempsql2);
  113.                                 dbc.executeUpdate(tempsql2);
  114.                                 udsql0 = udsql0 + "'"+uids[i]+"'";
  115.                                 dbc.executeUpdate(udsql0);
  116.                                 //System.out.println("ttt" + checkInfo[i][0]);
  117.                                 break;
  118.                             }
  119.                         }
  120.                     }
  121.                     if (l <= i && l == h) {
  122.                         if (checkInfo[i][0] != null)
  123.                             if (!temp.equals("b")) {
  124.                                 tempsql2 =
  125.                                         "delete from userdepar where deparid = " +
  126.                                         dep + " and userid =" + checkInfo[i][0];
  127.                                 //System.out.println(tempsql2);
  128.                                 udsql0 = udsql0 + "'"+uids[i]+"'";
  129.                                 dbc.executeUpdate(udsql0);
  130.                                 dbc.executeUpdate(tempsql2);
  131.                                 //System.out.println("ttt" + checkInfo[i][0]);
  132.                             }
  133.                     }
  134.                 }
  135.             }else{
  136.                 String[] un = new String[jj];
  137.                 String temp = "emp";
  138.                 for (int i = 0; i < jj; i++) {
  139.                     un[i] = request.getParameter("un" + i);
  140.                     if (un[i] != null) {
  141.                         temp = "notemp";
  142.                         String acheck =
  143.                                 "select * from userdepar where deparid=" +
  144.                                 dep + " and userid = " + un[i];
  145.                         //System.out.println(acheck);
  146.                         String[][] check = dbc.getArray(acheck);
  147.                         if (check == null) {
  148.                             String asql =
  149.                                     "insert into userdepar (deparid,userid) values (" +
  150.                                     dep + "," + un[i] + ")";
  151.                             //System.out.println(asql);
  152.                             udsql1 = udsql1 + "'"+uids[i]+"'";
  153.                             dbc.executeUpdate(udsql1);
  154.                             dbc.executeUpdate(asql);
  155.                         } else {
  156.                             request.setAttribute("msg", "用户已经添加,请不要重复添加!");
  157.                         }
  158.                     }
  159.                 }
  160.                 if (temp.equals("emp")) {
  161.                     request.setAttribute("msg", "用户名不能为空!");
  162.                     return mapping.findForward("succ");
  163.                 }
  164.             }
  165.         } catch (Exception ex) {
  166.             ex.printStackTrace();
  167.         }
  168.         request.setAttribute("msg", "修改成功!");
  169.         return mapping.findForward("succ");
  170.     }
  171. }