コード例 #1
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            if (catalogueListBox.SelectedIndex < 0)
            {
                return;
            }
            var catalogueInfo = catalogueListBox.SelectedItem as Catalogue;
            if (catalogueInfo == null)
            {
                return;
            }
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var siteStoreInfo = _storeInfoList.Find(x => x.storeId == catalogueInfo.StoreId);
            var oldStoreInfo = textBox4.Tag as StoreInfoEntity;
            var storeInfoEntity = GetStoreInfoEntity(catalogueInfo, oldStoreInfo, siteStoreInfo);
            var storeBll = new StoreInfoBll();
            var storeInfoBll = new Maticsoft.BLL.StoreInfo();
            var storePictureBll = new Maticsoft.BLL.StorePicture();
            var storePicture = new Maticsoft.Model.StorePicture();
            storePicture.PID = Guid.NewGuid().ToString();
            storePicture.PictureName = string.Format("{0}.jpg", storeInfoEntity.BizID);
            storePicture.PicType = "Shop";
            storePicture.PicturePath = siteStoreInfo.StorePictureHref;
            storePicture.StoreId = storeInfoEntity.BizID;
            if (storeBll.Exists(storeInfoEntity.BizID))
            {
                storeBll.Update(storeInfoEntity);
                storeInfoBll.Update(siteStoreInfo);
            }
            else
            {
                storeInfoEntity.ShortID = storeBll.GetMaxShortID();
                storeInfoBll.Add(siteStoreInfo);
                storeBll.Add(storeInfoEntity);
            }
            if (!string.IsNullOrEmpty(storePicture.PicturePath))
            {
                storePictureBll.Remove(string.Format("PicType = 'Shop' and StoreId = '{0}'", storeInfoEntity.BizID));
                storePictureBll.Add(storePicture);
            }
            var saveStoreEntity = new SaveStoreEntity();
            saveStoreEntity.CataloEventHandler += UpdateIncrement;
            saveStoreEntity.InitProgress();
            var specialTagList = chlBoxSpecialTag.CheckedItems.Cast<SpecialTag>().ToList();
            Action<StoreInfoEntity, List<SpecialTag>> storeSpecialTagDelegate = saveStoreEntity.SaveStoreSpecialTag;
            storeSpecialTagDelegate.BeginInvoke(storeInfoEntity, specialTagList, null, null);

            var cookingStylesList = chbCookingStyles.CheckedItems.Cast<CookingStyles>().ToList();
            Action<StoreInfoEntity, IEnumerable<CookingStyles>> cookingStylesDelegate = saveStoreEntity.SaveCookingStyles;
            cookingStylesDelegate.BeginInvoke(storeInfoEntity, cookingStylesList, null, null);

            var cityLocalTagEntityList = clbStoreTag.CheckedItems.Cast<CityLocalTagEntity>().ToList();
            Action<StoreInfoEntity, IEnumerable<CityLocalTagEntity>> cityLocalTagEntityDelegate = saveStoreEntity.SaveCityLocalTagEntity;
            cityLocalTagEntityDelegate.BeginInvoke(storeInfoEntity, cityLocalTagEntityList, null, null);

            if (chbDish.Checked)
            {
                Action<StoreInfoEntity, StoreInfo> dishesDelegate = saveStoreEntity.SaveDishes;
                dishesDelegate.BeginInvoke(storeInfoEntity, siteStoreInfo, null, null);
            }
            if (chbPic.Checked)
            {
                Action<StoreInfoEntity, StoreInfo> storePicturesDelegate = saveStoreEntity.SaveStorePictures;
                storePicturesDelegate.BeginInvoke(storeInfoEntity, siteStoreInfo, null, null);
            }

            saveStoreEntity.DoProgress();
            foreach (var selectedIndex in clbStoreTag.CheckedIndices)
            {
                clbStoreTag.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
            }
            saveStoreEntity.DoProgress();
            foreach (var selectedIndex in chlBoxSpecialTag.CheckedIndices)
            {
                chlBoxSpecialTag.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
            }
            saveStoreEntity.DoProgress();
            foreach (var selectedIndex in chbCookingStyles.CheckedIndices)
            {
                chbCookingStyles.SetItemCheckState((int)selectedIndex, CheckState.Unchecked);
            }
            saveStoreEntity.DoProgress();
            stopwatch.Stop();
            Invoke(_showMessageBox, string.Format(@"{0}保存成功,耗时{1}毫秒", storeInfoEntity.StoreName, stopwatch.ElapsedMilliseconds));
            catalogueListBox.SetItemCheckState(catalogueListBox.SelectedIndex, CheckState.Checked);
            if (catalogueListBox.SelectedIndex < catalogueListBox.Items.Count - 1)
            {
                catalogueListBox.SelectedIndex += 1;
            }
            SetCatalogueListBox();
        }
コード例 #2
0
        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));
        }