深入.NET编程 第十一章 影院售票系统

主窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using Microsoft.SqlServer.Server;
using Microsoft.Win32;

namespace 影院售票系统
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string key = null;
        Dictionary<string, Label> labels = new Dictionary<string, Label>();
        private Cinema cinma = new Cinema();
        private void Form1_Load(object sender, EventArgs e)
        {
            this.label10.Text = "";
            this.label11.Text = "";
            this.label12.Text = "";
            this.label13.Text = "";
            this.label14.Text = "";
            this.label15.Text = "";
            this.label16.Text = "";
            this.textBox1.Enabled = false;
            this.comboBox1.Enabled = false;
            this.radioButton1.Checked = true;

            //cinema = new Cinema();
            //初始化放映厅座位

            Intile();
       
        }

        //初始化TreeView控件

        //treeview 绑定
        public void InitTreeView()
        {

            this.treeView1.Nodes.Clear();
            string movieName = null;
            TreeNode tn = null;
            Schedule s = new Schedule();
            s.LoadItems();
           
            foreach (KeyValuePair<string, ScheduleItem> item in s.Items)
            {

                //如果不存在此电影节点,创建电影节点 
                if (item.Value.Movie.MovieName != movieName)
                {
                    tn = new TreeNode(item.Value.Movie.MovieName);
                    //tn.Tag = item.Movie;
                    this.treeView1.Nodes.Add(tn);
                }
                //增加场次时间节点 
                TreeNode time = new TreeNode(item.Value.Time);
                tn.Nodes.Add(time);
                //获取当前场次的电影名字,重新遍历 
                movieName = item.Value.Movie.MovieName;

            }

        }


        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {


        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

       private ScheduleItem sch = null;

        //点击座位(购票 变色)
        private void label_Click(object sender, EventArgs e)
        {

                Label lbl = sender as Label;
                string customerName = this.textBox1.Text.ToString();
                int discount = 0;
                string type = "";
              //如果是学生票
                if (this.radioButton3.Checked)
                {
                    type = "StudentTickey";
                   
                        if (comboBox1.Text == null)
                        {
                            MessageBox.Show("请输入折扣数!", "提示");
                            return;
                        }
                       else
                    {
                        discount = int.Parse(this.comboBox1.Text);
                    }
                    
                }
                    //如果是赠票
                else if (this.radioButton2.Checked)
                {
                    if (string.IsNullOrEmpty(this.textBox1.Text))
                    {
                        MessageBox.Show("请输入赠票者姓名!", "提示");
                        return;
                    }
                    type = "FreeTicket";
                }
                key = treeView1.SelectedNode.Text;
            MessageBox.Show(key.ToString());
                Ticket newTicket = TicketUtil.CreareTicket(sch, cinma.Seats[lbl.Text], discount,
                    customerName, type);
            if (cinma.Seats[lbl.Text].Color == Color.Yellow )
            {
                DialogResult result = MessageBox.Show("是否购买?", "提示", MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information
                    );
               if (result == DialogResult.OK)
                {
                    newTicket.CalcPrice();
                    cinma.soldTickets.Add(newTicket);
                    //UpdateSeat();
                    label16.Text = newTicket.Price.ToString();
                    newTicket.Print();
                    cinma.Seats[lbl.Text].Color = Color.Red;
                    lbl.BackColor = Color.Red;
                }
            }
            else
            {
                foreach (Ticket tickets in cinma.soldTickets)
      
  • 14
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值