package com.jj.sx;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import javax.swing.JOptionPane;
import com.jj.sx.jiemian.b1handler;
import com.jj.sx10.Analyse;
import com.jj.sx10.Movie;
import com.jj.sx10.Ticket;
import com.jj.sx10.TicketType;
/*
* 书写一个票据生成类
*/
public class Ticketcreate {
String l1;
String l2;
String l3;
String l4;
String l5;
String l6;
static int count;
HashMap<String, Movie> h1;
public Ticketcreate(String l1, String l2, String l3, String l4, String l5,
String l6, HashMap<String, Movie> h1) throws IOException,
ClassNotFoundException {
// *******************8
super();
this.l1 = l1;
this.l2 = l2;
this.l3 = l3;
this.l4 = l4;
this.l5 = l5;
this.l6 = l6;
this.h1 = h1;
File file = new File("e:\\售票信息.txt");
if (!file.exists()) {
file.createNewFile();
}
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
ArrayList<Ticket> list = new ArrayList<>();
list = (ArrayList<Ticket>) ois.readObject();
ois.close();
boolean flag=false;
for (Ticket ticket : list) {
if (ticket.getSeat().equals(l4)) {
flag=true;
JOptionPane.showMessageDialog(null, "该票已售出,请重新选择座位号");
return ;
}
}
// ********************生成电影票的对象*****************
int price = 0;
price = Integer.parseInt(h1.get(l1).getPrice());
Ticket ticket = null;
switch (l3) {
case "1.普通票":
ticket = new Ticket(l1, l4, price, TicketType.普通票, l2);
break;
case "2":
ticket = new Ticket(l1, l4, price, l5, TicketType.学生票, l2);
break;
default:
ticket = new Ticket(l1, l4, price, l6, TicketType.赠票, l2);
break;
}
// 记录打印票的个数
count++;
// ***************打印票*****************/
File file2 = new File("e:\\出票\\出票" + count + ".txt");
if (!file2.exists()) {
file2.createNewFile();
}
FileWriter fw = new FileWriter(file2);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("*****************************");
bw.newLine();
bw.write(" 青鸟影院 ");
bw.newLine();
bw.write("------------");
bw.newLine();
bw.write("电影名:" + l1);
bw.newLine();
bw.write("时间:" + l2);
bw.newLine();
bw.write("座位号:" + l4);
bw.newLine();
switch (l3) {
case "1.普通票":
bw.write("价格:" + ticket.getPrice());
break;
case "2.学生票":
bw.write("价格:" + (ticket.getPrice() * Integer.parseInt(l5) / 10));
break;
case "3.赠票":
bw.write("姓名:" + l6);
break;
}
bw.close();
fw.close();
// ***********************8
// 生成一个arraylist储存生成的电影票
ArrayList<Ticket> arrayList = new ArrayList<>();
arrayList.add(ticket);
// 序列化将arraylist写到硬盘上
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
file));
oos.writeObject(arrayList);
oos.close();
JOptionPane.showMessageDialog(null, "出票成功");
}
}