import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
+
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import businessLogic.BookingManager;
import domain.Booking;
+import domain.Client;
import domain.Offer;
import domain.RuralHouse;
private JTextField telIn;
private int row;
private JLabel labelPhone;
+ private JLabel lblName;
+ private JTextField nameField;
+ private JLabel lblEmail;
+ private JTextField mailField;
/**
* Create the frame.
final Date LastDay) {
this.rh = RH;
this.getContentPane().setLayout(null);
- setBounds(100, 100, 500, 583);
+ setBounds(100, 100, 500, 700);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
scrollPane.setViewportView(table);
JButton btnBookSelected = new JButton("Book SelectedOffer");
- btnBookSelected.setBounds(238, 505, 178, 23);
+ btnBookSelected.setBounds(238, 614, 178, 23);
contentPane.add(btnBookSelected);
btnBookSelected.addActionListener(new ActionListener() {
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Telephone num:");
- lblNewLabel_1.setBounds(10, 509, 83, 14);
+ lblNewLabel_1.setBounds(10, 618, 83, 14);
contentPane.add(lblNewLabel_1);
telIn = new JTextField();
- telIn.setBounds(99, 505, 129, 20);
+ telIn.setBounds(103, 615, 129, 20);
contentPane.add(telIn);
telIn.setColumns(10);
labelPhone.setBounds(238, 252, 178, 14);
contentPane.add(labelPhone);
+ lblName = new JLabel("Name:");
+ lblName.setBounds(10, 516, 46, 14);
+ contentPane.add(lblName);
+
+ nameField = new JTextField();
+ nameField.setBounds(103, 513, 178, 20);
+ contentPane.add(nameField);
+ nameField.setColumns(10);
+
+ lblEmail = new JLabel("E-mail:");
+ lblEmail.setBounds(10, 565, 46, 14);
+ contentPane.add(lblEmail);
+
+ mailField = new JTextField();
+ mailField.setBounds(103, 562, 178, 20);
+ contentPane.add(mailField);
+ mailField.setColumns(10);
+
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
Enumeration<Offer> rhs = rh.getAllOffers().elements();
while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
- if (of.getBookings().size()==1&&of.getBookings().get(0).isAccepted()) {
+ if (of.getBookings() == null
+ || !(of.getBookings().size() == 1 && of.isBooked())) {
Vector<Object> row = new Vector<Object>();
row.add(of.getOfferNumber());
row.add(of.getFirstDay());
private void jButton_ActionPerformed(ActionEvent arg0) {
BookingManager bookingM = new BookingManager();
- // RegExp to see if telephone number is correct??TODO
- if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) {
+
+ if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")
+ && mailField
+ .getText()
+ .matches(
+ "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
+ && !nameField.getText().isEmpty()) {
labelPhone.setText("");
- Booking book = null;
+ Vector<Booking> book = null;
try {
- if (table.getRowCount() != 0)
+ if (table.getRowCount() != 0) {
+ Client cl = new Client(nameField.getText(),
+ mailField.getText(), telIn.getText());
book = bookingM.createBooking(rh, rh.offers.get(row)
- .getFirstDay(), rh.offers.get(row).getLastDay(),
- telIn.getText());
+ .getFirstDay(), rh.offers.get(row).getLastDay(),cl);
+ }
} catch (Exception e) {
e.printStackTrace();
}
if (book != null) {
BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow(
- book);
+ book.lastElement());
confirmWindow.setVisible(true);
}
} else {
- labelPhone.setText("Phone format is wrong");
+ labelPhone.setText("Bad formatted data.");
}
}