using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Model;using System.Diagnostics;using System.Xml;using System.Reflection;using System.IO;using System.Threading;using Common.PageHelper;namespace 程序员{ public partial class frmMain : Form { public frmMain() { InitializeComponent(); } private static int index = 1; List<Types> list = null; private void InitList(List<Model.Article> list, ListView lstArticle) { for (int i = 0; i < list.Count; i ) { string[] item = { list[i].Title, list[i].Link, list[i].CreateTime.ToString(), list[i].SourceShowName }; ListViewItem listItem = new ListViewItem(item); lstArticle.Items.Add(listItem); } } private void InitOpenBrowser() { IList<Browser> list = new List<Browser>(); BLL.BrowserManager browser = new BLL.BrowserManager(); list = browser.GetBrowserPath(); if (list != null && list.Count > 0) { int selectedIndex = 0; int num = 0; foreach (Browser current in list) { if (current.IsDefault) { selectedIndex = num; } num ; } this.cbOpenBrowser.DisplayMember = "BrowserName"; this.cbOpenBrowser.ValueMember = "BrowserPath"; this.cbOpenBrowser.DataSource = list; this.cbOpenBrowser.SelectedIndex = selectedIndex; return; } MessageBox.Show("检测不到系统浏览器,请确认是否安装了浏览器"); } private List<Model.Types> GetUrl(string category) { var type = from t in list where (t.Category == category && t.IsSelect == true) select t; return type.ToList<Types>(); } public List<Types> LoadXmlFile() { #region Types List<Types> list = new List<Types>(); Types type = null; //实例化XML对象 XmlDocument doc = null; try { doc = new XmlDocument(); //加载XML文件 doc.Load("Configuration.xml"); //找到根节点 XmlNode rootNode = doc.DocumentElement; //读写XML文件 foreach (XmlNode childNode in rootNode.ChildNodes) { type = new Types(); foreach (XmlNode sunNode in childNode.ChildNodes) { switch (sunNode.Name) { case "Category": type.Category = sunNode.InnerText; break; case "DomainName": type.DomainName = sunNode.InnerText; break; case "Url": type.Url = sunNode.InnerText; break; case "IsSelect": type.IsSelect = bool.Parse(sunNode.InnerText); break; } } list.Add(type);//添加到集合中 } } catch (Exception ex) { throw ex; } #endregion return list; } public void SaveToXmlFile(List<Types> list) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<types></types>"); XmlNode root = doc.SelectSingleNode("types"); for (int i = 0; i < list.Count; i ) { XmlElement type = doc.CreateElement("type"); XmlElement Category = doc.CreateElement("Category"); XmlElement DomainName = doc.CreateElement("DomainName"); XmlElement Url = doc.CreateElement("Url"); XmlElement IsSelect = doc.CreateElement("IsSelect"); root.AppendChild(type); type.AppendChild(Category); type.AppendChild(DomainName); type.AppendChild(Url); type.AppendChild(IsSelect); Category.InnerText = list[i].Category; DomainName.InnerText = list[i].DomainName; Url.InnerText = list[i].Url; IsSelect.InnerText = list[i].IsSelect.ToString(); } doc.Save("Configuration.xml"); } private void GetArticleHtml(string articleUrl, string comefrom) { HttpItem item = new HttpItem() { Method = "get", URL = articleUrl }; HttpHelper http = new HttpHelper(); HttpResult result = http.GetHtml(item); string html = result.Html; } private void frmMain_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; // skinEngine1.SkinFile = @"skin\vista1.ssk"; cbArticleType.SelectedIndex = 0; InitOpenBrowser(); this.list = LoadXmlFile(); this.picLoading.Visible = false; this.lblLoading.Visible = false; this.Text = "程序员资讯助手v1.0"; InitCategoryTree(); } private void InitCategoryTree() { string[] type = new string[] { "Winform", "ASP.NET", "SQL", "前端", "WP开发", "Android", "IOS", "PHP", "Java", "C " }; foreach (string t in type) { trvCategory.Nodes.Add(t); } } private void btnGet_Click(object sender, EventArgs e) { #region 开始下载文章 Thread thread = new Thread(new ThreadStart(delegate() { Stopwatch sw = new Stopwatch(); picLoading.Visible = true; lblLoading.Visible = true; sw.Start(); lstList.Items.Clear(); string category = cbArticleType.Text; List<Model.Types> types = GetUrl(category); for (int i = 0; i < types.Count; i ) { if (types[i].DomainName == "CSDN") { BLL.CSDNManager csdn = new BLL.CSDNManager(); List<Article> list = csdn.Init(types[i].Url, index); InitList(list, lstList); } if (types[i].DomainName == "Cnblogs") { BLL.CnbolgManager cnblogs = new BLL.CnbolgManager(); List<Article> list = cnblogs.Init(types[i].Url, index); InitList(list, lstList); } if (types[i].DomainName == "ITEyeBlog") { BLL.ITEyeBlogManager ITEyeBlog = new BLL.ITEyeBlogManager(); List<Article> list = ITEyeBlog.Init(types[i].Url, index); InitList(list, lstList); } } sw.Stop(); this.picLoading.Visible = false; this.lblLoading.Visible = false; lblInfo.Text = "共耗时" (sw.ElapsedMilliseconds / 1000.0).ToString() "秒"; this.lblRowsCount.Text = string.Format("当前第{0}页,本页共{1}条数据", index.ToString(), lstList.Items.Count.ToString()); })); thread.Start(); #endregion } private void lstList_DoubleClick(object sender, EventArgs e) { if (lstList.SelectedItems.Count > 0) { string titleUrl = lstList.SelectedItems[0].SubItems[1].Text; string comefrom = lstList.SelectedItems[0].SubItems[3].Text; if (ckViewCode.Checked) { Process.Start(cbOpenBrowser.SelectedValue.ToString(), titleUrl); } else { new frmViewCode(titleUrl, comefrom).ShowDialog(); } } } private void btnPreview_Click(object sender, EventArgs e) { if (index >= 2) { index--; btnGet.PerformClick(); } } private void btnNext_Click(object sender, EventArgs e) { index ; btnGet.PerformClick(); } private void trvCategory_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { this.panel1.Visible = true; this.cbCSDN.Visible = false; this.cbCnbolg.Visible = false; this.cbITEyeBlog.Visible = false; this.cbCSDN.Checked = false; this.cbCnbolg.Checked = false; this.cbITEyeBlog.Checked = false; string category = e.Node.Text; var type = from t in this.list where (t.Category == category) select t; foreach (Types item in type.ToList<Types>()) { if (item.IsSelect) { if (item.DomainName == "CSDN") { this.cbCSDN.Visible = true; this.cbCSDN.Checked = true; } if (item.DomainName == "Cnblogs") { this.cbCnbolg.Visible = true; this.cbCnbolg.Checked = true; } if (item.DomainName == "ITEyeBlog") { this.cbITEyeBlog.Visible = true; this.cbITEyeBlog.Checked = true; } } } } private void btnSave_Click(object sender, EventArgs e) { string category = trvCategory.SelectedNode.Text; for (int i = 0; i < this.list.Count; i ) { if (list[i].Category == category) { if (list[i].DomainName == "CSDN") { if (cbCSDN.Checked) { list[i].IsSelect = true; } else { list[i].IsSelect = false; } } if (list[i].DomainName == "Cnblogs") { if (cbCnbolg.Checked) { list[i].IsSelect = true; } else { list[i].IsSelect = false; } } if (list[i].DomainName == "ITEyeBlog") { if (cbITEyeBlog.Checked) { list[i].IsSelect = true; } else { list[i].IsSelect = false; } } } } } private void cbSelectAll_CheckedChanged(object sender, EventArgs e) { if (cbSelectAll.Checked) { this.cbCSDN.Checked = true; this.cbCnbolg.Checked = true; this.cbITEyeBlog.Checked = true; } else { this.cbCSDN.Checked = false; this.cbCnbolg.Checked = false; this.cbITEyeBlog.Checked = false; } } private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { SaveToXmlFile(this.list); } }}
下载C#开发的 程序员专用RSS阅读器用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论