基本信息
源码名称:C#开发的 程序员专用RSS阅读器
源码大小:0.28M
文件格式:.rar
开发语言:C#
更新时间:2013-10-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

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);
        }
    }
}