public MaterialPageBySearchList FindMaterialPageBySearchListByQDT(int PageIndex, int PageSize, string Keyword, string MatBrand, Guid CatID, string IsStatUs) { var query = (from M in db.Material where true select M).AsQueryable(); //品牌判断 if (!string.IsNullOrEmpty(MatBrand)) { query = query.Where(m => m.MatBrand.Contains(MatBrand)).AsQueryable(); } ICategory ICat = new CategoryBase(); CatTree CT = ICat.GetCatTreeByQDT(); //分类判断 if (CatID != Guid.Empty) { if (CT.SecondCatTree.Where(c => c.CatID == CatID).Count() > 0) { query = query.Where(c => c.LinkQDTCatID == CatID).AsQueryable(); } } //发布 新品 置顶判断 if (IsStatUs == MatISNo.IsPublic.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.GroupToMatID == Guid.Empty).AsQueryable(); } else if (IsStatUs == MatISNo.IsNotPublic.ToString()) { query = query.Where(x => x.IsPublic == 0 && x.GroupToMatID == Guid.Empty).AsQueryable(); } else if (IsStatUs == MatISNo.IsTop.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.IsTop == 1 && x.GroupToMatID == Guid.Empty).AsQueryable(); } else if (IsStatUs == MatISNo.IsNotTop.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.IsTop == 0 && x.GroupToMatID == Guid.Empty).AsQueryable(); } else if (IsStatUs == MatISNo.IsNew.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.IsNew == 1 && x.GroupToMatID == Guid.Empty).AsQueryable(); } else if (IsStatUs == MatISNo.IsNotNew.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.IsNew == 0 && x.GroupToMatID == Guid.Empty).AsQueryable(); } else if (IsStatUs == MatISNo.IsPromotion.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.IsPromotion == 1 && x.IsGroupMat <= 0).AsQueryable(); } else if (IsStatUs == MatISNo.IsNotPromotion.ToString()) { query = query.Where(x => x.IsPublic == 1 && x.IsPromotion == 0 && x.IsGroupMat <= 0).AsQueryable(); } if (!string.IsNullOrEmpty(Keyword)) { Keyword = Regex.Replace(Keyword, @"( )\1+", "$1", RegexOptions.None); string[] KeywordStr = Keyword.Split(' '); foreach (var K in KeywordStr) { if (!string.IsNullOrEmpty(K)) { query = query.Where( m => m.MatSn.Contains(K) || m.MatBrand.Contains(K) || m.MatManufacturerSn.Contains(K) || m.MatSpecifications.Contains(K) || m.MatName.Contains(K) || m.KeywordIndex.Contains(K) ).AsQueryable(); } } } //获取以过滤的品牌项 var queryBrand = query.Where(x => x.MatBrandID != Guid.Empty).GroupBy(x => x.MatBrandID).Select(x => x.Key).AsQueryable(); List<P_Brand> PBL = new List<P_Brand>(); P_Brand PB = new P_Brand(); Brand B = new Brand(); foreach (var x in queryBrand) { B = db.Brand.Find(x); if (B != null) { PB = new P_Brand(); PB.BID = B.BID; PB.BrandName = B.BrandName; PB.BrandEnName = B.BrandNameEn; PB.BrandLogo = B.BrandLogo; PBL.Add(PB); }else{ PB = new P_Brand(); PB.BID = Guid.Empty; PB.BrandName = string.Empty; PB.BrandEnName = string.Empty; PB.BrandLogo = string.Empty; PBL.Add(PB); } } List<P_Brand> PBLNew = new List<P_Brand>(); var QueryBrandNew = from x in PBL where true && x.BID != Guid.Empty && x.BrandLogo != string.Empty && x.BrandName != string.Empty group x by x.BrandName into g select new { BID = g.FirstOrDefault().BID, BrandLogo = g.FirstOrDefault().BrandLogo, BrandName = g.FirstOrDefault().BrandName, BrandEnName = g.FirstOrDefault().BrandEnName, }; P_Brand NewB = new P_Brand(); foreach(var x in QueryBrandNew) { NewB = new P_Brand(); NewB.BID = x.BID; NewB.BrandLogo = x.BrandLogo; NewB.BrandEnName = x.BrandEnName; NewB.BrandName = x.BrandName; PBLNew.Add(NewB); } //获取以过滤分类项 var queryCat = from x in query where true && x.CategoryID != Guid.Empty && x.LinkQDTCatID != Guid.Empty group x by x.LinkQDTCatID into g select new { CID = g.Key, Count = g.Count() }; List<P_Cat> PCL = new List<P_Cat>(); P_Cat PC = new P_Cat(); Category Cat = new Category(); foreach (var x in queryCat) { PC = new P_Cat(); if (CT.SecondCatTree.Where(c => c.CatID == x.CID).Count() > 0) { PC.CatID = x.CID; PC.CatCount = x.Count; PC.CatName = CT.SecondCatTree.Where(c => c.CatID == x.CID).FirstOrDefault().CategoryName; PCL.Add(PC); } } List<Material> ML = query.OrderByDescending(s => s.LastUpdateTime).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); List<Material> SubGroupML = new List<Material>(); IBrand IB = new BrandBase(); string MaxPrice = string.Empty; string MinPrice = string.Empty; foreach (var x in ML) { x.MoreDetail = string.Empty; if (x.IsGroupMat > 0) { SubGroupML = this.GetMaterialByGroupMatID(Guid.Empty, x.MatID); x.LinkGroupMatCount = SubGroupML.Count(); try { MaxPrice = SubGroupML.Where(c => c.PriceInfo.SalesPrice > 0).Max(c => c.PriceInfo.SalesPrice).ToString("N"); MinPrice = SubGroupML.Where(c => c.PriceInfo.SalesPrice > 0).Min(c => c.PriceInfo.SalesPrice).ToString("N"); if (MaxPrice != MinPrice) { x.LinkGroupPrice = MinPrice + " ~ " + MaxPrice; } else { x.LinkGroupPrice = MinPrice; } } catch { x.LinkGroupPrice = string.Empty; } } } ML = IB.GetMatSalesPriceInfoList(ML, Guid.Empty); MaterialPageBySearchList MP = new MaterialPageBySearchList(); MP.PageIndex = PageIndex; MP.PageSize = PageSize; MP.TotalRecord = query.Count(); MP.Rows = ML; MP.Brand = PBLNew; MP.Cat = PCL; return MP; }
public MaterialPageBySearchList FindMaterialPageByIsGroupSearchList(int PageIndex, int PageSize, string Keyword, Guid LinkMainCID) { var query = (from M in db.Material where true && M.LinkMainCID.Equals(LinkMainCID) && M.IsGroupMat == 1 select M).AsQueryable(); if (!string.IsNullOrEmpty(Keyword)) { Keyword = Regex.Replace(Keyword, @"( )\1+", "$1", RegexOptions.None); string[] KeywordStr = Keyword.Split(' '); foreach (var K in KeywordStr) { if (!string.IsNullOrEmpty(K)) { query = query.Where( m => m.MatSn.Contains(K) || m.MatBrand.Contains(K) || m.MatManufacturerSn.Contains(K) || m.MatSpecifications.Contains(K) || m.MatName.Contains(K) || m.KeywordIndex.Contains(K) ).AsQueryable(); } } } //获取以过滤的品牌项 var queryBrand = query.Where(x => x.MatBrandID != Guid.Empty).GroupBy(x => x.MatBrandID).Select(x => x.Key).AsQueryable(); List<P_Brand> PBL = new List<P_Brand>(); P_Brand PB = new P_Brand(); Brand B = new Brand(); foreach (var x in queryBrand) { B = db.Brand.Find(x); if (B != null) { PB = new P_Brand(); PB.BID = B.BID; PB.BrandName = B.BrandName; PB.BrandEnName = B.BrandNameEn; PB.BrandLogo = B.BrandLogo; PBL.Add(PB); } } //获取以过滤分类项 var queryCat = from x in query where true && x.CategoryID != Guid.Empty group x by x.CategoryID into g select new { CID = g.Key, Count = g.Count() }; ICategory IC = new CategoryBase(); CatTree CT = IC.GetCatTree(LinkMainCID); List<P_Cat> PCL = new List<P_Cat>(); P_Cat PC = new P_Cat(); Category Cat = new Category(); foreach (var x in queryCat) { PC = new P_Cat(); if (CT.TopCatTree.Where(c => c.CatID == x.CID).Count() > 0) { PC.CatID = x.CID; PC.CatCount = x.Count; PC.CatName = CT.TopCatTree.Where(c => c.CatID == x.CID).FirstOrDefault().CategoryName; PCL.Add(PC); } else if (CT.SecondCatTree.Where(c => c.CatID == x.CID).Count() > 0) { PC.CatID = x.CID; PC.CatCount = x.Count; PC.CatName = CT.SecondCatTree.Where(c => c.CatID == x.CID).FirstOrDefault().CategoryName; PCL.Add(PC); } else if (CT.EndCatTree.Where(c => c.CatID == x.CID).Count() > 0) { PC.CatID = x.CID; PC.CatCount = x.Count; PC.CatName = CT.EndCatTree.Where(c => c.CatID == x.CID).FirstOrDefault().CategoryName; PCL.Add(PC); } } List<Material> ML = query.OrderByDescending(s => s.LastUpdateTime).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); foreach (var x in ML) { x.MoreDetail = string.Empty; x.LinkGroupMatCount = db.Material.Where(c => c.GroupToMatID == x.MatID).Count(); } MaterialPageBySearchList MP = new MaterialPageBySearchList(); MP.PageIndex = PageIndex; MP.PageSize = PageSize; MP.TotalRecord = query.Count(); MP.Rows = ML; MP.Brand = PBL; MP.Cat = PCL; return MP; }