Graduation Design of C Cinema Ticketing System (3)

  • 2021-08-17 00:46:23
  • OfStack

The first article "C # Cinema Ticketing System Graduation Design (2)" summarizes the dynamic drawing control, ticket type switching and data display in the form. Continue to summarize today!

This paper summarizes the core part of the project-ticket purchase, the change of seat color status and the display of seat status.

Analysis:

1. Update the seat status (label implementation) after the selected time (session), and the sold ones are red and the unsold ones are yellow.

2. Sold prompt has been sold and does not carry out any operation. Unsold prompt asks whether to buy or not.

3. Create different ticket objects according to whether you choose ordinary ticket, complimentary ticket or student ticket

If you choose to give tickets, you need to check whether the giver fills them in

If you select a student ticket, you need to check whether the discount is selected

4. Get the seat number of the selected seat, call the CreateTicket () method of the tool class to create the ticket corresponding to the selected type, and the ordinary ticket is directly created by using the Ticket class

5. After the user chooses to purchase, the color of the seat set is changed to red; Re-use the price calculation method of ticket category; Add the sold tickets to the SoldTickets set in the Cinema class; Update the seat color status and explain the code in detail


try
 {
  // Gets the seat number of the currently clicked seat label (Text Attribute )
  string seatNum = ((Label)sender).Text.ToString();
  // Name of giver 
  string customerName = this.txtGiver.Text.ToString();
  // Discount 
  int discount = 0;
  // Type of ticket 
  string type = "";
  // If the student ticket is selected 
  if (this.rdoStuTicket.Checked)
  {
  type = "StudentTicket";
  if (this.cboDiscount.Text == null)
  {
  MessageBox.Show(" Please enter the discount number! ", " Prompt ");
  return;
  }
  else
  {
  discount = int.Parse(this.cboDiscount.Text);
  }
  }
  // If the complimentary ticket is selected 
  else if (this.rdoGiveTicket.Checked)
  {
  if (string.IsNullOrEmpty(this.txtGiver.Text))
  {
  MessageBox.Show(" Please enter the name of the ticket giver! ", " Prompt ");
  return;
  }
  type = "FreeTicket";
  }
  // Create a ticket   Using static methods of tool classes 
  Ticket newTicket = TicketUtil.CreateTicket(cinema.Schedule.Items[key], cinema.Seats[seatNum], discount, customerName, type);
  // If the current seat color is yellow - To be sold 
  if (cinema.Seats[seatNum].Color == Color.Yellow)
  {
  // Inquiry 
  DialogResult result = MessageBox.Show(" Do you want to buy? ", " Prompt ", MessageBoxButtons.YesNo);
  if (result == DialogResult.Yes)
  {
  // Recalculate fares 
  newTicket.CalcPrice();
  // Add tickets to the collection of sold tickets 
  cinema.SoldTickets.Add(newTicket);
  // Update seat color status 
  UpdateSeat();
  lblPreferentialPrice.Text = newTicket.Price.ToString();
  newTicket.Print();
  // Change the color state of the seat set 
  cinema.Seats[seatNum].Color = Color.Red;
  }
  }
  // If it is a ticket that has been sold, 
  else
  {
  // Display current ticketing information 
  foreach (Ticket ticket0 in cinema.SoldTickets)
  {
  // The seat number of the sold ticket set is equal to the current clicked seat number   And   The selected time is equal to the time of the games for which tickets were sold   And   The name of the movie in the plan of selling tickets is equal to TreeView The parent node of the selected time is the movie name 
  if (ticket0.Seat.SeatNum == seatNum && ticket0.ScheduItem.Time == treeView1.SelectedNode.Text && ticket0.ScheduItem.Movie.MovieName == treeView1.SelectedNode.Parent.Text)
  {
  ticket0.Show();
  }
  }
  }
 
 }
 catch (Exception ex)
 {
  MessageBox.Show(" Please select the number of games first! " + ex.Message);
 }

It is necessary to call a method of seat color update UpdateSeat (). First, initialize the colors of Seats set and labels set, that is, reset the colors to yellow, and then set the colors of sold seats to red according to the information of sold tickets set


 // Reset labels Set label Color of 
 foreach (string lkey in labels.Keys)
 {
  labels[lkey].BackColor = Color.Yellow;
 }
 // Reset the seat set color 
 foreach (string key in cinema.Seats.Keys)
 {
  cinema.Seats[key].Color = Color.Yellow;
 }
 // Traversing the sold ticket collection 
 foreach (Ticket ticket in cinema.SoldTickets)
 {
  // If the number of games 1 To, and the name of the movie 1 To 
  if (ticket.ScheduItem.Time == this.treeView1.SelectedNode.Text && ticket.ScheduItem.Movie.MovieName == this.lblName.Text)
  {
  // Change the color again 
  labels[ticket.Seat.SeatNum].BackColor = Color.Red;
  cinema.Seats[ticket.Seat.SeatNum].Color = Color.Red;
  }
 }

In this way, the change of seat color state after ticket purchase is realized.

Then, according to the selected time (session) node of TreeView, the tickets sold in each session are refreshed.

This is the event treeView1_AfterSelect in the previous article 2. Just call our UpdateSeat method, so that the seat sales will be updated once every time you select one session.

The above is the whole content of this paper. The last article, "C # Cinema Ticketing System Graduation Design (4)", continues to save the sales information locally, and loads the last saved sales information every time it is opened, and makes an overall summary of the whole project.

I hope this site collation of this 1 series of articles to help you learn, I hope you can like it.


Related articles: