public static ArrayList<Reservation> getReservations(Show[] shows, Customer[] customers) { Logger.log("Database.getReservations"); ArrayList<Reservation> reservations = new ArrayList<Reservation>(); try { ArrayList<Reservation> tempReservations = new ArrayList<Reservation>(); Show show = null; Customer customer = null; ResultSet rs = query("SELECT COUNT(*) FROM reservation"); rs.next(); rs = query("SELECT * FROM reservation"); while (rs.next()) { ArrayList<Point> position = new ArrayList<Point>(); for (Show s : shows) { if (s.getID() == rs.getInt("forestilling_id")) { show = s; } } position.add(new Point(rs.getInt("pos_x"), rs.getInt("pos_y"))); for (Customer c : customers) { if (c.getID() == rs.getInt("kunde_id")) { customer = c; } } tempReservations.add( new Reservation(show, position, customer, rs.getInt("reservation_id"))); } // Merge all reservations which have the same show AND customer and save them in reservations // list while (tempReservations.size() != 0) { Customer cus = tempReservations.get(0).getCustomer(); Show s = tempReservations.get(0).getShow(); ArrayList<Point> seats = new ArrayList<Point>(); int ID = tempReservations.get(0).getID(); for (int x = 0; x < tempReservations.size(); x++) { if (tempReservations.get(x).getCustomer() == cus && tempReservations.get(x).getShow() == s) { seats.add(tempReservations.get(x).getFirstPos()); tempReservations.remove(tempReservations.get(x)); // After deleting the object, decrease x with 1 (else one element would never be // reached) x--; } } reservations.add(new Reservation(s, seats, cus, ID)); } } catch (SQLException exception) { Logger.log(exception, "Database:getReservations"); } Logger.log("Database.getReservations"); return reservations; }
public static boolean createReservation(Show show, Point[] points, Customer c) { Logger.log("Database.createReservation"); String sql = ""; for (Point seat : points) { sql = "INSERT INTO reservation(forestilling_id, pos_x, pos_y, kunde_id) VALUES (" + show.getID() + "," + seat.x + "," + seat.y + "," + c.getID() + ");"; if (update(sql)) { continue; } return false; } Logger.log("Database.createReservation"); return true; }
/** * This is the constructor for objects of the class ChangeReservationDialog * * @param markedSeats A collection of the seats marked in the room overview * @param show The show chosen in the result table * @param customerID The phonenumber of the customer * @param frame The frame the dialog was called from */ public ChangeReservationDialog( ArrayList<Seat> markedSeats, Show show, int customerID, MainFrame frame) { super("Reservation"); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); Border standart = BorderFactory.createEmptyBorder(5, 5, 5, 5); JPanel north = new JPanel(); north.setBorder(standart); contentPane.add(north, BorderLayout.NORTH); JLabel topText = new JLabel( "Du forsøger at ændre en reservation til en med følgende " + markedSeats.size() + " sæder til: " + show.toString()); north.add(topText); JPanel center = new JPanel(); center.setLayout(new FlowLayout()); center.setBorder(standart); contentPane.add(center, BorderLayout.CENTER); String seatString = "<html>"; for (Seat s : markedSeats) { seatString += s.toString() + "<br>"; } seatString += "</html>"; JLabel seatText = new JLabel(seatString); seatText.setBackground(Color.WHITE); center.add(seatText); JPanel south = new JPanel(); south.setLayout(new BorderLayout()); south.setBorder(standart); contentPane.add(south, BorderLayout.SOUTH); JPanel phoneSection = new JPanel(); JLabel costumerText = new JLabel("Kundens telefonnummer: " + customerID); phoneSection.add(costumerText); JPanel buttons = new JPanel(); JButton cancel = new JButton("Annuller"); cancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); JButton reserve = new JButton("Ændre"); reserve.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String number = "" + customerID; if (number.length() == 8) { Database.deleteReservations(show, customerID); for (Seat s : markedSeats) { Database.makeReservation(show, new Customer(Integer.parseInt(number)), s); } ChangeReservationDialog.this.dispose(); frame.reset(); } } }); buttons.add(cancel); buttons.add(reserve); south.add(buttons, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); pack(); setVisible(true); }
public static void main(String[] args) { // TODO 自动生成的方法存根 Show.inFrame(new Table(), 200, 200); }
public static void main(String args[]) { Show.inFrame(new Menus(), 300, 200); }