一.框架

 

二.主窗体

 

 三.进入代码阶段

1.xml文件

 ①.FullChannels.xml 

TypeA
北京电视台
files/北京电视台.xml
TypeB
凤凰卫视
files/凤凰卫视.xml

 

②.北京电视台.xml

北京电视台
2013-9-29 16:19
下午档
《玫瑰剧场》55集剧:闯关东中篇(24)
**
2013-9-29 18:00
晚间档
新闻晚高峰
**
2013-9-29 18:30
晚间档
北京新闻
**
2013-9-29 18:56
晚间档
天气预报
**
2013-9-29 19:00
晚间档
转播CCTV新闻联播
**
2013-9-29 19:31
晚间档
看气象
**
2013-9-29 19:40
晚间档
专题片:我爱你,中国(15)
**
2013-9-29 20:22
晚间档
《爸妈都是老党员》首播庆典
**
2013-9-29 21:21
晚间档
《红星剧场》38集剧:咱爸咱妈六十年(1)
**
2013-9-29 23:25
晚间档
重播文艺:花样年华歌舞大赛(5)
**
 

③.ChannelManager.cs

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml;namespace Day_网络_电视精灵{    //频道管理类   public  class ChannelManager   {    public    List
list = new List
(); public void ResolveChannel() { XmlDocument xd=new XmlDocument(); xd.Load("FullChannels.xml"); XmlNode root = xd.DocumentElement; foreach (XmlNode item in root.ChildNodes) { ChannelBase channel = Factory.Fc(item["channelType"].InnerText); channel.Type = item["channelType"].InnerText; channel.ChannelName = item["tvChannel"].InnerText; channel.Path = item["path"].InnerText; list.Add(channel); } } }}

 

 ④.Factory.cs

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Day_网络_电视精灵{  public  class Factory    {      //创建一个工厂类      public static ChannelBase Fc(string type)      {          ChannelBase types = null;          switch (type)          {              case "TypeA":                  types = new TypeA();                  break;              case "TypeB":                  types=new TypeB();                  break;          }          return types;      }    }}

⑤.TypeA.cs

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml;namespace Day_网络_电视精灵{   public class TypeA:ChannelBase   {       public override void Cb()       {           XmlDocument xd = new XmlDocument();           xd.Load("北京电视台.xml");           XmlNode root = xd.DocumentElement;           foreach (XmlNode item in root.ChildNodes)           {               if (item.Name.Equals("tvProgramTable"))               {                   foreach (XmlNode item2 in item.ChildNodes)                   {                       TVprogram tp=new TVprogram();                       tp.PlayTime = Convert.ToDateTime(item2["playTime"].InnerText);                       tp.Meridien = item2["meridien"].InnerText;                       tp.ProgramName = item2["programName"].InnerText;                       tp.Path = item2["path"].InnerText;                       ProgremList.Add(tp);                   }               }           }       }   }}

⑥.TypeB.cs

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml;namespace Day_网络_电视精灵{  public  class TypeB:ChannelBase    {      public override void Cb()      {          XmlDocument xd = new XmlDocument();          xd.Load("凤凰卫视.xml");          XmlNode root = xd.DocumentElement;          foreach (XmlNode item in root.ChildNodes)          {              if (item.Name.Equals("ProgramList"))              {                  foreach (XmlNode item2 in item.ChildNodes)                  {                      TVprogram tp = new TVprogram();                      tp.PlayTime = Convert.ToDateTime(item2["playTime"].InnerText);                      tp.ProgramName = item2["name"].InnerText;                      tp.Path = item2["path"].InnerText;                      ProgremList.Add(tp);                  }              }          }      }    }}

⑦.FrmMain.cs

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Day_网络_电视精灵{    public partial class FrmMain : Form    {        public FrmMain()        {            InitializeComponent();        }        public ChannelManager manager = new ChannelManager();        private void FrmMain_Load(object sender, EventArgs e)        {                                                                                      //添加根节点            dataGridView1.AutoGenerateColumns = false;            TreeNode node=new TreeNode();            node.Text = "我的电视台";            treeView1.Nodes.Add(node);            TreeNode nodee = new TreeNode();            nodee.Text = "所有电视台";            treeView1.Nodes.Add(nodee);                       manager.ResolveChannel();            List
list = manager.list; int num = 0; foreach (ChannelBase item in list) { TreeNode tn=new TreeNode(); tn.Text = item.ChannelName; tn.Tag = num; nodee.Nodes.Add(tn); num++; } } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode tn= treeView1.SelectedNode; ChannelBase channel= manager.list[Convert.ToInt16(tn.Tag)]; channel.ProgremList.Clear(); channel.Cb(); List
list= channel.ProgremList; dataGridView1.DataSource = list; } }}