/// <summary>
        /// 查询根节点
        /// </summary>
        /// <returns></returns>
        private ProductCategoryEntity GetRoot()
        {
            string Key = string.Format(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE, this.CompanyID);
            List <ProductCategoryEntity> listSource = GetList();

            if (listSource.IsNullOrEmpty())
            {
                ProductCategoryEntity entity = new ProductCategoryEntity();
                entity.SnNum      = ConvertHelper.NewGuid();
                entity.CateNum    = new TNumProvider(this.CompanyID).GetSwiftNum(typeof(ProductCategoryEntity), 5);
                entity.IsDelete   = (int)EIsDelete.NotDelete;
                entity.CreateTime = DateTime.Now;
                entity.CateName   = "Root";
                entity.ParentNum  = "";
                entity.CompanyID  = this.CompanyID;
                entity.Left       = 1;
                entity.Right      = 2;
                entity.IncludeAll();
                int line = this.ProductCategory.Add(entity);
                if (line > 0)
                {
                    CacheHelper.Remove(Key);
                }
            }
            listSource = GetList();

            ProductCategoryEntity result = listSource.First(item => item.ParentNum.IsEmpty());

            return(result);
        }
        /// <summary>
        /// 查询所有的产品类别
        /// </summary>
        /// <returns></returns>
        public List <ProductCategoryEntity> GetList()
        {
            string Key = string.Format(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE, this.CompanyID);

            List <ProductCategoryEntity> list = CacheHelper.Get(Key) as List <ProductCategoryEntity>;

            if (!list.IsNullOrEmpty())
            {
                return(list);
            }
            ProductCategoryEntity entity = new ProductCategoryEntity();

            entity.OrderBy(a => a.ID, EOrderBy.DESC);
            entity.IncludeAll();
            entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete)
            .And(a => a.CompanyID == this.CompanyID);
            list = this.ProductCategory.GetList(entity);
            if (!list.IsNullOrEmpty())
            {
                foreach (ProductCategoryEntity item in list)
                {
                    int depth = list.Where(a => a.Left <= item.Left && a.Right >= item.Right).Count();
                    item.Depth = depth;

                    if (item.ParentNum.IsNotEmpty())
                    {
                        ProductCategoryEntity parent = list.FirstOrDefault(a => a.SnNum == item.ParentNum);
                        item.ParentName = item != null && parent.CateName != "Root" ? parent.CateName : string.Empty;
                    }
                }
                CacheHelper.Insert(Key, list);
            }
            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// 添加产品类别
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Add(ProductCategoryEntity entity)
        {
            entity.IncludeAll();
            int line = this.ProductCategory.Add(entity);

            if (line > 0)
            {
                CacheHelper.Remove(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE);
            }
            return(line);
        }
Esempio n. 4
0
        /// <summary>
        /// 查询所有的产品类别
        /// </summary>
        /// <returns></returns>
        public List <ProductCategoryEntity> GetList()
        {
            List <ProductCategoryEntity> list = CacheHelper.Get(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE) as List <ProductCategoryEntity>;

            if (!list.IsNullOrEmpty())
            {
                return(list);
            }
            ProductCategoryEntity entity = new ProductCategoryEntity();

            entity.OrderBy(a => a.ID, EOrderBy.DESC);
            entity.IncludeAll();
            entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete);
            list = this.ProductCategory.GetList(entity);
            if (!list.IsNullOrEmpty())
            {
                CacheHelper.Insert(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE, list);
            }
            return(list);
        }
Esempio n. 5
0
        /// <summary>
        /// 查询产品类别分页
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="pageInfo"></param>
        /// <returns></returns>
        public List <ProductCategoryEntity> GetList(ProductCategoryEntity entity, ref PageInfo pageInfo)
        {
            entity.IncludeAll();
            entity.Where(a => a.IsDelete == (int)EIsDelete.NotDelete);
            entity.OrderBy(a => a.ID, EOrderBy.DESC);
            int rowCount = 0;
            List <ProductCategoryEntity> list = this.ProductCategory.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount);

            pageInfo.RowCount = rowCount;
            if (!list.IsNullOrEmpty())
            {
                AdminProvider adminProvider = new AdminProvider();
                foreach (ProductCategoryEntity item in list)
                {
                    if (!item.CreateUser.IsEmpty())
                    {
                        AdminEntity admin = adminProvider.GetAdmin(item.CreateUser);
                        item.CreateUser = admin.IsNotNull() ? admin.UserName : item.CreateUser;
                    }
                }
            }
            return(list);
        }
        /// <summary>
        /// 添加产品类别
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Add(ProductCategoryEntity entity)
        {
            string Key = string.Format(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE, this.CompanyID);
            List <ProductCategoryEntity> listSource = GetList();

            listSource = listSource.IsNull() ? new List <ProductCategoryEntity>() : listSource;
            if (entity.ParentNum.IsEmpty())
            {
                ProductCategoryEntity parent = GetRoot();
                entity.ParentNum = GetRoot().SnNum;
            }
            listSource = GetList();
            using (TransactionScope ts = new TransactionScope())
            {
                //查询新增节点的上一个节点
                ProductCategoryEntity parent = listSource.FirstOrDefault(item => item.SnNum == entity.ParentNum);
                int rightValue = parent.Right;

                List <ProductCategoryEntity> listNodes = listSource.Where(item => item.Right >= rightValue).ToList();
                if (!listNodes.IsNullOrEmpty())
                {
                    foreach (ProductCategoryEntity item in listNodes)
                    {
                        item.Right += 2;
                        item.IncludeRight(true);
                        item.Where(b => b.SnNum == item.SnNum).And(b => item.CompanyID == this.CompanyID);
                        this.ProductCategory.Update(item);
                    }
                }

                listNodes = listSource.Where(item => item.Left >= rightValue).ToList();
                if (!listNodes.IsNullOrEmpty())
                {
                    foreach (ProductCategoryEntity item in listNodes)
                    {
                        item.Left += 2;
                        item.IncludeLeft(true);
                        item.Where(b => b.SnNum == item.SnNum).And(b => item.CompanyID == this.CompanyID);
                        this.ProductCategory.Update(item);
                    }
                }

                entity.SnNum   = entity.SnNum.IsEmpty()? ConvertHelper.NewGuid():entity.SnNum;
                entity.CateNum = entity.CateNum.IsEmpty() ? new TNumProvider(CompanyID).GetSwiftNum(typeof(ProductCategoryEntity), 5) : entity.CateNum;

                entity.CompanyID  = this.CompanyID;
                entity.IsDelete   = (int)EIsDelete.NotDelete;
                entity.CreateTime = DateTime.Now;
                entity.Left       = rightValue;
                entity.Right      = rightValue + 1;
                entity.IncludeAll();

                int line = this.ProductCategory.Add(entity);
                if (line > 0)
                {
                    CacheHelper.Remove(Key);
                }
                ts.Complete();
                return(line);
            }
        }