Ejemplo n.º 1
0
        /// <summary>
        /// 根据部门查询用户分页列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="permissionScopeCode">权限代码</param>
        /// <param name="searchValue">查询</param>
        /// <param name="enabled">有效</param>
        /// <param name="auditStates">审核状态</param>
        /// <param name="roleIds">用户角色</param>
        /// <param name="showRole">是否显示角色信息</param>
        /// <param name="departmentId">部门主键</param>
        /// <returns></returns>
        public DataTable GetUserPageDTByDepartment(UserInfo userInfo, string permissionScopeCode, string searchValue, bool?enabled, string auditStates, string[] roleIds, bool showRole, bool userAllInformation, out int recordCount, int pageIndex = 0, int pageSize = 100, string sort = null, string departmentId = null)
        {
            if (departmentId == null)
            {
                departmentId = string.Empty;
            }
            var parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_Search);
            int myrecordCount = 0;
            var dt            = new DataTable(PiUserTable.TableName);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, (dbProvider) =>
            {
                var userManager = new PiUserManager(dbProvider, userInfo);
                dt           = userManager.SearchByPage(permissionScopeCode, searchValue, roleIds, enabled, auditStates, departmentId, showRole, userAllInformation, out myrecordCount, pageIndex, pageSize, sort);
                dt.TableName = PiUserTable.TableName;
                // 是否显示角色信息
                if (showRole)
                {
                    // 这里是获取角色列表
                    PiRoleManager roleManager = new PiRoleManager(dbProvider, userInfo);
                    DataTable dataTableRole   = roleManager.GetDT();
                    if (!dt.Columns.Contains("RoleName"))
                    {
                        dt.Columns.Add("RoleName");
                    }
                    // 友善的显示属于多个角色的功能
                    string roleName = string.Empty;
                    foreach (DataRow dr in dt.Rows)
                    {
                        roleName = string.Empty;
                        // 获取所在角色
                        roleIds = userManager.GetRoleIds(dr[PiUserTable.FieldId].ToString());
                        if (roleIds != null)
                        {
                            for (int i = 0; i < roleIds.Length; i++)
                            {
                                roleName = roleName + BusinessLogic.GetProperty(dataTableRole, roleIds[i], PiRoleTable.FieldRealName) + ", ";
                            }
                        }
                        // 设置角色的名称
                        if (!string.IsNullOrEmpty(roleName))
                        {
                            roleName       = roleName.Substring(0, roleName.Length - 2);
                            dr["RoleName"] = roleName;
                        }
                    }
                    dt.AcceptChanges();
                }
            });
            recordCount = myrecordCount;
            return(dt);
        }