Booking confirmation and e-mail service added. Some bugs to be solved.
[RRRRHHHH_Code] / ruralHouses / src / gui / HouseFeaturesGUI.java
index 849e3af..9008a65 100644 (file)
@@ -9,6 +9,7 @@ import java.awt.event.MouseEvent;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Vector;
+
 import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
@@ -23,6 +24,7 @@ import javax.swing.table.DefaultTableModel;
 
 import businessLogic.BookingManager;
 import domain.Booking;
+import domain.Client;
 import domain.Offer;
 import domain.RuralHouse;
 
@@ -53,6 +55,10 @@ public class HouseFeaturesGUI extends JFrame {
        private JTextField telIn;
        private int row;
        private JLabel labelPhone;
+       private JLabel lblName;
+       private JTextField nameField;
+       private JLabel lblEmail;
+       private JTextField mailField;
 
        /**
         * Create the frame.
@@ -62,7 +68,7 @@ public class HouseFeaturesGUI extends JFrame {
                        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);
@@ -171,7 +177,7 @@ public class HouseFeaturesGUI extends JFrame {
                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() {
@@ -189,11 +195,11 @@ public class HouseFeaturesGUI extends JFrame {
                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);
 
@@ -201,6 +207,24 @@ public class HouseFeaturesGUI extends JFrame {
                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) {
@@ -210,7 +234,8 @@ public class HouseFeaturesGUI extends JFrame {
                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());
@@ -251,25 +276,32 @@ public class HouseFeaturesGUI extends JFrame {
 
        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.");
 
                }
        }