青鸟影院售票系统(一)
来源:互联网 发布:java架构师 编辑:程序博客网 时间:2024/04/29 02:14
闲话不多说,先抖一张效果图:
好,咱们正式进入主题
一、问题分析
1.系统开发步骤
(1)明确需求
(2)设计类
(3)创建项目
(4)确定编码顺序
1.主窗体
2.查看新放映列表
3.查看电影介绍
4.查看影票票价
5.查看放映厅座位
6.购票和打印电影票
7.继续购票
(5)测试
二、类的设计
献上这9个类的代码
(1)Seat 类:保存影院的座位信息
public class Seat { public Seat(string seatNum, Color color) { this.SeatNum = seatNum; this.Color = color; } /// <summary> /// 座位号 /// </summary> private string seatNum; public string SeatNum { get { return seatNum; } set { seatNum = value; } } /// <summary> /// 显示售出与否的颜色属性 /// </summary> private Color color; public Color Color { get { return color; } set { color = value; } } }
(2)Movie:电影类
public enum MovieType { //喜剧 Comedy, //战争 War, //爱情 Romance, //动作 Action, //卡通 Cartoon, //恐怖 Thriller, //冒险 Adventure } [Serializable] public class Movie { public Movie() { } public Movie(string movieName, string poster, string director,string actor,MovieType movieType,int price) { this.MovieName = movieName; this.Poster = poster; this.Director = director; this.Actor = actor; this.MovieType = movieType; this.Price = price; } /// <summary> /// 电影名称 /// </summary> private string movieName; public string MovieName { get { return movieName; } set { movieName = value; } } /// <summary> /// 海报图片名 /// </summary> private string poster; public string Poster { get { return poster; } set { poster = value; } } /// <summary> /// 导演名 /// </summary> private string director; public string Director { get { return director; } set { director = value; } } /// <summary> /// 主演 /// </summary> private string actor; public string Actor { get { return actor; } set { actor = value; } } /// <summary> /// 电影类型 /// </summary> private MovieType movieType; public MovieType MovieType { get { return movieType; } set { movieType = value; } } /// <summary> /// 电影定价 /// </summary> private int price; public int Price { get { return price; } set { price = value; } } }
(3)Ticket:电影票父类,保存电影票信息
public class Ticket { public Ticket() { } public Ticket(ScheduleItem scheduleItem, Seat seat) { this.ScheduleItem = scheduleItem; this.Seat = seat; } /// <summary> /// 座位对象 /// </summary> private Seat seat; public Seat Seat { get { return seat; } set { seat = value; } } /// <summary> /// 票价 /// </summary> private int price; public int Price { get { return price; } set { price = value; } } /// <summary> /// 所属的放映场次 /// </summary> private ScheduleItem scheduleItem; public ScheduleItem ScheduleItem { get { return scheduleItem; } set { scheduleItem = value; } } /// <summary> /// 计算票价的方法 /// 可重写 /// </summary> public virtual void CalcPrice() { this.Price = this.ScheduleItem.Movie.Price; } /// <summary> /// 打印票实现 /// </summary> public virtual void Print() { string fileName = this.ScheduleItem.Time.Replace(":","-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("***************************"); sw.WriteLine(" 青鸟影院"); sw.WriteLine("---------------------------"); sw.WriteLine(" 电影名:\t{0}", this.ScheduleItem.Movie.MovieName); sw.WriteLine(" 时间: \t{0}", this.ScheduleItem.Time); sw.WriteLine(" 座位号:\t{0}", this.Seat.SeatNum); sw.WriteLine(" 价格: \t{0}", this.Price.ToString()); sw.WriteLine("***************************"); sw.Close(); fs.Close(); } /// <summary> /// 显示售出票信息 /// </summary> public virtual void Show() { MessageBox.Show("已售出"); } }
(4)StudentTicket:学生票子类,继承父类Ticket,保存特殊的学生票信息
public class StudentTicket:Ticket { public StudentTicket() { } public StudentTicket(ScheduleItem scheduleItem, Seat seat, int discount) : base(scheduleItem, seat) { this.Discount = discount; } //折扣数 private int discount; public int Discount { get { return discount; } set { discount = value; } } /// <summary> /// 重写价格 /// </summary> public override void CalcPrice() { this.Price = this.ScheduleItem.Movie.Price * Discount / 10; } /// <summary> /// 打印数据 /// </summary> public override void Print() { string fileName = this.ScheduleItem.Time.Replace(":", "-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("***************************"); sw.WriteLine(" 青鸟影院 (学生)"); sw.WriteLine("---------------------------"); sw.WriteLine(" 电影名:\t{0}", this.ScheduleItem.Movie.MovieName); sw.WriteLine(" 时间: \t{0}", this.ScheduleItem.Time); sw.WriteLine(" 座位号:\t{0}", this.Seat.SeatNum); sw.WriteLine(" 价格: \t{0}", this.Price.ToString()); sw.WriteLine("***************************"); sw.Close(); fs.Close(); } /// <summary> /// 显示售出票信息 /// </summary> public override void Show() { MessageBox.Show("已售出!\n\n " + this.discount + "折学生票!"); } }
(5)FreeTicket:赠票子类,继承父类Ticket,保存特殊的赠票信息
public class FreeTicket:Ticket { public FreeTicket() { } public FreeTicket(ScheduleItem scheduleItem, Seat seat, string customerName) : base(scheduleItem, seat) { this.CustomerName = customerName; } private string customerName; public string CustomerName { get { return customerName; } set { customerName = value; } } public override void CalcPrice() { this.Price = 0; } public override void Print() { string fileName = this.ScheduleItem.Time.Replace(":", "-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("***************************"); sw.WriteLine(" 青鸟影院 (赠票)"); sw.WriteLine("---------------------------"); sw.WriteLine(" 电影名:\t{0}", this.ScheduleItem.Movie.MovieName); sw.WriteLine(" 时间: \t{0}", this.ScheduleItem.Time); sw.WriteLine(" 座位号:\t{0}", this.Seat.SeatNum); sw.WriteLine(" 姓名: \t{0}", this.CustomerName); sw.WriteLine("***************************"); sw.Close(); fs.Close(); } /// <summary> ///显示售出票信息 /// </summary> public override void Show() { MessageBox.Show("已售出!\n\n 赠送者:"+this.CustomerName); } }
(6 )ScheduleItem:影院每天放映计划的场次,保存每场电影的信息
public class ScheduleItem { public ScheduleItem() { movie = new Movie(); } /// <summary> /// 放映时间 /// </summary> private string time; public string Time { get { return time; } set { time = value; } } /// <summary> /// 要放映的电影对象 /// </summary> private Movie movie; public Movie Movie { get { return movie; } set { movie = value; } } }
(7)Schedule:放映计划类,保存影院当天的放映计划集合
public class Schedule { public Schedule() { items = new Dictionary<string, ScheduleItem>(); } /// <summary> /// 放映计划中的放映列表 /// </summary> private Dictionary<string, ScheduleItem> items; /// <summary> /// 放映计划中的放映列表 /// </summary> public Dictionary<string, ScheduleItem> Items { get { return items; } set { items = value; } } /// <summary> /// 从XML文件读取放映列表数据 /// </summary> public void LoadItems() { if (items == null) items = new Dictionary<string, ScheduleItem>(); items.Clear(); XmlDocument myXml = new XmlDocument(); myXml.Load("ShowList.xml"); XmlNode feednode = myXml.DocumentElement; //中间变量 string movieName = null; string playBill = null; string director = null; string actor = null; string movieType = null; string price = null; foreach (XmlNode node in feednode.ChildNodes) { if (node.Name == "Movie") { foreach (XmlNode subNode in node.ChildNodes) { switch (subNode.Name) { case "Name": movieName = subNode.InnerText; break; case "Poster": playBill = subNode.InnerText; break; case "Director": director = subNode.InnerText; break; case "Actor": actor = subNode.InnerText; break; case "Type": movieType = subNode.InnerText; break; case "Price": price = subNode.InnerText; break; case "Schedule": foreach (XmlNode scheduleNode in subNode.ChildNodes) { ScheduleItem item = new ScheduleItem(); item.Time = scheduleNode.InnerText; item.Movie.MovieName = movieName; item.Movie.Poster = playBill; item.Movie.Director = director; item.Movie.Actor = actor; item.Movie.MovieType = (MovieType)Enum.Parse(typeof(MovieType), movieType); item.Movie.Price = int.Parse(price); items.Add(item.Time,item); } break; } } } } } }
(8)Cinema:影院类,保存放映计划和座位类
public class Cinema { public Cinema() { seats = new Dictionary<string, Seat>(); soldTickets = new List<Ticket>(); schedule = new Schedule(); } /// <summary> /// 放映厅座位集合 /// </summary> private Dictionary<string, Seat> seats; public Dictionary<string, Seat> Seats { get { return seats; } set { seats = value; } } private Schedule schedule; /// <summary> /// 当天的放映计划 /// </summary> public Schedule Schedule { get { return schedule; } set { schedule = value; } } private List<Ticket> soldTickets; public List<Ticket> SoldTickets { get { return soldTickets; } set { soldTickets = value; } } //保存售票信息到文件中 public void Save() { FileStream fs = new FileStream("soldTickets.txt", FileMode.OpenOrCreate); StreamWriter writer = new StreamWriter(fs, Encoding.Default); for (int index = 0; index < SoldTickets.Count; index++) { Ticket ticket = SoldTickets[index]; string info = "|" + ticket.ScheduleItem.Movie.MovieName + "|" + ticket.ScheduleItem.Movie.Poster + "|" + ticket.ScheduleItem.Movie.Director + "|" + ticket.ScheduleItem.Movie.Actor + "|" + ticket.ScheduleItem.Movie.MovieType.ToString() + "|" + ticket.ScheduleItem.Movie.Price + "|" + ticket.ScheduleItem.Time + "|" + ticket.Seat.SeatNum + "|" + ticket.Seat.Color + "|" + ticket.Price + "|"; if (ticket is FreeTicket) { string customerName=((FreeTicket)ticket).CustomerName; writer.WriteLine("free" + info + customerName); } else if (ticket is StudentTicket) { writer.WriteLine("student" + info + ""); } else { writer.WriteLine("" + info + ""); } } writer.WriteLine("The End"); writer.Close(); fs.Close(); } //从文件中读取售票信息 public void Load() { try { StreamReader reader = new StreamReader("soldTickets.txt", Encoding.GetEncoding("GB2312")); string line = reader.ReadLine(); string[] propertyValues; Ticket ticket = null; while (line.Trim() != "The End") { propertyValues = line.Split('|'); string type = propertyValues[0]; Movie movie = new Movie(propertyValues[1], propertyValues[2], propertyValues[3], propertyValues[4], (MovieType)Enum.Parse(typeof(MovieType), propertyValues[5]), int.Parse(propertyValues[6])); ScheduleItem scheduleItem = new ScheduleItem(); scheduleItem.Time = propertyValues[7]; scheduleItem.Movie = movie; string color = propertyValues[9]; string endColor = color.Substring(color.IndexOf("[") + 1, color.Length - 1 - color.IndexOf("[") - 1); Seat seat = new Seat(propertyValues[8], Color.FromName(endColor)); int discount = 10; switch (type) { case "student": discount = 7; ticket = TicketUtil.CreateTicket(scheduleItem, seat, discount, "", type); break; case "free": discount = 0; ticket = TicketUtil.CreateTicket(scheduleItem, seat, discount, propertyValues[11], type); break; default: discount = 10; ticket = TicketUtil.CreateTicket(scheduleItem, seat, discount, "", ""); break; } this.SoldTickets.Add(ticket); line = reader.ReadLine(); } reader.Close(); } catch (Exception ex) { Console.WriteLine("出错了:"+ex.Message); soldTickets = new List<Ticket>(); } } }
(9)TicketUtil:工具类,根据输入的值,判断创建不同的电影票对象
public class TicketUtil { public static Ticket CreateTicket(ScheduleItem scheduleItem, Seat seat, int discount,string customerName, string type) { Ticket newTicket = null; switch (type) { case "student": newTicket = new StudentTicket(scheduleItem, seat, discount); break; case "free": newTicket = new FreeTicket(scheduleItem, seat, customerName); break; case "": newTicket = new Ticket(scheduleItem, seat); break; } return newTicket; } }
0 0
- 青鸟影院售票系统(一)
- 青鸟影院售票系统
- 影院售票系统
- C#影院售票系统
- 影院售票系统源代码
- 影院售票系统
- 影院售票系统
- 深入.NET 青鸟影院系统
- 影院售票
- 论学习的重要性之 -- 影院售票系统
- 深入.NET编程 第十一章 影院售票系统
- "青鸟影院"三分之一
- "青鸟影院"三分之二
- 影院售票管理源码
- 影院管理系统的后台(一): 注册
- "青鸟影院"的最后一部分
- 影院售票座位的设计
- 影院管理系统(GTK)
- 多重继承和单重继承
- Tensorflow学习总结(1):CNN
- Java 修饰符
- 三次握手和四次挥手的状态解析
- 第四届蓝桥杯 省赛 JavaB组 马虎的算式
- 青鸟影院售票系统(一)
- 求助 webBrowser 的兼容性问题 有偿的 500红包
- 卡尔曼滤波(Kalman Filter) 的进一步讨论
- DES算法的Java实现
- 基于 ionic 的 apk 自动升级
- hduoj-5344【位运算】
- fabric
- c语言中的#号和##号的作用
- Cracking the Coding Interview: Trees and Graphs