SoFunction
Updated on 2025-03-06

C# Cinema Ticketing System Graduation Design (3)

Previous article"C# Cinema Ticket Sales System Graduation Design (2)"It summarizes dynamic drawing controls, ticket type switching, and data presentation in the form. Continue to summarize today!

This article summarizes the most core part of the project-Ticket purchase, change of seat color status and display of seat status

analyze:

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

2. Sold prompts that it has been sold and no action is performed. If it is not sold, ask whether to purchase it.

3. Create different ticket objects according to whether you choose a normal ticket, a free ticket, or a student ticket.

If you choose a ticket, you need to check whether the gifter fills in it.

If you choose 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 corresponding selected type of ticket, and the ordinary ticket is created directly using the Ticket class.

5. After the user chooses to change the color of the seat collection to red after purchasing; reuse the price calculation method of the ticket class; add the sold tickets to the SoldTickets collection in the Cinema class; update the seat color status, and explain the above code in detail

try
 {
  //Get the seat number of the currently clicked seat label (Text attribute)  string seatNum = ((Label)sender).();
  //The name of the giftee  string customerName = ();
  //Discount  int discount = 0;
  //Type of ticket  string type = "";
  //If the student ticket is selected  if ()
  {
  type = "StudentTicket";
  if ( == null)
  {
  ("Please enter the discount number!", "hint");
  return;
  }
  else
  {
  discount = ();
  }
  }
  //If the ticket is selected  else if ()
  {
  if (())
  {
  ("Please enter the name of the ticket giver!", "hint");
  return;
  }
  type = "FreeTicket";
  }
  //Create tickets Static methods using tool class  Ticket newTicket = ([key], [seatNum], discount, customerName, type);
  //If the color of the current seat is yellow - for sale  if ([seatNum].Color == )
  {
  //ask  DialogResult result = ("Purchase?", "hint", );
  if (result == )
  {
  //Recalculate the ticket price  ();
  //Add tickets to the collection of sold tickets  (newTicket);
  //Update the seat color status  UpdateSeat();
   = ();
  ();
  //Change the color state of the seat collection  [seatNum].Color = ;
  }
  }
  //If it is a ticket that has been sold  else
  {
  //Show current ticket sales information  foreach (Ticket ticket0 in )
  {
  //The seat number of the sold ticket set is equal to the current click seat number and the selected time is equal to the time of the number of the tickets sold. And the movie name in the number of the tickets sold is equal to the time selected by TreeView, which is the movie name.  if ( == seatNum &&  ==  &&  == )
  {
  ();
  }
  }
  }
 
 }
 catch (Exception ex)
 {
  ("Please select the game first!" + );
 }

Here you need to call a method to update the seat color UpdateSeat(). First, initialize the colors of the Seats collection and labels collection, that is, reset the color to yellow, and then set the color of the sold seat to red based on the information of the sold ticket collection.

 //Reset the color of labels collection label foreach (string lkey in )
 {
  labels[lkey].BackColor = ;
 }
 //Reset seat collection color foreach (string key in )
 {
  [key].Color = ;
 }
 //Travel over the sales ticket collection foreach (Ticket ticket in )
 {
  //If the number of scenes is the same and the name of the movie is the same  if ( == this. &&  == )
  {
  //Change the color again  labels[].BackColor = ;
  [].Color = ;
  }
 }

This will change the seat color status after purchasing the ticket.

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

It is the treeView1_AfterSelect event in the second article before. Just call our UpdateSeat method, so that the seat sales situation will be updated every time the event is selected.

The above is the entire content of this article, the last article"C# Cinema Ticketing System Graduation Design (4)"continueRealize local saving of sales information, load the last saved sales information every time it is opened, and make an overall summary of the entire project