影院项目的内容信息
---恢复内容开始---
一:影院的基本框架
需要的类图:
二:实现效果:
绑定treeview,解析xml
实现绑定TreeView:
public void Bingding() { items = new Schedule(); items.LoadItem(); cinema.Schedule = items; string name = null; TreeNode tr = null; foreach (KeyValuePair<string, Scheduleltem> item in cinema.Schedule.items) { if (name != item.Value.Movie.MovieName) { tr = new TreeNode(); tr.Text = item.Value.Movie.MovieName; tvMovies.Nodes.Add(tr); } tr.Nodes.Add(item.Key); name = item.Value.Movie.MovieName; }
解析xml:
public void LoadItem() { XmlDocument doc = new XmlDocument(); doc.Load("ShowList.xml"); XmlNode root = doc.DocumentElement; foreach (XmlNode item in root.ChildNodes) { Movie Movie = new Movie(); Movie.MovieName = item["Name"].InnerText; Movie.Poster = item["Poster"].InnerText; Movie.Director = item["Director"].InnerText; Movie.Price =Convert.ToInt32( item["Price"].InnerText); Movie.Actor = item["Actor"].InnerText; Movie.MovieType = MovieType.Action; foreach (XmlNode item1 in item["Schedule"].ChildNodes) { Scheduleltem sch = new Scheduleltem(); sch.Movie = Movie; sch.Time = item1.InnerText; items.Add(sch.Time, sch); }
点击时间将影片的信息进行传值
TreeNode node = tvMovies.SelectedNode; if (node == null) return; if (node.Level != 1) return; key = node.Text; if (tvMovies.SelectedNode.Level > 0) { this.lblMovieName.Text = cinema.Schedule.items[key].Movie.MovieName; this.lblDirector.Text = cinema.Schedule.items[key].Movie.Director; this.lblActor.Text = cinema.Schedule.items[key].Movie.Actor; this.lblPrice.Text = cinema.Schedule.items[key].Movie.Price.ToString(); this.lblTime.Text = cinema.Schedule.items[key].Time; this.lblType.Text = cinema.Schedule.items[key].Movie.MovieType.ToString(); this.picMovie.Image = Image.FromFile(cinema.Schedule.items[key].Movie.Poster); this.lblCalcPrice.Text = "";
遍历座位的方法:
private void initseats() { Label label; Seat seat; int num = 5;//定义列 int num1 = 7;//定义行 for (int i = 0; i < num1; i++) { for (int j = 0; j < num; j++) { Label lab = new Label(); lab.BackColor = Color.Yellow; lab.Font = new System.Drawing.Font("宋体", 14.25F); lab.Size = new System.Drawing.Size(50, 20); //坐位号 lab.Text = (j + 1).ToString() + "-" + (1 + i).ToString(); //字体居中 lab.TextAlign = ContentAlignment.MiddleCenter; //设置位置 lab.Location = new Point(40 + (i * 90), 50 + (j * 60)); //所有的标签都绑定到同一事件 lab.Click += new System.EventHandler(lblSeat_Click); tpCinema.Controls.Add(lab); tpCinema.Controls.Add(lab); //实例化一个座位 seat = new Seat((j+1).ToString()+"-"+(i+1).ToString(),Color.Yellow); //保存座位的集合 cinema.Seats.Add(seat.SeatNum,seat); lab.Click += lab_Click; labels.Add(lab.Text,lab); } } }
注意:用的方法写的 要记住调用方法
选择不同的票的方法是:有些的方法是禁用的 即为显示的为不能写的列表
private void rdoFree_CheckedChanged(object sender, EventArgs e) { if (rdoNormal.Checked == true) { this.label12.Enabled = false; this.label13.Enabled = false; this.cmbDisCount.Enabled = false; this.txtCustomer.Enabled = false; this.cmbDisCount.SelectedIndex = -1; } else if (rdoFree.Checked == true) { this.label12.Enabled = false; this.cmbDisCount.Enabled = false; this.txtCustomer.Enabled = true; this.label13.Enabled = true; this.cmbDisCount.SelectedIndex = -1; } else if (rdoStudent.Checked == true) { this.label13.Enabled = false; this.txtCustomer.Enabled = false; this.label12.Enabled = true; this.cmbDisCount.Enabled = true; this.cmbDisCount.SelectedIndex = 0; } }
在选中座位时,既有座位的时候点击保存,退出程序,再一次点击购票,点击继续销售,返回你当初订电影票的时候所选中的电影票,就会发现上次所选中的票依然还在, 点击获取新放映列表的时候会重新订票 依然不显示已经订票的结果 会重新刷列表
点击保存的时候会显示是否刷新保存当前的内容
private void tsmiSave_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("是否保存当前销售状态?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //退出时序列化Cinema对象 cinema.laod(); } }