| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:看看这个代码那有有错
只看楼主 加入收藏
ganmaoaq
Rank: 2
等 级:论坛游民
帖 子:11
专家分:43
注 册:2009-8-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
看看这个代码那有有错
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;


namespace Accp
{
    public partial class MyCinema : Form
    {
        Cinema cinema;
        int tickets = 0;
        string key = null;
        Dictionary<string, Label> labels = new Dictionary<string, Label>();
      
        public MyCinema()
        {
            InitializeComponent();
        }

        //点击一个座位买票事件
        public void lblSeats_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.lblMovieName.Text))
            {
                MessageBox.Show("您没有选择电影");
                return;
            }
            tickets++;
            try
            {
                string seatName = ((Label)sender).Text.ToString();
                string customename = txtZ.Text.ToString();
                string type = "";
                int discount=0;
                if (this.rdoStudent.Checked)
                {
                    type = "student";
                    if (this.cboStu.Text == null)
                    {
                        MessageBox.Show("请输入折扣数");
                        return;
                    }
                    else
                    {
                        discount = int.Parse(this.cboStu.Text);
                    }
                }
                else if(this.rdoZ.Checked)
                {
                  
                    if (this.txtZ.Text==null)
                    {
                        MessageBox.Show("请输入你要赠送的人");
                        return;
                    }
                    else
                    {
                        type = "free";
                    }

                }
                Ticket newTicket = TicketFactory.ticket(cinema.Schedule.Item[key], cinema.Seats1[seatName], discount, customename, type);
                if (cinema.Seats1[seatName].Color==Color.Yellow)
                {
                    DialogResult result = MessageBox.Show("是否购买~~~","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
                    if (result==DialogResult.OK)
                    {
                        cinema.Seats1[seatName].Color = Color.Red;
                        UpdateSet();
                        cinema.SoldTickets.Add(newTicket);
                        //计算价格
                        newTicket.CalcPrice();
                        lblCalePrice.Text = newTicket.Price.ToString();
                        newTicket.Print();
                    }
                    else if(result==DialogResult.No)
                    {
                        return;

                    }
                }
                else
                {
                    MessageBox.Show("已售出");
                }


            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        //普通票的时候不能输入
        private void rdoPutong_CheckedChanged(object sender, EventArgs e)
        {
            txtZ.Enabled = false;
            cboStu.Enabled = false;
            txtZ.Text = "";
            cboStu.Text = "";

        }
        //赠送票的时候
        private void rdoZ_CheckedChanged(object sender, EventArgs e)
        {
            txtZ.Enabled = true;
            cboStu.Enabled = false;
            cboStu.Text = "";

        }
        //学生票的时候
        private void rdoStudent_CheckedChanged(object sender, EventArgs e)
        {
            cboStu.Enabled = true;
            txtZ.Enabled = false;
            txtZ.Text = "";

        }
        //清空 座位
        public void ClearSeat()
        {
            foreach (Seat seat in cinema.Seats1.Values)
            {
                seat.Color = Color.Yellow;
            }
        }
        //更新座位状态
        public void UpdateSet()
        {
            foreach (string key in cinema.Seats1.Keys)
            {
                labels[key].BackColor = cinema.Seats1[key].Color;
            
            }
        }
        private void MyCinema_Load(object sender, EventArgs e)
        {
            this.lblDirector.Text = "";//导演
            this.lblMoiveType.Text = "";//影片类型
            this.lblAtor.Text = "";//主演
            this.lblMovieName.Text = "";//片名
            this.lblTime.Text = "";  //放映时间
            this.lblCalePrice.Text = ""; //价格
            this.lblPrice.Text = "";  //票的价格
            this.txtZ.Enabled = false;
            this.cboStu.Enabled = false;
            this.rdoPutong.Checked = true;
            cinema = new Cinema();
            cinema.Load();
            InitSeats(6,7,tbSitDown);
         
         



        }
        //添加动态加在座位的方法
        private void InitSeats(int seatRow,int seatLine,TabPage tb)
        {
            Label lable;
            Seat seat;
            for (int i = 0; i < seatRow; i++)
            {
                for (int j = 0; j < seatLine; j++)
                {
                    lable = new Label();
                    lable.BackColor = Color.Yellow;
                    lable.AutoSize = false;
                    lable.Font = new System.Drawing.Font("宋体",14.25F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)

(134)));
                    lable.Location = new System.Drawing.Point(30, 30);
                    lable.Name="lbl"+(j+1).ToString()+"_"+(i+1).ToString();
                    lable.Size=new System.Drawing.Size(50,25);
                    //计算坐位号
                    lable.Text = (j + 1) + "-" + (i + 1);
                    lable.TextAlign = ContentAlignment.MiddleCenter;
                    //确定座位
                    lable.Location = new Point(20+(i*90),50+(j*60));
                    //帮定到单击事件
                    lable.Click += new System.EventHandler(lblSeats_Click);
                    //在放映厅TabLontrol空件添加Lable
                    tb.Controls.Add(lable);
                   labels.Add(lable.Text,lable);
                   seat = new Seat((j+1)+"-"+(i+1),Color.Yellow);
                   cinema.Seats1.Add(seat.SeatNum,seat);//将座位保存到集合
                }              
            }
        }
        /// <summary>
        /// 遍历到TreeView
        /// </summary>
        private void InTreeView()
        {
            tvDate.BeginUpdate();
            tvDate.Nodes.Clear();
            string moiveName = "";
            TreeNode feedNode = new TreeNode();
            foreach (ScheduleItem sched in cinema.Schedule.Item.Values)
            {
               
                if (moiveName != sched.Movie.MovieName)
                {
                    feedNode = new TreeNode(sched.Movie.MovieName);
                    tvDate.Nodes.Add(feedNode);
                }
                TreeNode feedNode1 = new TreeNode(sched.Time);
                feedNode.Nodes.Add(feedNode1);
                moiveName = sched.Movie.MovieName;
            }
            tvDate.EndUpdate();           
        }

      
        //退出
        private void tspExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //获取影片的信息
        private void tspBagin_Click(object sender, EventArgs e)
        {
            cinema.Schedule.LoadItems();
            cinema.SoldTickets.Clear();
            InTreeView();

        }
        //关闭时的事件
        private void MyCinema_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("要保存销售状态吗?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
            if (result==DialogResult.OK)
            {
                cinema.Save();
            }

        }
        //取得tree的值
        private void tvDate_AfterSelect(object sender, http://www.)
        {
            TreeNode nodes = tvDate.SelectedNode;
            if (nodes == null) return;
            if (nodes.Level != 1) return;
            key = nodes.Text;
           //将详细信息显示
            this.lblMovieName.Text = cinema.Schedule.Item[key].Movie.MovieName;
            this.lblDirector.Text = cinema.Schedule.Item[key].Movie.Director;
            this.lblAtor.Text = cinema.Schedule.Item[key].Movie.Actor;
            this.lblPrice.Text = cinema.Schedule.Item[key].Movie.Price.ToString();
            this.lblTime.Text = cinema.Schedule.Item[key].Time;
            this.lblMoiveType.Text = cinema.Schedule.Item[key].Movie.MovieType.ToString();
            this.lblCalePrice.Text = "";
            this.picNewspaper.Image = Image.FromFile((http://www.[key].Movie.Poster));
            //清空座位
            ClearSeat();
            foreach (Ticket ti in cinema.SoldTickets)
            {
                foreach (Seat se in cinema.Seats1.Values)
                {
                    if ((ti.Scheduleitem.Time==key)&&ti.Seat.SeatNum==se.SeatNum)
                    {
                        se.Color = Color.Red;

                    }
                }
            }
            //更新座位的状态
            UpdateSet();

            
        }
        //继续销售
        private void tspComeNo_Click(object sender, EventArgs e)
        {
            if (cinema.Schedule.Item.Count==0)
            {
                cinema.Schedule.LoadItems();
            }
            InTreeView();
        }
        //保存
        private void tspOk_Click(object sender, EventArgs e)
        {
            cinema.Save();
        }
    }

[ 本帖最后由 ganmaoaq 于 2009-8-17 07:40 编辑 ]
搜索更多相关主题的帖子: 代码 
2009-08-17 07:27
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:20 
编译看看,能过就是没错啊
这一堆代码怎么看啊

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2009-08-17 08:30
domon
Rank: 3Rank: 3
来 自:河南
等 级:论坛游侠
帖 子:92
专家分:191
注 册:2009-10-26
收藏
得分:0 
同一一楼的看法,单看代码,会出人命的

希望,是走出来的!!!
2009-10-26 13:19
快速回复:看看这个代码那有有错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040246 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved