private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { Chapter chapter = todoList[pbrChapter.Value]; StringBuilder textBuffer = new StringBuilder(); foreach (HtmlElement item in webBrowser1.Document.All) { if (!String.IsNullOrEmpty(item.InnerHtml)) { textBuffer.AppendLine(item.InnerText); break; } } string text = textBuffer.ToString(); bool result = chapterService.NewChapter(chapter, text.Split('\r')); if (!result) { MyMessage.Fail(chapterService.ResultMessage); return; } if (pbrChapter.Value == todoList.Count - 1) { MyMessage.Success("处理完毕!!!"); return; } pbrChapter.Value++; Chapter nextChapter = todoList[pbrChapter.Value]; string html = webReaderService.ReadLineList(nextChapter.GetChapterUrl()); webBrowser1.DocumentText = html; }
/// <summary> /// 保存. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (webChapterList == null || webChapterList.Count == 0) { MyMessage.Warn("没有读取到 Web 数据!"); return; } // 取得代码. string bookCode = this.cboBooks.SelectedValue as string; todoList = new List <Chapter>(); foreach (Chapter c in webChapterList) { if (!c.IsActive) { continue; } if (!this.loaclChapterList.Exists(p => p.ChapterCode == c.ChapterCode)) { // 设置章节的 书籍代码. c.BookCode = bookCode; todoList.Add(c); } } if (todoList.Count == 0) { MyMessage.Warn("没有新章节需要读取!"); return; } String message = String.Format("确认要批量新增这 {0} 个章节么?", todoList.Count); if (!MyMessage.Makesure(message)) { return; } pbrChapter.Value = 0; pbrChapter.Maximum = todoList.Count; Chapter chapter = todoList[0]; string html = webReaderService.ReadLineList(chapter.GetChapterUrl()); webBrowser1.DocumentText = html; this.btnSave.Enabled = false; }