欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

C#开发的 程序员专用RSS阅读器

介绍 评论 失效链接反馈

C#开发的 程序员专用RSS阅读器 C#网络编程-第1张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); } }}

下载声明:

本站资源均有第三方用户自行上传分享推荐,非本站自制,仅供玩家做交流学习之用!切勿用于商业用途!游戏作品版权归原作者享有,如有版权问题,请附带版权证明至邮件,本平台将应您的要求删除。
相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复