灭顶之灾之网络电视精灵——S2 2.8

从前,有一个神奇的东西叫做搞搞精灵

关于他,有一段历史。

哎呀!我去!写不下去了。

-。-以上玩笑

首先需求分析 

TreeView显示两种频道 TypeA和TypeB

所以创建三个类 ChannelBase TypeA TypeB

然后每个频道有节目单

节目单也因频道不同而不同 分为两种

所以也是三个类

Programme ProgramA ProgramB

新建一个ChannelBase对象的list集合

load事件

判断快捷菜单用

判断然后给DataGridView设置数据源

频道父类:

A子类

B子类

节目父类

public class ChannelManager
    {
        public void Resolve(List<ChannelBase> list)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("files/FullChannels.xml");
            XmlNode root = doc.DocumentElement;
            foreach (XmlNode item in root.ChildNodes)
            {
                if (item["channelType"].InnerText.Equals("TypeA"))
                {
                    TypeA channel = new TypeA();
                    channel.Type = item["channelType"].InnerText;
                    channel.ChannelName = item["tvChannel"].InnerText;
                    channel.Path = item["path"].InnerText;

                    List<ProgramA> proList = new List<ProgramA>();
                    XmlDocument doc2 = new XmlDocument();
                    doc2.Load(item["path"].InnerText);
                    XmlNode node = doc2.DocumentElement;
                    foreach (XmlNode key in node.ChildNodes[1])
                    {
                        ProgramA p = new ProgramA();
                        p.Time = Convert.ToDateTime(key["playTime"].InnerText);
                        p.Meridien = key["meridien"].InnerText;
                        p.Name = key["programName"].InnerText;
                        p.Path = key["path"].InnerText;

                        proList.Add(p);
                    }
                    channel.List = proList;
                    list.Add(channel);
                }
                else
                {
                    TypeB channel = new TypeB();
                    channel.Type = item["channelType"].InnerText;
                    channel.ChannelName = item["tvChannel"].InnerText;
                    channel.Path = item["path"].InnerText;

                    List<ProgramB> proList = new List<ProgramB>();
                    XmlDocument doc2 = new XmlDocument();
                    doc2.Load(item["path"].InnerText);
                    XmlNode node = doc2.DocumentElement;
                    foreach (XmlNode key in node.ChildNodes[0])
                    {
                        ProgramB p = new ProgramB();
                        p.Time = Convert.ToDateTime(key["playTime"].InnerText);
                        p.Name = key["name"].InnerText;
                        p.Path = key["path"].InnerText;

                        proList.Add(p);
                    }
                    channel.List = proList;
                    list.Add(channel);
                }
                
            }
        }
    }

最后 核心的代码

然后 完成

原文地址:https://www.cnblogs.com/swordtm/p/5846308.html