From 6a5d4dad58d39bd2f78b516a2e2062472716eeef Mon Sep 17 00:00:00 2001 From: camjan Date: Sun, 17 May 2015 22:35:45 +0200 Subject: [PATCH] Booking confirmation and e-mail service added. Some bugs to be solved. --- ruralHouses/.classpath | 1 + ruralHouses/config.xml | 2 +- .../src/businessLogic/AccountManager.java | 11 ++- .../src/businessLogic/BookingManager.java | 32 ++++++--- .../src/businessLogic/MailManager.java | 66 ++++++++++++++++++ ruralHouses/src/dataAccess/DB4oManager.java | 68 +++++++++++++++---- ruralHouses/src/domain/Booking.java | 9 +-- ruralHouses/src/domain/Offer.java | 17 +++-- ruralHouses/src/domain/RuralHouse.java | 46 ++++++------- ruralHouses/src/gui/HouseFeaturesGUI.java | 58 ++++++++++++---- ruralHouses/src/gui/OwnerMenuGUI.java | 2 +- ruralHouses/src/gui/OwnerRegistrationGUI.java | 16 ++--- .../src/gui/listOfBookingRequestsGUI.java | 34 ++++++---- ruralHouses/src/gui/listOfOffers.java | 45 ++++-------- 14 files changed, 279 insertions(+), 128 deletions(-) create mode 100644 ruralHouses/src/businessLogic/MailManager.java diff --git a/ruralHouses/.classpath b/ruralHouses/.classpath index 3caf01b..833b790 100644 --- a/ruralHouses/.classpath +++ b/ruralHouses/.classpath @@ -4,5 +4,6 @@ + diff --git a/ruralHouses/config.xml b/ruralHouses/config.xml index b97aa1b..9099bad 100644 --- a/ruralHouses/config.xml +++ b/ruralHouses/config.xml @@ -9,7 +9,7 @@ localhost db/casas.db4o initialize - 8 + 10 8 8100 softEng diff --git a/ruralHouses/src/businessLogic/AccountManager.java b/ruralHouses/src/businessLogic/AccountManager.java index 6f3b626..7b5efe9 100644 --- a/ruralHouses/src/businessLogic/AccountManager.java +++ b/ruralHouses/src/businessLogic/AccountManager.java @@ -1,5 +1,7 @@ package businessLogic; +import javax.mail.MessagingException; + import dataAccess.DB4oManager; import domain.Account; @@ -18,8 +20,15 @@ public class AccountManager { } public boolean addAccount(Account ac){ - if(this.dbMngr.addAccount(ac)) + if(this.dbMngr.addAccount(ac)){ + try { + MailManager.getInstance().Send(ac.getOwner().getMailAccount(), "Entered into the system", "Congratulations"); + } catch (MessagingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } return true; + } return false; } diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java index 6651fd2..017b1aa 100644 --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@ -3,13 +3,14 @@ package businessLogic; import java.util.Date; import java.util.Vector; +import javax.mail.MessagingException; + import com.db4o.ObjectContainer; import com.db4o.ObjectSet; import dataAccess.DB4oManager; import domain.Booking; -import domain.Offer; -import domain.Owner; +import domain.Client; import domain.RuralHouse; import exceptions.OfferCanNotBeBooked; @@ -60,12 +61,27 @@ public final class BookingManager { return theBookingManager; } - public void removeBooking(Booking B) { - // TODO - + public void removeDenyBooking(Booking b){ + b.getOffer().getBookings().remove(b); + this.dbMngr.removeBooking(b); } + public void acceptBooking(Booking b){ + b.getOffer().setBooked(true); + for(Booking boo : b.getOffer().getBookings()){ + if(!boo.equals(b)) + b.getOffer().getBookings().remove(b); + } + this.dbMngr.acceptBooking(b.getOffer()); + try { + MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill"); + } catch (MessagingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } /** * This method creates a book with a corresponding parameters * @@ -73,12 +89,12 @@ public final class BookingManager { * day, last day, house number and telephone * @return a book */ - public Booking createBooking(RuralHouse ruralHouse, Date firstDate, - Date lastDate, String bookTelephoneNumber) + public Vector createBooking(RuralHouse ruralHouse, Date firstDate, + Date lastDate, Client client) throws OfferCanNotBeBooked { return dbMngr.createBooking(ruralHouse, firstDate, lastDate, - bookTelephoneNumber); + client); } } \ No newline at end of file diff --git a/ruralHouses/src/businessLogic/MailManager.java b/ruralHouses/src/businessLogic/MailManager.java new file mode 100644 index 0000000..7ecf491 --- /dev/null +++ b/ruralHouses/src/businessLogic/MailManager.java @@ -0,0 +1,66 @@ +package businessLogic; + +import java.security.Security; +import java.util.Date; +import java.util.Properties; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + +import com.sun.mail.smtp.SMTPTransport; + +public class MailManager { + + private String user = "ruralhousesrh"; + private String password = "RHRHRHRHRH"; + private static MailManager mm = null; + + public static MailManager getInstance() { + if (mm == null) + return new MailManager(); + else + return mm; + } + + + public void Send( String recipientEmail, String title, String message) throws AddressException, MessagingException { + + Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); + final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; + + + Properties props = System.getProperties(); + props.setProperty("mail.smtps.host", "smtp.gmail.com"); + props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY); + props.setProperty("mail.smtp.socketFactory.fallback", "false"); + props.setProperty("mail.smtp.port", "465"); + props.setProperty("mail.smtp.socketFactory.port", "465"); + props.setProperty("mail.smtps.auth", "true"); + + props.put("mail.smtps.quitwait", "false"); + + Session session = Session.getInstance(props, null); + + // -- Create a new message -- + final MimeMessage msg = new MimeMessage(session); + + // -- Set the FROM and TO fields -- + msg.setFrom(new InternetAddress(user + "@gmail.com")); + msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail, false)); + + + msg.setSubject(title); + msg.setText(message, "utf-8"); + msg.setSentDate(new Date()); + + SMTPTransport t = (SMTPTransport)session.getTransport("smtps"); + + t.connect("smtp.gmail.com", user, password); + t.sendMessage(msg, msg.getAllRecipients()); + t.close(); + } +} \ No newline at end of file diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 61dd24b..a541e95 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -5,7 +5,6 @@ import java.io.File; //import java.util.Vector; import java.rmi.RemoteException; import java.util.Date; -import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Vector; @@ -22,6 +21,7 @@ import configuration.ConfigXML; import domain.Account; import domain.Administrator; import domain.Booking; +import domain.Client; import domain.HouseFeatures; import domain.Offer; //import dataModel.Offer; @@ -246,7 +246,6 @@ public class DB4oManager { } - @SuppressWarnings("static-access") public void storeAdmin() { if (c.isDatabaseLocal() == false) openSDB(); @@ -288,16 +287,15 @@ public class DB4oManager { * day, last day, house number and telephone * @return a book */ - public Booking createBooking(RuralHouse ruralHouse, Date firstDate, - Date lastDate, String bookTelephoneNumber) - throws OfferCanNotBeBooked { + public Vector createBooking(RuralHouse ruralHouse, Date firstDate, + Date lastDate, Client cl) throws OfferCanNotBeBooked { if (c.isDatabaseLocal() == false) openSDB(); else openDB(); - Booking bok = null; + Vector book = new Vector() ; try { @@ -313,13 +311,14 @@ public class DB4oManager { offer = rh.findOffer(firstDate, lastDate); if (offer != null) { - offer.createBooking(theDB4oManagerAux.bookingNumber++, - bookTelephoneNumber); + offer.createBooking(theDB4oManagerAux.bookingNumber++, cl); db.store(theDB4oManagerAux); // To store the new value for // bookingNumber + db.store(offer); db.commit(); - bok = offer.getBooking(); + book = offer.getBookings(); + } } catch (com.db4o.ext.ObjectNotStorableException e) { @@ -330,7 +329,7 @@ public class DB4oManager { } finally { db.close(); } - return bok; + return book; } /** @@ -524,9 +523,10 @@ public class DB4oManager { openDB(); try { - //TODO realize if there is another account with same username. Quite difficult with the f***ing salt - db.store(acc); - db.commit(); + // TODO realize if there is another account with same username. + // Quite difficult with the f***ing salt + db.store(acc); + db.commit(); } catch (Exception exc) { exc.printStackTrace(); } finally { @@ -534,11 +534,49 @@ public class DB4oManager { } return true; } - - //TODO remove account + + // TODO remove account public boolean removeAccount(Account acc) { return false; } + + //TODO this method should be improved. + public void acceptBooking(Offer of){ + Offer off = new Offer(of.getOfferNumber(),of.getRuralHouse(),of.getFirstDay(),of.getLastDay(),of.getPrice()); + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + try { + ObjectSet result = db.queryByExample(off); + this.deleteOffer(result.get(0)); + db.store(of); + db.close(); + + } catch (Exception e) { + e.printStackTrace();; + } + } + + public void removeBooking(Booking b){ + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + try { + ObjectSet result = db.queryByExample(b); + ObjectSet result2= db.queryByExample(b.getClient()); + db.delete(result.get(0)); + db.delete(result2.get(0)); + db.commit(); + } catch (Exception e) { + e.printStackTrace();; + }finally{ + db.close(); + } + + + } } diff --git a/ruralHouses/src/domain/Booking.java b/ruralHouses/src/domain/Booking.java index 40638c7..51546c3 100644 --- a/ruralHouses/src/domain/Booking.java +++ b/ruralHouses/src/domain/Booking.java @@ -10,7 +10,6 @@ public class Booking implements Serializable { private Date bookingDate; private Client client; private Offer offer; - private boolean isAccepted; public Booking() { @@ -24,7 +23,6 @@ public class Booking implements Serializable { //Booking date is assigned to actual date this.bookingDate= new java.util.Date(System.currentTimeMillis()); this.isPaid=false; - this.isAccepted=false; } public void imprimete(){ @@ -32,8 +30,7 @@ public class Booking implements Serializable { System.out.println(isPaid); System.out.println(bookingDate); System.out.println(client.toString()); - System.out.println(offer); - System.out.println(this.isAccepted); + System.out.println(offer); } public int getBookNumber() { @@ -72,9 +69,7 @@ public class Booking implements Serializable { return isPaid; } - public boolean isAccepted(){ - return this.isAccepted; - } + public Client getClient() { return client; diff --git a/ruralHouses/src/domain/Offer.java b/ruralHouses/src/domain/Offer.java index 00a3e70..3442a6a 100644 --- a/ruralHouses/src/domain/Offer.java +++ b/ruralHouses/src/domain/Offer.java @@ -2,7 +2,6 @@ package domain; import java.io.Serializable; import java.util.Date; -import java.util.LinkedList; import java.util.Vector; @@ -13,8 +12,9 @@ public class Offer implements Serializable { private int offerNumber; private Date firstDay; // Dates are stored as java.util.Date objects instead of java.sql.Date objects private Date lastDay; // because, they are not well stored in db4o as java.util.Date objects - private float price; // This is coherent because objects of java.sql.Date are objects of java.util.Date - private Vector bookings; // That is: java.sql.Date is a subclass (or extends) java.util.Date + private float price; // This is coherent because objects of java.sql.Date are objects of java.util.Date รง + private boolean isBooked; + private Vector bookings = new Vector(); // That is: java.sql.Date is a subclass (or extends) java.util.Date private RuralHouse ruralHouse; @@ -118,11 +118,10 @@ public class Offer implements Serializable { * @param First day, last day, house number and telephone * @return a book */ - public Booking createBooking(int numBooking,String bookTelephoneNumber,String name , String mail) { - Client client = new Client(name,mail,bookTelephoneNumber); + public Vector createBooking(int numBooking,Client client) { Booking b = new Booking(numBooking,this,client); this.bookings.add(b); - return b; + return this.bookings; } @@ -135,4 +134,10 @@ public class Offer implements Serializable { public void setBookings(Vector bookings) { this.bookings = bookings; } + public boolean isBooked() { + return isBooked; + } + public void setBooked(boolean isBooked) { + this.isBooked = isBooked; + } } \ No newline at end of file diff --git a/ruralHouses/src/domain/RuralHouse.java b/ruralHouses/src/domain/RuralHouse.java index 9d6b226..4245458 100644 --- a/ruralHouses/src/domain/RuralHouse.java +++ b/ruralHouses/src/domain/RuralHouse.java @@ -119,7 +119,7 @@ public class RuralHouse implements Serializable { offer = e.next(); if ((offer.getFirstDay().compareTo(firstDay) >= 0) && (offer.getLastDay().compareTo(lastDay) <= 0) - && (offer.getBooking() == null)) + && (!offer.isBooked())) availableOffers.add(offer); } return availableOffers; @@ -130,28 +130,28 @@ public class RuralHouse implements Serializable { return this.offers; } -// /** -// * This method obtains the offer that match exactly with a given dates that -// * has not been booked -// * -// * @param firstDay -// * , first day in a period range -// * @param lastDay -// * , last day in a period range -// * @return the offer(Offer class) available for a this period -// */ -// public Offer findOffer(Date firstDay, Date lastDay) { -// Iterator e = offers.iterator(); -// Offer offer = null; -// while (e.hasNext()) { -// offer = e.next(); -// if ((offer.getFirstDay().compareTo(firstDay) == 0) -// && (offer.getLastDay().compareTo(lastDay) == 0) -// && (offer.getBooking() == null)) -// return offer; -// } -// return null; -// } + /** + * This method obtains the offer that match exactly with a given dates that + * has not been booked + * + * @param firstDay + * , first day in a period range + * @param lastDay + * , last day in a period range + * @return the offer(Offer class) available for a this period + */ + public Offer findOffer(Date firstDay, Date lastDay) { + Iterator e = offers.iterator(); + Offer offer = null; + while (e.hasNext()) { + offer = e.next(); + if ((offer.getFirstDay().compareTo(firstDay) == 0) + && (offer.getLastDay().compareTo(lastDay) == 0) + && (!offer.isBooked())) + return offer; + } + return null; + } public Offer overlapsWith(Date firstDay, Date lastDay) { diff --git a/ruralHouses/src/gui/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java index 849e3af..9008a65 100644 --- a/ruralHouses/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses/src/gui/HouseFeaturesGUI.java @@ -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 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 row = new Vector(); 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 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."); } } diff --git a/ruralHouses/src/gui/OwnerMenuGUI.java b/ruralHouses/src/gui/OwnerMenuGUI.java index e49909e..244b242 100644 --- a/ruralHouses/src/gui/OwnerMenuGUI.java +++ b/ruralHouses/src/gui/OwnerMenuGUI.java @@ -9,10 +9,10 @@ import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.EmptyBorder; import domain.Owner; -import javax.swing.LayoutStyle.ComponentPlacement; public class OwnerMenuGUI extends JFrame { diff --git a/ruralHouses/src/gui/OwnerRegistrationGUI.java b/ruralHouses/src/gui/OwnerRegistrationGUI.java index d8994b8..c088e39 100644 --- a/ruralHouses/src/gui/OwnerRegistrationGUI.java +++ b/ruralHouses/src/gui/OwnerRegistrationGUI.java @@ -1,24 +1,20 @@ package gui; -import java.awt.BorderLayout; -import java.awt.EventQueue; -import java.awt.Frame; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.JButton; +import javax.swing.border.EmptyBorder; import businessLogic.AdminManager; import domain.Account; import domain.Owner; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - public class OwnerRegistrationGUI extends JFrame { private JPanel panel; diff --git a/ruralHouses/src/gui/listOfBookingRequestsGUI.java b/ruralHouses/src/gui/listOfBookingRequestsGUI.java index 2a70df5..831cc3c 100644 --- a/ruralHouses/src/gui/listOfBookingRequestsGUI.java +++ b/ruralHouses/src/gui/listOfBookingRequestsGUI.java @@ -5,7 +5,6 @@ import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Enumeration; -import java.util.LinkedList; import java.util.Vector; import javax.swing.JButton; @@ -20,8 +19,6 @@ import javax.swing.table.DefaultTableModel; import businessLogic.BookingManager; import domain.Booking; import domain.Offer; -import domain.Owner; -import domain.RuralHouse; public class listOfBookingRequestsGUI extends JFrame { @@ -51,7 +48,7 @@ public class listOfBookingRequestsGUI extends JFrame { } private void init() throws Exception { - setBounds(100, 100, 600, 450); + setBounds(100, 100, 600, 500); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); @@ -81,8 +78,7 @@ public class listOfBookingRequestsGUI extends JFrame { }; scrollPane.setViewportView(table); tableModel = new DefaultTableModel(null, new String[] { - "Booking Number", "Is paid", "Booking Date", "Telephone", - "Offer" }); + "Booking Number", "Is paid", "Booking Date","Name","E-mail", "Telephone" }); // Maybe there is a better way to avoid interaction. // table.setEnabled(false); @@ -92,23 +88,36 @@ public class listOfBookingRequestsGUI extends JFrame { btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { - + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { + Booking book = bookings.get(table.getSelectedRow()); + bookM.acceptBooking(book); + } } } }); - btnNewButton.setBounds(88, 396, 169, 25); + btnNewButton.setBounds(33, 396, 169, 25); contentPane.add(btnNewButton); JButton btnDenyAddition = new JButton("Deny Booking"); btnDenyAddition.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { - + Booking book = bookings.get(table.getSelectedRow()); + bookM.removeDenyBooking(book); } } }); - btnDenyAddition.setBounds(300, 396, 169, 25); + btnDenyAddition.setBounds(390, 395, 169, 25); contentPane.add(btnDenyAddition); + + JButton btnSetAsPaid = new JButton("Set as paid"); + btnSetAsPaid.setBounds(239, 395, 89, 23); + btnSetAsPaid.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + } + }); + contentPane.add(btnSetAsPaid); Enumeration en = this.bookings.elements(); Booking book; while (en.hasMoreElements()) { @@ -117,8 +126,9 @@ public class listOfBookingRequestsGUI extends JFrame { row.add(book.getBookNumber()); row.add(book.isPaid()); row.add(book.getBookDate()); - row.add(book.getClient()); - row.add(book.getOffer()); + row.add(book.getClient().getName()); + row.add(book.getClient().getMailAccount()); + row.add(book.getClient().getTelephone()); tableModel.addRow(row); } diff --git a/ruralHouses/src/gui/listOfOffers.java b/ruralHouses/src/gui/listOfOffers.java index 9ca4537..76006af 100644 --- a/ruralHouses/src/gui/listOfOffers.java +++ b/ruralHouses/src/gui/listOfOffers.java @@ -2,13 +2,11 @@ package gui; import java.awt.Font; import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.Enumeration; -import java.util.LinkedList; import java.util.Vector; -import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @@ -17,11 +15,8 @@ import javax.swing.JTable; import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; -import businessLogic.BookingManager; -import domain.Booking; import domain.Offer; import domain.Owner; -import domain.RuralHouse; public class listOfOffers extends JFrame { @@ -32,7 +27,7 @@ public class listOfOffers extends JFrame { private JPanel contentPane; private JTable table; private Owner owner; - private BookingManager bookM = new BookingManager(); + private DefaultTableModel tableModel; private Vector offers = new Vector(); @@ -66,12 +61,12 @@ public class listOfOffers extends JFrame { lblNewLabel .setText("There are not bookings to be confirmed or denied"); else - lblNewLabel.setText("List of bookings:"); + lblNewLabel.setText("List of offers:"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); scrollPane.setBounds(23, 113, 536, 271); contentPane.add(scrollPane); - + table = new JTable() { private static final long serialVersionUID = 1L; @@ -79,35 +74,22 @@ public class listOfOffers extends JFrame { return false; }; }; + scrollPane.setViewportView(table); tableModel = new DefaultTableModel(null, new String[] { "Offer #", - "FirstDay", "LastDay", "Price" }); + "FirstDay", "LastDay", "Price" ,"RuralHouse"}); // Maybe there is a better way to avoid interaction. // table.setEnabled(false); table.setModel(tableModel); - - JButton btnNewButton = new JButton("Confirm Booking"); - btnNewButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { - - } - } - }); - btnNewButton.setBounds(88, 396, 169, 25); - contentPane.add(btnNewButton); - - JButton btnDenyAddition = new JButton("Deny Booking"); - btnDenyAddition.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { - - } + table.addMouseListener( new MouseAdapter(){ + @Override + public void mouseClicked(MouseEvent arg0) { + int row = table.getSelectedRow(); + listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row)); + feat.setVisible(true); } }); - btnDenyAddition.setBounds(300, 396, 169, 25); - contentPane.add(btnDenyAddition); Enumeration rhs = this.offers.elements(); while (rhs.hasMoreElements()) { Offer of = rhs.nextElement(); @@ -116,6 +98,7 @@ public class listOfOffers extends JFrame { row.add(of.getFirstDay()); row.add(of.getLastDay()); row.add(of.getPrice()); + row.add(of.getRuralHouse().getHouseName()); tableModel.addRow(row); } -- 2.20.1