第八章课后作业

时间:2022-11-22 09:09:31
第八章课后作业第八章课后作业
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lesson8MyTv
{
//频道类
public abstract class ChannelBase
{
public string ChannelName { get; set; }//频道名称
public string Path { get; set; }//频道地址
public List<TvProgram> Tvlist { get; set; }//频道列表
public string Type { get; set; }//频道类型
public ChannelBase(string type,string path,string channelName)
{
this.ChannelName = channelName;
this.Path = path;
this.Type = type;
this.Tvlist = new List<TvProgram>();
}
public ChannelBase()
{

}
public abstract void Fetch();
}
}
频道类
第八章课后作业第八章课后作业
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace lesson8MyTv
{
//北京电视台
public class BeijingTv:ChannelBase
{
public BeijingTv()
{

}
public BeijingTv(string type, string path, string channelName)
:
base(type, path, channelName)
{

}
//解析北京电视台xml文件
public override void Fetch()
{
XmlDocument doc
= new XmlDocument();
doc.Load(
"北京电视台.xml");
XmlNode node
= doc.DocumentElement;
foreach (XmlNode item in node)
{
if (item.Name == "tvProgramTable")
{
foreach (XmlNode no in item)
{
TvProgram tv
= new TvProgram(Convert.ToDateTime(no["playTime"].InnerText), no["programName"].InnerText, no["Path"].InnerText);
this.Tvlist.Add(tv);
}
}
}

}
}
}
北京电视台类
第八章课后作业第八章课后作业
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace lesson8MyTv
{
//凤凰卫视
public class FenghuangTv:ChannelBase
{
public FenghuangTv()
{

}
public FenghuangTv(string channelName, string path, string type)
:
base(channelName, path, type)
{

}
//解析北京电视台xml文件
public override void Fetch()
{
XmlDocument doc
= new XmlDocument();
doc.Load(
"凤凰卫视.xml");
XmlNode node
= doc.DocumentElement;
foreach (XmlNode item in node)
{
if (item.Name == "ProgramList")
{
foreach (XmlNode no in item)
{
TvProgram tv
= new TvProgram(Convert.ToDateTime(no["playTime"].InnerText), no["programName"].InnerText, no["Path"].InnerText);
this.Tvlist.Add(tv);
}
}
}

}
}
}
凤凰卫视类
第八章课后作业第八章课后作业
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace lesson8MyTv
{
/// <summary>
/// 加载所有频道信息
/// </summary>
public class Management
{
public static List<ChannelBase> load()
{
List
<ChannelBase> list = new List<ChannelBase>();
XmlDocument dic
= new XmlDocument();
dic.Load(
"FullChannel.xml");
XmlNode root
=dic.DocumentElement;
foreach (XmlNode item in root)
{
ChannelBase cb
= ChannelManager.CreateChannel(item["channeltype"].InnerText, item["tvChannel"].InnerText, item["path"].InnerText);
cb.Fetch();
list.Add(cb);

}
return list;
}
}
}
管理类
第八章课后作业第八章课后作业
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lesson8MyTv
{
//类型查询工具类
public class ChannelManager
{
public static ChannelBase CreateChannel(string Type,string Name,string path)
{
ChannelBase cb
= null;
switch (Type)
{
case "TypeA":
cb
= new BeijingTv(Type,path,Name);
break;
case "TypeB":
cb
= new FenghuangTv(Type, path, Name);
break;
}
return cb;
}
}
}
工具类
第八章课后作业第八章课后作业
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 lesson8MyTv
{
public partial class FrmTV : Form
{
TreeNode root
= null;
public FrmTV()
{
InitializeComponent();
}
/// <summary>
/// 初始我的电视台
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmTV_Load(object sender, EventArgs e)
{
dgvTV.AutoGenerateColumns
= false;
root
= new TreeNode("我的电视台");
tvTV.Nodes.Add(root);
info();
}
//添加“所有电视台”
private void info()
{

TreeNode node
= new TreeNode("所有电视台");
this.tvTV.Nodes.Add(node);
//管理集合
List<ChannelBase> list = Management.load();
foreach (ChannelBase item in list)
{
item.Fetch();

TreeNode no
= new TreeNode(item.ChannelName);
no.Tag
= item;
node.Nodes.Add(no);
}
}
/// <summary>
/// 加入频道
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvTV_AfterSelect(object sender, TreeViewEventArgs e)
{
if (tvTV.SelectedNode.Tag != null)
{
dgvTV.DataSource
= ((ChannelBase)tvTV.SelectedNode.Tag).Tvlist;
}
foreach (TreeNode item in tvTV.Nodes)
{
foreach (TreeNode no in item.Nodes)
{
//选择右击快捷键显示

if (no.Parent.Text == tvTV.Nodes[0].Text && no == tvTV.SelectedNode)
{
cmsiTv.Items[
0].Visible = false;
cmsiTv.Items[
1].Visible = true;
}
else if (no.Parent.Text == tvTV.Nodes[1].Text && no == tvTV.SelectedNode)
{
cmsiTv.Items[
1].Visible = false;
cmsiTv.Items[
0].Visible = true;
}
else if (item == tvTV.SelectedNode)
{
cmsiTv.Items[
1].Visible = false;
cmsiTv.Items[
0].Visible = false;
}
}
}
}
//添加节目到我的电视台
private void tsmiAddTV_Click(object sender, EventArgs e)
{
bool fa = true;
//循环判断
foreach (TreeNode item in tvTV.Nodes[0].Nodes)
{
if (item.Text == tvTV.SelectedNode.Text)
{
fa
= false;
}
}
if (fa)
{
TreeNode node
= new TreeNode(tvTV.SelectedNode.Text);
node.Tag
= tvTV.SelectedNode.Tag;
root.Nodes.Add(node);
}
else
{
MessageBox.Show(
"已经添加到我的电视了", "提示");
}
}
/// <summary>
/// 删除我的电视台的节目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiDeleteTV_Click(object sender, EventArgs e)
{
tvTV.SelectedNode.Remove();
}
}
}
主窗体
第八章课后作业第八章课后作业
<?xml version="1.0" encoding="utf-8" ?>
<TypeA>
<channelName>北京电视台</channelName>
<tvProgramTable>
<tvProgram>
<playTime>2017-4-15 06:20</playTime>
<meridien>早间档</meridien>
<programName>重播:国际双行线</programName>
<Path>**</Path>
</tvProgram>

