最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#影院售票系統(tǒng)畢業(yè)設(shè)計(jì)(1)

 更新時(shí)間:2015年11月05日 09:38:11   作者:樂智  
這篇文章主要介紹了C#影院售票系統(tǒng)畢業(yè)設(shè)計(jì),獻(xiàn)上了9個(gè)類的設(shè)計(jì),需要的朋友可以參考下

 C#學(xué)習(xí)經(jīng)歷從基本語法結(jié)構(gòu)到窗體再到面向?qū)ο蠼K于走完了.NET初級(jí)程序員的道路,用了大概一天半的時(shí)間做完這個(gè)練手項(xiàng)目《影院售票系統(tǒng)》,先上效果截圖一張

抽出時(shí)間做些這個(gè)對(duì)目前的我來說算不小的項(xiàng)目。

用到的知識(shí)點(diǎn)有:面向?qū)ο笏枷?、TreeView、XML讀取、File文件流、泛型集合,這里面對(duì)我來說難度最大的是面向?qū)ο笈c泛型集合的結(jié)合,看來學(xué)習(xí)一門編程語言的難點(diǎn)還是在設(shè)計(jì)思想上。

再來介紹一下項(xiàng)目需求:在影片列表中選擇某個(gè)時(shí)段的一場(chǎng)電影,單擊座位選擇一個(gè)種類的電影票,并創(chuàng)建電影,計(jì)算價(jià)格并打印影票信息,然后該座位被置為紅色表示已經(jīng)售出。

影院每天更新放映列表,系統(tǒng)支持實(shí)時(shí)查看,包括電影放映場(chǎng)次時(shí)間、電影概況。

影院提供三類影票:普通票、贈(zèng)票和學(xué)生票(贈(zèng)票免費(fèi);學(xué)生票有折扣)

允許用戶查看某場(chǎng)次座位的售出情況

支持購(gòu)票,并允許用戶選座

用戶可以選擇場(chǎng)次、影票類型及空閑座位進(jìn)行購(gòu)票,并打印電影票

系統(tǒng)可以保存銷售情況,并允許對(duì)其進(jìn)行恢復(fù)

一、問題分析

1.系統(tǒng)開發(fā)步驟

(1)明確需求

(2)設(shè)計(jì)類

(3)創(chuàng)建項(xiàng)目

(4)確定編碼順序

      1.主窗體

      2.查看新放映列表

      3.查看電影介紹

      4.查看影票票價(jià)

     5.查看放映廳座位

     6.購(gòu)票和打印電影票

     7.繼續(xù)購(gòu)票

(5)測(cè)試

二、類的設(shè)計(jì)

 獻(xiàn)上這9個(gè)類的代碼,根據(jù)依賴編寫類的順序,不能完全按照上面順序

1.Seat:保存影院的座位信息,主要屬性如下

座位號(hào)(SeatNum):string類型

座位賣出狀態(tài)顏色(Color):System.Drawing.Color類型

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Drawing;
 
 namespace 影院售票系統(tǒng)
 {
 /// <summary>
 /// 保存影院的座位信息
 /// </summary>
 public class Seat
 {
 public Seat() { }
 public Seat(string seatNum,Color color) 
 {
 this.SeatNum = seatNum;
 this.Color = color;
 }
 private string _seatNum;
 /// <summary>
 /// 座位號(hào)
 /// </summary>
 public string SeatNum
 {
 get { return _seatNum; }
 set { _seatNum = value; }
 }
 private Color _color;
 /// <summary>
 /// 座位賣出狀態(tài)顏色
 /// </summary>
 public Color Color
 {
 get { return _color; }
 set { _color = value; }
 }
 }
 }

2.Movie:電影類

電影名(MovieName):string類型

海報(bào)圖片路徑(Poster):string類型

導(dǎo)演名(Director):string類型

主演(Actor):string類型

電影類型(MovieType):MovieType自定義枚舉類型

