private string GetRoleId(Button btnRole) { string returnValue = string.Empty; BaseRoleManager roleManager = new BaseRoleManager(this.UserInfo); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldOrganizeId, this.EntityId)); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldCategoryCode, "Duty")); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, btnRole.Name.Substring(3).Replace("Delete", ""))); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldDeletionStateCode, 0)); returnValue = roleManager.GetProperty(parameters, BaseRoleEntity.FieldId); btnRole.Tag = returnValue; return(returnValue); }
////////////////////////////////////////////////////////////////////////////////////////////////////// /// 用户权限判断相关(需要实现对外调用) ////////////////////////////////////////////////////////////////////////////////////////////////////// #region public bool IsInRole(BaseUserInfo userInfo, string userId, string roleName) /// <summary> /// 用户是否在指定的角色里 /// </summary> /// <param name="userInfo">用户</param> /// <param name="UserId">用户主键</param> /// <param name="roleName">角色名称</param> /// <returns>在角色里</returns> public bool IsInRole(BaseUserInfo userInfo, string userId, string roleName) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif bool returnValue = false; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // 先获得角色主键 BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); string roleCode = roleManager.GetProperty(new KeyValuePair <string, object>(BaseRoleEntity.FieldRealName, roleName), BaseRoleEntity.FieldCode); // 判断用户的默认角色 if (!string.IsNullOrEmpty(roleCode)) { BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); returnValue = userManager.IsInRoleByCode(userId, roleCode); } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_IsInRole, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }