/// <summary>
        ///  ����һ������
        /// </summary>
        public void Add(ProductModel model)
        {
            DbCommand dbCommand = dbw.GetStoredProcCommand("UP_pdProduct_ADD");
            dbw.AddInParameter(dbCommand, "ProductId", DbType.Int32, model.ProductId);
            dbw.AddInParameter(dbCommand, "ProductName", DbType.AnsiString, model.ProductName);
            dbw.AddInParameter(dbCommand, "ProductCode", DbType.AnsiString, model.ProductCode);
            dbw.AddInParameter(dbCommand, "CatePath", DbType.AnsiString, model.CatePath);
            dbw.AddInParameter(dbCommand, "CateId", DbType.Int32, model.CateId);
            dbw.AddInParameter(dbCommand, "TradePrice", DbType.Decimal, model.TradePrice);
            dbw.AddInParameter(dbCommand, "MerchantPrice", DbType.Decimal, model.MerchantPrice);
            dbw.AddInParameter(dbCommand, "ReducePrice", DbType.Decimal, model.ReducePrice);
            dbw.AddInParameter(dbCommand, "Stock", DbType.Int32, model.Stock);
            dbw.AddInParameter(dbCommand, "SmallImage", DbType.AnsiString, model.SmallImage);
            dbw.AddInParameter(dbCommand, "MediumImage", DbType.AnsiString, model.MediumImage);
            dbw.AddInParameter(dbCommand, "LargeImage", DbType.AnsiString, model.LargeImage);
            dbw.AddInParameter(dbCommand, "Keywords", DbType.AnsiString, model.Keywords);
            dbw.AddInParameter(dbCommand, "Brief", DbType.AnsiString, model.Brief);
            dbw.AddInParameter(dbCommand, "PageView", DbType.Int32, model.PageView);
            dbw.AddInParameter(dbCommand, "InsertTime", DbType.DateTime, model.InsertTime);
            dbw.AddInParameter(dbCommand, "ChangeTime", DbType.DateTime, model.ChangeTime);
            dbw.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            dbw.AddInParameter(dbCommand, "SortValue", DbType.Int32, model.SortValue);
            dbw.AddInParameter(dbCommand, "Score", DbType.Int32, model.Score);
            dbw.AddInParameter(dbCommand, "brandid", DbType.Int32, model.BrandID);
            dbw.AddInParameter(dbCommand, "specifications", DbType.AnsiString, model.Specifications);
            dbw.AddInParameter(dbCommand, "packinglist", DbType.AnsiString, model.PackingList);
            dbw.AddInParameter(dbCommand, "aftersaleservice", DbType.AnsiString, model.AfterSaleService);
            dbw.AddInParameter(dbCommand, "offerset", DbType.AnsiString, model.OfferSet);
            dbw.AddInParameter(dbCommand, "weight", DbType.Decimal, model.Weight);
            dbw.AddInParameter(dbCommand, "StockTip", DbType.AnsiString, model.StockTip);
            dbw.AddInParameter(dbCommand, "RelateProducts", DbType.AnsiString, model.RelateProducts);

            dbw.ExecuteNonQuery(dbCommand);
        }
        public static ProductModel GetMainImageUrl(ProductModel Product)
        {
            Product.SmallImage = config.UrlRoot + Product.SmallImage;
            Product.MediumImage = config.UrlRoot + Product.MediumImage;
            Product.LargeImage = config.UrlRoot + Product.LargeImage;

            return Product;
        }
        private int AddProduct()
        {
            int rtnValue = 0;
            string strErr = "";
            if (this.txtProductName.Text == "")
            {
                strErr += "产品名称不能为空!\\n";
            }
            if (!PageValidate.IsDecimal(txtTradePrice.Text))
            {
                strErr += "市场价输入有误!\\n";
            }
            if (!PageValidate.IsDecimal(txtMerchantPrice.Text))
            {
                strErr += "销售价输入有误!\\n";
            }
            if (!PageValidate.IsDecimal(txtReducePrice.Text))
            {
                strErr += "直降价输入有误!\\n";
            }
            if (!PageValidate.IsNumber(txtScore.Text))
            {
                strErr += "商品积分输入有误!\\n";
            }
            if (!PageValidate.IsDecimal(txtWeight.Text))
            {
                strErr += "商品重量输入有误!\\n";
            }
            if (this.fulImage.FileName == "")
            {
                strErr += "产品图片不能为空!\\n";
            }
            if (this.txtKeywords.Text == "")
            {
                strErr += "关键词不能为空!\\n";
            }
            if (this.TextBox_Description.Text == "")
            {
                strErr += "商品简介不能为空!\\n";
            }
            if (!PageValidate.IsNumber(drpStatus.SelectedValue))
            {
                strErr += "商品状态选择有误!\\n";
            }
            int TempNewsID = 0;
            if (!String.IsNullOrEmpty(txtNewsID.Text) && !int.TryParse(txtNewsID.Text, out TempNewsID))
            {
                strErr += "关联资讯ID输入有误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                rtnValue = 1;
                return rtnValue;
            }

            if (bll.Exists(txtProductName.Text))
            {
                MessageBox.Show(this, "对不起,该商品名称已存在,无法添加同名商品");
                rtnValue = 1;
                return rtnValue;
            }
            CategoryModel cate = new CategoryModelBll().GetModel(Convert.ToInt32(txtCategoryID.Value));

            string[] MainImages;

            if (ProductMainImageRule.SaveProductMainImage(ProductID, cate.CatePath, fulImage.PostedFile, out MainImages))
            {
                ProductModel product = new ProductModel();

                product.ProductId = ProductID;
                product.ProductCode = String.IsNullOrEmpty(txtProductCode.Text) ? ProductID.ToString() : txtProductCode.Text;
                product.ProductName = txtProductName.Text;

                product.CateId = cate.CateId;
                product.CatePath = cate.CatePath;
                product.InsertTime = DateTime.Now;
                product.ChangeTime = DateTime.Now;
                product.Keywords = txtKeywords.Text;
                product.Brief = TextBox_Description.Text;
                product.BrandID = Convert.ToInt32(DropDown_Brand.SelectedValue);

                product.SmallImage = MainImages[0];
                product.MediumImage = MainImages[1];
                product.LargeImage = MainImages[2];

                product.MerchantPrice = Convert.ToDecimal(txtMerchantPrice.Text);
                product.ReducePrice = Convert.ToDecimal(txtReducePrice.Text);
                product.TradePrice = Convert.ToDecimal(txtTradePrice.Text);
                product.PageView = 0;
                product.Score = 0;
                //product.SortValue = "";
                product.Status = Convert.ToInt32(drpStatus.SelectedValue);
                product.Stock = int.MaxValue;

                product.Specifications = TextBox_Specification.Text;
                product.PackingList = TextBox_Packing.Text;
                product.AfterSaleService = TextBox_Service.Text;
                product.OfferSet = TextBox_OfferSet.Text;

                product.Weight = Convert.ToDecimal(txtWeight.Text);

                product.StockTip = GetStockTip();
                product.RelateProducts = txtRelateProduct.Text.Replace(",",",");

                new ProductNewsBll().Add(new ProductNewsModel() { ProdutID = ProductID, NewsID = TempNewsID });

                bll.Add(product);

                //添加产品检索属性
                foreach (GridViewRow row in GridView_Parameter.Rows)
                {
                    RadioButtonList ParameterValueList =((RadioButtonList)row.Cells[0].FindControl("RadioList_ParameterValue"));
                    if (!String.IsNullOrEmpty(ParameterValueList.SelectedValue))
                    {
                        int ParameterID = Convert.ToInt32(((HiddenField)row.Cells[0].FindControl("Hidden_ParameterID")).Value);
                        string ParameterValue = Convert.ToString(ParameterValueList.SelectedItem.Text);
                        ProductParaModel para = new ProductParaModel();

                        para.ParaId = ParameterID;
                        para.ProductId = product.ProductId;
                        para.ParaValue = ParameterValue;

                        pvBll.Add(para);
                    }
                }
                //添加产品基本属性
                foreach (GridViewRow row in GridView_Specification.Rows)
                {
                    RadioButtonList ParameterValueList = ((RadioButtonList)row.Cells[0].FindControl("RadioList_SpecificationValue"));
                    if (!String.IsNullOrEmpty(ParameterValueList.SelectedValue))
                    {
                        int ParameterID = Convert.ToInt32(((HiddenField)row.Cells[0].FindControl("Hidden_SpecificationID")).Value);
                        string ParameterValue = Convert.ToString(ParameterValueList.SelectedItem.Text);
                        ProductParaModel para = new ProductParaModel();

                        para.ParaId = ParameterID;
                        para.ProductId = product.ProductId;
                        para.ParaValue = ParameterValue;

                        pvBll.Add(para);
                    }
                }
                //添加商品多图
                foreach (string s in Request.Files.AllKeys)
                {
                    if (s.StartsWith("multiImageUpload") && Request.Files[s].ContentLength>0)
                    {
                        string[] FileNames;
                        ProductMultiImageRule.SaveProductMultiImage(ProductID,cate.CatePath, Request.Files[s], out FileNames);

                        if (FileNames != null)
                        {
                            ProductImageModel model = new ProductImageModel();
                            model.ImageId = CommDataHelper.GetNewSerialNum("pd");
                            model.ProductId = ProductID;
                            model.LargeImage = FileNames[1];
                            model.OriginImage = FileNames[2];
                            model.SmallImage = FileNames[0];
                            model.Title = String.Empty;

                            new ProductImageModelBll().Add(model);
                        }
                    }
                }

                //创建索引
                try
                {
                    DataIndexerProduct SearchIndexer = new DataIndexerProduct(Config.Searches["product"]);
                    SearchIndexer.CreateSingleIndex(new Search.Entities.ProductModel()
                    {
                        EntityIdentity = product.ProductId,
                        CategoryID = product.CateId,
                        CategoryPath = product.CatePath,
                        CreateTime = product.InsertTime,
                        Description = product.Brief,
                        Keywords = product.Keywords,
                        Price = product.MerchantPrice,
                        ProcessType = NoName.NetShop.Search.Entities.EntityProcessType.insert,
                        ProductImage = product.MediumImage,
                        ProductName = product.ProductName,
                        UpdateTime = product.ChangeTime
                    });
                }
                catch { }

                return rtnValue;
            }
            else
            {
                MessageBox.Show(this, "图片上传失败,请检查!");
                rtnValue = 1;
                return rtnValue;
            }
        }
        /// <summary>
        /// ����ʵ�������
        /// </summary>
        public ProductModel ReaderBind(IDataReader dataReader)
        {
            ProductModel model=new ProductModel();
            object ojb;
            ojb = dataReader["ProductId"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.ProductId=(int)ojb;
            }
            model.ProductName=dataReader["ProductName"].ToString();
            model.ProductCode=dataReader["ProductCode"].ToString();
            model.CatePath=dataReader["CatePath"].ToString();
            ojb = dataReader["CateId"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.CateId=(int)ojb;
            }
            ojb = dataReader["TradePrice"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.TradePrice=(decimal)ojb;
            }
            ojb = dataReader["MerchantPrice"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.MerchantPrice=(decimal)ojb;
            }
            ojb = dataReader["ReducePrice"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.ReducePrice=(decimal)ojb;
            }
            ojb = dataReader["Stock"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.Stock=(int)ojb;
            }
            model.SmallImage=dataReader["SmallImage"].ToString();
            model.MediumImage=dataReader["MediumImage"].ToString();
            model.LargeImage=dataReader["LargeImage"].ToString();
            model.Keywords=dataReader["Keywords"].ToString();
            model.Brief=dataReader["Brief"].ToString();
            ojb = dataReader["PageView"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.PageView=(int)ojb;
            }
            ojb = dataReader["InsertTime"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.InsertTime=(DateTime)ojb;
            }
            ojb = dataReader["ChangeTime"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.ChangeTime=(DateTime)ojb;
            }
            ojb = dataReader["Status"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.Status=Convert.ToInt32(ojb);
            }
            ojb = dataReader["SortValue"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.SortValue=(int)ojb;
            }
            ojb = dataReader["Score"];
            if(ojb != null && ojb != DBNull.Value)
            {
                model.Score=(int)ojb;
            }
            ojb = dataReader["brandid"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BrandID = Convert.ToInt32(ojb);
            }

            model.Specifications = Convert.ToString(dataReader["Specifications"]);
            model.PackingList = Convert.ToString(dataReader["PackingList"]);
            model.AfterSaleService = Convert.ToString(dataReader["AfterSaleService"]);
            model.OfferSet = Convert.ToString(dataReader["OfferSet"]);
            model.Weight = Convert.ToDecimal(dataReader["weight"]);
            model.StockTip = Convert.ToString(dataReader["stocktip"]);
            model.RelateProducts = Convert.ToString(dataReader["RelateProducts"]);
            return model;
        }
 /// <summary>
 /// ����һ������
 /// </summary>
 public void Add(ProductModel model)
 {
     dal.Add(model);
 }
 /// <summary>
 /// ����һ������
 /// </summary>
 public void Update(ProductModel model)
 {
     dal.Update(model);
 }
 /// <summary>
 /// ��������б�
 /// </summary>
 public List<ProductModel> GetModelList(string strWhere)
 {
     DataSet ds = dal.GetList(strWhere);
     List<ProductModel> modelList = new List<ProductModel>();
     int rowsCount = ds.Tables[0].Rows.Count;
     if (rowsCount > 0)
     {
         ProductModel model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new ProductModel();
             if(ds.Tables[0].Rows[n]["ProductId"].ToString()!="")
             {
                 model.ProductId=int.Parse(ds.Tables[0].Rows[n]["ProductId"].ToString());
             }
             model.ProductName=ds.Tables[0].Rows[n]["ProductName"].ToString();
             model.ProductCode=ds.Tables[0].Rows[n]["ProductCode"].ToString();
             model.CatePath=ds.Tables[0].Rows[n]["CatePath"].ToString();
             if(ds.Tables[0].Rows[n]["CateId"].ToString()!="")
             {
                 model.CateId=int.Parse(ds.Tables[0].Rows[n]["CateId"].ToString());
             }
             if(ds.Tables[0].Rows[n]["TradePrice"].ToString()!="")
             {
                 model.TradePrice=decimal.Parse(ds.Tables[0].Rows[n]["TradePrice"].ToString());
             }
             if(ds.Tables[0].Rows[n]["MerchantPrice"].ToString()!="")
             {
                 model.MerchantPrice=decimal.Parse(ds.Tables[0].Rows[n]["MerchantPrice"].ToString());
             }
             if(ds.Tables[0].Rows[n]["ReducePrice"].ToString()!="")
             {
                 model.ReducePrice=decimal.Parse(ds.Tables[0].Rows[n]["ReducePrice"].ToString());
             }
             if(ds.Tables[0].Rows[n]["Stock"].ToString()!="")
             {
                 model.Stock=int.Parse(ds.Tables[0].Rows[n]["Stock"].ToString());
             }
             model.SmallImage=ds.Tables[0].Rows[n]["SmallImage"].ToString();
             model.MediumImage=ds.Tables[0].Rows[n]["MediumImage"].ToString();
             model.LargeImage=ds.Tables[0].Rows[n]["LargeImage"].ToString();
             model.Keywords=ds.Tables[0].Rows[n]["Keywords"].ToString();
             model.Brief=ds.Tables[0].Rows[n]["Brief"].ToString();
             if(ds.Tables[0].Rows[n]["PageView"].ToString()!="")
             {
                 model.PageView=int.Parse(ds.Tables[0].Rows[n]["PageView"].ToString());
             }
             if(ds.Tables[0].Rows[n]["InsertTime"].ToString()!="")
             {
                 model.InsertTime=DateTime.Parse(ds.Tables[0].Rows[n]["InsertTime"].ToString());
             }
             if(ds.Tables[0].Rows[n]["ChangeTime"].ToString()!="")
             {
                 model.ChangeTime=DateTime.Parse(ds.Tables[0].Rows[n]["ChangeTime"].ToString());
             }
             if(ds.Tables[0].Rows[n]["Status"].ToString()!="")
             {
                 model.Status=int.Parse(ds.Tables[0].Rows[n]["Status"].ToString());
             }
             if(ds.Tables[0].Rows[n]["SortValue"].ToString()!="")
             {
                 model.SortValue=int.Parse(ds.Tables[0].Rows[n]["SortValue"].ToString());
             }
             if(ds.Tables[0].Rows[n]["Score"].ToString()!="")
             {
                 model.Score=int.Parse(ds.Tables[0].Rows[n]["Score"].ToString());
             }
             modelList.Add(model);
         }
     }
     return modelList;
 }