定價(jià)(Price):int類型

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

 namespace 影院售票系統(tǒng)
 {
 /// <summary>
 /// 電影類
 /// </summary>
 public class Movie
 {
 private string _movieName;
 /// <summary>
 /// 電影名
 /// </summary>
 public string MovieName
 {
 get { return _movieName; }
 set { _movieName = value; }
 }
 private string _poster;
 /// <summary>
 /// 海報(bào)圖片名
 /// </summary>
 public string Poster
 {
 get { return _poster; }
 set { _poster = value; }
 }
 private string _director;
 /// <summary>
 /// 導(dǎo)演名
 /// </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>
 /// 定價(jià)
 /// </summary>
 public int Price
 {
 get { return _price; }
 set { _price = value; }
 }
 /// <summary>
 /// 電影類型
 /// </summary>
 public MovieType MovieType { get; set; }
 }
 /// <summary>
 /// 電影類型,1喜劇2戰(zhàn)爭(zhēng)3愛情
 /// </summary>
 public enum MovieType
 {
 /// <summary>
 /// 動(dòng)作片
 /// </summary>
 Action = 0,
 /// <summary>
 /// 戰(zhàn)爭(zhēng)片
 /// </summary>
 War = 1,
 /// <summary>
 /// 愛情片
 /// </summary>
 Comedy = 2
 }
 }

3.Ticket:電影票父類,保存電影票信息

放映場(chǎng)次(ScheduleItem):ScheduleItem自定義類

所屬座位對(duì)象(Seat):Seat自定義類型

票價(jià)(Price):int類型

計(jì)算票價(jià)的虛方法CalcPrice()

打印售票信息的虛方法Print()

顯示當(dāng)前售出票信息的虛方法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 影院售票系統(tǒng)
 {
 /// <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>
 /// 票價(jià)
 /// </summary>
 public int Price
 {
 get { return _price; }
 set { _price = value; }
 }
 /// <summary>
 /// 放映場(chǎng)次
 /// </summary>
 public ScheduleItem ScheduItem { get; set; }
 /// <summary>
 /// 計(jì)算票價(jià)
 /// </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時(shí)間:\t{1}\n座位號(hào):\t{2}\n價(jià)格:\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();
 }
 /// <summary>
 /// 顯示當(dāng)前售票信息
 /// </summary>
 public virtual void Show()
 {
 string info = string.Format("已售出!\n普通票!");
 MessageBox.Show(info);
 }
 }
 }

4.StudentTicket:學(xué)生票子類,繼承父類Ticket

學(xué)生票的折扣(Discount):int類型

重寫父類計(jì)算票價(jià)CalcPrice

重寫父類打印售票信息的Print()

重寫父類顯示當(dāng)前出票信息的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 影院售票系統(tǒng)
 {
 /// <summary>
 /// 學(xué)生票
 /// </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>
 /// 學(xué)生票的折扣
 /// </summary>
 public int Discount
 {
 get { return _discount; }
 set { _discount = value; }
 }
 /// <summary>
 /// 計(jì)算學(xué)生票價(jià)
 /// </summary>
 public override void CalcPrice()
 {
 this.Price =this.ScheduItem.Movie.Price* Discount / 10;
 }
 /// <summary>
 /// 打印學(xué)生票的售票信息
 /// </summary>
 public override void Print()
 {
 string info = string.Format("************************************************\n\t青鳥影院(學(xué)生)\n------------------------------------------------\n電影名:\t{0}\n時(shí)間:\t{1}\n座位號(hào):\t{2}\n價(jià)格:\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();
 }
 /// <summary>
 /// 顯示當(dāng)前售出票信息
 /// </summary>
 public override void Show()
 {
 string info = string.Format("已售出!\n{0}折學(xué)生票!",this.Discount);
 MessageBox.Show(info);
 }
 }
 }

5.FreeTicket:贈(zèng)票子類,繼承父類Ticket

獲得贈(zèng)票者的名字屬性(CustomerName):string類型

重寫父類計(jì)算票價(jià)CalcPrice()

重寫父類打印售票信息Print()

