PopogroupModAction.java~77~
上传用户: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.             if (!pgname.equals("")) {
  28.                 String checksql =
  29.                         "SELECT popedomgroup.popeid FROM popedomgroup WHERE popegroup = '" +
  30.                         pgname +
  31.                         "' GROUP BY popedomgroup.popeid ";
  32.                 DBConn dbc = new DBConn();
  33.                 String[][] checkInfo = dbc.getArray(checksql);
  34.                 int type = 0; //修改类型0不变,1添加,2删除
  35.                 int len = 0;
  36.                 if (ids.length <= checkInfo.length) {
  37.                     len = checkInfo.length;
  38.                 } else {
  39.                     len = ids.length;
  40.                 }
  41.                 String[] same = new String[len];
  42.                 int j = 0;
  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.                                 dbc.executeUpdate(tempsql1);
  74.                                 //System.out.println("dd" + ids[i]);
  75.                                 break;
  76.                             }
  77.                         }
  78.                     }
  79.                     if (l < i && l == h) {
  80.                         if (ids[i] != null) {
  81.                             tempsql1 =
  82.                                     "insert into popedomgroup (popeid,popegroup) values(" +
  83.                                     ids[i] + ",'" + pgname + "')";
  84.                             //System.out.println(tempsql1);
  85.                             dbc.executeUpdate(tempsql1);
  86.                             //System.out.println("dd" + ids[i]);
  87.                         }
  88.                     }
  89.                 }
  90.                 l = 0;
  91.                 h = 0;
  92.                 for (int i = 0; i < checkInfo.length; i++) {
  93.                     //得出应该删除的
  94.                     String temp = "a";
  95.                     String tempsql2 = "";
  96.                     for (int k = l; k < same.length; k++) {
  97.                         h = l;
  98.                         if (same[k] != null && checkInfo[i][0] != null) {
  99.                             if (same[k].equals(checkInfo[i][0])) {
  100.                                 l++;
  101.                                 break;
  102.                             } else {
  103.                                 temp = "b";
  104.                                 tempsql2 =
  105.                                         "DELETE FROM popedomgroup WHERE popeid=" +
  106.                                         checkInfo[i][0]
  107.                                         + " AND popegroup='" + pgname + "' ";
  108.                                 //System.out.println(tempsql2);
  109.                                 dbc.executeUpdate(tempsql2);
  110.                                 //System.out.println("ttt" + checkInfo[i][0]);
  111.                                 break;
  112.                             }
  113.                         }
  114.                     }
  115.                     if (l < i && l == h) {
  116.                         if (checkInfo[i][0] != null)
  117.                             if (!temp.equals("b")) {
  118.                                 tempsql2 =
  119.                                         "DELETE FROM popedomgroup WHERE popeid=" +
  120.                                         checkInfo[i][0]
  121.                                         + " AND popegroup='" + pgname + "' ";
  122.                                 //System.out.println(tempsql2);
  123.                                 dbc.executeUpdate(tempsql2);
  124.                                 //System.out.println("ttt" + checkInfo[i][0]);
  125.                             }
  126.                     }
  127.                 }
  128.             } else {
  129.                 request.setAttribute("msg", "paname is null");
  130.                 return mapping.findForward("succ");
  131.                 //System.out.println("pgname is null");
  132.             }
  133.         } catch (Exception ex) {
  134.             ex.printStackTrace();
  135.         }
  136.         return mapping.findForward("succ");
  137.     }
  138. }