您的位置:首页 > 编程语言 > C#

ACCPS2深入.net和c#编程影院售票系统 购票.打印.持续销售

2017-03-14 19:22 274 查看
/// <summary>
/// 清空座位
/// </summary>
private void ClearSeat()
{
foreach (Seat seat in cinema.Seats.Values)
{
seat.Color = Color.Yellow;
}
}
/// <summary>
/// 更新座位状态
/// </summary>
private void UpdateSeat()
{
foreach (string key in cinema.Seats.Keys)
{
labels[key].BackColor = cinema.Seats[key].Color;
}
}
/// <summary>
/// 点击一个座位
/// 买票事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lblSeat_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(this.lblMovieName.Text))
{
MessageBox.Show("您还没选择电影!","提示");
return;
}
ticket++;
try
{
string seatNum = ((Label)sender).Text.ToString();
string customerName = this.txtCustomer.Text.ToString();
int discount = 0;
string type = "";
if (this.rdoStudent.Checked)
{
type = "student";
if (this.cmbDisCount.Text == null)
{
MessageBox.Show("请输入折扣数!","提示");
return;
}
else
{
discount = int.Parse(this.cmbDisCount.Text);
}
}
else if (this.rdoFree.Checked)
{
if (String.IsNullOrEmpty(this.txtCustomer.Text))
{
MessageBox.Show("请输入赠票者姓名!","提示");
return;
}
else
{
type = "free";
}
}

//调用工具类创建票
Ticket newTicket = TicketUtil.CreateTicket(cinema.Schedule.Items[key], cinema.Seats[seatNum],
discount, customerName, type);
if (cinema.Seats[seatNum].Color == Color.Yellow)
{
//打印
DialogResult result;
result = MessageBox.Show("是否购买?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
cinema.Seats[seatNum].Color = Color.Red;
UpdateSeat();
newTicket.CalcPrice();
cinema.SoldTickets.Add(newTicket);
lblCalcPrice.Text = newTicket.Price.ToString();
newTicket.Print();
}
else if (result == DialogResult.No)
{
return;
}
}
else
{
//显示当前售出票的信息
foreach (Ticket ticket0 in cinema.SoldTickets)
{
//判断是否为同场次、同电影、同座位号
if (ticket0.Seat.SeatNum == seatNum && ticket0.ScheduleItem.Time==tvMovies.SelectedNode.Text && ticket0.ScheduleItem.Movie.MovieName==tvMovies.SelectedNode.Parent.Text)
{
ticket0.Show();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void tsmiExit_Click(object sender, EventArgs e)
{
cinema.Save();
this.Dispose();
}

private void tsmiSave_Click(object sender, EventArgs e)
{
cinema.Save();
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult close;
close = MessageBox.Show("是否保存当前销售状态?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (close == DialogResult.Yes)
{
//退出时保存Cinema对象
cinema.Save();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: