コード例 #1
0
 public virtual void DeletePicture(string storeId)
 {
     var storePicturelist = StorePictureBll.GetModelList(string.Format("StoreID = '{0}' and picType ='{1}'", storeId, PicturType));
     foreach (var storePicture in storePicturelist)
     {
         StorePictureBll.Delete(storePicture.PID);
     }
     var storePicturesTableBll = new StorePicturesTable();
     var storePicturesTableList = storePicturesTableBll.GetModelList(string.Format("businessID = '{0}'", storeId));
     foreach (var storePicturesTable in storePicturesTableList)
     {
         storePicturesTableBll.Delete(storePicturesTable.StorePicturesID);
     }
 }
コード例 #2
0
        /// <summary>
        /// 获取图片详细
        /// </summary>
        public void GetPicture(Maticsoft.Model.StoreInfo storeInfo)
        {
            var picturePathName = "PhotoAlbum";
            var picPullList = new List<PicPull>() { PicPull.Environmental, PicPull.Cake };
            //var picThumbnail = string.Format(newThumbnail, picturePathName, storeInfo.StoreName);
            //var newPathThumb = string.Format(newPathThu, picturePathName);
            //try
            //{
            //    string CreatePath = string.Format(newPath, storeInfo.StoreName, picturePathName, string.Empty);
            //    if (!Directory.Exists(CreatePath))
            //    {
            //        Directory.CreateDirectory(CreatePath);
            //    }
            //    if (!Directory.Exists(picThumbnail))
            //    {
            //        Directory.CreateDirectory(picThumbnail);
            //    }
            //    if (!Directory.Exists(newPathThumb))
            //    {
            //        Directory.CreateDirectory(newPathThumb);
            //    }

            //}
            //catch (Exception e)
            //{
            //}

            var storePictureBll = new StorePicture();

            var storePicturelist = storePictureBll.GetModelList(string.Format("StoreID = '{0}' and picType ='{1}'", storeInfo.storeId, picturePathName));
            foreach (var storePicture in storePicturelist)
            {
                storePictureBll.Delete(storePicture.PID);
            }
            var storePicturesTableBll = new StorePicturesTable();
            var storePicturesTableList = storePicturesTableBll.GetModelList(string.Format("businessID = '{0}'", storeInfo.storeId));
            foreach (var storePicturesTable in storePicturesTableList)
            {
                storePicturesTableBll.Delete(storePicturesTable.StorePicturesID);
            }
            foreach (var picPull in picPullList)
            {
                var busphotoAlbumTable = new Maticsoft.Model.BusPhotoAlbumTable();
                busphotoAlbumTable.BusinessID = storeInfo.storeId;
                if (picPull == PicPull.Cake)
                {
                    busphotoAlbumTable.AlbumName = @"菜品图片";
                }
                else
                {
                    busphotoAlbumTable.AlbumName = @"餐厅环境";
                }
                busphotoAlbumTable.BusPhotoAlbumID = Guid.NewGuid().ToString();
                busphotoAlbumTable.IsDefault = true;
                var busPhotoAlbumTableBll = new Maticsoft.BLL.BusPhotoAlbumTable();
                busPhotoAlbumTableBll.Add(busphotoAlbumTable);

                var pageIndex = 1;
                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 = @"http://www.xiaomishu.com/shop/new/ajax/picpull.aspx?resid=C21C09K22533&time=6";
                    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) || dishesPicturePath.EndsWith("food_nopic.png"))
                        {
                            return;
                        }
                        var storePicture = new Maticsoft.Model.StorePicture();
                        storePicture.PID = Guid.NewGuid().ToString();
                        var pictureName = string.Format("{0}.jpg", storePicture.PID);
                        storePicture.PictureName = pictureName;
                        storePicture.PicType = picturePathName;
                        storePicture.PicturePath = dishesPicturePath;
                        storePicture.StoreId = storeInfo.storeId;
                        //dishesPicturePath = @"http://f2.95171.cn/pic/D22I15N56303/3cfeefbe-cadd-49af-904b-a33a4b1d6c70.jpg";
                        //try
                        //{
                        //    db.DownFile(dishesPicturePath.Replace("/320_0/", "/").Replace(@"/300_200/", "/"), string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName));
                        //}
                        //catch (Exception)
                        //{
                        //}
                        //try
                        //{
                        //    db.DownFile(dishesPicturePath, newPathThumb + pictureName);
                        //}
                        //catch (Exception)
                        //{
                        //    throw;
                        //}
                        //var storePath = string.Format(newPath, storeInfo.StoreName, picturePathName, pictureName);

                        //db.ZoomAuto(newPathThumb + pictureName, picThumbnail + pictureName, 320, 240);//生成缩略图
                        //db.ZoomAuto(newPathThumb + pictureName, picThumbnail + "640_480_" + pictureName, 640, 480);//生成缩略图
                        //db.ZoomAuto(newPathThumb + pictureName, picThumbnail + "320_240_" + pictureName, 320, 240);//生成缩略图
                        //db.ZoomAuto(newPathThumb + pictureName, picThumbnail
                        //     + "160_120_" + pictureName, 160, 120);//生成缩略图
                        storePictureBll.Add(storePicture);

                        var storePicturesTable = new Maticsoft.Model.StorePicturesTable();
                        storePicturesTable.StorePicturesID = Guid.NewGuid().ToString();
                        storePicturesTable.BusPhotoAlbumID = busphotoAlbumTable.BusPhotoAlbumID;
                        storePicturesTable.BusinessID = busphotoAlbumTable.BusinessID;
                        storePicturesTable.PictureAddress = pictureName;
                        storePicturesTable.PicState = 2;
                        //storePicturesTable.PicName = dishesPicturePath;
                        storePicturesTable.UploadTime = DateTime.Now;
                        storePicturesTableBll.Add(storePicturesTable);
                    }
                }
            }
        }