Пример #1
0
        /// <summary>
        /// 获取数据权限列表
        /// </summary>
        /// <param name="objectId">对象Id</param>
        /// <returns></returns>
        public IEnumerable <AuthorizeDataEntity> GetAuthorizeDataList(string objectId)
        {
            var sql = PetaPoco.Sql.Builder.Append(@"select * from Base_AuthorizeData where 1=1");

            if (!string.IsNullOrEmpty(objectId))
            {
                sql.Append(" and ObjectId=@0", objectId);
            }
            sql.Append(" order by SortCode");
            var list = Base_AuthorizeDatum.Query(sql);

            return(EntityConvertTools.CopyToList <Base_AuthorizeDatum, AuthorizeDataEntity>(list.ToList()));
        }
Пример #2
0
        /// <summary>
        /// 添加授权
        /// </summary>
        /// <param name="authorizeType">权限分类</param>
        /// <param name="objectId">对象Id</param>
        /// <param name="moduleIds">功能Id</param>
        /// <param name="moduleButtonIds">按钮Id</param>
        /// <param name="moduleColumnIds">视图Id</param>
        /// <param name="authorizeDataList">数据权限</param>
        public void SaveAuthorize(AuthorizeTypeEnum authorizeType, string objectId, string[] moduleIds, string[] moduleButtonIds, string[] moduleColumnIds, IEnumerable <AuthorizeDataEntity> authorizeDataList)
        {
            try
            {
                using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction())
                {
                    //删除授权
                    Base_Authorize.Delete("where ObjectId=@0", objectId);

                    #region 功能
                    int SortCode = 1;
                    foreach (string item in moduleIds)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = (int)authorizeType;
                        authorizeEntity.ObjectId = objectId;
                        authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.菜单;
                        authorizeEntity.ItemId   = item;
                        authorizeEntity.SortCode = SortCode++;
                        Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null);
                        authorize.Insert();
                    }
                    #endregion

                    #region  钮
                    SortCode = 1;
                    foreach (string item in moduleButtonIds)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = (int)authorizeType;
                        authorizeEntity.ObjectId = objectId;
                        authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.钮;
                        authorizeEntity.ItemId   = item;
                        authorizeEntity.SortCode = SortCode++;
                        Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null);
                        authorize.Insert();
                    }
                    #endregion

                    #region 视图
                    SortCode = 1;
                    foreach (string item in moduleColumnIds)
                    {
                        AuthorizeEntity authorizeEntity = new AuthorizeEntity();
                        authorizeEntity.Create();
                        authorizeEntity.Category = (int)authorizeType;
                        authorizeEntity.ObjectId = objectId;
                        authorizeEntity.ItemType = (int)Enums.FormElementTypeEnum.视图;
                        authorizeEntity.ItemId   = item;
                        authorizeEntity.SortCode = SortCode++;
                        Base_Authorize authorize = EntityConvertTools.CopyToModel <AuthorizeEntity, Base_Authorize>(authorizeEntity, null);
                        authorize.Insert();
                    }
                    #endregion

                    #region 数据权限
                    SortCode = 1;
                    Base_AuthorizeDatum.Delete("where objectId=@0", objectId);
                    int index = 0;
                    foreach (AuthorizeDataEntity authorizeDataEntity in authorizeDataList)
                    {
                        authorizeDataEntity.Create();
                        authorizeDataEntity.Category = (int)authorizeType;
                        authorizeDataEntity.ObjectId = objectId;
                        authorizeDataEntity.SortCode = SortCode++;
                        Base_AuthorizeDatum authorizedata = EntityConvertTools.CopyToModel <AuthorizeDataEntity, Base_AuthorizeDatum>(authorizeDataEntity, null);
                        authorizedata.Insert();
                        index++;
                    }
                    #endregion
                    tran.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }