Ejemplo n.º 1
0
        /// <summary>
        /// 加载全部试用数据
        /// </summary>
        private void LoadAllTaobaoTryData()
        {
            this.isRequesting = true;
            List <TBTryItem> items = new List <TBTryItem>();

            try
            {
                string pSize  = "100";
                int    pCount = 1;
                for (int i = 0; (i < pCount) && this.bContinueLoadAll; i++)
                {
                    string        result     = this.MakeRequest((i + 1).ToString(), pSize);
                    TBTryResponse tbResponse = SerializeUtility.JsonDeserizlize2 <TBTryResponse>(result);
                    if (tbResponse == null ||
                        tbResponse.result == null ||
                        tbResponse.success == false ||
                        tbResponse.result.items == null ||
                        tbResponse.result.items.Count == 0 ||
                        tbResponse.result.paging == null)
                    {
                        break;
                    }
                    else
                    {
                        //总页数
                        pCount = tbResponse.result.paging.pages;
                        //将数据添加进结果集
                        TBTryItemComparer comparer = new TBTryItemComparer();
                        foreach (var item in tbResponse.result.items)
                        {
                            int index = items.BinarySearch(item, comparer);
                            if (index >= 0)
                            {
                                continue;
                            }
                            items.Insert(~index, item);
                        }
                    }
                    this.RefershResult(i + 1, pCount, items.Count);
                    Thread.Sleep(200);
                }
                this.DispAllResult(items);
            }
            finally
            {
                this.isRequesting = false;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 请求结果数据的处理
 /// </summary>
 /// <param name="result"></param>
 private void DispResult(string result)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new Action <string>(this.DispResult), result);
     }
     else
     {
         //解析json
         TBTryResponse tbResponse = SerializeUtility.JsonDeserizlize2 <TBTryResponse>(result);
         if (tbResponse == null ||
             tbResponse.result == null ||
             tbResponse.success == false ||
             tbResponse.result.items == null ||
             tbResponse.result.items.Count == 0 ||
             tbResponse.result.paging == null)
         {
             this.lblCurPage.Text  = "0";
             this.lblPageSize.Text = "0";
             this.ClearGrid();
             if (tbResponse != null &&
                 tbResponse.success == false &&
                 !string.IsNullOrWhiteSpace(tbResponse.error))
             {
                 MessageBox.Show("请求失败:\r\n" + tbResponse.error);
             }
             return;
         }
         else
         {
             this.lblCurPage.Text  = string.Format("{0}/{1}", tbResponse.result.paging.page, tbResponse.result.paging.pages);
             this.lblPageSize.Text = tbResponse.result.items.Count.ToString();
             //重新显示页码
             this.cmbCurPage.Items.Clear();
             for (int i = 0; i < tbResponse.result.paging.pages; i++)
             {
                 this.cmbCurPage.Items.Add(i + 1);
             }
             this.cmbCurPage.Text = tbResponse.result.paging.page.ToString();
             //显示数据
             this.ClearGrid();
             DataView view = this.MakeViewData(tbResponse.result.items);
             this.gridResult.DataSource = view;
             this.DoFilter();
         }
     }
 }