<?xml version="1.0" encoding="utf-8" ?>
<ShowList>
<Movie>
<Name>不二神探</Name>
<Poster>不二神探.png</Poster>
<Director>王子鸣</Director>
<Actor>李连杰、文章、陈妍希</Actor>
<Type>动作</Type>
<Price>60</Price>
<Schedule>
<Item>9:00</Item>
<Item>13:00</Item>
</Schedule>
</Movie>
<Movie>
<Name>西游降魔篇</Name>
<Poster>西游降魔篇.png</Poster>
<Director>郭子健、周星驰</Director>
<Actor>黄渤、舒淇、文章</Actor>
<Type>喜剧</Type>
<Price>60</Price>
<Schedule>
<Item>11:20</Item>
<Item>15:45</Item>
<Item>19:25</Item>
</Schedule>
</Movie>
<Movie>
<Name>中国合伙人</Name>
<Poster>中国合伙人.png</Poster>
<Director>陈可辛</Director>
<Actor>黄晓明、邓超、佟大为</Actor>
<Type>喜剧</Type>
<Price>70</Price>
<Schedule>
<Item>21:00</Item>
<Item>23:10</Item>
</Schedule>
</Movie>
<Movie>
<Name>钢铁侠</Name>
<Poster>钢铁侠.png</Poster>
<Director>沙恩布莱克</Director>
<Actor>小罗伯特唐尼</Actor>
<Type>动作</Type>
<Price>70</Price>
<Schedule>
<Item>17:30</Item>
</Schedule>
</Movie>
</ShowList>
class Cinema //影院类
{
public Cinema()
{
Seats = new Dictionary<string, Seat>();
SoldTicket = new List<Ticket>();
SeSchedule = new Schedule();
}
//座位集合
public Dictionary<string, Seat> Seats { get; set; }
//放映计划
public Schedule SeSchedule { get; set; }
//已售出电影票
public List<Ticket> SoldTicket { get; set; }
public void Save()
{
FileStream fs = new FileStream("soldTickets.txt", FileMode.OpenOrCreate);
StreamWriter writer = new StreamWriter(fs, Encoding.Default);
for (int index = 0; index < SoldTicket.Count; index++)
{
Ticket ticket = SoldTicket[index];
string info = "|" + ticket.SeScheduleItem.Movie.MovieName + "|" + ticket.SeScheduleItem.Movie.Poster + "|" +
ticket.SeScheduleItem.Movie.Director + "|" + ticket.SeScheduleItem.Movie.Actor + "|" + ticket.SeScheduleItem.Movie.MoveType.ToString()
+ "|" + ticket.SeScheduleItem.Movie.Price + "|" + ticket.SeScheduleItem.Time + "|" + ticket.Seat.SeatName + "|" +
ticket.Seat.Color + "|" + ticket.Price + "|";
if (ticket is FreeTicket)
{
string customerName = ((FreeTicket)ticket).CustomerName;
writer.WriteLine("free" + info + customerName);
}
else if (ticket is StudentTicket)
{
writer.WriteLine("student" + info + "");
}
else
{
writer.WriteLine("" + info + "");
}
}
writer.WriteLine("the end");
writer.Close();
fs.Close();
}
public void Load()
{
try
{
StreamReader reader = new StreamReader("soldTickets.txt", Encoding.GetEncoding("GB2312"));
string line = reader.ReadLine();
string[] propertyValues;
Ticket ticket = null;
while (line.Trim() != "the end")
{
propertyValues = line.Split('|');
string type = propertyValues[0];
Movie movie = new Movie(propertyValues[1], propertyValues[2], propertyValues[3], propertyValues[4], (MovieType)Enum.Parse(typeof(MovieType), propertyValues[5]), int.Parse(propertyValues[6]));
ScheduleItem scheduleItem = new ScheduleItem();
scheduleItem.Time = propertyValues[7];
scheduleItem.Movie = movie;
string color = propertyValues[9];
string endcolor = color.Substring(color.IndexOf("[") + 1, color.Length - 1 - color.IndexOf("[") - 1);
Seat seat = new Seat(propertyValues[8], Color.FromName(endcolor));
int discount = 10;
switch (type)
{
case "student":
discount = 7;
ticket = TicketUtil.CreateTicket(sch