public override ProductBrowseInfo GetProductBrowseInfo(int productId, int?maxReviewNum, int?maxConsultationNum) { Member user; int memberDiscount = 100; int gradeId = 0; int num3 = HiContext.Current.SiteSettings.UserId.Value; if (HiContext.Current.User.UserRole == UserRole.Underling) { user = HiContext.Current.User as Member; memberDiscount = MemberProvider.Instance().GetMemberDiscount(user.GradeId); gradeId = user.GradeId; } ProductBrowseInfo info = new ProductBrowseInfo(); StringBuilder builder = new StringBuilder(); builder.Append("UPDATE distro_Products SET VistiCounts = VistiCounts + 1 WHERE ProductId = @ProductId AND DistributorUserId = @DistributorUserId;"); builder.Append(" SELECT dp.*, p.Unit, p.ImageUrl1, p.ImageUrl2, p.ImageUrl3, p.ImageUrl4, p.ImageUrl5, p.LowestSalePrice, p.PenetrationStatus, p.TaobaoProductId"); builder.Append(",CASE WHEN dp.BrandId IS NULL THEN NULL ELSE (SELECT bc.BrandName FROM Hishop_BrandCategories bc WHERE bc.BrandId=dp.BrandId) END AS BrandName"); builder.Append(" FROM distro_Products dp JOIN Hishop_Products p ON dp.ProductId = p.ProductId where dp.ProductId=@ProductId AND dp.DistributorUserId = @DistributorUserId;"); if (HiContext.Current.User.UserRole == UserRole.Underling) { user = HiContext.Current.User as Member; memberDiscount = MemberProvider.Instance().GetMemberDiscount(user.GradeId); builder.Append("SELECT SkuId, ProductId, SKU,Weight, Stock, AlertStock, CostPrice, PurchasePrice,"); builder.AppendFormat(" CASE WHEN (SELECT COUNT(*) FROM distro_SKUMemberPrice WHERE SkuId = s.SkuId AND GradeId = {0} AND DistributoruserId = {1}) = 1", user.GradeId, num3); builder.AppendFormat(" THEN (SELECT MemberSalePrice FROM distro_SKUMemberPrice WHERE SkuId = s.SkuId AND GradeId = {0} AND DistributoruserId = {1})", user.GradeId, num3); builder.AppendFormat(" ELSE (SELECT SalePrice FROM vw_distro_SkuPrices WHERE SkuId = s.SkuId AND DistributoruserId = {0})*{1}/100 END AS SalePrice", num3, memberDiscount); } else { builder.Append("SELECT SkuId, ProductId, SKU,Weight, Stock, AlertStock, CostPrice, PurchasePrice,"); builder.AppendFormat(" (SELECT SalePrice FROM vw_distro_SkuPrices WHERE SkuId = s.SkuId AND DistributoruserId = {0}) AS SalePrice", num3); } builder.Append(" FROM Hishop_SKUs s WHERE ProductId = @ProductId"); if (maxReviewNum.HasValue) { builder.AppendFormat(" SELECT TOP {0} * FROM distro_ProductReviews where ProductId=@ProductId AND DistributorUserId=@DistributorUserId ORDER BY ReviewId DESC;", maxReviewNum); } if (maxConsultationNum.HasValue) { builder.AppendFormat(" SELECT TOP {0} * FROM distro_ProductConsultations where ProductId=@ProductId AND DistributorUserId=@DistributorUserId AND ReplyUserId IS NOT NULL ORDER BY ConsultationId DESC ;", maxConsultationNum); } builder.Append(" SELECT a.AttributeId, AttributeName, ValueStr FROM Hishop_ProductAttributes pa JOIN Hishop_Attributes a ON pa.AttributeId = a.AttributeId"); builder.Append(" JOIN Hishop_AttributeValues v ON a.AttributeId = v.AttributeId AND pa.ValueId = v.ValueId WHERE ProductId = @ProductId ORDER BY a.DisplaySequence DESC, v.DisplaySequence DESC"); builder.Append(" SELECT SkuId, a.AttributeId, AttributeName, UseAttributeImage, av.ValueId, ValueStr, ImageUrl FROM Hishop_SKUItems s join Hishop_Attributes a on s.AttributeId = a.AttributeId join Hishop_AttributeValues av on s.ValueId = av.ValueId WHERE SkuId IN (SELECT SkuId FROM Hishop_SKUs WHERE ProductId = @ProductId) ORDER BY a.DisplaySequence DESC,av.DisplaySequence DESC;"); builder.AppendFormat(" SELECT TOP 20 ProductId,ProductName,ThumbnailUrl60,ThumbnailUrl100,ThumbnailUrl160, ThumbnailUrl180,ThumbnailUrl220,ThumbnailUrl310,MarketPrice,SalePrice FROM vw_distro_BrowseProductList WHERE SaleStatus = {0}", 1); builder.AppendFormat(" AND DistributorUserId = {0} AND ProductId IN (SELECT RelatedProductId FROM distro_RelatedProducts WHERE ProductId = {1} AND DistributorUserId = {0})", num3, productId); builder.AppendFormat(" UNION SELECT TOP 20 ProductId,ProductName,ThumbnailUrl60,ThumbnailUrl100,ThumbnailUrl160, ThumbnailUrl180,ThumbnailUrl220,ThumbnailUrl310,MarketPrice,SalePrice FROM vw_distro_BrowseProductList WHERE SaleStatus = {0}", 1); builder.AppendFormat(" AND DistributorUserId = {0} AND ProductId<>{1} AND CategoryId = (SELECT CategoryId FROM distro_Products WHERE ProductId={1} AND SaleStatus = {2} AND DistributorUserId = {0})", num3, productId, 1); builder.AppendFormat(" AND ProductId NOT IN (SELECT RelatedProductId FROM distro_RelatedProducts WHERE ProductId = {0} AND DistributorUserId = {1})", productId, num3); DbCommand sqlStringCommand = this.database.GetSqlStringCommand(builder.ToString()); this.database.AddInParameter(sqlStringCommand, "ProductId", DbType.Int32, productId); this.database.AddInParameter(sqlStringCommand, "DistributorUserId", DbType.Int32, num3); using (IDataReader reader = this.database.ExecuteReader(sqlStringCommand)) { if (reader.Read()) { info.Product = DataMapper.PopulateProduct(reader); if (reader["BrandName"] != DBNull.Value) { info.BrandName = (string)reader["BrandName"]; } } if (reader.NextResult() && (info.Product != null)) { while (reader.Read()) { info.Product.Skus.Add((string)reader["SkuId"], DataMapper.PopulateSKU(reader)); } } if (maxReviewNum.HasValue && reader.NextResult()) { info.DBReviews = DataHelper.ConverDataReaderToDataTable(reader); } if (maxConsultationNum.HasValue && reader.NextResult()) { info.DBConsultations = DataHelper.ConverDataReaderToDataTable(reader); } if (reader.NextResult() && (info.Product != null)) { DataTable table = DataHelper.ConverDataReaderToDataTable(reader); if ((table != null) && (table.Rows.Count > 0)) { DataTable table2 = table.Clone(); foreach (DataRow row in table.Rows) { bool flag = false; if (table2.Rows.Count > 0) { foreach (DataRow row2 in table2.Rows) { if (((int)row2["AttributeId"]) == ((int)row["AttributeId"])) { DataRow row4; flag = true; (row4 = row2)["ValueStr"] = row4["ValueStr"] + ", " + row["ValueStr"]; } } } if (!flag) { DataRow row3 = table2.NewRow(); row3["AttributeId"] = row["AttributeId"]; row3["AttributeName"] = row["AttributeName"]; row3["ValueStr"] = row["ValueStr"]; table2.Rows.Add(row3); } } info.DbAttribute = table2; } } if (reader.NextResult()) { info.DbSKUs = DataHelper.ConverDataReaderToDataTable(reader); } if (reader.NextResult()) { info.DbCorrelatives = DataHelper.ConverDataReaderToDataTable(reader); } } return(info); }