DeparuserAddAction.java~74~
上传用户: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(temping);
  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.                                 temping = "";
  89.                                 temping = udsql1 + "'"+uids[i]+"'";
  90.                                 dbc.executeUpdate(temping);
  91.                                 //System.out.println("dd" + ids[i]);
  92.                             }
  93.                         }
  94.                     }
  95.                 }
  96.                 l = 0;
  97.                 h = 0;
  98.                 for (int i = 0; i < checkInfo.length; i++) {
  99.                     //得出应该删除的
  100.                     String temp = "a";
  101.                     String tempsql2 = "";
  102.                     for (int k = l; k < same.length; k++) {
  103.                         h = l;
  104.                         if (same[k] != null && checkInfo[i][0] != null) {
  105.                             if (same[k].equals(checkInfo[i][0])) {
  106.                                 l++;
  107.                                 break;
  108.                             } else {
  109.                                 temp = "b";
  110.                                 tempsql2 =
  111.                                         "delete from userdepar where deparid = " +
  112.                                         dep + " and userid =" + checkInfo[i][0];
  113.                                 //System.out.println(tempsql2);
  114.                                 dbc.executeUpdate(tempsql2);
  115.                                 udsql0 = udsql0 + "'"+uids[i]+"'";
  116.                                 dbc.executeUpdate(udsql0);
  117.                                 //System.out.println("ttt" + checkInfo[i][0]);
  118.                                 break;
  119.                             }
  120.                         }
  121.                     }
  122.                     if (l <= i && l == h) {
  123.                         if (checkInfo[i][0] != null)
  124.                             if (!temp.equals("b")) {
  125.                                 tempsql2 =
  126.                                         "delete from userdepar where deparid = " +
  127.                                         dep + " and userid =" + checkInfo[i][0];
  128.                                 //System.out.println(tempsql2);
  129.                                 udsql0 = udsql0 + "'"+uids[i]+"'";
  130.                                 dbc.executeUpdate(udsql0);
  131.                                 dbc.executeUpdate(tempsql2);
  132.                                 //System.out.println("ttt" + checkInfo[i][0]);
  133.                             }
  134.                     }
  135.                 }
  136.             }else{
  137.                 String[] un = new String[jj];
  138.                 String temp = "emp";
  139.                 for (int i = 0; i < jj; i++) {
  140.                     un[i] = request.getParameter("un" + i);
  141.                     if (un[i] != null) {
  142.                         temp = "notemp";
  143.                         String acheck =
  144.                                 "select * from userdepar where deparid=" +
  145.                                 dep + " and userid = " + un[i];
  146.                         //System.out.println(acheck);
  147.                         String[][] check = dbc.getArray(acheck);
  148.                         if (check == null) {
  149.                             String asql =
  150.                                     "insert into userdepar (deparid,userid) values (" +
  151.                                     dep + "," + un[i] + ")";
  152.                             //System.out.println(asql);
  153.                             udsql1 = udsql1 + "'"+uids[i]+"'";
  154.                             dbc.executeUpdate(udsql1);
  155.                             dbc.executeUpdate(asql);
  156.                         } else {
  157.                             request.setAttribute("msg", "用户已经添加,请不要重复添加!");
  158.                         }
  159.                     }
  160.                 }
  161.                 if (temp.equals("emp")) {
  162.                     request.setAttribute("msg", "用户名不能为空!");
  163.                     return mapping.findForward("succ");
  164.                 }
  165.             }
  166.         } catch (Exception ex) {
  167.             ex.printStackTrace();
  168.         }
  169.         request.setAttribute("msg", "修改成功!");
  170.         return mapping.findForward("succ");
  171.     }
  172. }