重寫父類顯示當(dāng)前出票信息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 影院售票系統(tǒng)
 {
 /// <summary>
 /// 贈(zèng)票
 /// </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>
 /// 獲得贈(zèng)票者的名字
 /// </summary>
 public string CustomerName
 {
 get { return _customerName; }
 set { _customerName = value; }
 }
 /// <summary>
 /// 計(jì)算票價(jià)
 /// </summary>
 public override void CalcPrice()
 {
 this.Price = 0;
 }
 /// <summary>
 /// 打印售票信息
 /// </summary>
 public override void Print()
 {
 string info = string.Format("************************************************\n\t青鳥影院(贈(zèng)票)\n------------------------------------------------\n電影名:\t{0}\n時(shí)間:\t{1}\n座位號(hào):\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();
 }
 /// <summary>
 /// 顯示當(dāng)前售出票信息
 /// </summary>
 public override void Show()
 {
 MessageBox.Show("已售出!\n贈(zèng)票!");
 }
 }
 }

6.ScheduleItem:影院每天計(jì)劃放映計(jì)劃的場(chǎng)次,保存每場(chǎng)電影的信息

放映時(shí)間屬性(Time):string類型

本場(chǎng)所放映電影屬性(Movie):Movie自定義類型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 namespace 影院售票系統(tǒng)
 {
 /// <summary>
 /// 影院每天計(jì)劃放映的場(chǎng)次,保存每場(chǎng)電影的信息
 /// </summary>
 public class ScheduleItem
 {
 private string _time;
 /// <summary>
 /// 放映時(shí)間
 /// </summary>
 public string Time
 {
 get { return _time; }
 set { _time = value; }
 }
 private Movie _movie = new Movie();
 
 /// <summary>
 /// 本場(chǎng)放映的電影
 /// </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>
 /// 本場(chǎng)次的座位狀態(tài)
 /// </summary>
 public Dictionary<string, Seat> Seats
 {
 get { return _seats; }
 set { _seats = value; }
 }
 }
 }

7.Schedule:放映計(jì)劃類

放映場(chǎng)次屬性(Items):自定義泛型集合Dictionary<string,ScheduleItem>

讀取XML文件獲取放映計(jì)劃集合的LoadItems()方法

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Xml;
 
namespace 影院售票系統(tǒng)
 {
 /// <summary>
 /// 放映計(jì)劃類,保存影院當(dāng)天的放映計(jì)劃集合
 /// </summary>
 public class Schedule
 {
 /// <summary>
 /// 放映場(chǎng)次
 /// </summary>
 public Dictionary<string, ScheduleItem> Items = new Dictionary<string, ScheduleItem>();
 /// <summary>
 /// 讀取XML文件獲取放映計(jì)劃集合
 /// </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:影院類,保存放映計(jì)劃和座位類

座位集合屬性(Seat):自定義泛型集合Dictionary<string,Seat>

放映計(jì)劃Schedule:Schedule自定義類型

已售出電影票的集合(SoldTicket):自定義泛型集合List<Ticket>

保存和讀取售票情況的Save()和Load()方法

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
 namespace 影院售票系統(tǒng)
 {
 /// <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>
 /// 放映計(jì)劃
 /// </summary>
 public Schedule Schedule
 {
 get { return _schedule; }
 set { _schedule = value; }
 }
 private List<Ticket> _soldTickets=new List<Ticket>();
 /// <summary>
 /// 已經(jīng)售出的票
 /// </summary>
 public List<Ticket> SoldTickets
 {
 get { return _soldTickets; }
 set { _soldTickets = value; }
 }
 /// <summary>
 /// 保存售票信息到文件中
 /// </summary>
 public void Save() 
 {
 //Save和Load的代碼在窗體的代碼實(shí)現(xiàn)了
 }
 /// <summary>
 /// 從文件中讀取售票信息
 /// </summary>
 public void Load() { }
 }
 }

9.工具類

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
 namespace 影院售票系統(tǒng)
 {
 /// <summary>
 /// 工具類
 /// </summary>
 public class TicketUtil
 {
 /// <summary>
 /// 創(chuàng)建電影票
 /// </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;
 }
 }
}

下篇文章將繼續(xù)更新,內(nèi)容有電影院座位的動(dòng)態(tài)繪制、電影信息綁定到窗體中展現(xiàn)出來,希望大家不要走開,有什么地方需要改進(jìn)的歡迎大家指出,共同探討進(jìn)步。

