/// <summary> /// 产品Top显示 新增重载,根据产品id筛选 /// </summary> public static DataTable GetHomeProductTop(string top, ProductInfo.ProductTop productTop, int CategoryId) { DistributorsInfo currentDistributors = DistributorsBrower.GetCurrentDistributors(); if (productTop == ProductInfo.ProductTop.MostLike) //如果是猜你喜欢的产品 { MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { DataTable favPros = ProductBrowser.GetFavorites(currentMember); if (favPros.Rows.Count > 0) { return(favPros); } } } return(new HomeProductDao().GetHomeProductTop(top, productTop, DistributorsBrower.GetCurrStoreProductRange(), CategoryId)); }
/// <summary> /// 绑定TOP类控件 /// </summary> private void BindProductTop(Control c) { //声明变量 DataTable dtProductTop = null; //找到控件后,获取对应的数据集 string topName = c.ID.Substring(c.ID.IndexOf("_") + 1); ProductInfo.ProductTop pt = (ProductInfo.ProductTop)Enum.Parse(typeof(ProductInfo.ProductTop), topName); switch (pt) { case ProductInfo.ProductTop.New: case ProductInfo.ProductTop.Hot: case ProductInfo.ProductTop.Discount: dtProductTop = ProductBrowser.GetHomeProductTop(3, pt); break; case ProductInfo.ProductTop.MostLike: dtProductTop = ProductBrowser.GetHomeProductTop(5, pt); break; case ProductInfo.ProductTop.Activity: dtProductTop = ProductBrowser.GetHomeProductTop(2, pt); break; default: //dtProductTop = ProductBrowser.GetHomeProductTop(3, pt); break; } //数据集处理 switch (SettingsManager.GetMasterSettings(true).VTheme.ToLower()) { case "green": dtProductTop.Columns.Add("styleName", typeof(string)); for (int i = 0; i < dtProductTop.Rows.Count; i++) { dtProductTop.Rows[i]["styleName"] = (i % 2 == 0) ? "imgstye_l" : "imgstye_r"; } break; case "e0404": for (int i = 1; i <= dtProductTop.Rows.Count; i++) { dtProductTop.Rows[i - 1]["ProductName"] = ((i + 4) % 5 == 0) ? dtProductTop.Rows[i - 1]["ProductName"] : ""; } break; case "style01": switch (pt) { case ProductInfo.ProductTop.New: dtProductTop = ProductBrowser.GetHomeProductTop(4, pt); break; case ProductInfo.ProductTop.Discount: dtProductTop = ProductBrowser.GetHomeProductTop(3, pt); break; case ProductInfo.ProductTop.MostLike: dtProductTop = ProductBrowser.GetHomeProductTop(6, pt); break; } break; case "style02": case "style03": switch (pt) { case ProductInfo.ProductTop.Category: DataTable categories = CategoryBrowser.GetAllCategoriesRange(DistributorsBrower.GetCurrStoreProductRange()); if (categories.Rows.Count > 0) { int cateCount = categories.Rows.Count; //把总行数用变量储存起来,以免循环删除列后,rows总数会随时变动. //只保留dt的前三行 for (int i = 0; i < cateCount; i++) { if (categories.Rows.Count > 3) { categories.Rows.RemoveAt(3); } else { break; } } //绑定 dtProductTop = categories; //ProductBrowser.GetHomeProductTop("3", pt,Convert.ToInt32( categories.Rows[0]["categoryid"])); } break; case ProductInfo.ProductTop.New: dtProductTop = ProductBrowser.GetHomeProductTop(4, pt); break; case ProductInfo.ProductTop.MostLike: dtProductTop = ProductBrowser.GetHomeProductTop(5, pt); break; case ProductInfo.ProductTop.Discount: dtProductTop = ProductBrowser.GetHomeProductTop(3, ProductInfo.ProductTop.Hot); break; } break; case "bytype": break; } (c as VshopTemplatedRepeater).ItemDataBound += new RepeaterItemEventHandler(this.rptProductTop_ItemDataBound); //绑定 (c as VshopTemplatedRepeater).DataSource = dtProductTop; (c as VshopTemplatedRepeater).DataBind(); }
/// <summary> /// 产品Top显示新增产品类型参数筛选 /// </summary> public DataTable GetHomeProductTop(string top, ProductInfo.ProductTop productTop, ProductInfo.ProductRanage productRanage, int CategoryId) { string where = "Where 1=1"; string order = ""; string topStr = " top " + top + " "; int currentDistributorId = Globals.GetCurrentDistributorId(); switch (productTop) { case ProductInfo.ProductTop.Category: topStr += "a.*,b.name"; where = string.Format(" a left join Hishop_Categories b on a.CategoryId=b.CategoryId where a.CategoryId = {0}", CategoryId); break; default: topStr += "a.*"; break; } switch (productRanage) { case ProductInfo.ProductRanage.NormalSelect: //正常显示店铺已上架的商品 where += string.Format(" AND ProductId IN (SELECT ProductId FROM Hishop_DistributorProducts WHERE UserId={0})", currentDistributorId); break; case ProductInfo.ProductRanage.All: //显示所有出售状态的商品 break; case ProductInfo.ProductRanage.RangeSelect: //根据上架范围显示已上架的商品 //本身上架的记录 where += string.Format(" AND a.ProductId IN (SELECT ProductId FROM Hishop_DistributorProducts WHERE UserId={0})", currentDistributorId); //代理取系统设置的上架范围,分销商取所属代理商的上架范围 int ofAgentID = currentDistributorId; DataTable dtDistributors = this.database.ExecuteDataSet(CommandType.Text, string.Format("Select UserId,IsAgent,AgentPath From aspnet_Distributors Where UserId={0}", ofAgentID)).Tables[0]; if (dtDistributors.Rows[0]["IsAgent"].ToString() != "1" && dtDistributors.Rows[0]["AgentPath"] != DBNull.Value) { ofAgentID = int.Parse(dtDistributors.Rows[0]["AgentPath"].ToString().Split('|')[dtDistributors.Rows[0]["AgentPath"].ToString().Split('|').Length - 1]); } DataTable dtProductRange = this.database.ExecuteDataSet(CommandType.Text, string.Format("Select * From Hishop_DistributorProductRange Where UserId={0}", ofAgentID)).Tables[0]; if (dtProductRange.Rows.Count == 0) { where += string.Format(" And 1=2 "); //未设置上架范围 } else { DataRow drProductRange = dtProductRange.Rows[0]; where += string.Format(" AND ("); if (drProductRange["ProductRange1"] != DBNull.Value) { where += string.Format(string.Format("a.CategoryId in({0})", drProductRange["ProductRange1"].ToString())); } else { where += string.Format("a.CategoryId in(null)"); } if (drProductRange["ProductRange2"] != DBNull.Value) { where += string.Format(string.Format(" or a.BrandId in({0})", drProductRange["ProductRange2"].ToString())); } else { where += string.Format(" or a.BrandId in(null)"); } if (drProductRange["ProductRange3"] != DBNull.Value) { where += string.Format(string.Format(" or a.TypeId in({0})", drProductRange["ProductRange3"].ToString())); } else { where += string.Format(" or a.TypeId in(null)"); } where += string.Format(")"); } break; } if (top == "0") { topStr = "count(*)"; } if (top == "0") { order = ""; } string selectSql = string.Format("Select {0} From vw_Hishop_BrowseProductList {1} {2}", topStr, where, order); return(this.database.ExecuteDataSet(CommandType.Text, selectSql).Tables[0]); }
/// <summary> /// 产品Top显示 数据集 /// </summary> public DataTable GetHomeProductTop(int top, ProductInfo.ProductTop productTop, ProductInfo.ProductRanage productRanage) { int currentDistributorId = Globals.GetCurrentDistributorId(); string where = "Where 1=1"; string order = ""; switch (productTop) { case ProductInfo.ProductTop.New: order = " order by AddedDate desc"; break; case ProductInfo.ProductTop.Hot: order = " order by ShowSaleCounts desc"; break; case ProductInfo.ProductTop.Discount: order = " order by (MarketPrice-SalePrice) desc"; break; case ProductInfo.ProductTop.MostLike: order = " order by VistiCounts desc"; break; case ProductInfo.ProductTop.Activity: order = " order by VistiCounts desc"; break; default: order = " order by ShowSaleCounts desc"; break; } switch (productRanage) { case ProductInfo.ProductRanage.NormalSelect: //正常显示店铺已上架的商品 where += string.Format(" AND ProductId IN (SELECT ProductId FROM Hishop_DistributorProducts WHERE UserId={0})", currentDistributorId); break; case ProductInfo.ProductRanage.All: //显示所有出售状态的商品 break; case ProductInfo.ProductRanage.RangeSelect: //根据上架范围显示已上架的商品 //本身上架的记录 where += string.Format(" AND ProductId IN (SELECT ProductId FROM Hishop_DistributorProducts WHERE UserId={0})", currentDistributorId); //代理取系统设置的上架范围,分销商取所属代理商的上架范围 int ofAgentID = currentDistributorId; DataTable dtDistributors = this.database.ExecuteDataSet(CommandType.Text, string.Format("Select UserId,IsAgent,AgentPath From aspnet_Distributors Where UserId={0}", ofAgentID)).Tables[0]; if (dtDistributors.Rows[0]["IsAgent"].ToString() != "1" && dtDistributors.Rows[0]["AgentPath"] != DBNull.Value) { ofAgentID = int.Parse(dtDistributors.Rows[0]["AgentPath"].ToString().Split('|')[dtDistributors.Rows[0]["AgentPath"].ToString().Split('|').Length - 1]); } DataTable dtProductRange = this.database.ExecuteDataSet(CommandType.Text, string.Format("Select * From Hishop_DistributorProductRange Where UserId={0}", ofAgentID)).Tables[0]; if (dtProductRange.Rows.Count == 0) { where += string.Format(" And 1=2 "); //未设置上架范围 } else { DataRow drProductRange = dtProductRange.Rows[0]; where += string.Format(" AND ("); if (drProductRange["ProductRange1"] != DBNull.Value) { where += string.Format(string.Format("CategoryId in({0})", drProductRange["ProductRange1"].ToString())); } else { where += string.Format("CategoryId in(null)"); } if (drProductRange["ProductRange2"] != DBNull.Value) { where += string.Format(string.Format(" or BrandId in({0})", drProductRange["ProductRange2"].ToString())); } else { where += string.Format(" or BrandId in(null)"); } if (drProductRange["ProductRange3"] != DBNull.Value) { where += string.Format(string.Format(" or TypeId in({0})", drProductRange["ProductRange3"].ToString())); } else { where += string.Format(" or TypeId in(null)"); } where += string.Format(")"); } break; } string topStr = (top == 0) ? "count(*)" : string.Format("top {0} *", top); if (top == 0) { order = ""; } string selectSql = string.Format("Select {0} From vw_Hishop_BrowseProductList {1} {2}", topStr, where, order); return(this.database.ExecuteDataSet(CommandType.Text, selectSql).Tables[0]); }