C#总结项目《影院售票系统》编写总结一
C#学习经历从基本语法结构到窗体再到面向对象终于走完了.NET初级程序员的道路,做为品德优良好学生更不能落下课程的总结项目-某某鸟《影院售票系统》。用了大概一天半的时间做完这个练手项目,先上效果截图一张
抽出时间做些这个对目前的我来说算不小的项目。
用到的知识点有:面向对象思想、TreeView、XML读取、File文件流、泛型集合,这里面对我来说难度最大的是面向对象与泛型集合的结合,看来学习一门编程语言的难点还是在设计思想上。
再来介绍一下项目需求:在影片列表中选择某个时段的一场电影,单击座位选择一个种类的电影票,并创建电影,计算价格并打印影票信息,然后该座位被置为红色表示已经售出。
影院每天更新放映列表,系统支持实时查看,包括电影放映场次时间、电影概况。
影院提供三类影票:普通票、赠票和学生票(赠票免费;学生票有折扣)
允许用户查看某场次座位的售出情况
支持购票,并允许用户选座
用户可以选择场次、影票类型及空闲座位进行购票,并打印电影票
系统可以保存销售情况,并允许对其进行恢复
二.问题分析
1.系统开发步骤
(1)明确需求
(2)设计类
(3)创建项目
(4)确定编码顺序
1.主窗体
2.查看新放映列表
3.查看电影介绍
4.查看影票票价
5.查看放映厅座位
6.购票和打印电影票
7.继续购票
(5)测试
三、类的设计
1.Seat:保存影院的座位信息,主要属性如下
座位号(SeatNum):string类型
座位卖出状态颜色(Color):System.Drawing.Color类型
2.Movie:电影类
电影名(MovieName):string类型
海报图片路径(Poster):string类型
导演名(Director):string类型
主演(Actor):string类型
电影类型(MovieType):MovieType自定义枚举类型
定价(Price):int类型
3.Ticket:电影票父类,保存电影票信息
放映场次(ScheduleItem):ScheduleItem自定义类
所属座位对象(Seat):Seat自定义类型
票价(Price):int类型
计算票价的虚方法CalcPrice()
打印售票信息的虚方法Print()
显示当前售出票信息的虚方法Show()
4.StudentTicket:学生票子类,继承父类Ticket
学生票的折扣(Discount):int类型
重写父类计算票价CalcPrice
重写父类打印售票信息的Print()
重写父类显示当前出票信息的Show()方法
5.FreeTicket:赠票子类,继承父类Ticket
获得赠票者的名字属性(CustomerName):string类型
重写父类计算票价CalcPrice()
重写父类打印售票信息Print()
重写父类显示当前出票信息Show()
6.ScheduleItem:影院每天计划放映计划的场次,保存每场电影的信息
放映时间属性(Time):string类型
本场所放映电影属性(Movie):Movie自定义类型
7.Schedule:放映计划类
放映场次属性(Items):自定义泛型集合Dictionary<string,ScheduleItem>
读取XML文件获取放映计划集合的LoadItems()方法
8.Cinema:影院类,保存放映计划和座位类
座位集合属性(Seat):自定义泛型集合Dictionary<string,Seat>
放映计划Schedule:Schedule自定义类型
已售出电影票的集合(SoldTicket):自定义泛型集合List<Ticket>
保存和读取售票情况的Save()和Load()方法
献上这9个类的代码,根据依赖编写类的顺序,不能完全按照上面顺序
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Drawing; 7 8 namespace 影院售票系统 9 { 10 /// <summary> 11 /// 保存影院的座位信息 12 /// </summary> 13 public class Seat 14 { 15 public Seat() { } 16 public Seat(string seatNum,Color color) 17 { 18 this.SeatNum = seatNum; 19 this.Color = color; 20 } 21 private string _seatNum; 22 /// <summary> 23 /// 座位号 24 /// </summary> 25 public string SeatNum 26 { 27 get { return _seatNum; } 28 set { _seatNum = value; } 29 } 30 private Color _color; 31 /// <summary> 32 /// 座位卖出状态颜色 33 /// </summary> 34 public Color Color 35 { 36 get { return _color; } 37 set { _color = value; } 38 } 39 } 40 }
Seat
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 影院售票系统 8 { 9 /// <summary> 10 /// 电影类 11 /// </summary> 12 public class Movie 13 { 14 private string _movieName; 15 /// <summary> 16 /// 电影名 17 /// </summary> 18 public string MovieName 19 { 20 get { return _movieName; } 21 set { _movieName = value; } 22 } 23 private string _poster; 24 /// <summary> 25 /// 海报图片名 26 /// </summary> 27 public string Poster 28 { 29 get { return _poster; } 30 set { _poster = value; } 31 } 32 private string _director; 33 /// <summary> 34 /// 导演名 35 /// </summary> 36 public string Director 37 { 38 get { return _director; } 39 set { _director = value; } 40 } 41 private string _actor; 42 /// <summary> 43 /// 主演 44 /// </summary> 45 public string Actor 46 { 47 get { return _actor; } 48 set { _actor = value; } 49 } 50 51 private int _price; 52 /// <summary> 53 /// 定价 54 /// </summary> 55 public int Price 56 { 57 get { return _price; } 58 set { _price = value; } 59 } 60 /// <summary> 61 /// 电影类型 62 /// </summary> 63 public MovieType MovieType { get; set; } 64 } 65 /// <summary> 66 /// 电影类型,1喜剧2战争3爱情 67 /// </summary> 68 public enum MovieType 69 { 70 /// <summary> 71 /// 动作片 72 /// </summary> 73 Action = 0, 74 /// <summary> 75 /// 战争片 76 /// </summary> 77 War = 1, 78 /// <summary> 79 /// 爱情片 80 /// </summary> 81 Comedy = 2 82 } 83 }
Movie
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows.Forms; 7 using System.IO; 8 9 namespace 影院售票系统 10 { 11 /// <summary> 12 /// 电影票父类 13 /// </summary> 14 public class Ticket 15 { 16 public Ticket() { } 17 public Ticket(ScheduleItem sch,Seat seat) 18 { 19 this.ScheduItem = sch; 20 this.Seat = seat; 21 } 22 private Seat _seat = new Seat(); 23 /// <summary> 24 /// 所属座位 25 /// </summary> 26 public Seat Seat 27 { 28 get { return _seat; } 29 set { _seat = value; } 30 } 31 32 private int _price; 33 /// <summary> 34 /// 票价 35 /// </summary> 36 public int Price 37 { 38 get { return _price; } 39 set { _price = value; } 40 } 41 /// <summary> 42 /// 放映场次 43 /// </summary> 44 public ScheduleItem ScheduItem { get; set; } 45 /// <summary> 46 /// 计算票价 47 /// </summary> 48 public virtual void CalcPrice() 49 { 50 this.Price = ScheduItem.Movie.Price; 51 } 52 /// <summary> 53 /// 打印售票信息 54 /// </summary> 55 public virtual void Print() 56 { 57 string info = string.Format("************************************************\n\t青鸟影院\n------------------------------------------------\n电影名:\t{0}\n时间:\t{1}\n座位号:\t{2}\n价格:\t{3}\n************************************************", this.ScheduItem.Movie.MovieName, this.ScheduItem.Time, this.Seat.SeatNum, this.Price); 58 MessageBox.Show(info); 59 //存到文件中 60 string fileName = this.ScheduItem.Time.Replace(":", "-")+" "+this.Seat.SeatNum+".txt"; 61 FileStream fs = new FileStream(fileName,FileMode.Create); 62 StreamWriter sw = new StreamWriter(fs); 63 sw.Write(info); 64 sw.Close(); 65 fs.Close(); 66 } 67 /// <summary> 68 /// 显示当前售票信息 69 /// </summary> 70 public virtual void Show() 71 { 72 string info = string.Format("已售出!\n普通票!"); 73 MessageBox.Show(info); 74 } 75 } 76 }
Ticket
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows.Forms; 7 using System.IO; 8 namespace 影院售票系统 9 { 10 /// <summary> 11 /// 学生票 12 /// </summary> 13 public class StudentTicket : Ticket 14 { 15 public StudentTicket() { } 16 public StudentTicket(ScheduleItem sch, Seat seat, int discount) 17 : base(sch, seat) 18 { 19 this.Discount = discount; 20 } 21 private int _discount; 22 /// <summary> 23 /// 学生票的折扣 24 /// </summary> 25 public int Discount 26 { 27 get { return _discount; } 28 set { _discount = value; } 29 } 30 /// <summary> 31 /// 计算学生票价 32 /// </summary> 33 public override void CalcPrice() 34 { 35 this.Price =this.ScheduItem.Movie.Price* Discount / 10; 36 } 37 /// <summary> 38 /// 打印学生票的售票信息 39 /// </summary> 40 public override void Print() 41 { 42 string info = string.Format("************************************************\n\t青鸟影院(学生)\n------------------------------------------------\n电影名:\t{0}\n时间:\t{1}\n座位号:\t{2}\n价格:\t{3}\n************************************************", this.ScheduItem.Movie.MovieName, this.ScheduItem.Time, this.Seat.SeatNum, this.Price); 43 MessageBox.Show(info); 44 //存到文件中 45 string fileName = this.ScheduItem.Time.Replace(":", "-") + " " + this.Seat.SeatNum + ".txt"; 46 FileStream fs = new FileStream(fileName, FileMode.Create); 47 StreamWriter sw = new StreamWriter(fs); 48 sw.Write(info); 49 sw.Close(); 50 fs.Close(); 51 } 52 /// <summary> 53 /// 显示当前售出票信息 54 /// </summary> 55 public override void Show() 56 { 57 string info = string.Format("已售出!\n{0}折学生票!",this.Discount); 58 MessageBox.Show(info); 59 } 60 } 61 }
StudentTicket
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows.Forms; 7 using System.IO; 8 9 namespace 影院售票系统 10 { 11 /// <summary> 12 /// 赠票 13 /// </summary> 14 public class FreeTicket:Ticket 15 { 16 public FreeTicket() { } 17 public FreeTicket(ScheduleItem sch,Seat seat,string name) 18 { 19 this.Seat = seat; 20 this.CustomerName = name; 21 this.ScheduItem = sch; 22 } 23 private string _customerName; 24 /// <summary> 25 /// 获得赠票者的名字 26 /// </summary> 27 public string CustomerName 28 { 29 get { return _customerName; } 30 set { _customerName = value; } 31 } 32 /// <summary> 33 /// 计算票价 34 /// </summary> 35 public override void CalcPrice() 36 { 37 this.Price = 0; 38 } 39 /// <summary> 40 /// 打印售票信息 41 /// </summary> 42 public override void Print() 43 { 44 string info = string.Format("************************************************\n\t青鸟影院(赠票)\n------------------------------------------------\n电影名:\t{0}\n时间:\t{1}\n座位号:\t{2}\n姓名:\t{3}\n************************************************", this.ScheduItem.Movie.MovieName, this.ScheduItem.Time, this.Seat.SeatNum, this.CustomerName); 45 MessageBox.Show(info); 46 //存到文件中 47 string fileName = this.ScheduItem.Time.Replace(":", "-") + " " + this.Seat.SeatNum + ".txt"; 48 FileStream fs = new FileStream(fileName, FileMode.Create); 49 StreamWriter sw = new StreamWriter(fs); 50 sw.Write(info); 51 sw.Close(); 52 fs.Close(); 53 } 54 /// <summary> 55 /// 显示当前售出票信息 56 /// </summary> 57 public override void Show() 58 { 59 MessageBox.Show("已售出!\n赠票!"); 60 } 61 } 62 }
FreeTicket
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 影院售票系统 8 { 9 /// <summary> 10 /// 影院每天计划放映的场次,保存每场电影的信息 11 /// </summary> 12 public class ScheduleItem 13 { 14 private string _time; 15 /// <summary> 16 /// 放映时间 17 /// </summary> 18 public string Time 19 { 20 get { return _time; } 21 set { _time = value; } 22 } 23 private Movie _movie = new Movie(); 24 25 /// <summary> 26 /// 本场放映的电影 27 /// </summary> 28 public Movie Movie 29 { 30 get { return _movie; } 31 set { _movie = value; } 32 } 33 private List<Ticket> _soldTickets=new List<Ticket>(); 34 35 private Dictionary<string, Seat> _seats=new Dictionary<string,Seat>(); 36 /// <summary> 37 /// 本场次的座位状态 38 /// </summary> 39 public Dictionary<string, Seat> Seats 40 { 41 get { return _seats; } 42 set { _seats = value; } 43 } 44 } 45 }
ScheduleItem
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 影院售票系统 9 { 10 /// <summary> 11 /// 放映计划类,保存影院当天的放映计划集合 12 /// </summary> 13 public class Schedule 14 { 15 /// <summary> 16 /// 放映场次 17 /// </summary> 18 public Dictionary<string, ScheduleItem> Items = new Dictionary<string, ScheduleItem>(); 19 /// <summary> 20 /// 读取XML文件获取放映计划集合 21 /// </summary> 22 public void LoadItems() 23 { 24 Items.Clear(); 25 XmlDocument xml = new XmlDocument(); 26 xml.Load("ShowList.xml"); 27 XmlElement root = xml.DocumentElement; 28 foreach (XmlNode item in root.ChildNodes) 29 { 30 Movie movie = new Movie(); 31 movie.MovieName = item["Name"].InnerText; 32 movie.Poster = item["Poster"].InnerText; 33 movie.Director = item["Director"].InnerText; 34 movie.Actor = item["Actor"].InnerText; 35 switch (item["Type"].InnerText) 36 { 37 case "Action": 38 movie.MovieType = MovieType.Action; 39 break; 40 case "War": 41 movie.MovieType = MovieType.War; 42 break; 43 case "Comedy": 44 movie.MovieType = MovieType.Comedy; 45 break; 46 } 47 movie.Price = Convert.ToInt32(item["Price"].InnerText); 48 if (item["Schedule"].HasChildNodes) 49 { 50 foreach (XmlNode item2 in item["Schedule"].ChildNodes) 51 { 52 ScheduleItem schItem = new ScheduleItem(); 53 schItem.Time = item2.InnerText; 54 schItem.Movie = movie; 55 Items.Add(schItem.Time, schItem); 56 } 57 } 58 59 } 60 61 62 } 63 } 64 }
Schedule
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 影院售票系统 8 { 9 /// <summary> 10 /// 影院类 11 /// </summary> 12 public class Cinema 13 { 14 private Dictionary<string, Seat> _seats = new Dictionary<string, Seat>(); 15 /// <summary> 16 /// 座位集合 17 /// </summary> 18 public Dictionary<string, Seat> Seats 19 { 20 get { return _seats; } 21 set { _seats = value; } 22 } 23 private Schedule _schedule = new Schedule(); 24 /// <summary> 25 /// 放映计划 26 /// </summary> 27 public Schedule Schedule 28 { 29 get { return _schedule; } 30 set { _schedule = value; } 31 } 32 private List<Ticket> _soldTickets=new List<Ticket>(); 33 /// <summary> 34 /// 已经售出的票 35 /// </summary> 36 public List<Ticket> SoldTickets 37 { 38 get { return _soldTickets; } 39 set { _soldTickets = value; } 40 } 41 /// <summary> 42 /// 保存售票信息到文件中 43 /// </summary> 44 public void Save() 45 { 46 //Save和Load的代码在窗体的代码实现了 47 } 48 /// <summary> 49 /// 从文件中读取售票信息 50 /// </summary> 51 public void Load() { } 52 } 53 }
Cinema
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 影院售票系统 8 { 9 /// <summary> 10 /// 工具类 11 /// </summary> 12 public class TicketUtil 13 { 14 /// <summary> 15 /// 创建电影票 16 /// </summary> 17 /// <returns></returns> 18 public static Ticket CreateTicket(ScheduleItem sch,Seat seat,int discount,string customerName,string type) 19 { 20 Ticket ticket=null; 21 switch (type) 22 { 23 case "StudentTicket": 24 ticket = new StudentTicket(sch,seat,discount); 25 break; 26 case "FreeTicket": 27 ticket = new FreeTicket(sch,seat,customerName); 28 break; 29 default: 30 ticket = new Ticket(sch,seat); 31 break; 32 } 33 return ticket; 34 } 35 } 36 }
TicketUtil
明天将继续更新-电影院座位的动态绘制、电影信息绑定到窗体中展现出来,也望各路大神出手斧正不合理的代码(不要涉及分层开发,我们在学,以后会用分层开发实现其他的项目)
转载于:https://www.cnblogs.com/AIThink/p/4931961.html
C#总结项目《影院售票系统》编写总结一相关推荐
- C#窗体项目————影院售票系统
影院售票系统(一) 现在学习到了C#的最后一本书,有一个窗体的结业案例. 先上图 运行起来是这样的 点击座位号弹出是否购票 买了之后座位变红色 对于老手来说可能so easy:但对我这菜鸟来说有点复杂 ...
- Jsp实现在线影院售票系统
此系统以MyEclipse作为前台开发工具和MySQL这款强大的数据库专业软件做后台数据库的设计,整个系统用简洁明快的界面展现出来,使操作简单可行,用户使用方便.简洁.本系统采用当今社会比较先进的SS ...
- Oracle影院订票系统,C#实现影院售票系统
本文实例为大家分享了C#实现影院售票系统的具体代码,供大家参考,具体内容如下 本人认为此项目的难点有4点 1.首先是将解析完的XML文件绑定到TreeView上 2.用代码动态生成座位的label,生 ...
- (附源码)计算机毕业设计SSM影院售票系统
项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...
- [附源码]java毕业设计影院售票系统
项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...
- 基于node.js和vue的前后端分离影院售票系统电影院影片管理
1,项目介绍 基于 node.js和vue 的影院售票系统拥有两种角色,分别为管理员和用户. 用户:热映.即将上映.电影和影院全局搜索.评论.选座.购票.点赞.收藏.订单等一系列购票功能 管理员:用户 ...
- asp.net影院售票系统
编号:646 随着时代的发展,人们在茶前饭后通常会到电影院看最新的影片信息,丰富自己的业余生活.传统的影院订票都是到电影院之后进行购票,但是通常情况下我们不知道影院是否已经满座,我们是否能够顺利的拿到 ...
- 影院售票系统java和数据库_影院售票管理系统的设计与实现(SSH,SQLServer)(含录像)...
影院售票管理系统的设计与实现(SSH,SQLServer)(含录像)(毕业论文15900字,程序代码,SQLServer数据库) 本毕业设计的内容,阐述了实现整个电影票预订系统功能的系统.从实现电影票 ...
- java 影院售票系统_java电影院售票系统
[实例简介] 有简单界面的电影院售票系统,功能有用XML存储电影资源,把已售的电影票信息保存到txt文件中,再以电影票的形式打印到txt文件中. [实例截图] [核心代码] saletickt_sys ...
- C#总结项目《影院售票系统》编写总结二
昨天发布了总结项目的第一篇,需求分析以及类的搭建,今天继续更新,动态绘制控件.票类型的切换以及数据在窗体中的展现. 先从简单的开始,票类型的切换. 分析: 1.当点击普通票时 学生折扣和赠送者是禁用的 ...
最新文章
- brave浏览器_Brave for Mac(安全浏览器)
- zabbix之微信告警(python版):微信个人报警,微信企业号告警脚本
- Python高级编程(二)
- 什么时候使用webservice1
- Python实例--文本词频统计
- MySQL Innodb表导致死锁日志情况分析与归纳
- 软件测试简历上的职业技能怎么写,软件测试岗位个人技能范文
- 13个坏习惯让IT工作者过度劳累
- Linux平台上文件同步——rsync+inotify之定时同步
- C/C++文件输入输出(详细介绍)
- 希尔排序(c语言实现)
- 怎样获得元气骑士的损坏的机器人_元气骑士损坏的机器人怎么修复?机器人修复方法...
- 仿真时信号出现高阻态、不定态——Test Bench中要做声明
- 解决:Mac 分屏时程序坞跑副屏问题
- SpringBoot和Mybatis配置多个数据库
- Myeclipse下载github上项目到本地(图解)
- n1 openwrt 挂载u盘_[Openwrt 扩展上篇]USB挂载U盘启动Samba共享
- 游戏音乐与影视音乐的区别
- canvas:心率图案例 + ES5/ES6封装该案例
- 大学相关比赛(常规和计算机类赛事)
热门文章
- Mac Dock截图的小技巧
- 从虚拟化到软件定义--重新定义IT产业格局
- 函数除颤/节流提高性能 + 原生实现滚动时到视口时展现
- win7(64位)php5.5-Apache2.4-环境安装
- Struts中s:checkboxlist的用法
- IWAM账号 HTTP500内部错误
- Dubbo介绍前篇------单一应用框架、垂直应用框架、分布式应用框架、流动计算框架,及RPC的简介
- EntityManager方法简介
- “阿里味” PUA 编程语言火上GitHub热榜,标星1.9K!
- 放弃用了7年的MyBatis !我选择 JDBCTemplate!