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

购票信息确认界面

private void button1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.lblMovieName.Text)) { MessageBox.Show("您还没选择电影!", "提示"); return; } int hID = tbSeat.SelectedIndex + 1; TreeNode node = tvMovies.SelectedNode; if (node == null) return; if (node.Level != 1) return; int sID = int.Parse(node.Name); double totalCost = 0; List<Ticket> selectSeats = new List<Ticket>(); string confireInfo = "您选择的电影票信息如下,请确认:\n\n"; foreach(CheckBox cb in checkBoxs[hID].Values) { if (cb.Checked && cb.Enabled == true) { selectSeats.Add(new Ticket(sID, cb.Text)); confireInfo += "电影名:" + lblMovieName.Text + " 场次:" + lblTime.Text + " 大厅:" + hID + " 座位:"+cb.Text+"\n"; totalCost += double.Parse(lblCalcPrice.Text); } } if (selectSeats.Count < 1) { MessageBox.Show("您没有选择任何座位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } confireInfo += "\n总金额:" + totalCost.ToString()+" 元"; if (MessageBox.Show(confireInfo, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { PayIsSuccess = false; PayForm pf = new PayForm(false); pf.Owner = this; pf.payMoney = totalCost; pf.ShowDialog(); //支付成功 if (PayIsSuccess) { //保存到数据库成功 if (TicketDAL.AddTickets(selectSeats)) { //生成取票码 //更新位置信息 foreach (Ticket t in selectSeats) { Seat s = null; if(seats[hID].TryGetValue(t.DetailSeat, out s)) { s.Color = Color.LightCoral; } } //更新UI UpdateSeats(hID); TicketForm tf = new TicketForm(); tf.Owner = this; tf.ticketCode = DateTime.Now.ToFileTimeUtc().ToString(); tf.ShowDialog(); } } } }

支付界面(获取购票信息,计算总票价,提示支付)

private void TicketForm_Load(object sender, EventArgs e) { label2.Text = ticketCode; Image qr = getqrcode(ticketCode); imageList1.Images.Add(qr); imageList1.ImageSize = new Size(150, 150); pictureBox1.Image = imageList1.Images[0]; } public Image getqrcode(string content) { var encoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode = encoder.Encode(content); GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(12, QuietZoneModules.Two), Brushes.Black, Brushes.White);//如需改变二维码大小,调整12即可 DrawingSize dSize = render.SizeCalculator.GetSize(qrCode.Matrix.Width); Bitmap map = new Bitmap(dSize.CodeWidth, dSize.CodeWidth); Graphics g = Graphics.FromImage(map); render.Draw(g, qrCode.Matrix); return map; }

取票信息界面(包括取票二维码以及取票序列号的实现)

private void button1_Click(object sender, EventArgs e) { MainForm m = (MainForm)Owner; m.PayIsSuccess = true; this.Close(); } private void PayForm_Load(object sender, EventArgs e) { label1.Text = payMoney.ToString(); } 05 数据库设计

数据库采用的是SQLSERVER,可以复制下面的脚本到查询框执行,即可得到数据库和样本数据。
系统中采用DbContext方式直接连接数据库。各表的设计如下:

Customer

Hall

Movie

Schedule

Ticket

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

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