Пример #1
0
        private async void pictureBoxFind_Click(object sender, EventArgs e)
        {
            pictureBoxFind.Enabled = false;//防止多次点击

            string bookName = uiTextBoxName.Text;

            _spiderController = new SpiderController(bookName);
            if (bookName == "")
            {
                MessageBox.Show("Please input book name before searching", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            _bookHtmlContents = new List <List <SpiderController.BookHtmlContent> > {
                (List <SpiderController.BookHtmlContent>) await _spiderController.ReadNextAsync()
            };
            int bookNo = 1;

            foreach (var item in _bookHtmlContents[_pageCount++])
            {
                uiDataGridViewBookInfo.AddRow(bookNo++.ToString(), item.Title, item.Rate, item.Subjects);
            }

            pictureBoxFind.Enabled = true;                      // 恢复再次查询按钮
            pictureBoxNext.Enabled = _spiderController.HasNext; // 可以点击下一页如果有下一页
        }
Пример #2
0
 public void Test1()
 {
     Assert.DoesNotThrowAsync(async() => await spider.ReadNextAsync());
     Assert.AreEqual(spider.HasNext, true);
 }
Пример #3
0
        private async void pictureBoxNext_Click(object sender, EventArgs e)
        {
            //if (!pictureBoxFind.Enabled) {//只有当搜索工作完成了以后,才允许点击下一栏
            //DataTable dt = new DataTable();
            //DataTable dt = GetDgvToTable(uiDataGridViewBookInfo);
            //dtStack.Push(dt);
            uiDataGridViewBookInfo.Rows.Clear();
            //try {
            if (_pageCurrentNo == _pageCount - 1)
            {
                _bookHtmlContents.Add((List <SpiderController.BookHtmlContent>) await _spiderController.ReadNextAsync());//继续加载下一个界面
                int bookNo = 1;
                ++_pageCount;
                foreach (var item in _bookHtmlContents[++_pageCurrentNo])
                {
                    uiDataGridViewBookInfo.AddRow(bookNo++.ToString(), item.Title, item.Rate, item.Subjects);
                }
            }
            else
            {
                ++_pageCurrentNo;
                for (int i = 0; i < _bookHtmlContents[_pageCurrentNo].Count; ++i)
                {
                    var item = _bookHtmlContents[_pageCurrentNo][i];
                    uiDataGridViewBookInfo.AddRow((i + 1).ToString(), item.Title, item.Rate, item.Subjects);
                }
            }
            pictureBoxBefore.Enabled = true;                      // 允许点击前一页
            pictureBoxNext.Enabled   = _spiderController.HasNext; // 是否还有下一页

            //}
            //catch (Exception error) {
            //    MessageBox.Show(error.Message, "Error");
            //}
            //}
        }