C#影院售票系統(tǒng)畢業(yè)設計(2)
本文繼續(xù)更新,動態(tài)繪制控件、票類型的切換以及數(shù)據(jù)在窗體中的展現(xiàn)。
先從簡單的開始,票類型的切換。
分析:
1.當點擊普通票時 學生折扣和贈送者是禁用的
2.點擊贈票時 啟用贈送者,禁用學生折扣
3.點擊學生票時 啟用學生折扣,禁用贈送者
學生折扣ComboBox下拉框可以選擇折扣,根據(jù)折扣實時折扣計算價格到優(yōu)惠價上。
需要注意的是:
如果沒有選擇ListView的電影場次(也就是時間),選擇贈票和學生票是沒有意義的甚至會引發(fā)學生票實時計算時的異常,所以我們要判斷
if (this.treeView1.SelectedNode == null) return;
因此我們便可以設計三個RadioButton的點擊事件代碼
private void rdoGiveTicket_CheckedChanged(object sender, EventArgs e) { if (this.treeView1.SelectedNode == null) return; this.lblOriginalPrice.Text = "0"; this.cboDiscount.Enabled = false; this.txtGiver.Enabled = true; }
private void rdoStuTicket_CheckedChanged(object sender, EventArgs e) { if (this.treeView1.SelectedNode == null) return; this.cboDiscount.Enabled = true; this.txtGiver.Enabled = false; }
private void rdoNormal_CheckedChanged(object sender, EventArgs e) { this.cboDiscount.Enabled = false; this.txtGiver.Enabled = false; if (!GetKey()) return; //更新原價,因為點擊贈票時價格為0了 this.lblOriginalPrice.Text = cinema.Schedule.Items[key].Movie.Price.ToString(); }
為了美觀也可以調(diào)用ClearContent()方法清空一下可能殘留的信息
private void ClearContent() { //點擊時間(場次)時切換回普通票 并清空可能殘留的信息 txtGiver.Text = ""; cboDiscount.Text = ""; }
由于普通票切換回來的時候需要刷新價格,所以要獲取價格;cinema電影院對象是一個全局對象(可以看上一篇的類),key是一個全局的變量,存儲的是選中場次的時間,用來做放映場次的Key。GetKey()方法是獲取選中場次的時間并返回布爾值,看代碼實例
public bool GetKey() { //選中節(jié)點 TreeNode node = this.treeView1.SelectedNode; //如果沒有選擇節(jié)點=》結束 if (node == null) return false; //如果選中節(jié)點不是場次(時間)=》結束 if (node.Level != 1) return false; //獲取時間作為key key = node.Text; if (key != "" && key != null) return true; return false; }
然后就是將XML中的數(shù)據(jù)綁定TreeView并在選擇TreeView的時間節(jié)點是將影片信息展現(xiàn)在窗體中
之前在搭建類的時候用到 Schedule 放映計劃類有一個方法LoadItems()就是將XML信息解析并添加到放映計劃集合中
提取出InitTreeView()方便更新時調(diào)用cinema.Schedule.LoadItems();放到窗體的加載事件或初始化中
private void InitTreeView() { this.treeView1.Nodes.Clear(); string movieName = ""; TreeNode tn = null; foreach (ScheduleItem item in cinema.Schedule.Items.Values) { //如果不存在此電影節(jié)點,創(chuàng)建電影節(jié)點 if (item.Movie.MovieName != movieName) { tn = new TreeNode(item.Movie.MovieName); tn.Tag = item.Movie; this.treeView1.Nodes.Add(tn); } //增加場次時間節(jié)點 TreeNode time = new TreeNode(item.Time); tn.Nodes.Add(time); //獲取當前場次的電影名字,重新遍歷 movieName = item.Movie.MovieName; } //展開所有的節(jié)點 this.treeView1.ExpandAll(); }
接下來就是選中場次節(jié)點時將電影的詳細信息展現(xiàn)在窗體中
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { //清空殘留信息 ClearContent(); rdoNormal.Checked = true; //獲取key if (!GetKey()) return; lblName.Text = cinema.Schedule.Items[key].Movie.MovieName; lblDate.Text = key; lblType.Text = cinema.Schedule.Items[key].Movie.MovieType.ToString(); lblOriginalPrice.Text = cinema.Schedule.Items[key].Movie.Price.ToString(); lblMainAct.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); this.lblPreferentialPrice.Text = ""; }
最后是將座位信息以label標簽的形式動態(tài)繪制到窗體里,這里也是最難的地方,參考了一下書
private void InitialSeat() { int seatRow = 7; int seatLine = 5; for (int i = 0; i < seatRow; i++)//列 { for (int j = 0; j < seatLine; j++)//行 { label = new Label(); //設置背景顏色 label.BackColor = Color.Yellow; //設置字體 字體,大小,指定應用到文本的字形信息為普通文本,指定給定數(shù)據(jù)的度量單位,新字體的GDI字符集 label.Font = new System.Drawing.Font("宋體", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); //取消自動尺寸方便我們設置尺寸 label.AutoSize = false; //指定label的寬和高 label.Size = new System.Drawing.Size(50, 25); //設置座位號 label.Text = (j + 1).ToString() + "-" + (i + 1).ToString(); label.TextAlign = ContentAlignment.MiddleCenter; //設置位置 label.Location = new Point(60 + (i * 100), 60 + (j * 60)); //所有的標簽綁定到同一事件,lblSeat_Click是我們手動寫的事件 label.Click += new System.EventHandler(lblSeat_Click); //tb是TabPage tb.Controls.Add(label); //加入到全局的labels集合中 labels.Add(label.Text, label); //實例化一個座位Seat構造函數(shù)的參數(shù)為座位號及顏色 seat = new Seat((j + 1).ToString() + "-" + (i + 1).ToString(), Color.Yellow); cinema.Seats.Add(seat.SeatNum, seat); } }
之后文章將會繼續(xù)更新:購票、座位顏色狀態(tài)的改變及場次座位狀態(tài)的顯示,希望大家繼續(xù)關注。
以上就是本文的全部內(nèi)容,希望大家喜歡。
相關文章
使用MSScriptControl 在 C# 中讀取json數(shù)據(jù)的方法
下面小編就為大家?guī)硪黄褂肕SScriptControl 在 C# 中讀取json數(shù)據(jù)的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01C#實現(xiàn)字符串與圖片的Base64編碼轉(zhuǎn)換操作示例
這篇文章主要介紹了C#實現(xiàn)字符串與圖片的Base64編碼轉(zhuǎn)換操作,結合實例形式分析了C#針對base64編碼與圖片的相互轉(zhuǎn)換操作技巧,需要的朋友可以參考下2017-06-06C# Winform 禁止用戶調(diào)整ListView的列寬
在使用 ListView 的時候, 有時我們不想讓別人隨意調(diào)整列寬, 或者某幾列的列寬, 以便達到美觀, 或者隱藏數(shù)據(jù)的作用. 那么可以用一下代碼來實現(xiàn)2011-05-05C#服務器NFS共享文件夾搭建與上傳圖片文件的實現(xiàn)
本文主要介紹了C#服務器NFS共享文件夾搭建與上傳圖片文件的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-07-07C#實現(xiàn)類似新浪微博長URL轉(zhuǎn)短地址的方法
這篇文章主要介紹了C#實現(xiàn)類似新浪微博長URL轉(zhuǎn)短地址的方法,涉及C#操作正則表達式的相關技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04