主窗体
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)
深入.NET编程 第十一章 影院售票系统
最新推荐文章于 2023-11-08 11:09:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)