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