Network TV Genie and cnetwork TV genie
I. Framework
Ii. Main form
Iii. Enter the code stage
1. xml file
①. FullChannels. xml
<? Xml version = "1.0" encoding = "UTF-8"?> <TVChannels> <Channel> <channelType> TypeA </channelType> <! -- Channel type --> <tvChannel> Beijing TV station </tvChannel> <! -- Channel name --> <path> files/Beijing TV station. xml </path> <! -- Local path of the XML file corresponding to the Channel --> </Channel> <channelType> TypeB </channelType> <tvChannel> Phoenix TV </tvChannel> <path> files/Phoenix satellite TV. xml </path> </Channel> </TVChannels>
② Beijing TV. xml
<? Xml version = "1.0" encoding = "UTF-8"?> <TypeA version = "1.0"> <channelName> Beijing TV </channelName> <tvProgramTable> <tvProgram> <playTime> </playTime> <meridien> afternoon </meridien> <programName> 55 episodes of Rose theater: shaoguan Zhongshu (24) </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening file </meridien> <programName> News evening peak </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening files </ meridien> <programName> Beijing News </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening files </meridien> <programName> weather forecast </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening video </meridien> <programName> broadcast CCTV News Broadcast </programName> <path> ** </path> </tvProgram> <playTime> </ playTime> <meridien> night files </meridien> <programName> weather </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening document </meridien> <programName> topic: I love you, China (15) </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening file </meridien> <programName> opening ceremony of "Mom and Dad are old members" </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening files </meridien> <programName> 38 episodes of red star theater: 60 years (1) </programName> <path> ** </path> </tvProgram> <playTime> </playTime> <meridien> evening file </meridien> <programName> replay Literature and Art: fantasia song and dance competition (5) </programName> <path> ** </path> </tvProgram> </tvProgramTable> </typeA>
③. Phoenix TV. xml
<? Xml version = "1.0" encoding = "UTF-8"?> <TypeB version = "1.0"> <ProgramList> <Program> <playTime> </playTime> <! -- Broadcast time --> <name> jinlongyu Phoenix Theater: Li computing (9) </name> <! -- Program name --> <path> ** </path> <! -- Local path of the Program video --> </Program> <playTime> </playTime> <! -- Broadcast time --> <name> inspection team (34) (R) </name> <! -- Program name --> <path> ** </path> <! -- Local path of the Program video --> </Program> </ProgramList> </typeB>
2. writing classes
①. TVprogram. cs
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace Day _ network_ TV genie {public class TVprogram {// time public DateTime PlayTime {get; set ;}// time range public string Meridien {get; set ;} // program name public string ProgramName {get; set ;}// video Path public string Path {get; set ;}}}
②. ChannelBase. cs
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace Day _ network_ TV genie {// channel parent class public abstract class ChannelBase {public string Type {get; set ;}// channel Type public string ChannelName {get; set ;}// channel name public string Path {get; set ;}// channel Path public List <TVprogram> ProgremList = new List <TVprogram> (); public abstract void Cb ();}}
③. ChannelManager. cs
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. xml; namespace Day _ network_ TV genie {// channel management class public ChannelManager {public List <ChannelBase> list = new List <ChannelBase> (); 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 _ network_ TV genie {public class Factory {// create a Factory class 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 _ network_ TV genie {public class TypeA: ChannelBase {public override void Cb () {XmlDocument xd = new XmlDocument (); xd. load ("Beijing TV. 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 );}}}}}}
6. TypeB. cs
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. xml; namespace Day _ network_ TV genie {public class TypeB: ChannelBase {public override void Cb () {XmlDocument xd = new XmlDocument (); xd. load ("Phoenix TV. 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 );}}}}}}
7. 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 _ network_ TV genie {public partial class FrmMain: Form {public FrmMain () {InitializeComponent ();} public ChannelManager manager = new ChannelManager (); private void FrmMain_Load (object sender, EventArgs e) {// Add the root node dataGridView1.AutoGenerateColumns = false; TreeNode node = new TreeNode (); node. text = "my TV station"; treeView1.Nodes. add (node); TreeNode nodee = new TreeNode (); nodee. text = "all TV stations"; treeView1.Nodes. add (nodee); manager. resolveChannel (); List <ChannelBase> 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 treeview=afterselect (object sender, TreeViewEventArgs e) {TreeNode tn = treeView1.SelectedNode; ChannelBase channel = manager. list [Convert. toInt16 (tn. tag)]; channel. progremList. clear (); channel. cb (); List <TVprogram> list = channel. progremList; dataGridView1.DataSource = list ;}}}
3. Now you can watch TV !!!!!! 1 !!!!
4. Success !!!!!!!!!!