Example #1
0
        //获取未被克隆的品牌列表
        public List <BrandByMainCom> GetBrandByMainComList(int PageIndex, int PageSize, out int TotalRecord, string Keyword)
        {
            //获取所有未被克隆的品牌
            var query = (from x in db.Material
                         where true
                         &&
                         Keyword == string.Empty ? true : x.MatBrand.Contains(Keyword)
                         &&
                         x.MatBrandID != Guid.Empty
                         &&
                         x.IsClone <= 0
                         group x by x.MatBrandID into g
                         select new {
                BrandID = g.Key,
                ProCount = g.Count(),
                ProIsPriceCount = g.Where(c => c.CostPrice > 0).Count()
            }).AsQueryable();

            TotalRecord = query.Count();

            List <BrandByMainCom> BML = new List <BrandByMainCom>();
            BrandByMainCom        BM  = new BrandByMainCom();
            Brand B = new Brand();

            foreach (var x in query.OrderByDescending(s => s.ProCount).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList())
            {
                B = db.Brand.Find(x.BrandID);

                if (B != null)
                {
                    BM                 = new BrandByMainCom();
                    BM.BID             = B.BID;
                    BM.BrandName       = B.BrandName;
                    BM.BrandType       = B.BrandType;
                    BM.ProCount        = x.ProCount;
                    BM.ProIsPriceCount = x.ProIsPriceCount;
                    BM.FromType        = "分销商";
                    BM.LinkMainCID     = B.LinkMainCID;
                    BM.LinkMainComName = string.Empty;
                    BML.Add(BM);
                }
            }


            MainCompany MCom = new MainCompany();

            foreach (var x in BML.GroupBy(x => x.LinkMainCID).Select(x => x.Key))
            {
                MCom = db.MainCompany.Find(x);
                if (MCom != null)
                {
                    foreach (var xx in BML.Where(c => c.LinkMainCID == x).ToList())
                    {
                        xx.LinkMainComName = MCom.MainCompanyName;
                    }
                }
            }
            return(BML);
        }
        //获取未被克隆的品牌列表
        public List<BrandByMainCom> GetBrandByMainComList(int PageIndex, int PageSize, out int TotalRecord, string Keyword)
        {
            //获取所有未被克隆的品牌
            var query = (from x in db.Material
                         where true
                         &&
                         Keyword == string.Empty ? true : x.MatBrand.Contains(Keyword)
                         &&
                         x.MatBrandID != Guid.Empty
                         &&
                         x.IsClone <= 0
                         group x by x.MatBrandID into g
                         select new {
                             BrandID = g.Key,
                             ProCount = g.Count(),
                             ProIsPriceCount = g.Where(c=>c.CostPrice > 0).Count()
                         }).AsQueryable();

            TotalRecord = query.Count();

            List<BrandByMainCom> BML = new List<BrandByMainCom>();
            BrandByMainCom BM = new BrandByMainCom();
            Brand B = new Brand();
            foreach (var x in query.OrderByDescending(s => s.ProCount).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList())
            {
                B = db.Brand.Find(x.BrandID);

                if (B != null)
                {
                    BM = new BrandByMainCom();
                    BM.BID = B.BID;
                    BM.BrandName = B.BrandName;
                    BM.BrandType = B.BrandType;
                    BM.ProCount = x.ProCount;
                    BM.ProIsPriceCount = x.ProIsPriceCount;
                    BM.FromType = "分销商";
                    BM.LinkMainCID = B.LinkMainCID;
                    BM.LinkMainComName = string.Empty;
                    BML.Add(BM);
                }
            }

            MainCompany MCom = new MainCompany();
            foreach(var x in BML.GroupBy(x=>x.LinkMainCID).Select(x=>x.Key))
            {
                MCom = db.MainCompany.Find(x);
                if(MCom != null)
                {
                    foreach (var xx in BML.Where(c => c.LinkMainCID == x).ToList())
                    {
                        xx.LinkMainComName = MCom.MainCompanyName;
                    }
                }
            }
            return BML;
        }