日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#电视节目单展示案例

發布時間:2025/5/22 C# 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#电视节目单展示案例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

需求:將文件中的電視節目單信息展示到列表中

步驟一:搭建電視節目單實體類

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

namespace TVListProgram
{
??? /// <summary>
??? /// 電視節目單實體類
??? /// </summary>
??? public class TVList
??? {
??????? /// <summary>
??????? /// 電視節目時間
??????? /// </summary>
??????? public string TVTime { get; set; }
??????? /// <summary>
??????? /// 電視節目頻道
??????? /// </summary>
??????? public string Channel { get; set; }
??????? /// <summary>
??????? /// 電視節目名稱
??????? /// </summary>
??????? public string TVName { get; set; }
????? ?
??? }
}

步驟二:搭建數據操作類。注意數據操作類的命名一般是在實體類后面加上Service

?

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

namespace TVListProgram
{
??? /// <summary>
??? /// 電視節目單數據操作類
??? /// </summary>
? public? class TVListService
??? {
??????? /// <summary>
??????? /// 將文件對象封裝到List集合中并返回
??????? /// </summary>
??????? /// <param name="path">節目單文件路徑</param>
??????? /// <param name="tvDate">節目單日期</param>
??????? /// <returns>返回電視節目單和節目單日期</returns>
??????? public List<TVList> LoadTVList(string path,out string tvDate)
??????? {
??????????? //創建文件流和文件讀取器
??????????? FileStream fs = new FileStream(path, FileMode.Open);
??????????? StreamReader sr = new StreamReader(fs,Encoding.Default);
??????????? tvDate = sr.ReadLine(); //讀取文本第一行的電視節目日期
??????????? sr.ReadLine();//讀取空行
??????????? //循環讀取電視節目列表到最后一行終止
??????????? string content = string.Empty;
??????????? List<TVList> list = new List<TVList>();
??????????? string[] array = null; //保存一行分割后的內容
??????????? while (true)
??????????? {
??????????????? content = sr.ReadLine();
??????????????? if (content == null || content.Length == 0)//讀取到空的內容處,跳出循環
??????????????? {
??????????????????? break;
??????????????? }
??????????????? else
??????????????? {
??????????????????? array = content.Split(Convert.ToChar("#"));
??????????????????? list.Add(new TVList()
??????????????????? {
??????????????????????? TVTime =array[0],
??????????????????????? Channel=array[1],
??????????????????????? TVName=array[2]
??????????????????? });
??????????????? }
??????????? }
???????? ?
??????????? //關閉文件流,讀取器
??????????? fs.Close();
??????????? sr.Close();
??????????? return list;
??????? }
??? }
}
步驟三:加載按鈕編寫窗體程序

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 TVListProgram
{
??? public partial class FrmTVList : Form
??? {
??????? public FrmTVList()
??????? {
??????????? InitializeComponent();
??????????? this.dgvTVList.AutoGenerateColumns = false;

??????? }
??????? TVListService objTVListService = new TVListService();
??????? private void dgvTVList_CellContentClick(object sender, DataGridViewCellEventArgs e)
??????? {

??????? }

??????? private void btnLoadTVList_Click(object sender, EventArgs e)
??????? {
??????????? OpenFileDialog ofd = new OpenFileDialog();
??????????? DialogResult result = ofd.ShowDialog();
??????????? if (result == DialogResult.OK)
??????????? {
??????????????? string tvDate = string.Empty;
?????????????? List<TVList> list= objTVListService.LoadTVList(ofd.FileName,out tvDate);
???????????? ?
??????????????? this.dgvTVList.DataSource = list;
??????????????? this.lblTVDate.Text = tvDate;
??????????? }
??????? }
??? }
}

?

轉載于:https://www.cnblogs.com/cuig/p/8854029.html

總結

以上是生活随笔為你收集整理的C#电视节目单展示案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。