public void GetDish(IDishSiteModel dishSiteModel, string storeID)
 {
     var dishes = new Maticsoft.Model.Dishes
     {
         DishesID = Guid.NewGuid().ToString(),
         DishesName = dishSiteModel.DishName,
         DishesMoney = dishSiteModel.DishesMoney,
         dishTypeID = dishSiteModel.DishTypeID,
         StoreId = storeID,
         popularity = dishSiteModel.Popularity.ToString(CultureInfo.InvariantCulture),
         DishesUnit = dishSiteModel.DishesUnit,
         DishesBrief = dishSiteModel.DishesBrief
     };
     if (!string.IsNullOrEmpty(dishSiteModel.PictureName))
     {
         var storePicture = new Maticsoft.Model.StorePicture();
         storePicture.PID = Guid.NewGuid().ToString();
         storePicture.PictureName = string.Format("{0}.jpg", storePicture.PID);
         storePicture.PicType = "Food";
         storePicture.PicturePath = dishSiteModel.PictureName;
         storePicture.StoreId = storeID;
         storePictureBll.Add(storePicture);
         dishes.PictureName = storePicture.PictureName;
     }
     dishesBll.Add(dishes);
 }
 public void GetDish(IDishSiteModel dishSiteModel, string storeID)
 {
     if (string.IsNullOrEmpty(dishSiteModel.DishName))
     {
         return;
     }
     var dishes = new Maticsoft.Model.Dishes
     {
         DishesID = Guid.NewGuid().ToString(),
         DishesName = dishSiteModel.DishName,
         DishesMoney = dishSiteModel.DishesMoney,
         dishTypeID = dishSiteModel.DishTypeID,
         StoreId = storeID,
         DishesUnit = string.IsNullOrEmpty(dishSiteModel.DishesUnit) ? "份" : dishSiteModel.DishesUnit
     };
     if (!string.IsNullOrEmpty(dishSiteModel.PictureName))
     {
         var storePicture = new Maticsoft.Model.StorePicture();
         storePicture.PID = Guid.NewGuid().ToString();
         storePicture.PictureName = string.Format("{0}.jpg", storePicture.PID);
         storePicture.PicType = "Food";
         storePicture.PicturePath = dishSiteModel.PictureName;
         storePicture.StoreId = storeID;
         storePictureBll.Add(storePicture);
         dishes.PictureName = storePicture.PictureName;
     }
     dishesBll.Add(dishes);
 }
Example #3
0
        /// <summary>
        /// 获取图片详细
        /// </summary>
        private void GetPicture()
        {
            var picturePathName = "picture";
            var picPullList = Enum.GetValues(typeof(PicPull));
            var storeInfoBll = new StoreInfo();
            var storeList = storeInfoBll.GetModelList(string.Empty);

            var storePictureBll = new StorePicture();
            foreach (var storeInfo in storeList)
            {
                try
                {
                    string CreatePath = string.Format(newPath, storeInfo.StoreName, picturePathName, string.Empty);
                    if (!Directory.Exists(CreatePath))
                    {
                        Directory.CreateDirectory(CreatePath);
                    }
                }
                catch (Exception e)
                {
                }
                var pageIndex = 1;
                foreach (var picPull in picPullList)
                {
                    while (true)
                    {
                        //t=-1 2 3时有值
                        var picturePath = @"{0}shop/new/ajax/picpull.aspx?resid={1}&t={2}&time={3}";

                        picturePath = string.Format(picturePath, _pageUrl, storeInfo.Fid, (int)picPull, pageIndex);
                        //picturePath =
                        pageIndex++;
                        var htmlWeb = new HtmlWeb();

                        var htmlDoc = htmlWeb.Load(picturePath);
                        var pictureNodeList = htmlDoc.DocumentNode.SelectNodes(".//div[@class='bdc bgf0 p10']/a/img");
                        if (pictureNodeList == null)
                        {
                            break;
                        }
                        foreach (var pictureNode in pictureNodeList)
                        {
                            var dishesPicturePath = pictureNode.Attributes["src"].Value;
                            if (string.IsNullOrEmpty(dishesPicturePath))
                            {
                                return;
                            }
                            var storePicture = new Maticsoft.Model.StorePicture();
                            storePicture.PID = Guid.NewGuid().ToString();
                            var pictureName = string.Format("{0}.jpg", storePicture.PID);
                            storePicture.PictureName = pictureName;
                            storePicture.StoreId = storeInfo.storeId;
                            //dishesPicturePath = @"http://f2.95171.cn/pic/D22I15N56303/3cfeefbe-cadd-49af-904b-a33a4b1d6c70.jpg";
                            dishesPicturePath = dishesPicturePath.Replace("/320_0/", "/");
                            try
                            {
                                db.DownFile(dishesPicturePath, string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName));
                            }
                            catch (Exception)
                            {
                                db.DownFile(dishesPicturePath, string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName));
                            }
                            db.ZoomAuto(string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName), newThumbnail + pictureName, 320, 240);//生成缩略图
                            db.ZoomAuto(string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName), newThumbnail + "640_480_" + pictureName, 640, 480);//生成缩略图
                            db.ZoomAuto(string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName), newThumbnail + "320_240_" + pictureName, 320, 240);//生成缩略图
                            db.ZoomAuto(string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName), newThumbnail + "160_120_" + pictureName, 160, 120);//生成缩略图
                            storePictureBll.Add(storePicture);

                        }
                    }

                }
            }
        }
        public void GetDish(IDishSiteModel dishSiteModel, string storeID)
        {
            string regex = @"([\u4E00-\u9FA5]*)(([\u4E00-\u9FA5]*))";
            var dishName = dishSiteModel.DishName;
            if (Regex.IsMatch(dishSiteModel.DishName, regex))
            {
                var matchCollection = Regex.Match(dishSiteModel.DishName, regex);
                dishName = matchCollection.Groups[1].Value.Trim();
                dishSiteModel.DishesUnit = string.IsNullOrEmpty(matchCollection.Groups[2].Value.Trim())
                    ? "份"
                    : matchCollection.Groups[2].Value.Trim();

            }
            if (string.IsNullOrEmpty(dishName))
            {
                return;
            }
            var dishes = new Maticsoft.Model.Dishes
            {
                DishesID = Guid.NewGuid().ToString(),
                DishesName = dishName,
                DishesMoney = dishSiteModel.DishesMoney,
                dishTypeID = dishSiteModel.DishTypeID,
                StoreId = storeID,
                DishesUnit = string.IsNullOrEmpty(dishSiteModel.DishesUnit) ? "份" : dishSiteModel.DishesUnit
            };
            if (!string.IsNullOrEmpty(dishSiteModel.PictureName))
            {
                var storePicture = new Maticsoft.Model.StorePicture();
                storePicture.PID = Guid.NewGuid().ToString();
                storePicture.PictureName = string.Format("{0}.jpg", storePicture.PID);
                storePicture.PicType = "Food";
                storePicture.PicturePath = dishSiteModel.PictureName;
                storePicture.StoreId = storeID;
                storePictureBll.Add(storePicture);
                dishes.PictureName = storePicture.PictureName;
            }
            dishesBll.Add(dishes);
        }