/// <summary>
        /// 商家列表页获取
        /// </summary>
        /// <param name="pageUrl"></param>
        /// <param name="poIndex"></param>
        public List<Model.Catalogue> InsretPage(string pageUrl, int poIndex)
        {
            var htmlWeb = new HtmlWeb();
            var htmlDoc = htmlWeb.Load(pageUrl);
            var list =
                htmlDoc.DocumentNode.SelectNodes(
                    ".//div[@class='constr']/div/div[@class='res_hm_c']/div[@class='res_sch_res schResList']/div[@class='l']/a");

            if (list == null)
            {
                return null;
            }
            var catalogueList = new List<Model.Catalogue>();
            foreach (var htmlNode in list)
            //Parallel.ForEach(list, htmlNode =>
            {
                var title = htmlNode.SelectSingleNode(".//img").Attributes["title"].Value;
                var href = htmlNode.Attributes["href"].Value;
                var keyList = href.Trim('/').Split('/');
                var keyID = string.Empty;
                var catalogue = new Maticsoft.Model.Catalogue();
                if (keyList.Count() == 2)
                {
                    keyID = keyList[1];
                    catalogue.FId = keyID;
                    catalogue.title = title;
                    catalogue.href = href;
                    catalogue.LocalTagID = poIndex;
                    catalogue.StoreId = Guid.NewGuid().ToString();
                    var storeInfoBll = new Maticsoft.BLL.StoreInfo();
                    var temStoreInfoList = storeInfoBll.GetModelList(string.Format("Fid = '{0}'", keyID));
                    var storePictureBll = new StorePicture();
                    if (temStoreInfoList != null && temStoreInfoList.Count > 0)
                    {
                        catalogue.IsRead = true;
                        var temStoreInfo = temStoreInfoList.FirstOrDefault();
                        if (temStoreInfo != null)
                        {
                            catalogue.StoreId = temStoreInfo.storeId;
                        }
                        var oldStorePicture =
                            storePictureBll.GetModelList(string.Format("PicType ='Shop' and StoreId = '{0}'",
                                catalogue.StoreId));
                        foreach (var storePicture in oldStorePicture)
                        {
                            storePictureBll.Delete(storePicture.PID);
                        }
                        //Parallel.ForEach(oldStorePicture, storePicture => storePictureBll.Delete(storePicture.PID));
                    }
                    else
                    {
                        catalogue.IsRead = false;
                    }
                    var imgNode = htmlNode.SelectSingleNode(".//img[@class='jsLazyImage']");
                    if (imgNode != null)
                    {
                        var shopPicturePath = imgNode.Attributes["data-url"].Value;
                        if (!string.IsNullOrEmpty(shopPicturePath) && !shopPicturePath.EndsWith("food_nopic.png"))
                        {
                            var storePicture = new Maticsoft.Model.StorePicture();
                            storePicture.PID = Guid.NewGuid().ToString();
                            var pictureName = string.Format("{0}.jpg", storePicture.PID);
                            storePicture.PictureName = pictureName;
                            storePicture.PicType = "Shop";
                            storePicture.PicturePath = shopPicturePath;
                            storePicture.StoreId = catalogue.StoreId;
                            storePictureBll.Add(storePicture);
                            catalogue.picName = storePicture.PictureName;
                        }

                    }
                    catalogueList.Add(catalogue);
                }
                //catalogueBll.Add(catalogue);
            }

            return catalogueList.OrderBy(x => x != null && x.IsRead).ThenBy(x => x != null ? x.FId : string.Empty).ToList();
        }
        public void GetFood(Maticsoft.Model.StoreInfo storeInfo)
        {
            var dishesPath = "Food";
            try
            {
                //string CreatePath = string.Format(newPath, storeInfo.StoreName, dishesPath, string.Empty);
                //if (!Directory.Exists(CreatePath))
                //{
                //    Directory.CreateDirectory(CreatePath);
                //}

                //var foodThumbnail = string.Format(newThumbnail, dishesPath, storeInfo.StoreName);
                //if (!Directory.Exists(foodThumbnail))
                //{
                //    Directory.CreateDirectory(foodThumbnail);
                //}

                //var newPathThumb = string.Format(newPathThu, dishesPath);
                //if (!Directory.Exists(newPathThumb))
                //{
                //    Directory.CreateDirectory(newPathThumb);
                //}

                var dishesBll = new Maticsoft.BLL.Dishes();
                var disheslist = dishesBll.GetModelList(string.Format("StoreId = '{0}'", storeInfo.storeId));
                foreach (var dishese in disheslist)
                {
                    dishesBll.Delete(dishese.DishesID);
                }
                var dishTypeBll = new Maticsoft.BLL.DishesTyepTable();
                var dishTypeList = dishTypeBll.GetModelList(string.Format("BusinessID = '{0}'", storeInfo.storeId));
                foreach (var dishesTyepTable in dishTypeList)
                {
                    dishTypeBll.Delete(dishesTyepTable.DishesTypeID);
                }
                var dishTypePath = string.Format("{0}shop/{1}/dish/", _pageUrl, storeInfo.Fid);

                var storePictureBll = new StorePicture();

                var storePicturelist = storePictureBll.GetModelList(string.Format("StoreID = '{0}' and picType ='{1}'", storeInfo.storeId, dishesPath));
                foreach (var storePicture in storePicturelist)
                {
                    storePictureBll.Delete(storePicture.PID);
                }

                //dishPath = @"http://www.xiaomishu.com/shop/D22I15N56303/dish/";
                var htmlWeb = new HtmlWeb();

                var htmlDoc = htmlWeb.Load(dishTypePath);
                var dishTypeNodeList = htmlDoc.DocumentNode.SelectNodes(".//div[@class='constr']/div[@class='constr_in']/div[@class='l float_four']/div[@class='bdc bgf0 pr10 pb10']/a[@class='res_food_ins_gra']");
                if (dishTypeNodeList == null)
                {
                    return;
                }
                foreach (var dishTypeNode in dishTypeNodeList)
                {
                    var dishType = new Maticsoft.Model.DishesTyepTable();
                    dishType.BusinessID = storeInfo.storeId;
                    dishType.CreateDate = DateTime.Now;
                    dishType.DishesTypeID = Guid.NewGuid().ToString();
                    var dishName = dishTypeNode.InnerText;
                    var dishlength = dishName.IndexOf('(');
                    dishType.DishesTypeName = dishTypeNode.InnerText.Substring(0, dishlength);
                    dishTypeBll.Add(dishType);

                    var pageIndex = 1;
                    while (true)
                    {
                        var dishUrl = dishTypeNode.Attributes["href"].Value;

                        var dishPath = string.Format("{0}{1}p{2}/", _pageUrl, dishUrl, pageIndex);

                        pageIndex++;
                        htmlDoc = htmlWeb.Load(dishPath);
                        var dishesNodeList =
                        htmlDoc.DocumentNode.SelectNodes(
                            ".//div[@class='constr']/div[@class='constr_in']/div[@class='cell pl10']/ul[@id='foodListUl']/li[@class='res_food_list']");
                        if (dishesNodeList == null || dishesNodeList.Count <= 1)
                        {
                            break;
                        }
                        foreach (var dishNode in dishesNodeList)
                        {
                            var dishes = new Maticsoft.Model.Dishes();
                            var foodList = dishNode.SelectSingleNode(".//div[@class='fix']");
                            if (foodList == null)
                            {
                                continue;
                            }
                            var foodChildList = foodList.ChildNodes;
                            var foodName = foodList.ChildNodes.Count > 1 ? foodChildList[1].InnerText ?? string.Empty : string.Empty;
                            var foodPrice = foodList.ChildNodes.Count > 3 ? foodChildList[3].InnerText ?? string.Empty : string.Empty;
                            var popularity = foodList.ChildNodes.Count > 5 ? foodChildList[5].InnerText ?? string.Empty : string.Empty;
                            dishes.DishesID = Guid.NewGuid().ToString();
                            dishes.DishesName = foodName.Trim();
                            foodPrice = foodPrice.Trim().Replace("¥", string.Empty).Replace("¥", string.Empty);
                            dishes.dishTypeID = dishType.DishesTypeID;
                            if (foodPrice.Trim() == "时价")
                            {
                                dishes.DishesMoney = "0";
                                dishes.IsCurrentPrice = true;
                            }
                            else if (foodPrice.Trim() == "不详")
                            {
                                dishes.DishesMoney = "0";
                            }
                            else
                            {
                                dishes.DishesMoney = foodPrice;
                            }

                            dishes.popularity = popularity.Trim();
                            dishes.StoreId = storeInfo.storeId;
                            var dishesPictureNode = dishNode.SelectSingleNode(
                                ".//div[@class='abs_out pt10']/div[@class='fix rel']/div[@class='pct50 l']/a[@class='g3']/img");
                            if (dishesPictureNode != null)
                            {
                                var dishesPicturePath = dishesPictureNode.Attributes["src"].Value;
                                if (!string.IsNullOrEmpty(dishesPicturePath) && !dishesPicturePath.EndsWith("food_nopic.png"))
                                {
                                    var storePicture = new Maticsoft.Model.StorePicture();
                                    storePicture.PID = Guid.NewGuid().ToString();
                                    var pictureName = string.Format("{0}.jpg", storePicture.PID);
                                    storePicture.PictureName = pictureName;
                                    storePicture.PicType = dishesPath;
                                    storePicture.PicturePath = dishesPicturePath;
                                    storePicture.StoreId = storeInfo.storeId;
                                    storePictureBll.Add(storePicture);

                                    dishes.PictureName = pictureName;
                                    //try
                                    //{
                                    //    db.DownFile(dishesPicturePath.Replace(@"/300_200/", "/").Replace("/320_0/", "/"), string.Format(newPath, storeInfo.StoreName, dishesPath, dishes.PictureName));
                                    //}
                                    //catch (Exception)
                                    //{
                                    //}
                                    //try
                                    //{
                                    //    db.DownFile(dishesPicturePath, newPathThumb + dishes.PictureName);
                                    //}
                                    //catch (Exception)
                                    //{

                                    //    throw;
                                    //}
                                    //var storeInfopath = string.Format(newPath, storeInfo.StoreName, dishesPath, dishes.PictureName);
                                    //db.ZoomAuto(newPathThumb + dishes.PictureName, foodThumbnail + dishes.PictureName, 320, 240);//生成缩略图
                                    //db.ZoomAuto(newPathThumb + dishes.PictureName, foodThumbnail + "640_480_" + dishes.PictureName, 640, 480);//生成缩略图
                                    //db.ZoomAuto(newPathThumb + dishes.PictureName, foodThumbnail + "320_240_" + dishes.PictureName, 320, 240);//生成缩略图
                                    //db.ZoomAuto(newPathThumb + dishes.PictureName, foodThumbnail + "160_120_" + dishes.PictureName, 160, 120);//生成缩略图

                                }
                            }
                            dishesBll.Add(dishes);
                        }
                    }
                }

            }
            catch (Exception e)
            {
            }
        }
        /// <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);
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var actionStoreInfoEntity = new Action<StoreInfoEntity>(store => listBox1.Items.Add(string.Format("{0}{1}", store.BizID, store.StoreName)));
            var storeCount = 0;
            try
            {
                CreatePath();
                var cityInfo = cbBoxCity.SelectedItem as Maticsoft.Model.City;
                if (cityInfo == null)
                {
                    return;
                }
                var storeInfoBll = new StoreInfoBll();
                var storeID = txtStoreID.Text;
                var whereStringBuilder = new StringBuilder();
                whereStringBuilder.Append(string.Format("CityID = '{0}'", cityInfo.CityID));
                if (!string.IsNullOrWhiteSpace(storeID))
                {
                    whereStringBuilder.Append(string.Format("and BizID = '{0}'", storeID));
                }
                var storeList = storeInfoBll.GetModelList(whereStringBuilder.ToString()) ?? new List<StoreInfoEntity>();
                storeCount = storeList.Count;
                var storePicture = new StorePicture();
                Action<List<StoreInfoEntity>> action = sList =>
                {
                    foreach (var storeInfoEntity in sList)
                    {
                        var storePictureList =
                            storePicture.GetModelList(string.Format("StoreId = '{0}'", storeInfoEntity.BizID)) ??
                            new List<Maticsoft.Model.StorePicture>();
                        //Parallel.ForEach(storePictureList, pictureInfo =>
                        if (string.IsNullOrEmpty(storeInfoEntity.ShortID))
                        {
                            storeInfoEntity.ShortID = storeInfoBll.GetMaxShortID();
                            storeInfoBll.Update(storeInfoEntity);
                        }
                        foreach (var pictureInfo in storePictureList)
                        {
                            if (pictureInfo.PicType == "Shop" && storeInfoEntity.StorePhoto != pictureInfo.PictureName)
                            {
                                storeInfoEntity.StorePhoto = pictureInfo.PictureName;
                                storeInfoBll.Update(storeInfoEntity);
                            }
                            var picPath = string.Format(PicturePath, pictureInfo.PicType);
                            var picThumbnail = string.Format(PictureThumbnail, pictureInfo.PicType);
                            try
                            {
                                db.DownFile(pictureInfo.PicturePath.Replace(@"/300_200/", "/").Replace("/320_0/", "/"),
                                    picPath + pictureInfo.PictureName);
                            }
                            catch (Exception exception)
                            {
                                try
                                {
                                    db.DownFile(
                                        pictureInfo.PicturePath.Replace(@"/300_200/", "/").Replace("/320_0/", "/"),
                                        picPath + pictureInfo.PictureName);
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                            db.ZoomAuto(picPath + pictureInfo.PictureName, picThumbnail + pictureInfo.PictureName, 320,
                                240);
                            //生成缩略图
                            db.ZoomAuto(picPath + pictureInfo.PictureName,
                                picThumbnail + "640_480_" + pictureInfo.PictureName,
                                640, 480); //生成缩略图
                            db.ZoomAuto(picPath + pictureInfo.PictureName,
                                picThumbnail + "320_240_" + pictureInfo.PictureName,
                                320, 240); //生成缩略图
                            db.ZoomAuto(picPath + pictureInfo.PictureName,
                                picThumbnail + "160_120_" + pictureInfo.PictureName,
                                160, 120); //生成缩略图
                            //});
                        }
                        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                        qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
                        qrCodeEncoder.QRCodeScale = 4;
                        qrCodeEncoder.QRCodeVersion = 8;
                        qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

                        Bitmap image;
                        String data = "http://www.51k7.com/wap/shop.aspx?sid=" + storeInfoEntity.ShortID;
                        image = qrCodeEncoder.Encode(data);
                        image.Save(@"./imagefiles/QrCode/" + storeInfoEntity.ShortID + ".png");
                        StoreInfoEntity entity = storeInfoEntity;
                        this.Invoke(actionStoreInfoEntity, entity);
                    }
                };
                Task task = new Task(() => action(storeList));
                task.Start();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show(string.Format("完成下载{0}家商家", storeCount));
        }