/// <summary> /// 获取用户的角色列表 /// </summary> /// <param name="userInfo">用户</param> /// <returns>数据表</returns> public DataTable GetRoleDT(BaseUserInfo userInfo) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif DataTable dataTable = new DataTable(BaseRoleEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldDeletionStateCode, 0)); BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); // 获取有效的,未必删除的数据,按排序码排序 dataTable = roleManager.GetDataTable(parameters, BaseRoleEntity.FieldSortCode); // 不是超级管理员,不能添加超级管理员 if (!userInfo.IsAdministrator) { foreach (DataRow dataRow in dataTable.Rows) { if (dataRow[BaseRoleEntity.FieldCode].ToString().Equals(DefaultRole.Administrators.ToString())) { dataRow.Delete(); } } dataTable.AcceptChanges(); } dataTable.TableName = BaseUserEntity.TableName; dataTable.DefaultView.Sort = BaseUserEntity.FieldSortCode; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.UserService_GetRoleDT, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }
/// <summary> /// 按某个权限域获取角色列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <param name="permissionItemCode">数据权限编号</param> /// <returns>数据表</returns> public DataTable GetRoleDTByPermissionScope(BaseUserInfo userInfo, string userId, string permissionItemCode) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseRoleEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // 若权限是空的,直接返回所有数据 if (userInfo.IsAdministrator || String.IsNullOrEmpty(permissionItemCode)) { // 获得角色列表 BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldIsVisible, 1)); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldDeletionStateCode, 0)); dataTable = roleManager.GetDataTable(parameters, BaseRoleEntity.FieldSortCode); } else { // 获得组织机构列表 BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo); dataTable = permissionScopeManager.GetRoleDT(userInfo.Id, permissionItemCode); } dataTable.TableName = BaseRoleEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GetRoleDTByPermission, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }
/// <summary> /// 获取角色列表 /// </summary> /// <param name="userInfo">用户</param> /// <returns>数据表</returns> public DataTable GetDataTable(BaseUserInfo userInfo) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif DataTable dataTable = new DataTable(BaseRoleEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string tableName = BaseRoleEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "Role"; } // 获得角色列表 BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo, tableName); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldDeletionStateCode, 0)); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldIsVisible, 1)); dataTable = roleManager.GetDataTable(parameters, BaseRoleEntity.FieldSortCode); dataTable.TableName = BaseRoleEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.RoleService_GetDataTable, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }
/// <summary> /// 按主键数组获取列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="ids">角色主键</param> /// <returns>数据表</returns> public DataTable GetDataTableByIds(BaseUserInfo userInfo, string[] ids) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseRoleEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string tableName = BaseRoleEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "Role"; } BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo, tableName); dataTable = roleManager.GetDataTable(BaseRoleEntity.FieldId, ids, BaseRoleEntity.FieldSortCode); dataTable.TableName = BaseRoleEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.RoleService_GetDataTableByIds, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }