当前位置: 移动技术网 > IT编程>开发语言>c# > C#影院售票系统毕业设计(4)

C#影院售票系统毕业设计(4)

2019年07月18日  | 移动技术网IT编程  | 我要评论

回顾:上一篇文章总结了影院售票系统核心部分-售票,整个项目也就完成了2/3了,需求中也要求了对销售信息的保存,今天就继续总结销售信息的保存以及加载销售信息

分析:退出程序时将已售出票集合中的对象循环写入到文本文件中,读取时循环读入并加入到已售出票集合中,下面看具体实现

 public void save()
  {
  //保存的文件
  filestream fs = new filestream("soldtickets.txt", filemode.openorcreate);
  streamwriter sw = new streamwriter(fs, encoding.default);
  for (int i = 0; i < cinema.soldtickets.count; i++)
  {
   //创建售出票对象
   ticket ticket = cinema.soldtickets[i];
   //票的类型
   string type = "";
   //票的折扣
   int discount = 0;
   //赠送者的名字
   string name = "";
   //用is判断属于哪个类,并根据类设置类型
   if (cinema.soldtickets[i] is studentticket)
   {
   type = "stu";
   discount = ((studentticket)cinema.soldtickets[i]).discount;
   }
   else if (cinema.soldtickets[i] is freeticket)
   {
   type = "free";
   name = ((freeticket)cinema.soldtickets[i]).customername;
   }
   else
   {
   type = "normal";
   }
   //将信息写入文本文件0.电影名1.场次2.座位号3.票价4.折扣5.类型6.赠送者
   string info = string.format("{0}|{1}|{2}|{3}|{4}|{5}|{6}", cinema.soldtickets[i].scheduitem.movie.moviename, cinema.soldtickets[i].scheduitem.time, cinema.soldtickets[i].seat.seatnum, cinema.soldtickets[i].price, discount, type, name);
   sw.writeline(info);
  }
  sw.writeline("the end");
  sw.close();
  fs.close();
  messagebox.show("保存成功!");
  }

读取数据

 public void loadlis()
  {
  streamreader reader = new streamreader("soldtickets.txt", encoding.default);
  //一行一行的读取,先预读一行给while判断用
  string line = reader.readline();
  //保存分割好的数据的数组
  string[] pv;
  ticket ticket = null;
  //当是the end时结束读取
  while (line.trim() != "the end")
  {
   pv = line.split('|');
   //读取文本信息
   string index = pv[1];
   //创建票对象
   ticket = ticketutil.createticket(cinema.schedule.items[index], cinema.seats[pv[2]], int.parse(pv[4]), pv[6], pv[5]);
   //加入到售出票集合
   cinema.soldtickets.add(ticket);
   line = reader.readline();
  }
  reader.close();
  }

到这,整个项目的需求就算是做完了

总结一下通过这个项目得到的收货

1、对项目的业务必然要了解透彻

2、项目的架构从大处着手,先骨架,然后血肉,最后皮毛;将大项问题分解成若干小问题,有条不紊,才不会做着做着蒙圈。

以上就是关于c#影院售票系统毕业设计的全部内容,所有的流程都已经分享给大家了,希望对大家的学习有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网