当前位置:   article > 正文

影院售票系统源代码

影院售票系统源代码
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Xml;
  9. using MyCinema.Models;
  10. namespace MyCinema
  11. {
  12. public partial class MainForm : Form
  13. {
  14. Cinema cinema;
  15. Dictionary<string, Label> labels = new Dictionary<string, Label>();
  16. int ticket = 0;
  17. string key = null;
  18. public MainForm()
  19. {
  20. InitializeComponent();
  21. }
  22. private void MainForm_Load(object sender, EventArgs e)
  23. {
  24. this.lblActor.Text = "";
  25. this.lblDirector.Text = "";
  26. this.lblMovieName.Text = "";
  27. this.lblPrice.Text = "";
  28. this.lblTime.Text = "";
  29. this.lblType.Text = "";
  30. this.lblCalcPrice.Text = "";
  31. this.txtCustomer.Enabled = false;
  32. this.cmbDisCount.Enabled = false;
  33. this.rdoNormal.Checked = true;
  34. cinema = new Cinema();
  35. //放映厅座位(初始)
  36. InitSeats(7, 5, tpCinema);
  37. cinema.Load();
  38. }
  39. private void InitSeats(int seatRow,int seatLine,TabPage tb)
  40. {
  41. Label label;
  42. Seat seat;
  43. for (int i = 0; i < seatRow; i++)
  44. {
  45. for (int j = 0; j < seatLine; j++)
  46. {
  47. label = new Label();
  48. label.BackColor = Color.Yellow;
  49. label.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));
  50. label.AutoSize = false;
  51. label.Size = new System.Drawing.Size(50, 25);
  52. label.Text = (j + 1).ToString() + "-" + (i + 1).ToString();
  53. label.TextAlign = ContentAlignment.MiddleCenter;
  54. label.Location = new Point(60 + (i * 90), 60 + (j * 60));
  55. label.Click += new System.EventHandler(lblSeat_Click);
  56. tb.Controls.Add(label);
  57. labels.Add(label.Text, label);
  58. seat = new Seat((j + 1).ToString() + "-" + (i + 1).ToString(), Color.Yellow);
  59. cinema.Seats.Add(seat.SeatNum, seat);
  60. }
  61. }
  62. }
  63. private void tsmiMovies_Click(object sender, EventArgs e)
  64. {
  65. //放映列表是否为空
  66. if (cinema.Schedule.Items.Count == 0)
  67. {
  68. cinema.Schedule.LoadItems();
  69. }
  70. InitTreeView();
  71. }
  72. //获取最新播放列表
  73. private void tsmiNew_Click(object sender, EventArgs e)
  74. {
  75. cinema.Schedule.LoadItems();
  76. cinema.SoldTickets.Clear();
  77. InitTreeView();
  78. }
  79. private void InitTreeView()
  80. {
  81. tvMovies.BeginUpdate();
  82. tvMovies.Nodes.Clear();
  83. string movieName = null;
  84. TreeNode movieNode = null;
  85. foreach (ScheduleItem item in cinema.Schedule.Items.Values)
  86. {
  87. if (movieName != item.Movie.MovieName)
  88. {
  89. movieNode = new TreeNode(item.Movie.MovieName);
  90. tvMovies.Nodes.Add(movieNode);
  91. }
  92. TreeNode timeNode = new TreeNode(item.Time);
  93. movieNode.Nodes.Add(timeNode);
  94. movieName = item.Movie.MovieName;
  95. }
  96. tvMovies.EndUpdate();
  97. }
  98. private void tvMovies_AfterSelect(object sender, TreeViewEventArgs e)
  99. {
  100. TreeNode node = tvMovies.SelectedNode;
  101. if (node == null) return;
  102. if (node.Level != 1) return;
  103. key = node.Text;
  104. //将详细信息显示
  105. this.lblMovieName.Text = cinema.Schedule.Items[key].Movie.MovieName;
  106. this.lblDirector.Text = cinema.Schedule.Items[key].Movie.Director;
  107. this.lblActor.Text = cinema.Schedule.Items[key].Movie.Actor;
  108. this.lblPrice.Text = cinema.Schedule.Items[key].Movie.Price.ToString();
  109. this.lblTime.Text = cinema.Schedule.Items[key].Time;
  110. this.lblType.Text = cinema.Schedule.Items[key].Movie.MovieType.ToString();
  111. this.picMovie.Image = Image.FromFile(cinema.Schedule.Items[key].Movie.Poster);
  112. this.lblCalcPrice.Text = "";
  113. //清空座位
  114. ClearSeat();
  115. //遍历座位情况
  116. foreach (Ticket ticket in cinema.SoldTickets)
  117. {
  118. foreach (Seat seat in cinema.Seats.Values)
  119. {
  120. if ((ticket.ScheduleItem.Time == key)
  121. &&(ticket.Seat.SeatNum == seat.SeatNum))
  122. {
  123. seat.Color = Color.Red;
  124. }
  125. }
  126. }
  127. UpdateSeat();
  128. }
  129. //清空座位
  130. private void ClearSeat()
  131. {
  132. foreach (S
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/155257
推荐阅读
相关标签
  

闽ICP备14008679号