相關(guān)文章

  • C# 中使用隱式和顯式操作符的示例

    C# 中使用隱式和顯式操作符的示例

    這篇文章主要介紹了C# 中使用隱式和顯式操作符的示例,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-04-04
  • C#表達(dá)式樹Expression基礎(chǔ)講解

    C#表達(dá)式樹Expression基礎(chǔ)講解

    這篇文章介紹了C#表達(dá)式樹Expression和基本用法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-12-12
  • C# WinForm捕獲未處理的異常實(shí)例解析

    C# WinForm捕獲未處理的異常實(shí)例解析

    這篇文章主要介紹了C# WinForm捕獲未處理的異常,包括了常見的未捕獲的異常、UI線程異常、非UI線程異常等,非常實(shí)用,需要的朋友可以參考下
    2014-09-09
  • C#?計(jì)算DataTime的4種時(shí)間差的方法(相差天數(shù)、相差小時(shí)、相差分鐘、相差秒)

    C#?計(jì)算DataTime的4種時(shí)間差的方法(相差天數(shù)、相差小時(shí)、相差分鐘、相差秒)

    這篇文章主要介紹了C#?計(jì)算DataTime的4種時(shí)間差(相差天數(shù)、相差小時(shí)、相差分鐘、相差秒),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05
  • C#事件處理和委托event delegate實(shí)例簡(jiǎn)述

    C#事件處理和委托event delegate實(shí)例簡(jiǎn)述

    這篇文章主要介紹了C#事件處理和委托event delegate的簡(jiǎn)單實(shí)例,較為詳細(xì)的講述了C#事件處理和委托的聲明與實(shí)現(xiàn)過程,代碼簡(jiǎn)單易懂,需要的朋友可以參考下
    2014-09-09
  • C#線性漸變畫刷LinearGradientBrush用法實(shí)例

    C#線性漸變畫刷LinearGradientBrush用法實(shí)例

    這篇文章主要介紹了C#線性漸變畫刷LinearGradientBrush用法,實(shí)例分析了線性漸變畫刷LinearGradientBrush的相關(guān)使用技巧,需要的朋友可以參考下
    2015-06-06
  • C#?在PDF中添加墨跡注釋Ink?Annotation的步驟詳解

    C#?在PDF中添加墨跡注釋Ink?Annotation的步驟詳解

    PDF中的墨跡注釋表現(xiàn)為徒手涂鴉式的形狀,該類型的注釋,可任意指定形狀頂點(diǎn)的位置及個(gè)數(shù),通過指定的頂點(diǎn),程序?qū)⑦B接各點(diǎn)繪制成平滑的曲線,下面通過C#程序代碼介紹下在pdf中添加注釋的步驟,感興趣的朋友一起看看吧
    2022-02-02
  • C#中Request.Cookies 和 Response.Cookies 的區(qū)別分析

    C#中Request.Cookies 和 Response.Cookies 的區(qū)別分析

    本文通過實(shí)例代碼向我們展示了C#中Request.Cookies 和 Response.Cookies 的區(qū)別,文章淺顯易懂,這里推薦給大家。
    2014-11-11
  • C#調(diào)用js庫(kù)的方法小結(jié)

    C#調(diào)用js庫(kù)的方法小結(jié)

    本文主要介紹了C#調(diào)用js庫(kù)的方法小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Unity3D UGUI特效之Image高斯模糊效果

    Unity3D UGUI特效之Image高斯模糊效果

    這篇文章主要為大家詳細(xì)介紹了Unity3D UGUI特效之Image高斯模糊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02

最新評(píng)論

丹阳市| 武强县| 广州市| 日照市| 沙田区| 灌云县| 石首市| 盐边县| 新民市| 紫云| 高尔夫| 南汇区| 浦江县| 全南县| 沅江市| 广安市| 师宗县| 潼关县| 牟定县| 通渭县| 临沧市| 都江堰市| 桦甸市| 瓦房店市| 定州市| 页游| 隆化县| 西吉县| 潮安县| 横峰县| 抚顺市| 开阳县| 宁海县| 银川市| 德化县| 徐水县| 鹤壁市| 阿鲁科尔沁旗| 潼南县| 广丰县| 新津县|