Yesterday released the first of a summary of the project, requirements analysis and construction of the class, continue to update today, dynamically draw controls, ticket types of switching and data in the form of the presentation.
First from the simple start, the ticket type of switching.
Analysis:
1. Student discounts and presenters are disabled when you click on a regular ticket
2. When you click the gift ticket, enable the presenter and disable student discounts
3. Activate student discounts when clicking on student tickets, disable the presenter
Student Discount ComboBox drop-down box allows you to select a discount and calculate the price to the discounted price based on the discount real-time discount.
It is important to note that:
If you do not select a ListView movie (i.e. time), it makes no sense to choose a free ticket and a student ticket, or even to cause an exception when the student ticket is calculated in real time, so we have to judge
1 if (thisnullreturn;
So we can design three RadioButton click event Codes.
1Privatevoid Rdogiveticket_checkedchanged (Objectsender, EventArgs e)2 {3 if (this.treeview1.selectednode = = null) return; 4 this.lbloriginalprice.text = "0" ; 5 this.cbodiscount.enabled = false; 6 this.txtgiver.enabled = true 7}
Gift Tickets Click
1private void rdostuticket_checkedchanged (object sender, EventArgs e) 2 {3 if (this.treeview1.selectednode = = null) return; 4 this.cbodiscount.enabled = true; 5 this.txtgiver.enabled = false 6}
Student Ticket Click
1 Private voidRdonormal_checkedchanged (Objectsender, EventArgs e)2 {3 This. cbodiscount.enabled =false;4 This. txtgiver.enabled =false;5 if(! GetKey ())return;6 //The original price is updated because it is 0 when you click the coupon.7 This. Lbloriginalprice.text =Cinema. Schedule.items[key]. Movie.Price.ToString ();8}
General Ticket Click
For aesthetics You can also call the ClearContent () method to clear the information that may remain
Private void clearcontent () { // Click Time to switch back to the regular ticket and empty the information that may remain "" ; "" ; }
Since the regular ticket switching back to need to refresh the price, so to get the price; Cinema Cinema object is a global object (you can look at a class), key is a global variable, which stores the time of the selected session, the key to play the show. The GetKey () method is to get the time of the selected session and return a Boolean value, looking at the code instance
1 Public BOOLGetKey ()2 {3 //Select Node4TreeNode node = This. Treeview1.selectednode;5 //if not selected node = "End6 if(node = =NULL)return false;7 //If the selected node is not session (time) = "End8 if(node. Level! =1)return false;9 //get time as keyTenKey =node. Text; One if(Key! =""&& Key! =NULL)return true; A return false; -}
Getkey Method
Then the data in the XML is bound to the TreeView and the Time node in the TreeView is selected to present the movie information in the form
There is a way to use the Schedule projection program class when building the Class LoadItems () is to parse the XML information and add it to the show plan collection
Extract Inittreeview () to be called when the update is convenient
Cinema. Schedule.loaditems (); Put into a load event or initialization of a form
1 Private voidInittreeview ()2 {3 This. TreeView1.Nodes.Clear ();4 stringMoviename ="";5TreeNode tn =NULL;6 foreach(ScheduleItem IteminchCinema. Schedule.Items.Values)7 {8 //If this festival point does not exist, create a festival point9 if(item. Movie.moviename! =moviename)Ten { OneTN =NewTreeNode (item. Movie.moviename); ATn. Tag =item. Movie; - This. TREEVIEW1.NODES.ADD (TN); - } the //Increase session time node -TreeNode time =NewTreeNode (item. time); - TN. Nodes.Add (time); - //gets the movie name of the current session and iterates over +Moviename =item. Movie.moviename; - } + //Expand all the nodes A This. Treeview1.expandall (); at}
Inittreeview binding to the TreeView
The next step is to show the details of the movie in the form when the session node is selected
1 Private voidtreeView1_AfterSelect (Objectsender, TreeViewEventArgs e)2 {3 //emptying residual information4 clearcontent ();5rdonormal.checked =true;6 //Get key7 if(! GetKey ())return;8Lblname.text =Cinema. Schedule.items[key]. Movie.moviename;9Lbldate.text =key;TenLbltype.text =Cinema. Schedule.items[key]. Movie.MovieType.ToString (); OneLbloriginalprice.text =Cinema. Schedule.items[key]. Movie.Price.ToString (); ALblmainact.text =Cinema. Schedule.items[key]. Movie.actor; -Lbldirect.text =Cinema. Schedule.items[key]. Movie.director; - This. pictureBox1.Image =Image.FromFile (Cinema. Schedule.items[key]. Movie.poster); the This. Lblpreferentialprice.text =""; -}
Show detailed information to the form
Finally, the seat information is dynamically drawn to the form in the form of a label label, which is also the hardest place to refer to the book
1 Private voidinitialseat ()2 {3 intSeatrow =7;4 intSeatline =5;5 for(inti =0; i < Seatrow; i++)//column6 {7 for(intj =0; J < Seatline; J + +)//Line8 {9Label =NewLabel ();Ten //Set Background color OneLabel. BackColor =Color.yellow; A //sets the font font, size, specifies that glyph information applied to text is normal text, specifies the unit of measure for the given data, and the GDI character set for the new font -Label. Font =NewSystem.Drawing.Font ("Song Body",14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - //Cancel Auto Size We set the size theLabel. AutoSize =false; - //Specifies the width and height of the label -Label. Size =NewSystem.Drawing.Size ( -, -); - //Set seat number +Label. Text = (j +1). ToString () +"-"+ (i +1). ToString (); -Label. TextAlign =ContentAlignment.MiddleCenter; + //Set Location ALabel. Location =NewPoint ( -+ (I * -), -+ (J * -)); at //all the tags are bound to the same event, Lblseat_click is the event we wrote manually -Label. Click + =NewSystem.EventHandler (Lblseat_click); - //TB is TabPage - TB. Controls.Add (label); - //adding to the global labels collection - labels. ADD (label. Text, label); in //instantiate a seat seat constructor parameters are seat number and color -Seat =NewSeat ((j +1). ToString () +"-"+ (i +1). ToString (), color.yellow); to Cinema. Seats.add (seat. Seatnum, seat); + } -}
dynamically draw Controls
Tomorrow will continue to update: ticket purchase, change of seat color status and display of seat status
Welcome to the Great God treatise Teachings
C # Summary Project "Cinema Ticketing System" compilation Summary II