PopogroupModAction.java
上传用户: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.                     String temp = "a";
  63.                     for (int k = l; k < same.length; k++) {
  64.                         h = l;
  65.                         if (same[k] != null && ids[i] != null) {
  66.                             if (same[k].equals(ids[i])) {
  67.                                 l++;
  68.                                 break;
  69.                             } else {
  70.                                 temp = "b";
  71.                                 tempsql1 =
  72.                                         "insert into popedomgroup (popeid,popegroup) values(" +
  73.                                         ids[i] + ",'" + pgname + "')";
  74.                                 //System.out.println(tempsql1);
  75.                                 dbc.executeUpdate(tempsql1);
  76.                                 //System.out.println("dd" + ids[i]);
  77.                                 break;
  78.                             }
  79.                         }
  80.                     }
  81.                     if (l <= i && l == h) {
  82.                         if (ids[i] != null) {
  83.                             if(temp.equals("a")){
  84.                                 tempsql1 =
  85.                                         "insert into popedomgroup (popeid,popegroup) values(" +
  86.                                         ids[i] + ",'" + pgname + "')";
  87.                                 //System.out.println(tempsql1);
  88.                                 dbc.executeUpdate(tempsql1);
  89.                                 //System.out.println("dd" + ids[i]);
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.                 l = 0;
  95.                 h = 0;
  96.                 for (int i = 0; i < checkInfo.length; i++) {
  97.                     //得出应该删除的
  98.                     String temp = "a";
  99.                     String tempsql2 = "";
  100.                     for (int k = l; k < same.length; k++) {
  101.                         h = l;
  102.                         if (same[k] != null && checkInfo[i][0] != null) {
  103.                             if (same[k].equals(checkInfo[i][0])) {
  104.                                 l++;
  105.                                 break;
  106.                             } else {
  107.                                 temp = "b";
  108.                                 tempsql2 =
  109.                                         "DELETE FROM popedomgroup WHERE popeid=" +
  110.                                         checkInfo[i][0]
  111.                                         + " AND popegroup='" + pgname + "' ";
  112.                                 //System.out.println(tempsql2);
  113.                                 dbc.executeUpdate(tempsql2);
  114.                                 //System.out.println("ttt" + checkInfo[i][0]);
  115.                                 break;
  116.                             }
  117.                         }
  118.                     }
  119.                     if (l <= i && l == h) {
  120.                         if (checkInfo[i][0] != null)
  121.                             if (!temp.equals("b")) {
  122.                                 tempsql2 =
  123.                                         "DELETE FROM popedomgroup WHERE popeid=" +
  124.                                         checkInfo[i][0]
  125.                                         + " AND popegroup='" + pgname + "' ";
  126.                                 //System.out.println(tempsql2);
  127.                                 dbc.executeUpdate(tempsql2);
  128.                                 //System.out.println("ttt" + checkInfo[i][0]);
  129.                             }
  130.                     }
  131.                 }
  132.             } else {
  133.                 request.setAttribute("msg", "paname is null");
  134.                 return mapping.findForward("succ");
  135.                 //System.out.println("pgname is null");
  136.             }
  137.         } catch (Exception ex) {
  138.             ex.printStackTrace();
  139.         }
  140.         return mapping.findForward("succ");
  141.     }
  142. }