影院售票系统
Posted 雅俗共赏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了影院售票系统相关的知识,希望对你有一定的参考价值。
1.此项目是模拟影院真实操作来搭建的
影院售票系统
所需要求:
1.影院售票每天都更新放映列表,系统支持实时查看,包括电影放映场次时间,电影情况。
2.影院提供3种影票:普通票,学生票,赠票(赠票免费,学生票有不同的折扣)
3.允许用户可以选择场次,影票的类型及其座位,进行购票,并打印电影票。
4.支持购票,并允许用户选座。
5.系统可以创建保存售票情况,并允许对其进行恢复。
下面是以下售票系统所需的类:
类图如下:
影院类:
//座位集合 public static Dictionary<string, Seat> seats = new Dictionary<string, Seat>(); //放映计划 public static Schedule Schedule = new Schedule(); //已售出电影票集合 public static List<Ticket> Soldticket = new List<Ticket>(); public string path = "影院售票/Save.txt"; //保存售票情况 public void Save() { FileStream filestream = new FileStream(path,FileMode.OpenOrCreate); StreamWriter streamWriter = new StreamWriter(filestream,Encoding.GetEncoding("GB2312")); foreach (Ticket item in Soldticket) { int num = 0; if (item is StudentTicket) { num = 1; } else if (item is FreeTicket) { num = 2; } streamWriter.Write(item.ScheduleItem.Time+"|"+ item.ScheduleItem.Movie.Moviesname+"|"+ item.ScheduleItem.Movie.Poster+"|"+ item.ScheduleItem.Movie.Director+"|"+ item.ScheduleItem.Movie.Actor+"|"+ item.ScheduleItem.Movie.Movietype+"|"+ item.ScheduleItem.Movie.Price+"|" +item.Seat.Seatnum+"|"+item.Price1+ "|"+num+"*"); } streamWriter.Close(); filestream.Close(); } //加载售票情况 public void Load() { FileStream filestream = new FileStream(path, FileMode.Open); StreamReader streamReader = new StreamReader(filestream, Encoding.GetEncoding("GB2312")); string str = streamReader.ReadToEnd(); string[] Info = str.Split(\'*\'); Soldticket = new List<Ticket>(); foreach (string item in Info) { string[] info = item.Split(\'|\'); if (info.Length==10) { ScheduleItem scheduleitem = new ScheduleItem(); scheduleitem.Time = info[0]; Movies movies = new Movies(); scheduleitem.Movie = movies; scheduleitem.Movie.Moviesname = info[1]; scheduleitem.Movie.Poster = info[2]; scheduleitem.Movie.Director = info[3]; scheduleitem.Movie.Actor = info[4]; scheduleitem.Movie.Movietype = (MovieType)Enum.Parse(typeof(MovieType), info[5]); scheduleitem.Movie.Price = Convert.ToDouble(info[6]); Seat seat = new Seat(); seat.Seatnum = info[7]; seat.Color = Color.Red; Ticket ticket = null; if (info[9] == "1") { ticket = new StudentTicket(Convert.ToDouble(info[8]), scheduleitem, seat); } else if (info[9] == "2") { ticket = new FreeTicket(Convert.ToDouble(info[8]), scheduleitem, seat); } else { ticket = new Ticket(Convert.ToDouble(info[8]), scheduleitem, seat); } Soldticket.Add(ticket); } } streamReader.Close(); filestream.Close(); } }
赠票子类继承父类Ticket
public FreeTicket() { } public FreeTicket(double price, ScheduleItem scheduleItem, Seat seat) : base(price, scheduleItem, seat) { } //计算票价信息 public override double CalcPrice() { return 0; } //打印票价信息 public override void Print() { StringBuilder stringBuilder = new StringBuilder("************************\\n"); stringBuilder.AppendLine(" 青鸟影视(赠票)"); stringBuilder.AppendLine("------------------------"); stringBuilder.AppendFormat(" 电影名:{0}\\n", this.ScheduleItem.Movie.Moviesname); stringBuilder.AppendFormat(" 时间:{0}\\n", this.ScheduleItem.Time); stringBuilder.AppendFormat(" 座位号:{0}\\n", this.Seat.Seatnum); stringBuilder.AppendFormat(" 价格:{0}\\n", this.Price1); stringBuilder.AppendFormat("************************\\n"); System.Windows.Forms.MessageBox.Show(stringBuilder.ToString()); } //显示票价信息 public override void Show() { StringBuilder stringBuilder = new StringBuilder("***********抱歉,已售出*************\\n"); stringBuilder.AppendLine(" 青鸟影视(赠票)"); stringBuilder.AppendLine(" ------------------------"); stringBuilder.AppendFormat(" 电影名:{0}\\n", this.ScheduleItem.Movie.Moviesname); stringBuilder.AppendFormat(" 时间:{0}\\n", this.ScheduleItem.Time); stringBuilder.AppendFormat(" 座位号:{0}\\n", this.Seat.Seatnum); stringBuilder.AppendFormat(" 价格:{0}\\n", this.Price1); stringBuilder.AppendFormat(" ************************\\n"); System.Windows.Forms.MessageBox.Show(stringBuilder.ToString()); } }
电影类:
public class Movies { //电影名 private string moviesname; public string Moviesname { get { return moviesname; } set { moviesname = 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 MovieType movietype; public MovieType Movietype { get { return movietype; } set { movietype = value; } } //定价 private double price; public double Price { get { return price; } set { price = value; } } public Movies() { } public Movies(string moviename,string poster,string director,string actor,MovieType movietype,double price) { this.Actor = actor; this.Director = director; this.Moviesname = moviename; this.Movietype = movietype; this.Poster = poster; this.Price = price; } }
电影类型:
public enum MovieType { Comedy,//喜剧 War,//战争 Romance,//角色 Action,//动作 Cartoon,//动画 Thriller,//惊悚 Adventure,//冒险 Love//爱情 }
放映计划类:
public class Schedule { //放映场次集合 public Dictionary<string,ScheduleItem> Items { get; set; } public Schedule() { } public Schedule(Dictionary<string, ScheduleItem> items) { this.Items = items; } //xml读取 public void LoadItems() { XmlDocument xml = new XmlDocument(); xml.Load("影院售票/ShowList.xml"); XmlElement xmlelement = xml.DocumentElement; foreach (XmlNode item in xmlelement.ChildNodes) { foreach (XmlNode item1 in item.ChildNodes) { if (item1.Name == "Schedule") { foreach (XmlNode item2 in item1.ChildNodes) { Movies movie = new Movies(item["Name"].InnerText, item["Poster"].InnerText, item["Director"].InnerText, item["Actor"].InnerText, (MovieType)Enum.Parse(typeof(MovieType), item["Type"].InnerText), Convert.ToDouble(item["Price"].InnerText)); ScheduleItem scheduleItem = new ScheduleItem(item2.InnerText, movie); Items.Add(scheduleItem.Time, scheduleItem); } } } }
放映场次集合:
public class ScheduleItem { //放映时间 private string time; public string Time { get { return time; } set { time = value; } } //电影属性 private Movies movie; public Movies Movie { get { return movie; } set { movie = value; } } public ScheduleItem() { } public ScheduleItem(string time,Movies movie) { this.Movie = movie; this.Time = time; } }
保存座位信息:
public class Seat { //座位号 private string seatnum; public string Seatnum { get { return seatnum; } set { seatnum = value; } } //座位颜色 private Color color; public Color Color { get { return color; } set { color = value; } } public Seat() { } public Seat(string seatnum,Color color) { this.Color = color; this.Seatnum = seatnum; } }
学生票类继承父类Ticket
public class StudentTicket:Ticket { public StudentTicket() { } public StudentTicket(double price, ScheduleItem scheduleItem, Seat seat):base(price,scheduleItem,seat) { } //计算票价信息 public override double CalcPrice() { return Price1 * 0.7; } //打印票价信息 public override void Print() { StringBuilder stringBuilder = new StringBuilder("************************\\n"); stringBuilder.AppendLine(" 青鸟影视(学生)"); stringBuilder.AppendLine("------------------------"); stringBuilder.AppendFormat(" 电影名:{0}\\n", this.ScheduleItem.Movie.Moviesname); stringBuilder.AppendFormat(" 时间:{0}\\n", this.ScheduleItem.Time); stringBuilder.AppendFormat(" 座位号:{0}\\n", this.Seat.Seatnum); stringBuilder.AppendFormat(" 价格:{0}\\n", this.Price1); stringBuilder.AppendFormat("************************\\n"); System.Windows.Forms.MessageBox.Show(stringBuilder.ToString()); } //显示票价信息 public override void Show() { StringBuilder stringBuilder = new StringBuilder("************抱歉,已售出************\\n"); stringBuilder.AppendLine(" 青鸟影视(学生)"); stringBuilder.AppendLine(" ------------------------"); stringBuilder.AppendFormat(" 电影名:{0}\\n", this.ScheduleItem.Movie.Moviesname); stringBuilder.AppendFormat(" 时间:{0}\\n", this.ScheduleItem.Time); stringBuilder.AppendFormat(" 座位号:{0}\\n", this.Seat.Seatnum); stringBuilder.AppendFormat(" 价格:{0}\\n", this.Price1); stringBuilder.AppendFormat(" ************************\\n"); System.Windows.Forms.MessageBox.Show(stringBuilder.ToString()); } }
电影票父类:
public class Ticket { //价格 private double price; public double Price1 { get { return price; } set { price = value; } } //放映场次 private ScheduleItem scheduleItem; public ScheduleItem ScheduleItem { get { return scheduleItem; } set { scheduleItem = value; } } //座位 private Seat seat; public Seat Seat { get { return seat; } set { seat = value; } } public Ticket() { } public Ticket(double price, ScheduleItem scheduleItem, Seat seat) { this.Price1 = price; this.ScheduleItem = scheduleItem; this.Seat = seat; } //计算票价信息 public virtual double CalcPrice() { return price; } //打印票价信息 public virtual void Print() { StringBuilder stringBuilder = new StringBuilder("************************\\n"); stringBuilder.AppendLine(" 青鸟影视"); stringBuilder.AppendLine("------------------------"); stringBuilder.AppendFormat(" 电影名:{0}\\n",scheduleItem.Movie.Moviesname); stringBuilder.AppendFormat(" 时间:{0}\\n",scheduleItem.Time); stringBuilder.AppendFormat(" 座位号:{0}\\n", seat.Seatnum); stringBuilder.AppendFormat(" 价格:{0}\\n",price); stringBuilder.AppendFormat("************************\\n"); System.Windows.Forms.MessageBox.Show(stringBuilder.ToString()); } //显示票价信息 public virtual void Show() { StringBuilder stringBuilder = new StringBuilder("***********抱歉,已售出*************\\n"); stringBuilder.AppendLine(" 青鸟影视"); stringBuilder.AppendLine(" ------------------------"); stringBuilder.AppendFormat(" 电影名:{0}\\n", scheduleItem.Movie.Moviesname); stringBuilder.AppendFormat(" 时间:{0}\\n", scheduleItem.Time); stringBuilder.AppendFormat(" 座位号:{0}\\n", seat.Seatnum); stringBuilder.AppendFormat(" 价格:{0}\\n", price); stringBuilder.AppendFormat(" ************************\\n"); System.Windows.Forms.MessageBox.Show(stringBuilder.ToString()); } }
工具类用来判断票的类型:
public class TicketUtil { //创建电影票 public void GreateTicket(ScheduleItem scheduleItem,Seat seat,double money,string type ) { }
影院售票系统XML文件:
<ShowList> <Movie> <Name>不二神探</Name> <Poster>影院售票/不二神探.png</Poster> <Director>王子鸣</Director> <Actor>李连杰、文章、陈妍希</Actor> <Type>Action</Type> <Price>60</Price> <Schedule> <Item>9:00</Item> <Item>13:00</Item> </Schedule> </Movie> <Movie> <Name>西游降魔篇</Name> <Poster>影院售票/西游降魔篇.png</Poster> <Director>周星驰、郭子键</Director> <Actor>罗志祥、文章、舒淇</Actor> <Type>Comedy</Type> <Price>120</Price> <Schedule> <Item>11:00</Item> <Item>15:00</Item> <Item>19:00</Item> </Schedule> </Movie> <Movie> <Name>中国合伙人</Name> <Poster>影院售票/中国合伙人.png</Poster> <Director>陈可辛</Director> <Actor>黄晓明、邓超、大为、杜鹃</Actor> <Type>Love</Type> <Price>100</Price> <Schedule> <Item>21:00</Item> <Item>23:00</Item> </Schedule> </Movie> <Movie> <Name>钢铁侠3</Name> <Poster>影院售票/钢铁侠3.png</Poster> <Director>沙恩·布莱克 </Director> <Actor>小罗伯·特唐尼、格温妮斯·帕特洛、盖皮尔斯、本金斯利</Actor> <Type>Romance</Type> <Price>150</Price> <Schedule> <Item>17:30</Item> </Schedule> </Movie> </ShowList>
以上是关于影院售票系统的主要内容,如果未能解决你的问题,请参考以下文章
影院售票系统-----一个让你有成就感的小项目,只有一丢丢哦
JavaWeb Springmvc 电影院售票管理系统(数据库+源码+论文可运行《精品毕设》)主要实现了用户管理电影管理影片浏览选择票务管理订单通知公告影院模拟支付个人信息等功能