Exemple #1
0
        public int Add(string moduleId, string permissionItemId)
        {
            int returnValue = 0;

            string[] names  = new string[4];
            string[] values = new string[4];
            names[0]  = PiPermissionTable.FieldResourceCategory;
            values[0] = PiModuleTable.TableName;
            names[1]  = PiPermissionTable.FieldResourceId;
            values[1] = moduleId;
            names[2]  = PiPermissionTable.FieldPermissionId;
            values[2] = permissionItemId;
            names[3]  = PiPermissionTable.FieldDeleteMark;
            values[3] = "0";
            // 检查记录是否重复
            if (!this.Exists(names, values))
            {
                PiPermissionEntity permissionEntity = new PiPermissionEntity
                {
                    ResourceId       = moduleId,
                    ResourceCategory = PiModuleTable.TableName,
                    Enabled          = 1,
                    DeleteMark       = 0,
                    PermissionId     = permissionItemId
                };
                PiPermissionManager permissionManager = new PiPermissionManager(this.DBProvider, this.UserInfo);
                permissionManager.AddEntity(permissionEntity);
                returnValue++;
            }
            return(returnValue);
        }
Exemple #2
0
        /// <summary>
        /// 授予资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="grantPermissionItemIds">操作权限主键</param>
        /// <returns>影响的行数</returns>
        public int GrantResourcePermission(UserInfo userInfo, string resourceCategory, string resourceId, string[] grantPermissionItemIds)
        {
            var returnValue = 0;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.PermissionService_GrantResourcePermission);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                if (grantPermissionItemIds != null)
                {
                    var permissionManager = new PiPermissionManager(dbProvider, userInfo);
                    for (int i = 0; i < grantPermissionItemIds.Length; i++)
                    {
                        var resourcePermissionEntity = new PiPermissionEntity
                        {
                            ResourceCategory = resourceCategory,
                            ResourceId       = resourceId,
                            PermissionId     = grantPermissionItemIds[i],
                            Enabled          = 1,
                            DeleteMark       = 0
                        };
                        permissionManager.Add(resourcePermissionEntity);
                        returnValue++;
                    }
                }
            });
            return(returnValue);
        }
Exemple #3
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">SQL语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, PiPermissionEntity entity)
 {
     sqlBuilder.SetValue(PiPermissionTable.FieldResourceId, entity.ResourceId);
     sqlBuilder.SetValue(PiPermissionTable.FieldResourceCategory, entity.ResourceCategory);
     sqlBuilder.SetValue(PiPermissionTable.FieldPermissionId, entity.PermissionId);
     sqlBuilder.SetValue(PiPermissionTable.FieldPermissionConstraint, entity.PermissionConstraint);
     sqlBuilder.SetValue(PiPermissionTable.FieldEnabled, entity.Enabled);
     sqlBuilder.SetValue(PiPermissionTable.FieldDeleteMark, entity.DeleteMark);
     sqlBuilder.SetValue(PiPermissionTable.FieldDescription, entity.Description);
 }
Exemple #4
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>主键</returns>
        public string AddPermission(PiPermissionEntity entity)
        {
            var returnValue = string.Empty;

            // 检查记录是否重复
            if (!this.PermissionExists(entity.PermissionId.ToString(), entity.ResourceCategory, entity.ResourceId.ToString()))
            {
                returnValue = this.AddEntity(entity);
            }
            return(returnValue);
        }
        //
        // 授予权限的实现部分
        //

        #region private string Grant(PiPermissionManager permissionManager, string organizeId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(PiPermissionManager permissionManager, string organizeId, string permissionItemId)
        {
            string             returnValue        = string.Empty;
            PiPermissionEntity resourcePermission = new PiPermissionEntity
            {
                ResourceCategory = PiOrganizeTable.TableName,
                ResourceId       = organizeId,
                PermissionId     = permissionItemId,
                Enabled          = 1
            };

            // 防止不允许为NULL的错误发生
            return(permissionManager.Add(resourcePermission));
        }
Exemple #6
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateEntity(PiPermissionEntity entity)
        {
            var sqlBuilder = new SQLBuilder(DBProvider);

            sqlBuilder.BeginUpdate(PiPermissionTable.TableName);
            this.SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiPermissionTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiPermissionTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiPermissionTable.FieldModifiedOn);
            sqlBuilder.SetWhere(PiPermissionTable.FieldId, entity.Id);
            return(sqlBuilder.EndUpdate());
        }
Exemple #7
0
        //
        // 授予权限的实现部分
        //

        #region private string Grant(PiPermissionManager 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(PiPermissionManager permissionManager, string id, string userId, string permissionItemId)
        {
            string             returnValue = string.Empty;
            PiPermissionEntity resourcePermissionEntity = new PiPermissionEntity
            {
                ResourceCategory = PiUserTable.TableName,
                ResourceId       = userId,
                PermissionId     = permissionItemId,
                Enabled          = 1
            };

            //存在相同的就不要再次重复授予了,以免产生垃圾数据
            if (!this.Exists(new string[] { PiPermissionTable.FieldResourceCategory, PiPermissionTable.FieldResourceId, PiPermissionTable.FieldPermissionId, PiPermissionTable.FieldDeleteMark },
                             new object[] { PiUserTable.TableName, userId, permissionItemId, 0 }))
            {
                returnValue = permissionManager.Add(resourcePermissionEntity);
            }
            return(returnValue);
        }
Exemple #8
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddEntity(PiPermissionEntity entity)
        {
            var sequence = string.Empty;

            this.Identity = false;
            var sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(PiPermissionTable.TableName, PiPermissionTable.FieldId);
            if (!this.Identity)
            {
                if (string.IsNullOrEmpty(entity.Id))
                {
                    sequence  = BusinessLogic.NewGuid();
                    entity.Id = sequence;
                }
                sqlBuilder.SetValue(PiPermissionTable.FieldId, entity.Id);
            }
            else
            {
                if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DBProvider.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(PiPermissionTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DBProvider.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(PiPermissionTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (entity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                var sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                                sequence = sequenceManager.GetSequence(this.CurrentTableName);
                            }
                            entity.Id = sequence;
                        }
                        sqlBuilder.SetValue(PiPermissionTable.FieldId, entity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiPermissionTable.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiPermissionTable.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiPermissionTable.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(PiPermissionTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(PiPermissionTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(PiPermissionTable.FieldModifiedOn);
            if (DBProvider.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
Exemple #9
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(PiPermissionEntity entity)
 {
     return(this.UpdateEntity(entity));
 }
Exemple #10
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(PiPermissionEntity entity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddEntity(entity));
 }
Exemple #11
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>主键</returns>
 public string Add(PiPermissionEntity entity)
 {
     return(this.AddEntity(entity));
 }