Cinema.cs类

    [Serializable]
// 电影院类
public class Cinema
{
public Cinema()
{
//二进制
SoldTickets = new List<Ticket>();
//时间表
Schedule = new Schedule();
//座位
Seats = new Dictionary<string, Seat>();
} public Schedule Schedule { get; set; } public Dictionary<string, Seat> Seats { get; set; } public List<Ticket> SoldTickets { get; set; } // 加载放映场次
public void Load()
{
using (FileStream fs = new FileStream("student.dat",FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
this.SoldTickets = bf.Deserialize(fs) as List<Ticket>;
}
} // 保存销售信息
public void Save()
{
using (FileStream fs = new FileStream("student.dat",FileMode.Create))
{
//序例化
BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, SoldTickets);
} }
}
}

Common.cs类

 // 电影类型 枚举
public enum MovieType
{
//喜剧片
Comedy,
//战争片
War,
//爱情片
Romance,
//动作片
Action,
//卡通片
Cartoon,
//惊悚片
Thriller,
//冒险片
Adventure
}
}

FreeTicket.cs类

 [Serializable]

    // 赠票
public class FreeTicket:Ticket
{
public FreeTicket() { }
public FreeTicket(string customerName,ScheduleItem scheduleItem,Seat seat):base(scheduleItem,seat)
{
this.CustomerName = customerName;
this.Price = CalcPrice();
} //赠票人姓名
public string CustomerName { get; set; } // 计算赠票票价
public override double CalcPrice()
{
return ;
} // 打印赠票
public override void Print()
{
string path = (this.ScheduleItem.Time + " " + this.Seat.SeatNum).Replace(":", "-") + ".txt";
using (FileStream fs = new FileStream(path, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
{
sw.WriteLine("*******************************");
sw.WriteLine(" 青鸟影院(赠票) ");
sw.WriteLine("-------------------------------");
sw.WriteLine("电影名:" + ScheduleItem.Movie.MovieName);
sw.WriteLine("时间:" + this.ScheduleItem.Time);
sw.WriteLine("座位号:" + this.Seat.SeatNum);
sw.WriteLine("赠送人:"+this.CustomerName);
sw.WriteLine("价格:" + this.Price);
sw.WriteLine("*******************************");
}
}
}
}
}

Movie.cs类

    [Serializable]
// 电影类
public class Movie
{
public Movie() { }
public Movie(string actor, string director, string movieName, MovieType movieType, string poster, double price)
{
this.Actor = actor;
this.Director = director;
this.MovieName = movieName;
this.MovieType = movieType;
this.Poster = poster;
this.Price = price;
} //导演
public string Actor { get; set; }
//演员
public string Director { get; set; }
//电影名
public string MovieName { get; set; }
//电影类型
public MovieType MovieType { get; set; }
//海报路径
public string Poster { get; set; }
//电影价格
public double Price { get; set; }
}
}

Schedule.cs类

[Serializable]
//放映计划类
public class Schedule
{
public Schedule() { Items = new Dictionary<string, ScheduleItem>(); }
public Schedule(Dictionary<string, ScheduleItem> items)
{
this.Items = items;
} public Dictionary<string, ScheduleItem> Items { get; set; } //加载XML中的放映场次信息
public void LoadItems()
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(@"Data\ShowList.xml");
XmlNode root = doc.DocumentElement; foreach (XmlNode var in root.ChildNodes)//Movie
{
Movie movie = new Movie();
foreach (XmlNode var2 in var.ChildNodes)//Name
{
switch (var2.Name)
{
case "Name":
movie.MovieName = var2.InnerText;
break;
case "Poster":
movie.Poster = var2.InnerText;
break;
case "Director":
movie.Director = var2.InnerText;
break;
case "Actor":
movie.Actor = var2.InnerText;
break;
case "Price":
movie.Price = Convert.ToDouble(var2.InnerText);
break;
case "Type":
movie.MovieType = (MovieType)Enum.Parse(typeof(MovieType), var2.InnerText);
break;
case "Schedule":
foreach (XmlNode var3 in var2.ChildNodes)//Item
{
ScheduleItem item = new ScheduleItem(movie, var3.InnerText);
this.Items.Add(var3.InnerText, item);
}
break;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}

ScheduleItem.cs类

  [Serializable]

    // 放映场次
public class ScheduleItem
{
public ScheduleItem() { }
public ScheduleItem(Movie movie,string time)
{
this.Movie = movie;
this.Time = time;
} //电影
public Movie Movie { get; set; }
//放映时间
public string Time { get; set; }
}
}

Seat.cs类

   [Serializable]

    // 座位类
public class Seat
{
public Seat() { }
public Seat(string seatNum,Color color)
{
this.SeatNum = seatNum;
this.Color = color;
} //座位号
public string SeatNum { get; set; }
//颜色
public Color Color { get; set; }
}
}

StudentTicket.cs类

