public int Add(ProductInfo model)
        {
            using (DataCommand cmd = DataCommandManager.GetDataCommand("InsertProduct"))
            {
                cmd.SetParameterValue("@id", model.Id);
                cmd.SetParameterValue("@title", model.Title);
                cmd.SetParameterValue("@cid", model.CategoryId);
                cmd.SetParameterValue("@price", model.Price);
                cmd.SetParameterValue("@desc", model.Desc);
                cmd.SetParameterValue("@content", model.Content);

                cmd.SetParameterValue("@isonline", model.IsOnline);
                cmd.SetParameterValue("@bigpicture", model.BigPicture);
                cmd.SetParameterValue("@smallpicture", model.SmallPicture);
                cmd.SetParameterValue("@mediumpicture", model.MediumPicture);
                cmd.SetParameterValue("@specifications", model.Specifications);
                cmd.SetParameterValue("@afterservice", model.AfterService);
                cmd.SetParameterValue("@UserId", model.UserId);
                cmd.SetParameterValue("@InDate", model.InDate);
                cmd.SetParameterValue("@FileUrl", model.FileUrl);
                cmd.SetParameterValue("@Keywords", model.Keywords);
                cmd.SetParameterValue("@MetaDesc", model.MetaDesc);
                cmd.SetParameterValue("@DisplayOrder", model.DisplayOrder);
                return cmd.ExecuteNonQuery();
            }
        }
 public object UpdateProduct()
 {
     var model = new ProductInfo();
     model.Id = Convert.ToInt32(HttpContext.Current.Request.Params["ProductId"]);
     model.Title = (string)HttpContext.Current.Request.Params["title"];
     model.CategoryId = Convert.ToInt32(HttpContext.Current.Request.Params["productCategory"]);
     //model.Price = Convert.ToDouble(HttpContext.Current.Request.Params["price"]);
     model.Content = (string)HttpContext.Current.Request.Params["Content"];
     model.Desc = (string)HttpContext.Current.Request.Params["Desc"];//产品简介
     //model.IsOnline = HttpContext.Current.Request.Params["isonline"];
     model.BigPicture = HttpContext.Current.Request.Params["bigpicture"];
     model.SmallPicture = HttpContext.Current.Request.Params["smallpicture"];
     model.MediumPicture = (string)HttpContext.Current.Request.Params["mediumpicture"];
     model.Specifications = (string)HttpContext.Current.Request.Params["specifications"];
     model.AfterService = (string)HttpContext.Current.Request.Params["afterservice"];
     model.InDate = DateTime.Now;
     model.FileUrl = HttpContext.Current.Request.Params["filedown"];
     model.Keywords = HttpContext.Current.Request.Params["Keywords"];
     model.MetaDesc = HttpContext.Current.Request.Params["Description"];
     IProductService productService = new ProductService();
     return productService.Update(model) > 0;
 }
        public void HtmlAgilityPack_Demo01()
        {
            var list = new List<string>();
            list.Add("2");
            list.Add("3");
            list.Add("4");
            list.Add("5");
            list.Add("7");
            list.Add("8");

            list.Add("9");
            list.Add("10");
            list.Add("11");
            list.Add("12");
            list.Add("13");
            list.Add("14");

            list.Add("15");
            list.Add("16");
            list.Add("17");
            list.Add("18");
            list.Add("19");

            list.Add("20");
            list.Add("21");
            list.Add("22");
            list.Add("23");
            list.Add("24");
            list.Add("25");

            list.Add("26");
            list.Add("27");
            list.Add("28");
            list.Add("29");
            list.Add("31");

            foreach (string s in list)
            {
                var webGet = new HtmlWeb();
                HttpClient httpClient1 = new HttpClient("http://www.yihui-lighting.com/productshow.asp?id="+s);
                HtmlAgilityPack.HtmlDocument htmlDocument1 = new HtmlAgilityPack.HtmlDocument();
                htmlDocument1.LoadHtml(httpClient1.Request());
                var document = htmlDocument1;

                var data = document.DocumentNode.SelectNodes("//*[@id=\"mitte2\"]");
                StringBuilder sb = new StringBuilder();
                int i = 0;
                foreach (HtmlNode htmlNode in data)
                {
                    var images = document.DocumentNode.SelectNodes("//img");
                    if (images != null && images.Count > 0)
                    {
                        int j = 0;
                        foreach (HtmlNode imageNode in images)
                        {
                            j++;
                            WebClient webClient = new WebClient();
                            var dir = "images\\content";
                            string filepath = "z:\\upload\\" + dir;
                            if (!Directory.Exists(filepath))
                            {
                                Directory.CreateDirectory("z:\\upload\\" + dir);
                            }

                            if (imageNode.Attributes["src"].Value != null)
                            {
                                try
                                {
                                    string url = "http://www.yihui-lighting.com/UpProduct";
                                    downloadfile(url + "//" + imageNode.Attributes["src"].Value.Substring(imageNode.Attributes["src"].Value.LastIndexOf('/') + 1), imageNode.Attributes["src"].Value.Substring(imageNode.Attributes["src"].Value.LastIndexOf('/') + 1));
                                }
                                catch
                                {

                                }

                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(htmlNode.InnerText))
                    {
                        //
                        var titleNode = document.DocumentNode.SelectSingleNode(
                            "/html/body/div/div[3]/div[3]/div[2]/div/h2/font");
                        var title = titleNode.InnerText??"";
                        var body = htmlNode.InnerHtml.Replace("UpProduct/", "upload/images/content/")??"";

                        var model = new ProductInfo();
                        model.Title = title;
                        model.CategoryId = 2;

                        model.Content = body;

                        model.InDate = DateTime.Now;
                        model.DisplayOrder = OrderGenerator.NewOrder();
                        IProductService productService = new ProductService();
                        try
                        {
                            productService.Add(model);
                        }
                        catch
                        {

                        }

                    }
                }
            }
        }
        public ProductInfo GetProductById(int id)
        {
            ProductInfo model = new ProductInfo();
            model.Category = new ProductCategoryInfo();
            using (DataCommand cmd = DataCommandManager.GetDataCommand("GetProductById"))
            {
                cmd.SetParameterValue("@id", id);
                using (IDataReader dr = cmd.ExecuteDataReader())
                {
                    while (dr.Read())
                    {
                        if (!Convert.IsDBNull(dr["id"]))
                        {
                            model.Id = Convert.ToInt32(dr["id"]);
                        }
                        if (!Convert.IsDBNull(dr["title"]))
                        {
                            model.Title = dr["title"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["cid"]))
                        {
                            model.CategoryId = (int)dr["cid"];
                            model.Category.Id = Convert.ToInt32(dr["cid"]);
                        }
                        if (!Convert.IsDBNull(dr["price"]))
                        {
                            model.Price = (double)dr["Price"];
                        }
                        if (!Convert.IsDBNull(dr["desc"]))
                        {
                            model.Desc = dr["desc"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["content"]))
                        {
                            model.Content = dr["content"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["isonline"]))
                        {
                            model.IsOnline = (bool)dr["IsOnline"];
                        }
                        if (!Convert.IsDBNull(dr["bigpicture"]))
                        {
                            model.BigPicture = dr["BigPicture"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["smallpicture"]))
                        {
                            model.SmallPicture = dr["SmallPicture"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["mediumpicture"]))
                        {
                            model.MediumPicture = dr["MediumPicture"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["specifications"]))
                        {
                            model.Specifications = dr["Specifications"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["afterService"]))
                        {
                            model.AfterService = dr["afterService"].ToString();
                        }

                        if(!Convert.IsDBNull(dr["CategoryName"]))
                        {
                            model.CategoryName = dr["CategoryName"].ToString();
                        }
                        if(!Convert.IsDBNull(dr["InDate"]))
                        {
                            model.InDate = Convert.ToDateTime(dr["Indate"]);
                        }
                        if (!Convert.IsDBNull(dr["FileUrl"]))
                        {
                            model.FileUrl = dr["FileUrl"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["IsFocusPicture"]))
                        {
                            model.IsFocusPicture = Convert.ToBoolean(dr["IsFocusPicture"]);
                        }
                        if (!Convert.IsDBNull(dr["Keywords"]))
                        {
                            model.Keywords = dr["Keywords"].ToString();
                        }
                        if (!Convert.IsDBNull(dr["MetaDesc"]))
                        {
                            model.MetaDesc = dr["MetaDesc"].ToString();
                        }
                        if(!Convert.IsDBNull(dr["DataStatus"]))
                        {
                            model.Category.DataStatus = Convert.ToInt32(dr["DataStatus"]);
                        }
                    }

                }
            }
            return model;
        }
 private ProductInfo GetModelFromDataReader(IDataReader dr)
 {
     var model = new ProductInfo();
     model.Category=new ProductCategoryInfo();
     if (!Convert.IsDBNull(dr["Id"]))
     {
         model.Id = (int)dr["Id"];
     }
     if (!Convert.IsDBNull(dr["Title"]))
     {
         model.Title = (string)dr["Title"];
     }
     if (!Convert.IsDBNull(dr["CategoryName"]))
     {
         model.CategoryName = Convert.ToString(dr["CategoryName"]);
     }
     if (!Convert.IsDBNull(dr["CId"]))
     {
         model.CategoryId = (int)dr["CId"];
     }
     if (!Convert.IsDBNull(dr["Price"]))
     {
         model.Price = (double)dr["Price"];
     }
     if (!Convert.IsDBNull(dr["Desc"]))
     {
         model.Desc = (string)dr["Desc"];
     }
     if (!Convert.IsDBNull(dr["content"]))
     {
         model.Content = dr["content"].ToString();
     }
     if (!Convert.IsDBNull(dr["IsOnline"]))
     {
         model.IsOnline = (bool)dr["IsOnline"];
     }
     if (!Convert.IsDBNull(dr["BigPicture"]))
     {
         model.BigPicture = (string)dr["BigPicture"];
     }
     if (!Convert.IsDBNull(dr["SmallPicture"]))
     {
         model.SmallPicture = (string)dr["SmallPicture"];
     }
     if (!Convert.IsDBNull(dr["MediumPicture"]))
     {
         model.MediumPicture = (string)dr["MediumPicture"];
     }
     if (!Convert.IsDBNull(dr["Specifications"]))
     {
         model.Specifications = (string)dr["Specifications"];
     }
     if (!Convert.IsDBNull(dr["AfterService"]))
     {
         model.AfterService = (string)dr["AfterService"];
     }
     if (!Convert.IsDBNull(dr["InDate"]))
     {
         model.InDate = Convert.ToDateTime(dr["Indate"]);
     }
     if (!Convert.IsDBNull(dr["FileUrl"]))
     {
         model.FileUrl = dr["FileUrl"].ToString();
     }
     if (!Convert.IsDBNull(dr["IsFocusPicture"]))
     {
         model.IsFocusPicture = Convert.ToBoolean(dr["IsFocusPicture"]);
     }
     if (!Convert.IsDBNull(dr["Keywords"]))
     {
         model.Keywords = dr["Keywords"].ToString();
     }
     if (!Convert.IsDBNull(dr["MetaDesc"]))
     {
         model.MetaDesc = dr["MetaDesc"].ToString();
     }
     if (!Convert.IsDBNull(dr["DataStatus"]))
     {
         model.Category.DataStatus = Convert.ToInt32(dr["DataStatus"]);
     }
     if (!Convert.IsDBNull(dr["DisplayOrder"]))
     {
         model.DisplayOrder = Convert.ToInt64(dr["DisplayOrder"]);
     }
     return model;
 }