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

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 = "DELETE FROM popedomgroup WHERE popeid="+checkInfo[i][0]
  102.                                          +" AND popegroup='"+pgname+"' ";
  103.                               System.out.println(tempsql2);
  104.                                 System.out.println("ttt" + checkInfo[i][0]);
  105.                                 break;
  106.                             }
  107.                         }
  108.                     }
  109.                     if (l < i && l == h) {
  110.                         if (checkInfo[i][0] != null)
  111.                             if (!temp.equals("b"))
  112.                                 tempsql2 = "DELETE FROM popedomgroup WHERE popeid="+checkInfo[i][0]
  113.                                          +" AND popegroup='"+pgname+"' ";
  114.                               System.out.println(tempsql2);
  115.                                 System.out.println("ttt" + checkInfo[i][0]);
  116.                     }
  117.                 }
  118.                 /*if(!checkInfo[x][0].equals(ids[i])){
  119.                  tempsql2 = "DELETE FROM popedomgroup WHERE popeid="+ids[i]
  120.                                           +" AND popegroup='"+pgname+"' ";
  121.                                System.out.println(tempsql2);
  122.                            }*/
  123.                 /*for(int x = 0; x < checkInfo.length; x++){
  124.                             String tempsql1 = "";
  125.                             String tempsql2 = "";
  126.                             if(!ids[i].equals(checkInfo[x][0])){
  127.                  tempsql1 = "insert into popedomgroup (popeid,popegroup) values(" +
  128.                                  ids[i] + ",'" + pgname + "')";
  129.                                 System.out.println(tempsql1);
  130.                                 break;
  131.                             }*/
  132.             } else {
  133.                 request.setAttribute("info", "paname is null");
  134.                 System.out.println("pgname is null");
  135.             }
  136.         } catch (Exception ex) {
  137.             ex.printStackTrace();
  138.         }
  139.         return mapping.findForward("succ");
  140.     }
  141. }