Cinema ticketing system, cinema Ticketing

Source: Internet
Author: User

Cinema ticketing system, cinema Ticketing

Demand Overview: this system can sell movie tickets for different periods of time each day. Because the playing time is different, all corresponding movie tickets have different preferential policies. In addition, you can also use free coupons!

 

Main function: select a movie for a certain period of time in the video list, select a category of movie tickets for a Single-host seat, create a movie ticket, calculate the price, and print the movie ticket information, then the seat is set to red to indicate it has been sold.

1. The cinema updates the screening list every day. The system supports real-time viewing, including the time and overview of movie screenings.

2. Three types of movie tickets are provided in the cinema: normal pass, complimentary pass, and student pass (free of charge, student pass discounts to varying degrees)

3. allow users to view the sale status of a specified seat

4. ticket purchase and seat selection are supported.

5. Users can purchase tickets by selecting the venue, movie ticket type, and free seats, and print movie tickets.

6. The system can save the sales information and allow recovery.

 

Development Environment: Visual Studio2012

Knowledge: encapsulation, inheritance, polymorphism, generic set, XML in C #

 

Class diagram:


Class details:
Seat: stores the cinema Seat information (Seat number, sales status color)

Movie: Cinema (Movie name, poster image name, Director name, starring role, Movie type, pricing)

Ticket: the parent category of a cinema. It stores the information of a movie Ticket (screenings, seats, fares, Virtual Methods for Calculating fares, and virtual methods for printing tickets)

StudentTicket: A Child class of the student Ticket. It inherits the parent class Ticket and stores special student Ticket information (Student Ticket Discount, overwrite the parent class to calculate the fare, and overwrite the parent class to print the Ticket information)

FreeTicket: a subclass of free tickets. It inherits the parent class Ticket and stores special coupon information (the method for obtaining the name and attributes of the coupon, rewriting the parent class to calculate the fare, and rewriting the parent class to print the Ticket information)

ScheduleItem)

Schedule: a screening plan class that stores the projection plan set for the cinema on the current day (screenings, methods for obtaining the projection plan set by reading XML files)

Cinema: Cinema leader, which stores the screening plan and number of seats (Seating set, screening plan, collection of sold movie tickets, methods for saving and reading ticket sales)

TicketUtil: tool class, used to determine the creation of different movie ticket objects based on input values (method of creating a movie ticket)

 

1. view the new screening list

Requirement: select "get new display list" in the "ticket purchase menu" to read the XML file of the display list and display the movie name and display time in TreeView.


Train of Thought Analysis:

1. Write related categories, including film, screening schedule, screenings, and cinemas

2. Compile the method to parse XML

3. Compile the method to initialize the TreeView

4. Write a form Load event to initialize the control.

Reference code for initializing TreeView:

1      /// <summary>
2 / / / get the show list and bind it to TreeView
3         /// </summary>
4         private void BingTreeView()
5 {
6             this.tvMovies.Nodes.Clear();
7 / / load XML
8             cinema.Schedule.LoadItems();
9 / / bind to TreeView
10             TreeNode root = null;
11             foreach (ScheduleItem var in cinema.Schedule.Items.Values)
12             {
13                 if (root == null || root.Text != var.Movie.MovieName)
14                 {
15 / / root node
16                     root = new TreeNode(var.Movie.MovieName);
17                     this.tvMovies.Nodes.Add(root);
18                 }
19 / / child node
20                 root.Nodes.Add(var.Time);
21             }
22}

2. View Movie Introduction

Requirement: select a movie session. The "details" panel displays the details of the movie.


Reference code:

1 private void tvMovies_AfterSelect(object sender, TreeViewEventArgs e)
2 {
3             if (this.tvMovies.SelectedNode.Level == 1)
4             {
5                 string time = this.tvMovies.SelectedNode.Text;
6                 ScheduleItem item = cinema.Schedule.Items[time];
7                 this.lblActor.Text = item.Movie.Actor;
8                 this.lblDirector.Text = item.Movie.Director;
9                 this.lblMovieName.Text = item.Movie.MovieName;
10                 this.lblPrice.Text = item.Movie.Price.ToString();
11                 this.lblTime.Text = item.Time;
12                 this.lblType.Text = item.Movie.MovieType.ToString();
13                 this.picMovie.Image = Image.FromFile(@"Image\" + item.Movie.Poster);
14                 this.lblCalcPrice.Text = item.Movie.Price.ToString();
Fifteen
Sixteen
17 / / set all seats to yellow
18                 foreach (Seat var in cinema.Seats.Values)
19                 {
20                     var.Color = Color.Yellow;
21                 }
22 / / loop judgment among sold tickets
23                 foreach (Ticket ticket in cinema.SoldTickets)
24                 {
25                     foreach (Seat seat in this.cinema.Seats.Values)
26                     {
27 / / same number and seat
28                         if (ticket.ScheduleItem.Time == time &amp;&amp; ticket.Seat.SeatNum == seat.SeatNum)
29                         {
30 / / update seat color
31                             seat.Color = Color.Red;
32                         }
33                     }
34                 }
35 / / update the seat color to the label
36                 foreach (Seat seat in cinema.Seats.Values)
37                 {
38                     foreach (Label lbl in tpCinema.Controls)
39                     {
40 / / if the seat number is the same, it is the corresponding label
41                         if (lbl.Text == seat.SeatNum)
42                         {
43                             lbl.BackColor = seat.Color;
44                         }
45                     }
46                 }
47             }
48}

3. View cinema fares

Requirement: When "Student Pass" is selected, the complimentary text box is unavailable. The default discount price is displayed on the "details" Panel. You can also choose different discounts to recalculate the discount price.

When "coupon" is selected, the student discount combo box is unavailable, and the discount price is "0" on the "details" panel"


Train of Thought Analysis:

1. Compile the CheckedChanged event handling methods for the three cell buttons respectively.

2. Compile the SelectedIndexChanged event handling method to save the student discount drop-down list

Reference code:

1 / / click common ticket
2         private void rdoNormal_CheckedChanged(object sender, EventArgs e)
3 {
4             this.cmbDisCount.Enabled = false;
5             this.txtCustomer.Enabled = false;
6             this.lblCalcPrice.Text = lblPrice.Text;
7}
Eight
9 / / click complimentary ticket
10         private void rdoFree_CheckedChanged(object sender, EventArgs e)
11 {
12             this.txtCustomer.Enabled = true;
13             this.cmbDisCount.Enabled = false;
14             this.lblCalcPrice.Text = lblPrice.Text;
15}
Sixteen
17 / / click on the student ticket
18         private void rdoStudent_CheckedChanged(object sender, EventArgs e)
19 {
20             if (this.lblPrice.Text != "")
21             {
22                 this.cmbDisCount.Enabled = true;
23                 this.txtCustomer.Enabled = false;
24                 this.lblCalcPrice.Text = (Convert.ToDouble(this.lblPrice.Text) * Convert.ToDouble(this.cmbDisCount.Text) / 10).ToString();
25             }
Twenty-six
27}

4. Check the auditorium seats.

Requirement Description: when the form is loaded, the auditorium seats are displayed.


Reference code:

1          /// <summary>
2 / / / initialize seat
3         /// </summary>
4         private void InitSeats(int row, int col)
5 {
6             for (int i = 0; i < row; i++)
7             {
8                 for (int j = 0; j < col; j++)
9                 {
10                     Label lb = new Label();
11                     lb.BackColor = Color.Yellow;
12                     lb.Location = new Point(20 + j * 100, 50 + i * 70);
13                     lb.Font = new Font("Courier New", 11);
14                     lb.Name = (i + 1) + "-" + (j + 1);
15                     lb.Size = new Size(80, 30);
16                     lb.TabIndex = 0;
17                     lb.Text = (i + 1) + "-" + (j + 1);
18                     lb.TextAlign = ContentAlignment.MiddleCenter;
19                     lb.Click += lb_Click;
20                     tpCinema.Controls.Add(lb);
21 / / add a seat object to the seats collection of cinema
22                     Seat seat = new Seat(lb.Text, Color.Yellow);
23                     cinema.Seats.Add(seat.SeatNum, seat);
24                 }
25             }
26}

5. purchase tickets

Requirement Description: select a movie session and ticket type, and click a seat in the screening room to purchase tickets.


Train of Thought Analysis:

1. Handle the Click Event of the seat label

Code reference:

1         /// <summary>
2 / / / ticket purchase
3         /// </summary>
4         /// <param name="sender"></param>
5         /// <param name="e"></param>
6         private void lb_Click(object sender, EventArgs e)
7 {
8             if (this.tvMovies.Nodes.Count == 0 || this.tvMovies.SelectedNode.Level ==0)
9             {
10                 return;
11             }
Twelve
13             lbl = sender as Label;
14             if (lbl.BackColor == Color.Red)
15             {
16 MessageBox.Show ("sold");
17             }
18             else
19             {
20 if (DialogResult. OK = = MessageBox. Show ("buy or not", "prompt", messageboxbuttons. Okcancel, messageboxicon. Question))
21                 {
22 / / get show time
23                     string time = this.tvMovies.SelectedNode.Text;
24 / / use time as the key to find the screening session object
25                     ScheduleItem item = cinema.Schedule.Items[time];
Twenty-six
27                     string type = string.Empty;
28                     type = rdoNormal.Checked ? "normal" : rdoFree.Checked ? "free" : "student";
29                     Ticket ticket = TicketUtil.CreateTicket(item, cinema.Seats[lbl.Text], txtCustomer.Text, Convert.ToDouble(cmbDisCount.Text), type);
Thirty
31 / / added to the sold collection
32                     cinema.SoldTickets.Add(ticket);
33 / / issue tickets
34                     ticket.Print();
35 / / update color
36                     lbl.BackColor = Color.Red;
37                     cinema.Seats[lbl.Text].Color = Color.Red;
38                 }
39             }
Forty
41}

6. Print movie tickets

Requirement Description: after purchasing a ticket, the ticket is printed automatically, and the selected seat is marked in red, that is, the sold status (for the code, refer to the ticket purchase)

7. Continue sales:

Requirement Description: Save the current sales status. When you select "Continue ticket sales", the previous sales status will be loaded to view the sales status of the seats.

Train of Thought Analysis: Write the Save () and Load () methods. when loading the form, Load the ticket information. When selecting the session, the sales status of the seat is displayed.

Reference code:

1          /// <summary>
2 / / / load shows
3         /// </summary>
4         public void Load()
5 {
6             using (FileStream fs = new FileStream("student.dat",FileMode.Open))
7             {
8                 BinaryFormatter bf = new BinaryFormatter();
9                 this.SoldTickets = bf.Deserialize(fs) as List<Ticket>;
10             }
11}
Twelve
13         /// <summary>
14 / / / save sales information
15         /// </summary>
16         public void Save()
17 {
18             //
19             using (FileStream fs = new FileStream("student.dat",FileMode.Create))
20             {
21                 BinaryFormatter bf = new BinaryFormatter();
22                 bf.Serialize(fs, SoldTickets);
23             }
Twenty-four
25} 

The main functions of the project are as follows! It is only for beginners to exchange and learn! Leave a message if you have any suggestions!

Project Source Code address: http://pan.baidu.com/s/1i35W6yD


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.