看看这个代码那有有错
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 编辑 ]