//
        // 授予权限的实现部分
        //

        #region private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="Id">主键</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId)
        {
            string returnValue = string.Empty;
            BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();

            resourcePermissionEntity.ResourceCategory = BaseUserEntity.TableName;
            resourcePermissionEntity.ResourceId       = userId;
            resourcePermissionEntity.PermissionId     = int.Parse(permissionItemId);
            resourcePermissionEntity.Enabled          = 1;
            return(permissionManager.Add(resourcePermissionEntity));
        }
        //
        // 授予权限的实现部分
        //

        #region private string Grant(BasePermissionManager permissionManager, string id, string roleId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="Id">主键</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(BasePermissionManager permissionManager, string roleId, string permissionItemId)
        {
            string returnValue = string.Empty;
            BasePermissionEntity resourcePermission = new BasePermissionEntity();

            resourcePermission.ResourceCategory = BaseRoleEntity.TableName;
            resourcePermission.ResourceId       = roleId;
            resourcePermission.PermissionId     = int.Parse(permissionItemId);
            // 防止不允许为NULL的错误发生
            resourcePermission.Enabled = 1;
            return(permissionManager.Add(resourcePermission));
        }
 /// <summary>
 /// 为了提高授权的运行速度
 /// </summary>
 /// <param name="permissionManager">资源权限读写器</param>
 /// <param name="Id">主键</param>
 /// <param name="userId">用户主键</param>
 /// <param name="permissionItemId">权限主键</param>
 /// <returns>主键</returns>
 private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId)
 {
     string returnValue = string.Empty;
     BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();
     resourcePermissionEntity.ResourceCategory = BaseUserEntity.TableName;
     resourcePermissionEntity.ResourceId = userId;
     resourcePermissionEntity.PermissionId = int.Parse(permissionItemId);
     resourcePermissionEntity.Enabled = 1;
     return permissionManager.Add(resourcePermissionEntity);
 }
        /// <summary>
        /// 授予资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="grantPermissionItemIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int GrantResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] grantPermissionItemIds)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseRoleScopeManager roleScopeManager = new BaseRoleScopeManager(dbHelper, userInfo);
                    // 小心异常,检查一下参数的有效性
                    if (grantPermissionItemIds != null)
                    {
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                        for (int i = 0; i < grantPermissionItemIds.Length; i++)
                        {
                            BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();
                            resourcePermissionEntity.ResourceCategory = resourceCategory;
                            resourcePermissionEntity.ResourceId = resourceId;
                            resourcePermissionEntity.PermissionId = int.Parse(grantPermissionItemIds[i]);
                            resourcePermissionEntity.Enabled = 1;
                            resourcePermissionEntity.DeletionStateCode = 0;
                            permissionManager.Add(resourcePermissionEntity);
                            returnValue++;
                        }
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GrantResourcePermission, 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;
        }
 /// <summary>
 /// 为了提高授权的运行速度
 /// </summary>
 /// <param name="permissionManager">资源权限读写器</param>
 /// <param name="Id">主键</param>
 /// <param name="roleId">角色主键</param>
 /// <param name="permissionItemId">权限主键</param>
 /// <returns>主键</returns>
 private string Grant(BasePermissionManager permissionManager, string roleId, string permissionItemId)
 {
     string returnValue = string.Empty;
     BasePermissionEntity resourcePermission = new BasePermissionEntity();
     resourcePermission.ResourceCategory = BaseRoleEntity.TableName;
     resourcePermission.ResourceId = roleId;
     resourcePermission.PermissionId = int.Parse(permissionItemId);
     // 防止不允许为NULL的错误发生
     resourcePermission.Enabled = 1;
     return permissionManager.Add(resourcePermission);
 }