<tvProgram>
<playTime>2017-4-15 07:20</playTime>
<meridien>早间档</meridien>
<programName>北京你早</programName>
<Path>**</Path>
</tvProgram>

<tvProgram>
<playTime>2017-4-15 07:40</playTime>
<meridien>早间档</meridien>
<programName>重播:《红星剧场》32集剧:勇者无敌(31)</programName>
<Path>**</Path>
</tvProgram>

<tvProgram>
<playTime>2017-4-15 08:30</playTime>
<meridien>早间档</meridien>
<programName>重播:《红星剧场》32集剧:勇者无敌(32)</programName>
<Path>**</Path>
</tvProgram>

<tvProgram>
<playTime>2017-4-15 08:50</playTime>
<meridien>早间档</meridien>
<programName>重播:专题片:我爱你,中华</programName>
<Path>**</Path>
</tvProgram>

<tvProgram>
<playTime>2017-4-15 09:50</playTime>
<meridien>早间档</meridien>
<programName>身边</programName>
<Path>**</Path>
</tvProgram>
</tvProgramTable>
</TypeA>
北京电视台
第八章课后作业第八章课后作业
<?xml version="1.0" encoding="utf-8" ?>
<TypeB>
<channelName>凤凰卫视</channelName>
<ProgramList>
<Program>
<playTime>2014-4-14 01:20</playTime>
<programName>金龙鱼凤凰剧场:李算(9)</programName>
<Path>**</Path>
</Program>

<Program>
<playTime>2014-4-14 02:00</playTime>
<programName>非凡人物论成功(713)</programName>
<Path>**</Path>
</Program>

<Program>
<playTime>2014-4-14 02:30</playTime>
<programName>有报天天读(28/09/09)</programName>
<Path>**</Path>
</Program>

<Program>
<playTime>2014-4-14 03:10</playTime>
<programName>娱乐大风暴(682)</programName>
<Path>**</Path>
</Program>

<Program>
<playTime>2014-4-14 03:50</playTime>
<programName>上海新长宁集团特约之2013中华小姐环球大赛-美丽前奏(41)</programName>
<Path>**</Path>
</Program>

<Program>
<playTime>2014-4-14 04:25</playTime>
<programName>完全时尚手册:天桥云裳(632)</programName>
<Path>**</Path>

<Program>
<playTime>2014-4-14 04:50</playTime>
<programName>东风康明斯凤凰冲击播:天力士特约之今日看世界(39)</programName>
<Path>**</Path>
</Program>
</Program>
</ProgramList>
</TypeB>
凤凰卫视
第八章课后作业第八章课后作业
<?xml version="1.0" encoding="utf-8" ?>
<TVChannels>
<Channel>
<channeltype>TypeA</channeltype>
<tvChannel>北京电视台</tvChannel>
<path>**</path>
</Channel>
<Channel>
<channeltype>TypeB</channeltype>
<tvChannel>凤凰卫视</tvChannel>
<path>**</path>
</Channel>
</TVChannels>
频道