Ejemplo n.º 1
0
        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();
                    }
                }
            }
        }