    [Serializable]

    // 学生票

    public class StudentTicket:Ticket
{
public StudentTicket() { }
public StudentTicket(ScheduleItem scheduleItem,Seat seat,double discount):base(scheduleItem,seat)
{
this.Discount = discount;
this.Price = CalcPrice();
} //折扣
public double Discount { get; set; } // 计算学生票价格
public override double CalcPrice()
{
return this.ScheduleItem.Movie.Price * this.Discount /;
}
// 打印学生票
public override void Print()
{
string path = (this.ScheduleItem.Time + " " + this.Seat.SeatNum).Replace(":", "-") + ".txt";
using (FileStream fs = new FileStream(path, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
{
sw.WriteLine("*******************************");
sw.WriteLine(" 青鸟影院(学生票) ");
sw.WriteLine("-------------------------------");
sw.WriteLine("电影名:" + ScheduleItem.Movie.MovieName);
sw.WriteLine("时间:" + this.ScheduleItem.Time);
sw.WriteLine("座位号:" + this.Seat.SeatNum);
sw.WriteLine("折扣:"+this.Discount);
sw.WriteLine("价格:" + this.Price);
sw.WriteLine("*******************************");
}
}
}
}
}

Ticket.cs类

 [Serializable]
// 电影票父类
public class Ticket
{
public Ticket() { }
public Ticket(ScheduleItem scheduleItem,Seat seat)
{
this.ScheduleItem = scheduleItem;
this.Seat = seat;
this.Price = CalcPrice();
} //价格
public double Price { get; set; }
//放映场次
public ScheduleItem ScheduleItem { get; set; }
//座位
public Seat Seat { get; set; } // 计算价格
public virtual double CalcPrice()
{
return this.ScheduleItem.Movie.Price;
} // 打印电影票
public virtual void Print()
{
string path = (this.ScheduleItem.Time + " " + this.Seat.SeatNum).Replace(":", "-") + ".txt";
using (FileStream fs = new FileStream(path,FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs,Encoding.Default))
{
sw.WriteLine("*******************************");
sw.WriteLine(" 青鸟影院 ");
sw.WriteLine("-------------------------------");
sw.WriteLine("电影名:"+ScheduleItem.Movie.MovieName);
sw.WriteLine("时间:"+this.ScheduleItem.Time);
sw.WriteLine("座位号:"+this.Seat.SeatNum);
sw.WriteLine("价格:"+this.Price);
sw.WriteLine("*******************************");
}
}
}
}
}

TicketUtil.cs类

 // 创建电影票工具类
// 使用简单工厂模式创建票
public class TicketUtil
{
public static Ticket CreateTicket(ScheduleItem item,Seat seat,string customerName,double discount,string type)
{
Ticket ticket = null;
switch (type)
{
case "normal":
ticket = new Ticket(item, seat);
break;
case "free":
ticket = new FreeTicket(customerName, item, seat);
break;
case "student":
ticket = new StudentTicket(item, seat, discount);
break;
}
return ticket;
}
}
}

主窗体代码:

        //实例化影院类(所有存储都是以影院类为基础)
