/// <summary> /// 写入小说信息文件 /// </summary> /// <param name="_path">存放路径</param> /// <param name="_tfdi">信息</param> /// <returns>true:写入成功 false:写入失败</returns> public static bool Write_Bookshelf_Info(tb_fiction_detail_info _tfdi, string _path) { try { //序列化 string str_json = ""; DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(tb_fiction_detail_info)); using (MemoryStream msObj = new MemoryStream()) { //将序列化之后的Json格式数据写入流中 js.WriteObject(msObj, _tfdi); msObj.Position = 0; //从0这个位置开始读取流中的数据 using (StreamReader sr = new StreamReader(msObj, Encoding.UTF8)) { str_json = sr.ReadToEnd(); } } //写入文件流 using (StreamWriter sw = new StreamWriter(_path)) { sw.WriteLine(str_json); } return(true); } catch { return(false); } }
/// <summary> /// 获取小说详细线程 /// </summary> /// <param name="_o"></param> public void Thread_Get_Fiction_Detail(object _o) { if (_i_OpenType == 0)//查找界面打开小数详情 { _tfdi_All_Info = _cfs_Search._o_Get_Fiction_All_Info(_tfi_Main); } else if (_i_OpenType == 1)//书架界面打开小说详情 { } Lv_Chapter_List.BeginInvoke(new Action(() => { if (_tfdi_All_Info != null) { Lab_Fiction_Name.Text = _tfdi_All_Info._tfi_Fiction.col_fiction_name; this.Text += Lab_Fiction_Name.Text; Lab_Fiction_Author.Text = _tfdi_All_Info._tfi_Fiction.col_fiction_author; Lab_Fiction_Type.Text = _tfdi_All_Info._tfi_Fiction.col_fiction_type; Lab_Update_Chapter.Text = _tfdi_All_Info._tfi_Fiction.col_update_chapter; Lab_Update_Chapter.Tag = _tfdi_All_Info._tfi_Fiction.col_update_chapter_url; Lab_Update_Time.Text = _tfdi_All_Info._tfi_Fiction.col_update_time.ToString("yyyy-MM-dd"); Lab_Fiction_Introduction.Text = _tfdi_All_Info._tfi_Fiction.col_fiction_introduction; if (_tfdi_All_Info._s_Poster == null || _tfdi_All_Info._s_Poster == "") { Pbx_Fiction_Poster.Image = _tfdi_All_Info._img_Poster; } else { Pbx_Fiction_Poster.Image = _2_BLL.Cls_Oprt_Image.Load_Image((_tfdi_All_Info._s_Poster)); } Lv_Chapter_List.Items.Clear(); foreach (tb_chapter_list _tcl in _tfdi_All_Info._ltcl_Chapter) { ListViewItem _lvi = new ListViewItem(_tcl.col_chapter_name); _lvi.Tag = _tcl; Lv_Chapter_List.Items.Add(_lvi); } } else { Lab_Fiction_Name.Text = "无数据!"; } Lab_Load.Visible = false; Mpgb_Load.Visible = false; Pal_Main.Enabled = true; })); }
public Frm_Fiction_Detail_Info(tb_fiction_detail_info _tfdi, int _type = 1) { InitializeComponent(); _tfdi_All_Info = _tfdi; _i_OpenType = _type; switch (_i_OpenType) { case 1: //书架界面打开 Btn_Add_BookShelf.Enabled = false; break; case 2: //下载完成打开 Btn_Add_BookShelf.Enabled = false; Btn_Download.Enabled = false; break; } }
/// <summary> /// 小说导出Txt /// </summary> /// <param name="_tfdi">小说实体</param> /// <param name="_path">路径</param> /// <returns></returns> public static bool Output_Fiction_To_Txt(tb_fiction_detail_info _tfdi, string _path) { try { using (StreamWriter sw = new StreamWriter(_path)) { //写入小说名 sw.WriteLine("《" + _tfdi._tfi_Fiction.col_fiction_name + "》" + "\r\n\r\n"); //写入小说内容 foreach (tb_chapter_list _tcl in _tfdi._ltcl_Chapter) { sw.WriteLine(_tcl.col_chapter_name); sw.WriteLine(_tcl.col_chapter_content); } } return(true); } catch { return(false); } }
/// <summary> /// 获取小说信息,包括章节,封皮 /// </summary> /// <param name="_tfi"></param> /// <returns></returns> public tb_fiction_detail_info _o_Get_Fiction_All_Info(tb_fiction_info _tfi) { if (_tfi == null) { return(null); } tb_fiction_detail_info _tfdi = new tb_fiction_detail_info(); _tfdi._tfi_Fiction = new tb_fiction_info(); _tfdi._ltcl_Chapter = new List <tb_chapter_list>(); HtmlWeb _web_Main = new HtmlWeb(); _web_Main.OverrideEncoding = Encoding.UTF8; try { HtmlAgilityPack.HtmlDocument _doc_Main = new HtmlAgilityPack.HtmlDocument(); _doc_Main = _web_Main.Load(_tfi.col_url_homepage); //判断是否有数据 if (_doc_Main.Text == "") { return(null); } //获取小说名 _tfdi._tfi_Fiction.col_fiction_name = _tfi.col_fiction_name; //小说主页链接 _tfdi._tfi_Fiction.col_url_homepage = _tfi.col_url_homepage; //获取小说信息 HtmlNodeCollection _hnc_Info = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div[starts-with(@id,'info')]"); if (_hnc_Info.Count == 0) { return(null); } //获取小说作者 _tfdi._tfi_Fiction.col_fiction_author = _tfi.col_fiction_author; //获取最后更新时间 _tfdi._tfi_Fiction.col_update_time = _tfi.col_update_time; //获取最后更新章节及链接 _tfdi._tfi_Fiction.col_update_chapter = _tfi.col_update_chapter; _tfdi._tfi_Fiction.col_update_chapter_url = _tfi.col_update_chapter_url; //获取小说简介 HtmlNodeCollection _hnc_Intro = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'maininfo')]/div[starts-with(@id,'intro')]"); if (_hnc_Intro.Count > 0) { _tfdi._tfi_Fiction.col_fiction_introduction = _hnc_Intro[0].InnerText.Trim(); } //小说封皮链接 HtmlNodeCollection _hnc_Poster_URL = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'sidebar')]/div/img"); if (_hnc_Poster_URL.Count > 0) { _tfdi._tfi_Fiction.col_url_poster = "https://www.qu.la" + _hnc_Poster_URL[0].Attributes["src"].Value; } //设置来源 _tfdi._tfi_Fiction.col_fiction_source = "笔趣阁"; //获取点击量 _tfdi._tfi_Fiction.col_click_count = _tfi.col_click_count; //获取状态 _tfdi._tfi_Fiction.col_fiction_stata = _tfi.col_fiction_stata; //小说类型 _tfdi._tfi_Fiction.col_fiction_type = _tfi.col_fiction_type; //获取章节列表 HtmlNodeCollection _hnc_Chapter_List = _doc_Main.DocumentNode.SelectNodes("//div[starts-with(@id,'list')]/dl/dd/a"); if (_hnc_Chapter_List.Count != 0) { foreach (HtmlNode _hn in _hnc_Chapter_List) { tb_chapter_list _tcl_one = new tb_chapter_list(); _tcl_one.col_fiction_id = _tfi.col_fiction_id; _tcl_one.col_volume_id = 0; _tcl_one.col_chapter_name = _hn.InnerText; _tcl_one.col_chapter_url = _tfi.col_url_homepage + _hn.Attributes["href"].Value; _tfdi._ltcl_Chapter.Add(_tcl_one); } } //获取小说封皮 //链接有误 if (_tfdi._tfi_Fiction.col_url_poster != "") { _tfdi._img_Poster = Image.FromStream(WebRequest.Create(_tfdi._tfi_Fiction.col_url_poster) .GetResponse().GetResponseStream()); } return(_tfdi); } catch { return(null); } }