請用心「品嚐」網絡電視精靈

市場上有許多電視軟件,所以咱們開發屬於本身的電視軟件!對於咱們初學者來講也是拿來對付行外人吹牛的資本「^_^」node

本套軟件所用的技術:架構

01.C/S架構,數據存儲在XML文件中 ide

    02.簡單工廠模式this

    03.繼承和多態spa

    04.解析XML文檔技術3d

   05.深刻剖析內存中數據的走向code

  06.TreeView控件的使用orm

首先你得建立如下這麼多類!xml

namespace IntertnetTVS
{
    //頻道基類
   pub
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Xml;
 7 
 8 namespace IntertnetTVS
 9 {
10     public class TypeAChannel : ChannelBase
11     {
12         public override void Fetch()
13         {
14             XmlDataDocument doc=new XmlDataDocument();
15             doc.Load("北京電視臺.xml");
16             if (TVlist==null)
17             {
18                 TVlist = new List<TVprogram>();
19             }
20             XmlNode root = doc.DocumentElement;
21             
22             foreach (XmlNode item in root.ChildNodes)
23             {
24                 if (item.Name == "tvProgramTable")
25                 {
26                     foreach (XmlNode mynode in item.ChildNodes)
27                     {
28                         TVprogram tp = new TVprogram();
29                         tp.PlayTime = DateTime.Parse(mynode["playTime"].InnerText);
30                         tp.MyProperty = mynode["meridien"].InnerText;
31                         tp.Name = mynode["programName"].InnerText;
32                         tp.Path = mynode["path"].InnerText;
33                         TVlist.Add(tp);
34                     }
35                 }
36             }
37 
38         }
39     }
40 }
 
 

 

lic abstract class ChannelBase
    {
       //頻道節目名稱
        public string ChannelName { get; set; }
      //儲存頻道節目路徑
        public string Path { get; set; }
       //儲存頻道下的各個節目
        public string Type { get; set; }
       //類型
        public List<TVprogram> TVlist { get; set; }
        public abstract void Fetch();
    }
}

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace IntertnetTVS
 8 {
 9     //節目類
10    public class TVprogram
11     {
12        //節目播出時間
13         public DateTime PlayTime { get; set; }
14        //節目播出時段
15         public string MyProperty { get; set; }
16         //節目名稱
17         public string Name{ get; set; }
18        //節目保存路徑
19         public string Path { get; set; }
20 
21     }
22 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 
 8 //工廠類
 9 namespace IntertnetTVS
10 {
11    public class ChannelFactory
12     {
13        //工廠來建立相應對象的簡單工廠
14        public static ChannelBase CreateBase(string type)
15        {
16            ChannelBase bases = null;
17            switch(type)
18            {
19                case "TypeA":
20                    bases=new TypeAChannel();
21                    break;
22                case "TypeB":
23                    bases=new TypeBChannel();
24                    break;
25            }
26            return bases;
27        }
28     }
29 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Xml;
 7 
 8 namespace IntertnetTVS
 9 {
10    public class ChannelManager
11     {
12        public ChannelManager()
13        {
14            fullChannels = new Dictionary<string, ChannelBase>();
15         }
16        //建立dictionary來儲存全部的頻道
17         private Dictionary<string, ChannelBase> fullChannels;
18         public Dictionary<string, ChannelBase> FullChannels
19         {
20             get { return fullChannels; }
21             set { fullChannels = value; }
22         }
23        //解析xml文檔將數據儲存到dictionary
24        public void ParseXmlToDictionary()
25        {
26            XmlDataDocument doc = new XmlDataDocument();
27            doc.Load("FullChannels.xml");
28            XmlNode root = doc.DocumentElement;
29            foreach (XmlNode item in root.ChildNodes)
30            {
31                //獲取type的類型
32                string type = item["channelType"].InnerText;
33               //將類型傳到工場中返回對應子類
34                ChannelBase mybase = ChannelFactory.CreateBase(type);
35                mybase.ChannelName = item["tvChannel"].InnerText;
36                mybase.Path = item["path"].InnerText;
37                mybase.Type = type;
38                FullChannels.Add(mybase.ChannelName, mybase);
39            }
40        }
41     }
42 }

窗體裝載代碼對象

 1 sing System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace IntertnetTVS
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19 
20         private void Form1_Load(object sender, EventArgs e)
21         {
22             chishi();
23             ChannelManager manager = new ChannelManager();
24             manager.ParseXmlToDictionary();
25             Dictionary<string, ChannelBase> ydy = manager.FullChannels;
26             foreach (var item in ydy.Values)
27             {
28                 TreeNode nodes = new TreeNode();
29                 nodes.Text = item.ChannelName;
30                 nodes.Tag = item;
31                 allnode.Nodes.Add(nodes);
32             }
33         }
34         TreeNode allnode = new TreeNode();
35         //將treeview控件添加初始默認列表
36         public void chishi()
37         {
38             allnode.Text = "全部電臺";
39             TreeNode mynode = new TreeNode();
40             mynode.Text = "個人電臺";
41             this.tvChannel.Nodes.Add(mynode);
42             this.tvChannel.Nodes.Add(allnode);
43 
44         }
45         private void tvChannel_AfterSelect(object sender, TreeViewEventArgs e)
46         {
47             TreeNode selectnodes =this.tvChannel.SelectedNode;
48             if (selectnodes.Level==1&&selectnodes.Parent.Text=="全部電臺")
49             {
50                 ChannelBase cb = (ChannelBase)selectnodes.Tag;
51                 if (cb.TVlist!=null)
52                 {
53                     cb.TVlist.Clear();
54                 }
55                 cb.Fetch();
56                 List<TVprogram> porje = cb.TVlist;
57                 this.dgvProgList.DataSource = porje;
58             }
59         }
60     }
61 }

多麼偉大的創做!多麼神奇的軟件!走過路過,千萬不要錯過!

相關文章
相關標籤/搜索