C#影院售票體系卒業設計(1)。本站提示廣大學習愛好者:(C#影院售票體系卒業設計(1))文章只能為提供參考,不一定能成為您想要的結果。以下是C#影院售票體系卒業設計(1)正文
C#進修閱歷從根本語法構造到窗體再到面向對象終究走完了.NET低級法式員的途徑,用了年夜概一天半的時光做完這個練手項目《影院售票體系》,先上後果截圖一張
抽出時光做些這個對今朝的我來講算不小的項目。
用到的常識點有:面向對象思惟、TreeView、XML讀取、File文件流、泛型聚集,這外面對我來講難度最年夜的是面向對象與泛型聚集的聯合,看來進修一門編程說話的難點照樣在設計思惟上。
再來引見一下項目需求:在影片列表當選擇某個時段的一場片子,單擊坐位選擇一個品種的片子票,並創立片子,盤算價錢並打印影票信息,然後該坐位被置為白色表現曾經售出。
影院天天更新放映列表,體系支撐及時檢查,包含片子放映場次時光、片子概略。
影院供給三類影票:通俗票、贈票和先生票(贈票收費;先生票有扣頭)
許可用戶檢查某場次坐位的售出情形
支撐購票,並許可用戶選座
用戶可以選擇場次、影票類型及余暇坐位停止購票,並打印片子票
體系可以保留發賣情形,並許可對其停止恢復
1、成績剖析
1.體系開辟步調
(1)明白需求
(2)設計類
(3)創立項目
(4)肯定編碼次序
1.主窗體
2.檢查新放映列表
3.檢查片子引見
4.檢查影票票價
5.檢查放映廳坐位
6.購票和打印片子票
7.持續購票
(5)測試
2、類的設計
獻上這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 影院售票體系 { /// <summary> /// 保留影院的坐位信息 /// </summary> public class Seat { public Seat() { } public Seat(string seatNum,Color color) { this.SeatNum = seatNum; this.Color = color; } private string _seatNum; /// <summary> /// 坐位號 /// </summary> public string SeatNum { get { return _seatNum; } set { _seatNum = value; } } private Color _color; /// <summary> /// 坐位賣出狀況色彩 /// </summary> 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 影院售票體系 { /// <summary> /// 片子類 /// </summary> public class Movie { private string _movieName; /// <summary> /// 片子名 /// </summary> public string MovieName { get { return _movieName; } set { _movieName = value; } } private string _poster; /// <summary> /// 海報圖片名 /// </summary> public string Poster { get { return _poster; } set { _poster = value; } } private string _director; /// <summary> /// 導演名 /// </summary> public string Director { get { return _director; } set { _director = value; } } private string _actor; /// <summary> /// 主演 /// </summary> public string Actor { get { return _actor; } set { _actor = value; } } private int _price; /// <summary> /// 訂價 /// </summary> public int Price { get { return _price; } set { _price = value; } } /// <summary> /// 片子類型 /// </summary> public MovieType MovieType { get; set; } } /// <summary> /// 片子類型,1悲劇2戰斗3戀愛 /// </summary> public enum MovieType { /// <summary> /// 舉措片 /// </summary> Action = 0, /// <summary> /// 戰斗片 /// </summary> War = 1, /// <summary> /// 戀愛片 /// </summary> 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 影院售票體系 { /// <summary> /// 片子票父類 /// </summary> public class Ticket { public Ticket() { } public Ticket(ScheduleItem sch,Seat seat) { this.ScheduItem = sch; this.Seat = seat; } private Seat _seat = new Seat(); /// <summary> /// 所屬坐位 /// </summary> public Seat Seat { get { return _seat; } set { _seat = value; } } private int _price; /// <summary> /// 票價 /// </summary> public int Price { get { return _price; } set { _price = value; } } /// <summary> /// 放映場次 /// </summary> public ScheduleItem ScheduItem { get; set; } /// <summary> /// 盤算票價 /// </summary> public virtual void CalcPrice() { this.Price = ScheduItem.Movie.Price; } /// <summary> /// 打印售票信息 /// </summary> 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.WordStr(":", "-")+" "+this.Seat.SeatNum+".txt"; FileStream fs = new FileStream(fileName,FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(info); sw.Close(); fs.Close(); } /// <summary> /// 顯示以後售票信息 /// </summary> 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 影院售票體系 { /// <summary> /// 先生票 /// </summary> public class StudentTicket : Ticket { public StudentTicket() { } public StudentTicket(ScheduleItem sch, Seat seat, int discount) : base(sch, seat) { this.Discount = discount; } private int _discount; /// <summary> /// 先生票的扣頭 /// </summary> public int Discount { get { return _discount; } set { _discount = value; } } /// <summary> /// 盤算先生票價 /// </summary> public override void CalcPrice() { this.Price =this.ScheduItem.Movie.Price* Discount / 10; } /// <summary> /// 打印先生票的售票信息 /// </summary> 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.WordStr(":", "-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(info); sw.Close(); fs.Close(); } /// <summary> /// 顯示以後售出票信息 /// </summary> 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 影院售票體系 { /// <summary> /// 贈票 /// </summary> 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; /// <summary> /// 取得贈票者的名字 /// </summary> public string CustomerName { get { return _customerName; } set { _customerName = value; } } /// <summary> /// 盤算票價 /// </summary> public override void CalcPrice() { this.Price = 0; } /// <summary> /// 打印售票信息 /// </summary> 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.WordStr(":", "-") + " " + this.Seat.SeatNum + ".txt"; FileStream fs = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(info); sw.Close(); fs.Close(); } /// <summary> /// 顯示以後售出票信息 /// </summary> 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 影院售票體系 { /// <summary> /// 影院天天籌劃放映的場次,保留每場片子的信息 /// </summary> public class ScheduleItem { private string _time; /// <summary> /// 放映時光 /// </summary> public string Time { get { return _time; } set { _time = value; } } private Movie _movie = new Movie(); /// <summary> /// 本場放映的片子 /// </summary> public Movie Movie { get { return _movie; } set { _movie = value; } } private List<Ticket> _soldTickets=new List<Ticket>(); private Dictionary<string, Seat> _seats=new Dictionary<string,Seat>(); /// <summary> /// 本場次的坐位狀況 /// </summary> public Dictionary<string, Seat> Seats { get { return _seats; } set { _seats = value; } } } }
7.Schedule:放映籌劃類
放映場次屬性(Items):自界說泛型聚集Dictionary<string,ScheduleItem>
讀取XML文件獲得放映籌劃聚集的LoadItems()辦法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace 影院售票體系 { /// <summary> /// 放映籌劃類,保留影院當天的放映籌劃聚集 /// </summary> public class Schedule { /// <summary> /// 放映場次 /// </summary> public Dictionary<string, ScheduleItem> Items = new Dictionary<string, ScheduleItem>(); /// <summary> /// 讀取XML文件獲得放映籌劃聚集 /// </summary> 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<string,Seat>
放映籌劃Schedule:Schedule自界說類型
已售出片子票的聚集(SoldTicket):自界說泛型聚集List<Ticket>
保留和讀取售票情形的Save()和Load()辦法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 影院售票體系 { /// <summary> /// 影院類 /// </summary> public class Cinema { private Dictionary<string, Seat> _seats = new Dictionary<string, Seat>(); /// <summary> /// 坐位聚集 /// </summary> public Dictionary<string, Seat> Seats { get { return _seats; } set { _seats = value; } } private Schedule _schedule = new Schedule(); /// <summary> /// 放映籌劃 /// </summary> public Schedule Schedule { get { return _schedule; } set { _schedule = value; } } private List<Ticket> _soldTickets=new List<Ticket>(); /// <summary> /// 曾經售出的票 /// </summary> public List<Ticket> SoldTickets { get { return _soldTickets; } set { _soldTickets = value; } } /// <summary> /// 保留售票信息到文件中 /// </summary> public void Save() { //Save和Load的代碼在窗體的代碼完成了 } /// <summary> /// 從文件中讀取售票信息 /// </summary> public void Load() { } } }
9.對象類
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 影院售票體系 { /// <summary> /// 對象類 /// </summary> public class TicketUtil { /// <summary> /// 創立片子票 /// </summary> /// <returns></returns> 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; } } }
下篇文章將持續更新,內容有片子院坐位的靜態繪制、片子信息綁定到窗體中展示出來,願望年夜家不要走開,有甚麼處所須要改良的迎接年夜家指出,配合商量提高。