根据商品ID查询出单个商品

 /// <summary>
        /// 根据商品ID查询出单个商品
        /// </summary>
        /// <param name="productId">商品ID</param>
        /// <returns></returns>
        public Entity_B2CSM.Products GetProduct(int productId)
        {
            Products product = null;
             string selectSql = string.Format(@"SELECT [Id]
                                                      ,[ProductCode]
                                                      ,[ProductName]
                                                      ,[CategoryId]
                                                      ,[BrandId]
                                                      ,[MarketPrice]
                                                      ,[ShopPrice]
                                                      ,[DetailDescription]
                                                      ,[IsOnSaled]
                                                      ,[IsNew]
                                                      ,[IsHotSale]
                                                      ,[IsBest]
                                                      ,[IsDeleted]
                                                      ,[ProductScore]
                                                      ,[KeyWords]
                                               FROM [Products]
                                               WHERE [Id]={0};
                                               SELECT [Id]
                                                      ,[ProductId]
                                                      ,[ImageUrl]
                                                      ,[SmallImageUrl]
                                                      ,[BigImageUrl]
                                                      ,[Description]
                                               FROM [ProductImage]
                                               WHERE [ProductId]={0};
                                               SELECT [ProductStorage].[Id]
                                                      ,[ProductId]
                                                      ,[SizeId]
                                                      ,[ColorId]
                                                      ,[Number]
                                                      ,'ColorName'=[ColorInfo].[ColorName]
                                                      ,'SizeName'=[SizeInfo].[SizeName]
                                               FROM [ProductStorage]
                                               INNER JOIN [ColorInfo] ON [ColorInfo].[Id]=[ProductStorage].[ColorId]
                                               INNER JOIN [SizeInfo] ON [SizeInfo].[Id]=[ProductStorage].[SizeId]
                                               WHERE [ProductStorage].[ProductId]={0};
                                               SELECT [Id]
                                                      ,[ProductId]
                                                      ,[PromoteStartDateTime]
                                                      ,[PromoteEndDateTime]
                                                      ,[PromotePrice]
                                               FROM [PromotionInfo]
                                               WHERE [ProductId]={0};", productId);
            DataSet ds=this.dataAccess.GetDataSet(selectSql);
            List<Products> productList = DataTableToList<Products>(ds.Tables[0]);
            List<ProductImage> productImageList=DataTableToList<ProductImage>(ds.Tables[1]);
            List<ProductStorage> productStorageList=DataTableToList<ProductStorage>(ds.Tables[2]);
            List<PromotionInfo> promotionList=DataTableToList<PromotionInfo>(ds.Tables[3]);
            if (productList.Count > 0)
            {
                product = productList[0];
                product.ProductImage.AddRange(productImageList);
                product.ProductStorage.AddRange(productStorageList);
                product.PromotionInfo.AddRange(promotionList);
            }
            return  product;
        }

posted @ 2011-07-29 20:30  _best  阅读(1287)  评论(0编辑  收藏  举报