Beispiel #1
0
        /// <summary>
        /// 设置用户部门(单个用户)
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="depIds">部门id,多个用逗号隔开</param>
        public bool SetDepartmentSingle(int userId, string depIds)
        {
            DataTable dt_user_dep_old = new ZGZY.BLL.Department().GetDepartmentByUserId(userId);      //用户之前拥有的部门
            List <ZGZY.Model.UserDepartment> dep_addList    = new List <ZGZY.Model.UserDepartment>(); //需要插入部门的sql语句集合
            List <ZGZY.Model.UserDepartment> dep_deleteList = new List <ZGZY.Model.UserDepartment>(); //需要删除部门的sql语句集合

            string[] str_dep = depIds.Trim(',').Split(',');                                           //传过来用户勾选的部门(有去勾的也有新勾选的)

            ZGZY.Model.UserDepartment userdepdelete = null;
            ZGZY.Model.UserDepartment userdepadd    = null;
            for (int i = 0; i < dt_user_dep_old.Rows.Count; i++)
            {
                //等于-1说明用户去掉勾选了某个部门 需要删除
                if (Array.IndexOf(str_dep, dt_user_dep_old.Rows[i]["departmentid"].ToString()) == -1)
                {
                    userdepdelete = new ZGZY.Model.UserDepartment();
                    userdepdelete.DepartmentId = Convert.ToInt32(dt_user_dep_old.Rows[i]["departmentid"].ToString());
                    userdepdelete.UserId       = userId;
                    dep_deleteList.Add(userdepdelete);
                }
            }

            if (!string.IsNullOrEmpty(depIds))
            {
                for (int j = 0; j < str_dep.Length; j++)
                {
                    //等于0那么原来的部门没有 是用户新勾选的
                    if (dt_user_dep_old.Select("departmentid = '" + str_dep[j] + "'").Length == 0)
                    {
                        userdepadd              = new ZGZY.Model.UserDepartment();
                        userdepadd.UserId       = userId;
                        userdepadd.DepartmentId = Convert.ToInt32(str_dep[j]);
                        dep_addList.Add(userdepadd);
                    }
                }
            }
            if (dep_addList.Count == 0 && dep_deleteList.Count == 0)
            {
                return(true);
            }
            else
            {
                return(dal.SetDepartmentSingle(dep_addList, dep_deleteList));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="columns">要取的列名(逗号分开)</param>
        /// <param name="order">排序</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="where">查询条件</param>
        /// <param name="totalCount">总记录数</param>
        public string GetPager(string tableName, string columns, string order, int pageSize, int pageIndex, string where, out int totalCount)
        {
            DataTable dt = ZGZY.Common.SqlPagerHelper.GetPager(tableName, columns, order, pageSize, pageIndex, where, out totalCount);

            dt.Columns.Add(new DataColumn("UserRoleId"));
            dt.Columns.Add(new DataColumn("UserRole"));
            dt.Columns.Add(new DataColumn("UserDepartmentId"));
            dt.Columns.Add(new DataColumn("UserDepartment"));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //这么写多连了20*2次数据库,待改进
                DataTable dtrole       = new ZGZY.BLL.Role().GetRoleByUserId(Convert.ToInt32(dt.Rows[i]["Id"]));
                DataTable dtdepartment = new ZGZY.BLL.Department().GetDepartmentByUserId(Convert.ToInt32(dt.Rows[i]["Id"]));
                dt.Rows[i]["UserRoleId"]       = ZGZY.Common.JsonHelper.ColumnToJson(dtrole, 0);
                dt.Rows[i]["UserRole"]         = ZGZY.Common.JsonHelper.ColumnToJson(dtrole, 1);
                dt.Rows[i]["UserDepartmentId"] = ZGZY.Common.JsonHelper.ColumnToJson(dtdepartment, 0);
                dt.Rows[i]["UserDepartment"]   = ZGZY.Common.JsonHelper.ColumnToJson(dtdepartment, 1);
            }
            return(ZGZY.Common.JsonHelper.ToJson(dt));
        }
Beispiel #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string action = context.Request.Params["action"];

            ZGZY.Model.UserOperateLog userOperateLog = null;   //操作日志对象
            try
            {
                ZGZY.Model.User user = ZGZY.Common.UserHelper.GetUser(context);   //获取cookie里的用户对象
                userOperateLog          = new Model.UserOperateLog();
                userOperateLog.UserIp   = context.Request.UserHostAddress;
                userOperateLog.UserName = user.UserId;
                switch (action)
                {
                case "getall":
                    context.Response.Write(new ZGZY.BLL.Department().GetAllDepartment("1=1"));
                    break;

                case "search":
                    string strJson = new ZGZY.BLL.Department().GetAllDepartment(null);
                    context.Response.Write(strJson);
                    userOperateLog.OperateInfo = "查询部门";
                    userOperateLog.IfSuccess   = true;
                    userOperateLog.Description = "查询条件:1=1";
                    ZGZY.BLL.UserOperateLog.InsertOperateInfo(userOperateLog);
                    break;

                case "searchDepartmentUser":
                    string userDepartmentIds       = context.Request.Params["departmentId"];
                    string sortDepartmentUser      = context.Request.Params["sort"];  //排序列
                    string orderDepartmentUser     = context.Request.Params["order"]; //排序方式 asc或者desc
                    int    pageindexDepartmentUser = int.Parse(context.Request.Params["page"]);
                    int    pagesizeDepartmentUser  = int.Parse(context.Request.Params["rows"]);

                    string strJsonDepartmentUser = new ZGZY.BLL.Department().GetPagerDepartmentUser(userDepartmentIds, sortDepartmentUser + " " + orderDepartmentUser, pagesizeDepartmentUser, pageindexDepartmentUser);
                    context.Response.Write(strJsonDepartmentUser);
                    userOperateLog.OperateInfo = "查询部门用户";
                    userOperateLog.IfSuccess   = true;
                    userOperateLog.Description = "查询部门Id:" + userDepartmentIds + " 排序:" + sortDepartmentUser + " " + orderDepartmentUser + " 页码/每页大小:" + pageindexDepartmentUser + " " + pagesizeDepartmentUser;
                    ZGZY.BLL.UserOperateLog.InsertOperateInfo(userOperateLog);
                    break;

                case "add":
                    if (user != null && new ZGZY.BLL.Authority().IfAuthority("department", "add", user.Id))
                    {
                        ZGZY.Model.Department departmentAdd = new Model.Department();
                        departmentAdd.DepartmentName = context.Request.Params["ui_department_departmentname_add"] ?? "";
                        departmentAdd.Sort           = Convert.ToInt32(context.Request.Params["ui_department_sort_add"]);
                        if (context.Request.Params["ui_department_parentid_add"] != null && context.Request.Params["ui_department_parentid_add"] != "")
                        {
                            departmentAdd.ParentId = Convert.ToInt32(context.Request.Params["ui_department_parentid_add"]);
                        }
                        else
                        {
                            departmentAdd.ParentId = 0;       //根节点
                        }
                        int departmentId = new ZGZY.BLL.Department().AddDepartment(departmentAdd);
                        if (departmentId > 0)
                        {
                            userOperateLog.OperateInfo = "添加部门";
                            userOperateLog.IfSuccess   = true;
                            userOperateLog.Description = "添加成功,部门主键:" + departmentId;
                            context.Response.Write("{\"msg\":\"添加成功!\",\"success\":true}");
                        }
                        else
                        {
                            userOperateLog.OperateInfo = "添加部门";
                            userOperateLog.IfSuccess   = false;
                            userOperateLog.Description = "添加失败";
                            context.Response.Write("{\"msg\":\"添加失败!\",\"success\":false}");
                        }
                    }
                    else
                    {
                        userOperateLog.OperateInfo = "添加部门";
                        userOperateLog.IfSuccess   = false;
                        userOperateLog.Description = "无权限,请联系管理员";
                        context.Response.Write("{\"msg\":\"无权限,请联系管理员!\",\"success\":true}");
                    }
                    ZGZY.BLL.UserOperateLog.InsertOperateInfo(userOperateLog);
                    break;

                case "edit":
                    if (user != null && new ZGZY.BLL.Authority().IfAuthority("department", "edit", user.Id))
                    {
                        ZGZY.Model.Department departmentEdit = new Model.Department();
                        departmentEdit.Id             = Convert.ToInt32(context.Request.Params["id"]);
                        departmentEdit.DepartmentName = context.Request.Params["ui_department_departmentname_edit"] ?? "";
                        departmentEdit.Sort           = Convert.ToInt32(context.Request.Params["ui_department_sort_edit"]);

                        bool result = new ZGZY.BLL.Department().EditDepartment(departmentEdit);
                        if (result)
                        {
                            userOperateLog.OperateInfo = "修改部门";
                            userOperateLog.IfSuccess   = true;
                            userOperateLog.Description = "修改成功,部门主键:" + departmentEdit.Id;
                            context.Response.Write("{\"msg\":\"修改成功!\",\"success\":true}");
                        }
                        else
                        {
                            userOperateLog.OperateInfo = "修改部门";
                            userOperateLog.IfSuccess   = false;
                            userOperateLog.Description = "修改失败,部门主键:" + departmentEdit.Id;
                            context.Response.Write("{\"msg\":\"修改失败!\",\"success\":false}");
                        }
                    }
                    else
                    {
                        userOperateLog.OperateInfo = "修改部门";
                        userOperateLog.IfSuccess   = false;
                        userOperateLog.Description = "无权限,请联系管理员";
                        context.Response.Write("{\"msg\":\"无权限,请联系管理员!\",\"success\":false}");
                    }
                    ZGZY.BLL.UserOperateLog.InsertOperateInfo(userOperateLog);
                    break;

                case "delete":
                    if (user != null && new ZGZY.BLL.Authority().IfAuthority("department", "delete", user.Id))
                    {
                        string departmentIds = context.Request.Params["id"];
                        if (new ZGZY.BLL.Department().DeleteDepartment(departmentIds))
                        {
                            userOperateLog.OperateInfo = "删除部门";
                            userOperateLog.IfSuccess   = true;
                            userOperateLog.Description = "删除成功,部门主键:" + departmentIds;
                            context.Response.Write("{\"msg\":\"删除成功!\",\"success\":true}");
                        }
                        else
                        {
                            userOperateLog.OperateInfo = "删除部门";
                            userOperateLog.IfSuccess   = false;
                            userOperateLog.Description = "删除失败,部门主键:" + departmentIds;
                            context.Response.Write("{\"msg\":\"删除失败!\",\"success\":false}");
                        }
                    }
                    else
                    {
                        userOperateLog.OperateInfo = "删除部门";
                        userOperateLog.IfSuccess   = false;
                        userOperateLog.Description = "无权限,请联系管理员";
                        context.Response.Write("{\"msg\":\"无权限,请联系管理员!\",\"success\":false}");
                    }
                    ZGZY.BLL.UserOperateLog.InsertOperateInfo(userOperateLog);
                    break;

                default:
                    context.Response.Write("{\"msg\":\"参数错误!\",\"success\":false}");
                    break;
                }
            }
            catch (Exception ex)
            {
                context.Response.Write("{\"msg\":\"" + ZGZY.Common.JsonHelper.StringFilter(ex.Message) + "\",\"success\":false}");
                userOperateLog.OperateInfo = "部门功能异常";
                userOperateLog.IfSuccess   = false;
                userOperateLog.Description = ZGZY.Common.JsonHelper.StringFilter(ex.Message);
                ZGZY.BLL.UserOperateLog.InsertOperateInfo(userOperateLog);
            }
        }