logo资料库

C#影院售票系统毕业设计(1).pdf

第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
资料共6页,全文预览结束
影院售票系统毕业设计(1)) C#影院售票系统毕业设计( 主要介绍了C#影院售票系统毕业设计,献上了9个类的设计,需要的朋友可以参考下  C#学习经历从基本语法结构到窗体再到面向对象终于走完了.NET初级程序员的道路,用了大概一天半的时间做完这个练手项目《影院售票系统》, 《影院售票系统》,先上效果截图一张 抽出时间做些这个对目前的我来说算不小的项目。 用到的知识点有:面向对象思想、 面向对象思想、TreeView、、XML读取、读取、File文件流、泛型集合 文件流、泛型集合,这里面对我来说难度最大的是面向对象与泛型集合的结合,看来学习一门编程语言的难点还是在设计思想上。 再来介绍一下项目需求 项目需求:在影片列表中选择某个时段的一场电影,单击座位选择一个种类的电影票,并创建电影,计算价格并打印影票信息,然后该座位被置为红色表示已经售出。 影院每天更新放映列表,系统支持实时查看,包括电影放映场次时间、电影概况。 影院提供三类影票: 影院提供三类影票:普通票、赠票和学生票(赠票免费;学生票有折扣) 允许用户查看某场次座位的售出情况 支持购票,并允许用户选座 用户可以选择场次、影票类型及空闲座位进行购票,并打印电影票 系统可以保存销售情况,并允许对其进行恢复 一、问题分析 一、问题分析 1.系统开发步骤 (1)明确需求 (2)设计类 (3)创建项目 (4)确定编码顺序 1.主窗体 2.查看新放映列表 3.查看电影介绍 4.查看影票票价 5.查看放映厅座位 6.购票和打印电影票 7.继续购票 (5)测试 二、类的设计 二、类的设计 献上这9个类的代码,根据依赖编写类的顺序,不能完全按照上面顺序 1.Seat:保存影院的座位信息,主要属性如下 :保存影院的座位信息,主要属性如下 座位号(SeatNum):string类型 座位卖出状态颜色(Color):System.Drawing.Color类型 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace 影院售票系统 { /// /// 保存影院的座位信息 /// public class Seat { public Seat() { } public Seat(string seatNum,Color color)
{ this.SeatNum = seatNum; this.Color = color; } private string _seatNum; /// /// 座位号 /// public string SeatNum { get { return _seatNum; } set { _seatNum = value; } } private Color _color; /// /// 座位卖出状态颜色 /// public Color Color { get { return _color; } set { _color = value; } } } } 2.Movie:电影类 :电影类 电影名(MovieName):string类型 海报图片路径(Poster):string类型 导演名(Director):string类型 主演(Actor):string类型 电影类型(MovieType):MovieType自定义枚举类型 定价(Price):int类型 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 影院售票系统 { /// /// 电影类 /// public class Movie { private string _movieName; /// /// 电影名 /// public string MovieName { get { return _movieName; } set { _movieName = value; } } private string _poster; /// /// 海报图片名 /// public string Poster { get { return _poster; } set { _poster = value; } } private string _director; /// /// 导演名 /// public string Director { get { return _director; } set { _director = value; } } private string _actor; /// /// 主演 /// public string Actor { get { return _actor; } set { _actor = value; } } private int _price; /// /// 定价 /// public int Price { get { return _price; } set { _price = value; } } /// /// 电影类型 /// public MovieType MovieType { get; set; } } /// /// 电影类型,1喜剧2战争3爱情 /// public enum MovieType { /// /// 动作片 /// Action = 0, /// /// 战争片 /// War = 1, /// /// 爱情片 /// Comedy = 2 } } 3.Ticket:电影票父类,保存电影票信息 :电影票父类,保存电影票信息 放映场次(ScheduleItem):ScheduleItem自定义类
所属座位对象(Seat):Seat自定义类型 票价(Price):int类型 计算票价的虚方法CalcPrice() 打印售票信息的虚方法Print() 显示当前售出票信息的虚方法Show() using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace 影院售票系统 { /// /// 电影票父类 /// public class Ticket { public Ticket() { } public Ticket(ScheduleItem sch,Seat seat) { this.ScheduItem = sch; this.Seat = seat; } private Seat _seat = new Seat(); /// /// 所属座位 /// public Seat Seat { get { return _seat; } set { _seat = value; } } private int _price; /// /// 票价 /// public int Price { get { return _price; } set { _price = value; } } /// /// 放映场次 /// public ScheduleItem ScheduItem { get; set; } /// /// 计算票价 /// public virtual void CalcPrice() { this.Price = ScheduItem.Movie.Price; } /// /// 打印售票信息 /// public virtual void Print() { 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); MessageBox.Show(info); //存到文件中 string fileName = this.ScheduItem.Time.Replace(":", "-")+" "+this.Seat.SeatNum+".txt"; FileStream fs = new FileStream(fileName,FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(info); sw.Close(); fs.Close(); } /// /// 显示当前售票信息 /// public virtual void Show() { string info = string.Format("已售出!\n普通票!"); MessageBox.Show(info); } } } 4.StudentTicket:学生票子类,继承父类 :学生票子类,继承父类Ticket 学生票的折扣(Discount):int类型 重写父类计算票价CalcPrice 重写父类打印售票信息的Print() 重写父类显示当前出票信息的Show()方法 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace 影院售票系统 { /// /// 学生票 /// public class StudentTicket : Ticket { public StudentTicket() { } public StudentTicket(ScheduleItem sch, Seat seat, int discount) : base(sch, seat) { this.Discount = discount; } private int _discount; /// /// 学生票的折扣 /// public int Discount { get { return _discount; } set { _discount = value; } } /// /// 计算学生票价
/// public override void CalcPrice() { this.Price =this.ScheduItem.Movie.Price* Discount / 10; } /// /// 打印学生票的售票信息 /// public override void Print() { 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); MessageBox.Show(info); //存到文件中 string fileName = this.ScheduItem.Time.Replace(":", "-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(info); sw.Close(); fs.Close(); } /// /// 显示当前售出票信息 /// public override void Show() { string info = string.Format("已售出!\n{0}折学生票!",this.Discount); MessageBox.Show(info); } } } 5.FreeTicket:赠票子类,继承父类 :赠票子类,继承父类Ticket 获得赠票者的名字属性(CustomerName):string类型 重写父类计算票价CalcPrice() 重写父类打印售票信息Print() 重写父类显示当前出票信息Show() using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace 影院售票系统 { /// /// 赠票 /// public class FreeTicket:Ticket { public FreeTicket() { } public FreeTicket(ScheduleItem sch,Seat seat,string name) { this.Seat = seat; this.CustomerName = name; this.ScheduItem = sch; } private string _customerName; /// /// 获得赠票者的名字 /// public string CustomerName { get { return _customerName; } set { _customerName = value; } } /// /// 计算票价 /// public override void CalcPrice() { this.Price = 0; } /// /// 打印售票信息 /// public override void Print() { 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); MessageBox.Show(info); //存到文件中 string fileName = this.ScheduItem.Time.Replace(":", "-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(info); sw.Close(); fs.Close(); } /// /// 显示当前售出票信息 /// public override void Show() { MessageBox.Show("已售出!\n赠票!"); } } } 6.ScheduleItem:影院每天计划放映计划的场次,保存每场电影的信息 :影院每天计划放映计划的场次,保存每场电影的信息 放映时间属性(Time):string类型 本场所放映电影属性(Movie):Movie自定义类型 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 影院售票系统 { /// /// 影院每天计划放映的场次,保存每场电影的信息 /// public class ScheduleItem { private string _time; /// /// 放映时间 ///
public string Time { get { return _time; } set { _time = value; } } private Movie _movie = new Movie(); /// /// 本场放映的电影 /// public Movie Movie { get { return _movie; } set { _movie = value; } } private List _soldTickets=new List(); private Dictionary _seats=new Dictionary(); /// /// 本场次的座位状态 /// public Dictionary Seats { get { return _seats; } set { _seats = value; } } } } 7.Schedule:放映计划类 :放映计划类 放映场次属性(Items):自定义泛型集合Dictionary 读取XML文件获取放映计划集合的LoadItems()方法 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace 影院售票系统 { /// /// 放映计划类,保存影院当天的放映计划集合 /// public class Schedule { /// /// 放映场次 /// public Dictionary Items = new Dictionary(); /// /// 读取XML文件获取放映计划集合 /// public void LoadItems() { Items.Clear(); XmlDocument xml = new XmlDocument(); xml.Load("ShowList.xml"); XmlElement root = xml.DocumentElement; foreach (XmlNode item in root.ChildNodes) { Movie movie = new Movie(); movie.MovieName = item["Name"].InnerText; movie.Poster = item["Poster"].InnerText; movie.Director = item["Director"].InnerText; movie.Actor = item["Actor"].InnerText; switch (item["Type"].InnerText) { case "Action": movie.MovieType = MovieType.Action; break; case "War": movie.MovieType = MovieType.War; break; case "Comedy": movie.MovieType = MovieType.Comedy; break; } movie.Price = Convert.ToInt32(item["Price"].InnerText); if (item["Schedule"].HasChildNodes) { foreach (XmlNode item2 in item["Schedule"].ChildNodes) { ScheduleItem schItem = new ScheduleItem(); schItem.Time = item2.InnerText; schItem.Movie = movie; Items.Add(schItem.Time, schItem); } } } } } } 8.Cinema:影院类,保存放映计划和座位类 :影院类,保存放映计划和座位类 座位集合属性(Seat):自定义泛型集合Dictionary 放映计划Schedule:Schedule自定义类型 已售出电影票的集合(SoldTicket):自定义泛型集合List 保存和读取售票情况的Save()和Load()方法 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 影院售票系统 { /// /// 影院类 /// public class Cinema { private Dictionary _seats = new Dictionary(); /// /// 座位集合 /// public Dictionary Seats {
get { return _seats; } set { _seats = value; } } private Schedule _schedule = new Schedule(); /// /// 放映计划 /// public Schedule Schedule { get { return _schedule; } set { _schedule = value; } } private List _soldTickets=new List(); /// /// 已经售出的票 /// public List SoldTickets { get { return _soldTickets; } set { _soldTickets = value; } } /// /// 保存售票信息到文件中 /// public void Save() { //Save和Load的代码在窗体的代码实现了 } /// /// 从文件中读取售票信息 /// public void Load() { } } } 9.工具类工具类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 影院售票系统 { /// /// 工具类 /// public class TicketUtil { /// /// 创建电影票 /// /// public static Ticket CreateTicket(ScheduleItem sch,Seat seat,int discount,string customerName,string type) { Ticket ticket=null; switch (type) { case "StudentTicket": ticket = new StudentTicket(sch,seat,discount); break; case "FreeTicket": ticket = new FreeTicket(sch,seat,customerName); break; default: ticket = new Ticket(sch,seat); break; } return ticket; } } } 下篇文章将继续更新,内容有电影院座位的动态绘制、电影信息绑定到窗体中展现出来,希望大家不要走开,有什么地方需要改进的欢迎大家指出,共同探讨进步。
分享到:
收藏