你的位置:首页 > ASP.net教程

[ASP.net教程]一个年轻的码农的一个C#项目


    话不多少,今天要写一个小项目。我们写项目要做好准备。我们要做项目分析。要知道用户需求,然后在根据需求来规划自己的项目。我们要用自己所学,做最好的程序。尽自己所能完成项目需求。精简代码!

  我们今天要写的项目叫网络电视精灵。首先我们要做到的是要把我们事先写好的

 

  有几个细节要求写到再说!下面有彩蛋!!!

做好的窗体是这个样子的!

启动是这个样子的 

所有的类是这个样子的

 

每个类的代码和注释

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Chap_网络电视精灵{  /// <summary>  /// 电视频道父类,抽象类  /// </summary>  public abstract class ChannelBase  {    //这是一堆自动属性,很简单就是要来接收

  

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Chap_网络电视精灵{  public class ChannelFactory  {    /// <summary>    /// 工厂类    /// </summary>    /// <param name="type"></param>    /// <returns></returns>    public static ChannelBase CreateChannel(string type)    {      ChannelBase channel = null;      switch(type)      {        case "TypeA":          channel = new TypeAChannel();          break;        case "TypeB":          channel = new TypeBChannel();          break;        default:          break;      }      return channel;    }  }}

  

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.

  

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Chap_网络电视精灵{  /// <summary>  /// 简单工厂类  /// </summary>  class Factory  {    //一个静态的返回值为ChannelBase类型的方法    public static ChannelBase CreateFactory(string type)    {      ChannelBase types = null;      switch (type)      {        case "TypeA":          types = new TypeAChannel();          break;        case "TypeB":          types = new TypeBChannel();          break;      }      return types;    }  }}

  

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Chap_网络电视精灵{  /// <summary>  /// 电视频道类  /// </summary>  public class TvProgram  {    //节目名称    public string ProgramName { get; set; }    //时段    public string Meridien { get; set; }    //节目路径    public string Path { get; set; }    //时间    public DateTime PlayTime { get; set; }  }}

  

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.

  

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.

  

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;using System.    //绑定TreeView的数据    public void Insert()    {            TreeNode minenode = new TreeNode();      minenode.Text = "我的电视台";      //bind      tvList.Nodes.Add(minenode);      //根节点      TreeNode root = new TreeNode();      root.Text = "所有电视台";      //bind      tvList.Nodes.Add(root);            ChannelManager manager = new ChannelManager();      manager.ResolveChannels();      List<ChannelBase> list = manager.List;      foreach (ChannelBase item in list)      {        TreeNode tn = new TreeNode();        tn.Text = item.ChannelName;        tn.Tag = item;        root.Nodes.Add(tn);              }    }    private void tvList_AfterSelect(object sender, TreeViewEventArgs e)    {      if(flag)      {
//让右键选择菜单分开显示 if (tvList.SelectedNode.Level == 0) { ctms.Items[0].Visible = false; ctms.Items[1].Visible = false; } else if (tvList.SelectedNode.Parent.Text == "我的电视台") { ctms.Items[0].Visible = true; ctms.Items[1].Visible = false; } else if (tvList.SelectedNode.Parent.Text == "所有电视台") { ctms.Items[0].Visible = false; ctms.Items[1].Visible = true; } TreeNode selectNode = tvList.SelectedNode; if (selectNode.Tag == null) { return; } ChannelBase channel = (ChannelBase)selectNode.Tag; //给LIst集合填充数据 channel.Fetch(); List<TvProgram> list = channel.ProgramList1; clear(list); } } public void clear(List<TvProgram> list) { dgvList.AutoGenerateColumns = false; dgvList.DataSource = new BindingList<TvProgram>(list); } private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void 加入我的电视台ToolStripMenuItem_Click(object sender, EventArgs e) {
//右键加入我的电视台 ChannelBase channel = (ChannelBase)tvList.SelectedNode.Tag; TreeNode node = new TreeNode(); node.Text = channel.ChannelName; node.Tag = channel; tvList.Nodes[0].Nodes.Add(node); } private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) { //删除所选中的节点

  我是彩蛋!!! 

  所有代码都在上面了,最后总结一下思路!我们首先把电视频道的