DeparuserAddAction.java~75~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:8k
源码类别:
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 officeol.mc.tools.*;
- public class DeparuserAddAction extends Action {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- try {
- request.setCharacterEncoding("GBK");
- DBConn dbc = new DBConn();
- String dep = request.getParameter("dep");
- int jj = Integer.parseInt(request.getParameter("j"));
- String[] uids = new String[jj];
- for (int i = 0; i < uids.length; i++) {
- uids[i] = request.getParameter("un" + i);
- }
- String[] sql = new String[jj];
- String checksql =
- "select userid from userdepar where deparid =" + dep;
- String udsql1 = "update [user] set deparment = 1 where id = ";
- String udsql0 = "update [user] set deparment = 0 where id = ";
- String temping = "";
- String[][] checkInfo = dbc.getArray(checksql);
- if(checkInfo!=null){
- int type = 0; //修改类型0不变,1添加,2删除
- int len = 0;
- if (uids.length <= checkInfo.length) {
- len = checkInfo.length;
- } else {
- len = uids.length;
- }
- String[] same = new String[len];
- int j = 0;
- //得出相同的,不用修改的权限ID
- for (int x = 0; x < checkInfo.length; x++) {
- for (int i = 0; i < uids.length; i++) {
- String tempsql1 = "";
- if (uids[i] != null) {
- if (checkInfo[x][0].equals(uids[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 < uids.length; i++) {
- //得出应该向数据库添加的
- String tempsql1 = "";
- String temp = "a";
- for (int k = l; k < same.length; k++) {
- h = l;
- if (same[k] != null && uids[i] != null) {
- if (same[k].equals(uids[i])) {
- l++;
- break;
- } else {
- temp = "b";
- tempsql1 =
- "insert into userdepar (userid,deparid) values (" +
- uids[i] + ",'" + dep + "')";
- //System.out.println(tempsql1);
- dbc.executeUpdate(tempsql1);
- temping = "";
- temping = udsql1 + "'"+uids[i]+"'";
- dbc.executeUpdate(temping);
- //System.out.println("dd" + ids[i]);
- break;
- }
- }
- }
- if (l <= i && l == h) {
- if (uids[i] != null) {
- if (temp.equals("a")) {
- tempsql1 =
- "insert into userdepar (userid,deparid) values (" +
- uids[i] + ",'" + dep + "')";
- //System.out.println(tempsql1);
- dbc.executeUpdate(tempsql1);
- temping = "";
- temping = udsql1 + "'"+uids[i]+"'";
- dbc.executeUpdate(temping);
- //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 userdepar where deparid = " +
- dep + " and userid =" + checkInfo[i][0];
- //System.out.println(tempsql2);
- dbc.executeUpdate(tempsql2);
- udsql0 = udsql0 + "'"+uids[i]+"'";
- dbc.executeUpdate(udsql0);
- //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 userdepar where deparid = " +
- dep + " and userid =" + checkInfo[i][0];
- //System.out.println(tempsql2);
- udsql0 = udsql0 + "'"+uids[i]+"'";
- dbc.executeUpdate(udsql0);
- dbc.executeUpdate(tempsql2);
- //System.out.println("ttt" + checkInfo[i][0]);
- }
- }
- }
- }else{
- String[] un = new String[jj];
- String temp = "emp";
- for (int i = 0; i < jj; i++) {
- un[i] = request.getParameter("un" + i);
- if (un[i] != null) {
- temp = "notemp";
- String acheck =
- "select * from userdepar where deparid=" +
- dep + " and userid = " + un[i];
- //System.out.println(acheck);
- String[][] check = dbc.getArray(acheck);
- if (check == null) {
- String asql =
- "insert into userdepar (deparid,userid) values (" +
- dep + "," + un[i] + ")";
- //System.out.println(asql);
- temping = "";
- temping = udsql1 + "'" + uids[i] + "'";
- dbc.executeUpdate(temping);
- dbc.executeUpdate(asql);
- } else {
- request.setAttribute("msg", "用户已经添加,请不要重复添加!");
- }
- }
- }
- if (temp.equals("emp")) {
- request.setAttribute("msg", "用户名不能为空!");
- return mapping.findForward("succ");
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- request.setAttribute("msg", "修改成功!");
- return mapping.findForward("succ");
- }
- }