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

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 java.io.UnsupportedEncodingException;
  9. import officeol.mc.tools.DBConn;
  10. public class PopogroupModAction extends Action {
  11.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  12.                                  HttpServletRequest request,
  13.                                  HttpServletResponse response) {
  14.         try {
  15.             request.setCharacterEncoding("GBK");
  16.         } catch (UnsupportedEncodingException ex) {
  17.             ex.printStackTrace();
  18.         }
  19.         try {
  20.             String num = request.getParameter("num");
  21.             String[] ids = new String[Integer.parseInt(num)];
  22.             for (int i = 0; i < ids.length; i++) {
  23.                 ids[i] = request.getParameter("id" + i);
  24.             }
  25.             String pgname = request.getParameter("pgname");
  26.             String[] sql = new String[Integer.parseInt(num)];
  27.             String checksql =
  28.                     "SELECT popedomgroup.popeid FROM popedomgroup WHERE popegroup = '" +
  29.                     pgname +
  30.                     "' GROUP BY popedomgroup.popeid ";
  31.             DBConn dbc = new DBConn();
  32.             String[][] checkInfo = dbc.getArray(checksql);
  33.             int type = 0; //修改类型0不变,1添加,2删除
  34.             int len = 0;
  35.             if (ids.length <= checkInfo.length) {
  36.                 len = checkInfo.length;
  37.             } else {
  38.                 len = ids.length;
  39.             }
  40.             String[] same = new String[len];
  41.             int j = 0;
  42.             if (!pgname.equals("")) {
  43.                 //得出相同的,不用修改的权限ID
  44.                 for (int x = 0; x < checkInfo.length; x++) {
  45.                     for (int i = 0; i < ids.length; i++) {
  46.                         String tempsql1 = "";
  47.                         if (ids[i] != null) {
  48.                             if (checkInfo[x][0].equals(ids[i])) {
  49.                                 same[j] = checkInfo[x][0];
  50.                                 j++;
  51.                                 System.out.println(checkInfo[x][0]);
  52.                                 continue;
  53.                             }
  54.                         }
  55.                     }
  56.                 }
  57.                 int l = 0;
  58.                 int h = 0;
  59.                 for (int i = 0; i < ids.length; i++) {
  60.                     //得出应该向数据库添加的
  61.                     String tempsql1 = "";
  62.                     for (int k = l; k < same.length; k++) {
  63.                         h = l;
  64.                         if (same[k] != null && ids[i] != null) {
  65.                             if (same[k].equals(ids[i])) {
  66.                                 l++;
  67.                                 break;
  68.                             } else {
  69.                                 tempsql1 =
  70.                                         "insert into popedomgroup (popeid,popegroup) values(" +
  71.                                         ids[i] + ",'" + pgname + "')";
  72.                                 System.out.println(tempsql1);
  73.                                 System.out.println("dd" + ids[i]);
  74.                                 break;
  75.                             }
  76.                         }
  77.                     }
  78.                     if (l < i && l == h) {
  79.                         if (ids[i] != null)
  80.                             tempsql1 =
  81.                                     "insert into popedomgroup (popeid,popegroup) values(" +
  82.                                     ids[i] + ",'" + pgname + "')";
  83.                         System.out.println(tempsql1);
  84.                         System.out.println("dd" + ids[i]);
  85.                     }
  86.                 }
  87.                 l = 0;
  88.                 h = 0;
  89.                 for (int i = 0; i < checkInfo.length; i++) {
  90.                     //得出应该删除的
  91.                     String temp = "a";
  92.                     String tempsql2 = "";
  93.                     for (int k = l; k < same.length; k++) {
  94.                         h = l;
  95.                         if (same[k] != null && checkInfo[i][0] != null) {
  96.                             if (same[k].equals(checkInfo[i][0])) {
  97.                                 l++;
  98.                                 break;
  99.                             } else {
  100.                                 temp = "b";
  101.                                 tempsql2 =
  102.                                         "DELETE FROM popedomgroup WHERE popeid=" +
  103.                                         checkInfo[i][0]
  104.                                         + " AND popegroup='" + pgname + "' ";
  105.                                 System.out.println(tempsql2);
  106.                                 System.out.println("ttt" + checkInfo[i][0]);
  107.                                 break;
  108.                             }
  109.                         }
  110.                     }
  111.                     if (l < i && l == h) {
  112.                         if (checkInfo[i][0] != null)
  113.                             if (!temp.equals("b"))
  114.                                 tempsql2 =
  115.                                         "DELETE FROM popedomgroup WHERE popeid=" +
  116.                                         checkInfo[i][0]
  117.                                         + " AND popegroup='" + pgname + "' ";
  118.                         System.out.println(tempsql2);
  119.                         System.out.println("ttt" + checkInfo[i][0]);
  120.                     }
  121.                 }
  122.                 /*if(!checkInfo[x][0].equals(ids[i])){
  123.                  tempsql2 = "DELETE FROM popedomgroup WHERE popeid="+ids[i]
  124.                                           +" AND popegroup='"+pgname+"' ";
  125.                                System.out.println(tempsql2);
  126.                            }*/
  127.                 /*for(int x = 0; x < checkInfo.length; x++){
  128.                             String tempsql1 = "";
  129.                             String tempsql2 = "";
  130.                             if(!ids[i].equals(checkInfo[x][0])){
  131.                  tempsql1 = "insert into popedomgroup (popeid,popegroup) values(" +
  132.                                  ids[i] + ",'" + pgname + "')";
  133.                                 System.out.println(tempsql1);
  134.                                 break;
  135.                             }*/
  136.             } else {
  137.                 request.setAttribute("info", "paname is null");
  138.                 System.out.println("pgname is null");
  139.             }
  140.         } catch (Exception ex) {
  141.             ex.printStackTrace();
  142.         }
  143.         return mapping.findForward("succ");
  144.     }
  145. }