Cinema cinema = new Cinema();
//存储lable控件信息
Label lbl = new Label(); //获取新放映列表
private void tsmiNew_Click(object sender, EventArgs e)
{
BingTreeView();
} //选择内容发生改变
private void tvMovies_AfterSelect(object sender, TreeViewEventArgs e)
{
if (this.tvMovies.SelectedNode.Level == )
{
string time = this.tvMovies.SelectedNode.Text;
ScheduleItem item = cinema.Schedule.Items[time];
this.lblActor.Text = item.Movie.Actor;
this.lblDirector.Text = item.Movie.Director;
this.lblMovieName.Text = item.Movie.MovieName;
this.lblPrice.Text = item.Movie.Price.ToString();
this.lblTime.Text = item.Time;
this.lblType.Text = item.Movie.MovieType.ToString();
this.picMovie.Image = Image.FromFile(@"Image\" + item.Movie.Poster);
this.lblCalcPrice.Text = item.Movie.Price.ToString(); //将所有座位设置为黄色
foreach (Seat var in cinema.Seats.Values)
{
var.Color = Color.Yellow;
} //在已售出的票中循环判断
foreach (Ticket ticket in cinema.SoldTickets)
{
foreach (Seat seat in this.cinema.Seats.Values)
{
//场次相同且座位号相同
if (ticket.ScheduleItem.Time == time && ticket.Seat.SeatNum == seat.SeatNum)
{
//更新座位颜色
seat.Color = Color.Red;
}
}
}
// 将座位颜色更新到Label上显示
foreach (Seat seat in cinema.Seats.Values)
{
foreach (Label lbl in tpCinema.Controls)
{
// 座位号相同证明是对应Label
if (lbl.Text == seat.SeatNum)
{
lbl.BackColor = seat.Color;
}
}
}
}
} //点击普通票
private void rdoNormal_CheckedChanged(object sender, EventArgs e)
{
this.cmbDisCount.Enabled = false;
this.txtCustomer.Enabled = false;
this.lblCalcPrice.Text = lblPrice.Text;
} //点击赠票
private void rdoFree_CheckedChanged(object sender, EventArgs e)
{
this.txtCustomer.Enabled = true;
this.cmbDisCount.Enabled = false;
this.lblCalcPrice.Text = lblPrice.Text;
} //点击学生票
private void rdoStudent_CheckedChanged(object sender, EventArgs e)
{
if (this.lblPrice.Text != "")
{
this.cmbDisCount.Enabled = true;
this.txtCustomer.Enabled = false;
this.lblCalcPrice.Text = (Convert.ToDouble(this.lblPrice.Text) * Convert.ToDouble(this.cmbDisCount.Text) / ).ToString();
} } //加载
private void FrmCinema_Load(object sender, EventArgs e)
{
this.rdoNormal.Checked = true;
this.cmbDisCount.SelectedIndex = ;
InitSeats(, );
skinEngine1.SkinFile = "Wave.ssk";
} //选择折扣变化:
private void cmbDisCount_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.lblPrice.Text != "")
{
this.lblCalcPrice.Text = (Convert.ToDouble(this.lblPrice.Text) * Convert.ToDouble(this.cmbDisCount.Text) / ).ToString();
} } // 获取放映列表绑定到TreeView
private void BingTreeView()
{
this.tvMovies.Nodes.Clear();
//加载XML
cinema.Schedule.LoadItems();
//绑定到TreeView
TreeNode root = null;
foreach (ScheduleItem var in cinema.Schedule.Items.Values)
{
if (root == null || root.Text != var.Movie.MovieName)
{
//根节点
root = new TreeNode(var.Movie.MovieName);
this.tvMovies.Nodes.Add(root);
}
//子节点
root.Nodes.Add(var.Time);
}
} // 初始化座位
private void InitSeats(int row, int col)
{
for (int i = ; i < row; i++)
{
for (int j = ; j < col; j++)
{
Label lb = new Label();
lb.BackColor = Color.Yellow;
lb.Location = new Point( + j * , + i * );
lb.Font = new Font("Courier New", );
lb.Name = (i + ) + "-" + (j + );
lb.Size = new Size(, );
lb.TabIndex = ;
lb.Text = (i + ) + "-" + (j + );
lb.TextAlign = ContentAlignment.MiddleCenter;
lb.Click += lb_Click;
tpCinema.Controls.Add(lb);
//添加座位对象到CInema的Seats集合中
Seat seat = new Seat(lb.Text, Color.Yellow);
cinema.Seats.Add(seat.SeatNum, seat);
}
}
} private void lb_Click(object sender, EventArgs e)
{
if (this.tvMovies.Nodes.Count == || this.tvMovies.SelectedNode.Level ==)
{
return;
} lbl = sender as Label;
if (lbl.BackColor == Color.Red)
{
MessageBox.Show("已售出");
}
else
{
if (DialogResult.OK == MessageBox.Show("是否购买", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
{
//取得放映时间
string time = this.tvMovies.SelectedNode.Text;
//使用时间作为键找到放映场次对象
ScheduleItem item = cinema.Schedule.Items[time]; string type = string.Empty;
type = rdoNormal.Checked ? "normal" : rdoFree.Checked ? "free" : "student";
Ticket ticket = TicketUtil.CreateTicket(item, cinema.Seats[lbl.Text], txtCustomer.Text, Convert.ToDouble(cmbDisCount.Text), type); //添加到已销售的集合中
cinema.SoldTickets.Add(ticket);
//出票
ticket.Print();
//更新颜色
lbl.BackColor = Color.Red;
cinema.Seats[lbl.Text].Color = Color.Red;
}
} } //保存
private void tsmiSave_Click(object sender, EventArgs e)
{
cinema.Save();
MessageBox.Show("保存成功");
} //继续销售
private void tsmiMovies_Click(object sender, EventArgs e)
{
cinema.Load();
// 将座位颜色更新到Label上显示
foreach (Seat seat in cinema.Seats.Values)
{
foreach (Label lbl in tpCinema.Controls)
{
// 座位号相同证明是对应Label
if (lbl.Text == seat.SeatNum)
{
lbl.BackColor = seat.Color;
}
}
}
} private void tsmiExit_Click(object sender, EventArgs e)
{
this.Close();
}

努力做一个优秀的programmer [ C# 影院售票系统]的更多相关文章

  1. C#总结项目《影院售票系统》编写总结一

    C#学习经历从基本语法结构到窗体再到面向对象终于走完了.NET初级程序员的道路,做为品德优良好学生更不能落下课程的总结项目-某某鸟<影院售票系统>.用了大概一天半的时间做完这个练手项目,先 ...

  2. C#编写影院售票系统(A project with a higher amount of gold )

    项目需求: 影院售票系统 1.基础设施 放映厅 座位集合 2.一个海报------------>放映计划 3.售票设置----------->观影 领域模型:程序中提炼出的实体 4.从电影 ...

  3. 「影院售票系统」 · Java Swing + MySQL JDBC开发

    目录 文档说明: 一.语言和环境 二.实现功能 三.数据库设计 四.具体要求及推荐实现步骤 五.注意事项 六.评分标准 实现代码: 一.数据库: 二.Java Swing: com.ynavc.Bea ...

  4. C#编写影院售票系统(A project with a higher amount of gold )(2:相关代码)

    此篇文章为项目代码,,,需要项目需求 ,思路分析与窗体效果请访问:http://www.cnblogs.com/lsy131479/p/8367304.html 项目类图: 影院类: using Sy ...

  5. C#总结项目《影院售票系统》编写总结完结篇

    回顾:昨天总结了影院售票系统核心部分-售票,整个项目也就完成了2/3了,需求中也要求了对销售信息的保存,今天就继续总结销售信息的保存以及加载销售信息. 分析:退出程序时将已售出票集合中的对象循环写入到 ...

  6. 利用JS跨域做一个简单的页面訪问统计系统

    事实上在大部分互联网web产品中,我们一般会用百度统计或者谷歌统计分析系统,通过在程序中引入特定的JS脚本,然后便能够在这些统计系统中看到自己站点页面详细的訪问情况.可是有些时候,因为一些特殊情况,我 ...

  7. C#总结项目《影院售票系统》编写总结三

    昨天总结了动态绘制控件.票类型的切换以及数据在窗体中的展现.今天继续总结,自己喜欢的就去做吧,让别人说去吧,省的自己再留下什么后悔遗憾,噢耶,加油! 今天总结项目中最核心的部分--购票.座位颜色状态的 ...

  8. C#总结项目《影院售票系统》编写总结二

    昨天发布了总结项目的第一篇,需求分析以及类的搭建,今天继续更新,动态绘制控件.票类型的切换以及数据在窗体中的展现. 先从简单的开始,票类型的切换. 分析: 1.当点击普通票时 学生折扣和赠送者是禁用的 ...

  9. fir.im Weekly - 如何做一个出色的程序员

    做一个出色的程序员,困难而高尚.本期 fir.im Weekly 精选了一些实用的 iOS,Android 开发工具和源码分享,还有一些关于程序员的成长 Tips 和有意思有质量的线下活动~ How ...

随机推荐

  1. 第二章 在Linux上部署.net core

    项目目标部署环境:CentOS 7+ 项目技术点:.netcore2.0 + Autofac +webAPI + NHibernate5.1 + mysql5.6 + nginx 开源地址:https ...

  2. MQ消息队列搭建命令及方法

    MQ 是一款稳定.安全又可靠的消息传递中间件.它使用消息和队列来支持应用程序.系统.服务和文件之间的信息交换.它可以简化和加速多个平台中不同应用程序和业务数据的集成.支持各种 API 和语言,并可以在 ...

  3. 使用redis PSUBSCRIBE实现实时任务

    PSUBSCRIBE可以监听键的过期事件 1.进行数据库的配置 notify-keyspace-events Ex 2.使用命令监听事件 psubscribe  __keyevnet@0__:expi ...

  4. java中关于IO流的知识总结(重点介绍文件流的使用)

    今天做软件构造实验一的时候,用到了java文件流的使用,因为之前学的不是很踏实,于是决定今天好好总结一下, 也方便以后的回顾. 首先,要分清IO流中的一些基础划分: 按照数据流的方向不同可以分为:输入 ...

  5. 长春理工大学第十四届程序设计竞赛(重现赛)I

    I.Fate Grand Order 题目链接:https://ac.nowcoder.com/acm/contest/912/I 题目: Fate Grand Order是型月社发行的角色扮演类手机 ...

  6. 新补充 JSSSS

    条件语句 补充: var a=“hello world” a这个变量是字符串了 对于里面每一个字母来说 他是字节 里面有11个字节 字节总数用length表示 如下: 根据上面的内容咱们又发现了一个运 ...

  7. 学习kafka自己发生的几个小错误记录

    一.  The method iterator() is ambiguous ConsumerIterator<byte[],byte[]> it =stream.iterator(); ...

  8. SqlDataReader的用法 转自https://www.cnblogs.com/sunxi/p/3924954.html

    datareader对象提供只读单向数据的快速传递,单向:您只能依次读取下一条数据;只读:DataReader中的数据是只读的,不能修改;相对地,DataSet中的数据可以任意读取和修改 01.usi ...

  9. Python中的函数及函数参数的使用

    函数:一个工具,随调随用 降级代码冗余 增加代码的复用性,提高开发效率,为了不成为cv战士 提高程序扩展性 函数有两个阶段:定义阶段,调用阶段. 定义时:只检查函数体内代码语法,不执行函数体内代码. ...

  10. 和朱晔一起复习Java并发(一):线程池

    和我之前的Spring系列文章一样,我们会以做一些Demo做实验的方式来复习一些知识点. 本文我们先从Java并发中最最常用的线程池开始. 从一个线程池实验开始 首先我们写一个方法来每秒一次定时输出线 ...