예제 #1
0
        private void SaveItem(SampleListItem item, string dirPath, WebClient client)
        {
            string fileUrl = item.PicPath;

            fileUrl = fileUrl.Substring(fileUrl.LastIndexOf('/')).TrimStart('/');
            string imgName = fileUrl.Substring(0, fileUrl.LastIndexOf('.'));

            string ext      = fileUrl.Substring(fileUrl.LastIndexOf('.'));
            string fileName = item.Id + "_" + imgName + ext;
            string infoName = fileName + ".info";

            if (Directory.GetFiles(dirPath, infoName, SearchOption.TopDirectoryOnly).Length == 0)
            {
                string filePath = string.Format(@"{0}\{1}", dirPath, fileName);
                string infoPath = string.Format(@"{0}\{1}", dirPath, infoName);
                client.DownloadFile(item.PicPath, filePath);

                using (StreamWriter writer = new StreamWriter(infoPath, false, Encoding.UTF8))
                {
                    writer.WriteLine(string.Format("ItemId:{0}", item.Id));
                    writer.WriteLine(string.Format("ItemTitle:{0}", item.Title));
                    writer.WriteLine(string.Format("ItemPrice:{0}", item.Price));
                    writer.WriteLine(string.Format("ImageLocalPath:{0}", filePath));
                    writer.WriteLine(string.Format("ImageUrl:{0}", item.PicPath));
                    writer.Flush();
                }
            }
        }
예제 #2
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     selectedIidList = new List <SampleListItem>();
     foreach (CtrlItem ctrl in fpnlList.Controls)
     {
         if (ctrl.Checked)
         {
             SampleListItem item = new SampleListItem();
             item.Id       = ctrl.Iid;
             item.Title    = ctrl.ItemName;
             item.Price    = ctrl.Price;
             item.PicPath  = ctrl.ImagePath;
             item.Location = ctrl.ImageUrl;
             selectedIidList.Add(item);
         }
     }
     DialogResult = DialogResult.OK;
     this.Close();
 }
예제 #3
0
        private void UpdateItems()
        {
            ucProgress.Title         = "正在更新商品...";
            ucProgress.Summary       = "正在从服务器获取需要更新的商品信息...";
            ucProgress.ProgressTotal = 100;
            ucProgress.ProgressValue = 1;
            ucProgress.Total         = -1;
            ucProgress.Value         = -1;
            ucProgress.DisplayProgress();
            Application.DoEvents();

            string currentPath = Assembly.GetExecutingAssembly().Location;
            string dir         = new FileInfo(currentPath).DirectoryName;

            dir = dir + "\\ShopItems";
            if (cbForce.Checked)
            {
                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }
            }
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            ItemFacade facade = new ItemFacade(defaultAppKey, defaultAppSecret);
            TOPDataList <SampleListItem> list = facade.QuerySampleListByNick(currentPageIndex++, pageSize, nick);

            while (true)
            {
                TOPDataList <SampleListItem> tmp = facade.QuerySampleListByNick(currentPageIndex++, pageSize, nick);
                list.AddRange(tmp);
                if (tmp.Count < pageSize)
                {
                    break;
                }
            }

            ucProgress.ProgressValue = 100;
            ucProgress.DisplayProgress();
            Application.DoEvents();

            ucProgress.Total         = list.Count;
            ucProgress.ProgressTotal = list.Count;

            isCanceled = false;
            using (WebClient client = new WebClient())
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (isCanceled)
                    {
                        break;
                    }
                    SampleListItem item = list[i];
                    ucProgress.Summary       = item.Title;
                    ucProgress.Value         = i + 1;
                    ucProgress.ProgressValue = i + 1;
                    ucProgress.DisplayProgress();
                    Application.DoEvents();
                    SaveItem(item, dir, client);
                }
            }
            ucProgress.Summary = "更新完毕";
            ucProgress.DisplayProgress();
            Application.DoEvents();
        }