干货 | C#开发的电影售票系统 (2)

同时,用户可以点击注册按钮,跳转到注册界面完成新用户的注册。

private void button3_Click(object sender, EventArgs e) { UserRegisterForm userRegisterForm = new UserRegisterForm(); userRegisterForm.Show(); this.Visible = false; }

用户注册界面

用户将身份信息写入文本框后,用其输入的信息创建新的customer对象,通过调用BLL层的服务将新的用户信息写入数据库,最后用判断语句激活弹窗对注册结果予以反馈。

private void button1_Click(object sender, EventArgs e) { PayForm payform = new PayForm(true); payform.ShowDialog(); //Thread.Sleep(7000); //payform.Visible = false; Customer cRegister = new Customer { UserName = this.textBox1.Text, PassWord = this.textBox2.Text }; if (CustomerBLL.Register(cRegister)) { MessageBox.Show("注册成功"); UserLoginForm userLoginForm = new UserLoginForm(); userLoginForm.Show(); this.Visible = false; } else { MessageBox.Show("注册失败"); } }

排片详情获取

/// <summary> /// 初始化TreeView控件 /// </summary> private void InitTreeView() { tvMovies.BeginUpdate(); tvMovies.Nodes.Clear(); TreeNode movieNode = null; foreach(Movie m in MovieDAL.GetAllMovies()) { movieNode = new TreeNode(m.MovieName); tvMovies.Nodes.Add(movieNode); foreach (Schedule s in ScheduleDAL.GetSchedulesByMovieID(m.MovieID)) { TreeNode timeNode = new TreeNode(s.DateTime); timeNode.Name = s.ScheduleID.ToString(); movieNode.Nodes.Add(timeNode); } } tvMovies.EndUpdate(); }

影厅初始化

/// <summary> /// 初始化放映厅座位 /// </summary> /// <param>行数</param> /// <param>列数</param> /// <param></param> //普通厅放映 private void InitSeatsCheckBox(int seatRow, int seatCol, TabPage tb, Dictionary<string, CheckBox> ckBox, Dictionary<string, Seat> cSeats) { CheckBox checkBox; Seat seat; for (int i = 0; i < seatRow; i++) /* 加载一号放映厅的位置*/ { for (int j = 0; j < seatCol; j++) { checkBox = new CheckBox(); //设置背景颜色 checkBox.BackColor = Color.LightBlue; //设置字体 checkBox.Font = font1; //new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134))); //设置尺寸 checkBox.AutoSize = false; checkBox.Size = new System.Drawing.Size(60, 25); //设置座位号 checkBox.Text = (j+1).ToString() + "-" + (i+1).ToString(); checkBox.TextAlign = ContentAlignment.MiddleCenter; //设置位置 checkBox.Location = new Point(60 + (i * 90), 60 + (j * 60)); //所有的标签都绑定到同一事件 //checkBox.Click += new System.EventHandler(lblSeat_Click); tb.Controls.Add(checkBox); ckBox.Add(checkBox.Text, checkBox); //实例化一个座位 seat = new Seat(checkBox.Text, Color.LightBlue); //保存的座位集合 cSeats.Add(seat.SeatNum, seat); } } Label lb = new Label(); lb.BackColor = Color.LightGray; lb.Font = font1; //设置尺寸 lb.AutoSize = false; lb.Size = new System.Drawing.Size(100, 25); // lb.Text = "荧幕中央"; lb.TextAlign = ContentAlignment.MiddleCenter; //设置位置 lb.Location = new Point(310, 20); tb.Controls.Add(lb); }

购票

private void tvMovies_AfterSelect(object sender, TreeViewEventArgs e) { /// <summary> /// 选择一场电影事件 /// </summary> /// <param></param> /// <param></param> TreeNode node = tvMovies.SelectedNode; if (node == null) return; if (node.Level != 1) return; int sID = int.Parse(node.Name); Schedule s = null; Movie m = null; s= ScheduleDAL.GetScheduleByScheduleID(sID); if (s == null) { MessageBox.Show("s should not be null"); return; } m = MovieDAL.GetMovieByMovieID(s.MovieID); if (m == null) { MessageBox.Show("m should not be null"); return; } //将详细信息显示 this.lblMovieName.Text = m.MovieName; this.lblDirector.Text = m.Director; this.lblActor.Text = m.Actor; this.lblPrice.Text = s.Price.ToString(); this.lblTime.Text = s.DateTime; this.lblType.Text = m.MovieType; this.picMovie.Image = Image.FromFile(m.Poster); if(this.customerVIP != null) { this.lblCalcPrice.Text = (s.Price * 0.8).ToString(); } else { this.lblCalcPrice.Text = lblPrice.Text; } otherHallIDs.Clear(); foreach (int hID in AllHallIDs) { if (hID == s.HallID) { continue; } otherHallIDs.Add(hID); } //清空座位 ReSetSeats(s.HallID); //遍历该场电影的座位销售情况 foreach (Ticket t in TicketDAL.GetTicketsByScheduleID(sID)) { foreach (Seat seat in seats[s.HallID].Values) { if (t.DetailSeat == seat.SeatNum) { seat.Color = Color.LightCoral; } } } UpdateSeats(s.HallID); tbSeat.SelectedTab = tbSeat.TabPages[s.HallID-1]; }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzspws.html