PopogroupModAction.java~76~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:6k
源码类别:
OA系统
开发平台:
Java
- package officeol.mc.actions;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.Action;
- import java.io.UnsupportedEncodingException;
- import officeol.mc.tools.DBConn;
- public class PopogroupModAction extends Action {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- try {
- request.setCharacterEncoding("GBK");
- } catch (UnsupportedEncodingException ex) {
- ex.printStackTrace();
- }
- try {
- String num = request.getParameter("num");
- String[] ids = new String[Integer.parseInt(num)];
- for (int i = 0; i < ids.length; i++) {
- ids[i] = request.getParameter("id" + i);
- }
- String pgname = request.getParameter("pgname");
- String[] sql = new String[Integer.parseInt(num)];
- if (!pgname.equals("")) {
- String checksql =
- "SELECT popedomgroup.popeid FROM popedomgroup WHERE popegroup = '" +
- pgname +
- "' GROUP BY popedomgroup.popeid ";
- DBConn dbc = new DBConn();
- String[][] checkInfo = dbc.getArray(checksql);
- int type = 0; //修改类型0不变,1添加,2删除
- int len = 0;
- if (ids.length <= checkInfo.length) {
- len = checkInfo.length;
- } else {
- len = ids.length;
- }
- String[] same = new String[len];
- int j = 0;
- //得出相同的,不用修改的权限ID
- for (int x = 0; x < checkInfo.length; x++) {
- for (int i = 0; i < ids.length; i++) {
- String tempsql1 = "";
- if (ids[i] != null) {
- if (checkInfo[x][0].equals(ids[i])) {
- same[j] = checkInfo[x][0];
- j++;
- //System.out.println(checkInfo[x][0]);
- continue;
- }
- }
- }
- }
- int l = 0;
- int h = 0;
- for (int i = 0; i < ids.length; i++) {
- //得出应该向数据库添加的
- String tempsql1 = "";
- for (int k = l; k < same.length; k++) {
- h = l;
- if (same[k] != null && ids[i] != null) {
- if (same[k].equals(ids[i])) {
- l++;
- break;
- } else {
- tempsql1 =
- "insert into popedomgroup (popeid,popegroup) values(" +
- ids[i] + ",'" + pgname + "')";
- //System.out.println(tempsql1);
- dbc.executeUpdate(tempsql1);
- //System.out.println("dd" + ids[i]);
- break;
- }
- }
- }
- if (l < i && l == h) {
- if (ids[i] != null){
- tempsql1 =
- "insert into popedomgroup (popeid,popegroup) values(" +
- ids[i] + ",'" + pgname + "')";
- //System.out.println(tempsql1);
- dbc.executeUpdate(tempsql1);
- //System.out.println("dd" + ids[i]);
- }
- }
- }
- l = 0;
- h = 0;
- for (int i = 0; i < checkInfo.length; i++) {
- //得出应该删除的
- String temp = "a";
- String tempsql2 = "";
- for (int k = l; k < same.length; k++) {
- h = l;
- if (same[k] != null && checkInfo[i][0] != null) {
- if (same[k].equals(checkInfo[i][0])) {
- l++;
- break;
- } else {
- temp = "b";
- tempsql2 =
- "DELETE FROM popedomgroup WHERE popeid=" +
- checkInfo[i][0]
- + " AND popegroup='" + pgname + "' ";
- //System.out.println(tempsql2);
- dbc.executeUpdate(tempsql2);
- //System.out.println("ttt" + checkInfo[i][0]);
- break;
- }
- }
- }
- if (l < i && l == h) {
- if (checkInfo[i][0] != null)
- if (!temp.equals("b")){
- tempsql2 =
- "DELETE FROM popedomgroup WHERE popeid=" +
- checkInfo[i][0]
- + " AND popegroup='" + pgname + "' ";
- //System.out.println(tempsql2);
- dbc.executeUpdate(tempsql2);
- //System.out.println("ttt" + checkInfo[i][0]);
- }
- }
- }
- } else {
- request.setAttribute("msg", "paname is null");
- return mapping.findForward("succ");
- //System.out.println("pgname is null");
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return mapping.findForward("succ");
- }
- }