From 7bf57b2f0f2b3cf0ae9489a8204918762e64648e Mon Sep 17 00:00:00 2001 From: camjan Date: Sun, 17 May 2015 13:59:22 +0200 Subject: [PATCH] Possibility of registering new owners added --- .../src/businessLogic/AccountManager.java | 33 ++++ .../src/businessLogic/AdminManager.java | 23 ++- .../src/businessLogic/BookingManager.java | 14 -- .../src/businessLogic/HouseManager.java | 3 +- ruralHouses/src/dataAccess/DB4oManager.java | 51 ++++-- ruralHouses/src/domain/Account.java | 21 +++ ruralHouses/src/domain/Administrator.java | 8 +- ruralHouses/src/domain/Booking.java | 25 ++- ruralHouses/src/domain/Client.java | 40 +++++ ruralHouses/src/domain/Offer.java | 36 ++--- ruralHouses/src/domain/Owner.java | 30 +++- ruralHouses/src/domain/RuralHouse.java | 44 +++--- ruralHouses/src/gui/AdminMenuGUI.java | 11 +- ruralHouses/src/gui/HouseFeaturesGUI.java | 2 +- ruralHouses/src/gui/LoginGUI.java | 23 ++- ruralHouses/src/gui/OwnerMenuGUI.java | 2 +- ruralHouses/src/gui/OwnerRegistrationGUI.java | 145 ++++++++++++++++++ .../src/gui/listOfBookingRequestsGUI.java | 10 +- ruralHouses/src/gui/listOfOffers.java | 124 +++++++++++++++ .../src/gui/ownerAddittionRequests.java | 128 ++++++++++++++++ 20 files changed, 665 insertions(+), 108 deletions(-) create mode 100644 ruralHouses/src/businessLogic/AccountManager.java create mode 100644 ruralHouses/src/domain/Client.java create mode 100644 ruralHouses/src/gui/OwnerRegistrationGUI.java create mode 100644 ruralHouses/src/gui/listOfOffers.java create mode 100644 ruralHouses/src/gui/ownerAddittionRequests.java diff --git a/ruralHouses/src/businessLogic/AccountManager.java b/ruralHouses/src/businessLogic/AccountManager.java new file mode 100644 index 0000000..6f3b626 --- /dev/null +++ b/ruralHouses/src/businessLogic/AccountManager.java @@ -0,0 +1,33 @@ +package businessLogic; + +import dataAccess.DB4oManager; +import domain.Account; + +public class AccountManager { + + private DB4oManager dbMngr; + + + public AccountManager() { + try { + dbMngr = DB4oManager.getInstance(); + } catch (Exception e) { + + e.printStackTrace(); + } + } + + public boolean addAccount(Account ac){ + if(this.dbMngr.addAccount(ac)) + return true; + return false; + + } + + public boolean removeAccount(Account ac){ + if(this.dbMngr.removeAccount(ac)) + return true; + return false; + + } +} diff --git a/ruralHouses/src/businessLogic/AdminManager.java b/ruralHouses/src/businessLogic/AdminManager.java index fe56a5b..a51ec98 100644 --- a/ruralHouses/src/businessLogic/AdminManager.java +++ b/ruralHouses/src/businessLogic/AdminManager.java @@ -2,6 +2,7 @@ package businessLogic; import java.util.Vector; +import domain.Account; import domain.Administrator; import domain.RuralHouse; @@ -20,6 +21,11 @@ public class AdminManager { .getRemoveRequest()); } + public Vector getOwnerAdditionReuests() { + return new Vector(Administrator.getInstance() + .getNewOwnerRequest()); + } + public void removeHouseAdditionRequests(RuralHouse house) { Administrator.getInstance().getAddRequest().remove(house); } @@ -27,7 +33,9 @@ public class AdminManager { public void removeHouseDeletionRequests(RuralHouse house) { Administrator.getInstance().getRemoveRequest().remove(house); } - + public void removeOwnerAdditionRequests(Account acc) { + Administrator.getInstance().getNewOwnerRequest().remove(acc); + } public boolean addAdditionRequest(RuralHouse rh) { if (this.getAdditionRequests().contains(rh)) { return false; @@ -40,4 +48,17 @@ public class AdminManager { return false; return Administrator.getInstance().getRemoveRequest().add(rh); } + + public boolean addAccount(Account acc) { + if (this.getOwnerAdditionReuests().contains(acc)) { + return false; + } + return Administrator.getInstance().getNewOwnerRequest().add(acc); + } + +// public boolean removeAccount(Account acc) { +// if (this.getDeletionRequests().contains(acc)) +// return false; +// return Administrator.getInstance().getNewOwnerRequest().add(acc); +// } } diff --git a/ruralHouses/src/businessLogic/BookingManager.java b/ruralHouses/src/businessLogic/BookingManager.java index 32fc3be..6651fd2 100644 --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@ -65,20 +65,6 @@ public final class BookingManager { } - public Vector getAllBookings(Owner ow) { - Vector books = new Vector(); - for (RuralHouse rh : ow.getRuralHouses()) { - Vector off = rh.getAllOffers(); - for (Offer of : off) { - System.out.print(of.toString()); - if (of.getBooking() != null) { - - books.add(of.getBooking()); - } - } - } - return books; - } /** * This method creates a book with a corresponding parameters diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index 68cf64e..e3e5317 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -8,7 +8,8 @@ import domain.Owner; import domain.RuralHouse; public class HouseManager implements HouseManagerInterface { - DB4oManager dbMngr; + + private DB4oManager dbMngr; public HouseManager() { try { diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 5ccfda4..61dd24b 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -119,18 +119,18 @@ public class DB4oManager { public void initializeDB() { try { - Owner jon = new Owner("Jon"); - Owner alfredo = new Owner("Alfredo"); + Owner jon = new Owner("Jon", "1349 5677 21 2133567777", + "Jon@gmail.com"); + Owner alfredo = new Owner("Alfredo", "4144 0087 23 9700002133", + "alfredo@gmail.com"); jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3, 3, 3); jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4, 4, 4, 4); - jon.setBankAccount("1349 5677 21 2133567777"); alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, 5, 5, 5, 5); alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6); - alfredo.setBankAccount("4144 0087 23 9700002133"); Account jonAcc = new Account("1", "1", jon); Account alfredoAcc = new Account("userAlfredo", "passAlfredo", alfredo); @@ -154,7 +154,7 @@ public class DB4oManager { openDB(); try { - Owner proto = new Owner(null, null); + Owner proto = new Owner(null, null, null); ObjectSet result = db.queryByExample(proto); while (result.hasNext()) { Owner o = (Owner) result.next(); @@ -219,7 +219,6 @@ public class DB4oManager { } } - public Administrator getAdminData() { if (c.isDatabaseLocal() == false) openSDB(); @@ -266,10 +265,12 @@ public class DB4oManager { } }); - - admL.get(0).setAddRequest(Administrator.getInstance().getAddRequest()); - admL.get(0).setRemoveRequest(Administrator.getInstance().getRemoveRequest()); - admL.get(0).setNewOwnerRequest(Administrator.getInstance().getNewOwnerRequest()); + admL.get(0).setAddRequest( + Administrator.getInstance().getAddRequest()); + admL.get(0).setRemoveRequest( + Administrator.getInstance().getRemoveRequest()); + admL.get(0).setNewOwnerRequest( + Administrator.getInstance().getNewOwnerRequest()); db.commit(); } catch (Exception e) { @@ -344,7 +345,7 @@ public class DB4oManager { openDB(); try { - Owner proto = new Owner(null, null); + Owner proto = new Owner(null, null, null); ObjectSet result = db.queryByExample(proto); Vector owners = new Vector(); while (result.hasNext()) @@ -417,8 +418,8 @@ public class DB4oManager { * @throws RemoteException * @throws Exception */ - public Vector getAccount(Account proto) - throws RemoteException, Exception { + public Vector getAccount(Account proto) throws RemoteException, + Exception { if (c.isDatabaseLocal() == false) openSDB(); @@ -516,4 +517,28 @@ public class DB4oManager { } + public boolean addAccount(Account acc) { + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + + try { + //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 { + db.close(); + } + return true; + } + + //TODO remove account + + public boolean removeAccount(Account acc) { + return false; + } + } diff --git a/ruralHouses/src/domain/Account.java b/ruralHouses/src/domain/Account.java index 53dff45..ba7a630 100644 --- a/ruralHouses/src/domain/Account.java +++ b/ruralHouses/src/domain/Account.java @@ -1,9 +1,13 @@ package domain; +import java.util.Arrays; + import businessLogic.SecurityManager; public class Account { + + private byte[] username; private byte[] password; private byte[] salt; @@ -65,5 +69,22 @@ public class Account { public void setSalt(byte[] salt) { this.salt = salt; } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Account other = (Account) obj; + if (!Arrays.equals(password, other.password)) + return false; + if (!Arrays.equals(username, other.username)) + return false; + return true; + } } diff --git a/ruralHouses/src/domain/Administrator.java b/ruralHouses/src/domain/Administrator.java index 9efed03..bead633 100644 --- a/ruralHouses/src/domain/Administrator.java +++ b/ruralHouses/src/domain/Administrator.java @@ -10,13 +10,13 @@ public class Administrator { private static Administrator admin = null; private static LinkedList addRequest; private static LinkedList removeRequest; - private static LinkedList newOwnerRequest; + private static LinkedList newOwnerRequest; static ConfigXML c; private Administrator() { addRequest = new LinkedList(); removeRequest = new LinkedList(); - newOwnerRequest = new LinkedList(); + newOwnerRequest = new LinkedList(); } public static Administrator getInstance() { @@ -65,11 +65,11 @@ public class Administrator { Administrator.removeRequest = removeRequest; } - public LinkedList getNewOwnerRequest() { + public LinkedList getNewOwnerRequest() { return newOwnerRequest; } - public void setNewOwnerRequest(LinkedList newOwnerRequest) { + public void setNewOwnerRequest(LinkedList newOwnerRequest) { Administrator.newOwnerRequest = newOwnerRequest; } diff --git a/ruralHouses/src/domain/Booking.java b/ruralHouses/src/domain/Booking.java index fd72de6..40638c7 100644 --- a/ruralHouses/src/domain/Booking.java +++ b/ruralHouses/src/domain/Booking.java @@ -8,7 +8,7 @@ public class Booking implements Serializable { private int bookingNumber; private boolean isPaid; private Date bookingDate; - private String telephone; + private Client client; private Offer offer; private boolean isAccepted; @@ -16,12 +16,11 @@ public class Booking implements Serializable { public Booking() { } - public Booking(int bN ,String telephone, Offer offer) { + public Booking(int bN , Offer offer,Client client) { this.bookingNumber = bN; - this.telephone=telephone; this.offer = offer; - //this.price = price; + this.client=client; //Booking date is assigned to actual date this.bookingDate= new java.util.Date(System.currentTimeMillis()); this.isPaid=false; @@ -32,7 +31,7 @@ public class Booking implements Serializable { System.out.println(bookingNumber); System.out.println(isPaid); System.out.println(bookingDate); - System.out.println(telephone); + System.out.println(client.toString()); System.out.println(offer); System.out.println(this.isAccepted); } @@ -61,14 +60,6 @@ public class Booking implements Serializable { return this.bookingDate; } - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - public String getTelephone() { - return this.telephone; - } - public void paid() { this.isPaid = true; } @@ -84,5 +75,13 @@ public class Booking implements Serializable { public boolean isAccepted(){ return this.isAccepted; } + + public Client getClient() { + return client; + } + + public void setClient(Client client) { + this.client = client; + } } \ No newline at end of file diff --git a/ruralHouses/src/domain/Client.java b/ruralHouses/src/domain/Client.java new file mode 100644 index 0000000..4dd9eb2 --- /dev/null +++ b/ruralHouses/src/domain/Client.java @@ -0,0 +1,40 @@ +package domain; + +public class Client { + + private String name; + private String mailAccount; + private String telephone; + + public Client(String name, String mailAccount, String telephone) { + super(); + this.name = name; + this.mailAccount = mailAccount; + this.telephone = telephone; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMailAccount() { + return mailAccount; + } + + public void setMailAccount(String mailAccount) { + this.mailAccount = mailAccount; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + +} diff --git a/ruralHouses/src/domain/Offer.java b/ruralHouses/src/domain/Offer.java index 8e4e785..00a3e70 100644 --- a/ruralHouses/src/domain/Offer.java +++ b/ruralHouses/src/domain/Offer.java @@ -2,6 +2,8 @@ package domain; import java.io.Serializable; import java.util.Date; +import java.util.LinkedList; +import java.util.Vector; @SuppressWarnings("serial") @@ -12,7 +14,7 @@ public class Offer implements Serializable { 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 Booking booking; // That is: java.sql.Date is a subclass (or extends) java.util.Date + private Vector bookings; // That is: java.sql.Date is a subclass (or extends) java.util.Date private RuralHouse ruralHouse; @@ -109,25 +111,6 @@ public class Offer implements Serializable { this.price = price; } - /** - * Get the book number - * - * @return book object - */ - public Booking getBooking() { - return this.booking; - } - - /** - * Set the book object - * - * @param book - * Book object - * @return None - */ - public void setBooking(Booking booking) { - this.booking = booking; - } /** * This method creates a book with a corresponding parameters @@ -135,12 +118,21 @@ public class Offer implements Serializable { * @param First day, last day, house number and telephone * @return a book */ - public Booking createBooking(int numBooking,String bookTelephoneNumber) { - return booking=new Booking(numBooking,bookTelephoneNumber,this); + public Booking createBooking(int numBooking,String bookTelephoneNumber,String name , String mail) { + Client client = new Client(name,mail,bookTelephoneNumber); + Booking b = new Booking(numBooking,this,client); + this.bookings.add(b); + return b; } public String toString(){ return firstDay.toString()+", "+lastDay.toString()+", "+price; } + public Vector getBookings() { + return bookings; + } + public void setBookings(Vector bookings) { + this.bookings = bookings; + } } \ No newline at end of file diff --git a/ruralHouses/src/domain/Owner.java b/ruralHouses/src/domain/Owner.java index 3ec14a4..a218f03 100644 --- a/ruralHouses/src/domain/Owner.java +++ b/ruralHouses/src/domain/Owner.java @@ -8,16 +8,18 @@ public class Owner implements Serializable { private String bankAccount = ""; private String name = ""; + private String mailAccount = ""; private Vector ruralHouses; - public Owner(String name) { - this.name = name; - ruralHouses = new Vector(); - } +// public Owner(String name) { +// this.name = name; +// ruralHouses = new Vector(); +// } - public Owner(String name, String bankAccount) { + public Owner(String name, String bankAccount,String mail) { this.bankAccount = bankAccount; this.name = name; + this.mailAccount = mail; ruralHouses = new Vector(); } @@ -61,4 +63,22 @@ public class Owner implements Serializable { return name; } + public String getMailAccount() { + return mailAccount; + } + + public void setMailAccount(String mailAccount) { + this.mailAccount = mailAccount; + } + + public Vector getAllOffers (){ + Vector offers = new Vector(); + for(RuralHouse rh: this.ruralHouses){ + for(Offer of : rh.getAllOffers()){ + offers.add(of); + } + } + return offers; + } + } \ No newline at end of file diff --git a/ruralHouses/src/domain/RuralHouse.java b/ruralHouses/src/domain/RuralHouse.java index 2f846eb..9d6b226 100644 --- a/ruralHouses/src/domain/RuralHouse.java +++ b/ruralHouses/src/domain/RuralHouse.java @@ -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.getBooking() == null)) +// return offer; +// } +// return null; +// } public Offer overlapsWith(Date firstDay, Date lastDay) { diff --git a/ruralHouses/src/gui/AdminMenuGUI.java b/ruralHouses/src/gui/AdminMenuGUI.java index a185a21..2ded6f6 100644 --- a/ruralHouses/src/gui/AdminMenuGUI.java +++ b/ruralHouses/src/gui/AdminMenuGUI.java @@ -22,10 +22,7 @@ public class AdminMenuGUI extends JFrame { private JPanel contentPane; - public static void main(String[] args){ - Frame a = new AdminMenuGUI(); - a.setVisible(true); - } + /** * Create the frame. */ @@ -57,6 +54,12 @@ public class AdminMenuGUI extends JFrame { }); JButton btnOwneraddition = new JButton("OwnerAddition"); + btnOwneraddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new ownerAddittionRequests(); + a.setVisible(true); + } + }); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) diff --git a/ruralHouses/src/gui/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java index 5237f93..849e3af 100644 --- a/ruralHouses/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses/src/gui/HouseFeaturesGUI.java @@ -210,7 +210,7 @@ public class HouseFeaturesGUI extends JFrame { Enumeration rhs = rh.getAllOffers().elements(); while (rhs.hasMoreElements()) { Offer of = rhs.nextElement(); - if (of.getBooking() == null) { + if (of.getBookings().size()==1&&of.getBookings().get(0).isAccepted()) { Vector row = new Vector(); row.add(of.getOfferNumber()); row.add(of.getFirstDay()); diff --git a/ruralHouses/src/gui/LoginGUI.java b/ruralHouses/src/gui/LoginGUI.java index 1e59e89..ab22f39 100644 --- a/ruralHouses/src/gui/LoginGUI.java +++ b/ruralHouses/src/gui/LoginGUI.java @@ -25,6 +25,7 @@ public class LoginGUI extends JFrame { private JPasswordField passwordField; private LoginManagerInterface loginManager = new LoginManager(); private JLabel loginFeedback; + private JButton btnRegister; public LoginGUI() { super(); initialize(); @@ -66,7 +67,7 @@ public class LoginGUI extends JFrame { jButton_ActionPerformed(arg0); } }); - loginButton.setBounds(164, 179, 117, 25); + loginButton.setBounds(95, 179, 117, 25); jContentPane.add(loginButton); loginFeedback = new JLabel(""); @@ -74,10 +75,28 @@ public class LoginGUI extends JFrame { loginFeedback.setHorizontalAlignment(SwingConstants.CENTER); loginFeedback.setBounds(83, 216, 269, 25); jContentPane.add(loginFeedback); + + btnRegister = new JButton("Register"); + btnRegister.setBounds(222, 180, 113, 23); + btnRegister.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + jButton_ActionPerformed2(arg0); + } + }); + jContentPane.add(btnRegister); } return jContentPane; } - + private void jButton_ActionPerformed2(ActionEvent e){ + + + this.setVisible(false); + Frame a = new OwnerRegistrationGUI(); + a.setVisible(true); + + + } private void jButton_ActionPerformed(ActionEvent e){ Account acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword())); diff --git a/ruralHouses/src/gui/OwnerMenuGUI.java b/ruralHouses/src/gui/OwnerMenuGUI.java index 8f97c1e..e49909e 100644 --- a/ruralHouses/src/gui/OwnerMenuGUI.java +++ b/ruralHouses/src/gui/OwnerMenuGUI.java @@ -55,7 +55,7 @@ public class OwnerMenuGUI extends JFrame { JButton btnBookings = new JButton("Bookings"); btnBookings.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - Frame a = new listOfBookingRequestsGUI(owner); + Frame a = new listOfOffers(owner); a.setVisible(true); } }); diff --git a/ruralHouses/src/gui/OwnerRegistrationGUI.java b/ruralHouses/src/gui/OwnerRegistrationGUI.java new file mode 100644 index 0000000..d8994b8 --- /dev/null +++ b/ruralHouses/src/gui/OwnerRegistrationGUI.java @@ -0,0 +1,145 @@ +package gui; + +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.awt.Frame; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.JButton; + +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; + private JTextField nameField; + private JTextField userNameField; + private AdminManager am = new AdminManager(); + private JTextField passField; + private JTextField bank1Field; + private JTextField bank2Field; + private JTextField bank3Field; + private JTextField bank4Field; + private JTextField emailField; + private JLabel lblWhenAcceptedYou; + private JLabel feedback; + + /** + * Create the frame. + */ + public OwnerRegistrationGUI() { + setTitle("Owner registration"); + setBounds(100, 100, 500, 400); + panel = new JPanel(); + panel.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(panel); + panel.setLayout(null); + + JLabel nameLb = new JLabel("Name:"); + nameLb.setBounds(37, 45, 46, 14); + panel.add(nameLb); + + nameField = new JTextField(); + nameField.setBounds(147, 42, 86, 20); + panel.add(nameField); + nameField.setColumns(10); + + JLabel lblUsername = new JLabel("Username:"); + lblUsername.setBounds(37, 212, 69, 14); + panel.add(lblUsername); + + userNameField = new JTextField(); + userNameField.setBounds(147, 209, 86, 20); + panel.add(userNameField); + userNameField.setColumns(10); + + JLabel lblPassword = new JLabel("Password:"); + lblPassword.setBounds(37, 258, 69, 14); + panel.add(lblPassword); + + passField = new JTextField(); + passField.setBounds(147, 255, 86, 20); + panel.add(passField); + passField.setColumns(10); + + JLabel lblBankAccount = new JLabel("Bank account:"); + lblBankAccount.setBounds(37, 94, 69, 14); + panel.add(lblBankAccount); + + bank1Field = new JTextField(); + bank1Field.setBounds(147, 91, 61, 20); + panel.add(bank1Field); + + bank2Field = new JTextField(); + bank2Field.setBounds(218, 91, 61, 20); + panel.add(bank2Field); + + bank3Field = new JTextField(); + bank3Field.setBounds(289, 91, 32, 20); + panel.add(bank3Field); + + bank4Field = new JTextField(); + bank4Field.setBounds(331, 91, 117, 20); + panel.add(bank4Field); + + JButton btnSendRegistrationRequest = new JButton( + "Send registration request"); + btnSendRegistrationRequest.setBounds(127, 316, 194, 23); + btnSendRegistrationRequest.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + jButton_ActionPerformed(arg0); + } + }); + + panel.add(btnSendRegistrationRequest); + + JLabel lblEmail = new JLabel("E-mail:"); + lblEmail.setBounds(37, 155, 46, 14); + panel.add(lblEmail); + + emailField = new JTextField(); + emailField.setBounds(147, 152, 148, 20); + panel.add(emailField); + emailField.setColumns(10); + + lblWhenAcceptedYou = new JLabel( + "When accepted you will receive an e-mail"); + lblWhenAcceptedYou.setForeground(Color.GREEN); + lblWhenAcceptedYou.setBounds(127, 291, 214, 14); + panel.add(lblWhenAcceptedYou); + + feedback = new JLabel(""); + feedback.setForeground(Color.RED); + feedback.setEnabled(false); + feedback.setBounds(127, 344, 214, 20); + panel.add(feedback); + } + + private void jButton_ActionPerformed(ActionEvent e) { + + Owner own = new Owner(this.nameField.getText(), + this.bank1Field.getText() + " " + this.bank2Field.getText() + + " " + this.bank3Field.getText() + " " + + this.bank4Field.getText(), this.emailField.getText()); + Account acc = new Account(this.userNameField.getText(), + this.passField.getText(), own); + + if (this.am.addAccount(acc)) { + this.feedback.setText("Request sended"); + } else { + this.feedback.setText("Can't send the request"); + } + + } +} diff --git a/ruralHouses/src/gui/listOfBookingRequestsGUI.java b/ruralHouses/src/gui/listOfBookingRequestsGUI.java index 80e1800..2a70df5 100644 --- a/ruralHouses/src/gui/listOfBookingRequestsGUI.java +++ b/ruralHouses/src/gui/listOfBookingRequestsGUI.java @@ -31,7 +31,7 @@ public class listOfBookingRequestsGUI extends JFrame { private static final long serialVersionUID = 1L; private JPanel contentPane; private JTable table; - private Owner own; + private Offer off; private BookingManager bookM = new BookingManager(); private DefaultTableModel tableModel; private Vector bookings = new Vector(); @@ -39,9 +39,9 @@ public class listOfBookingRequestsGUI extends JFrame { /** * Create the frame. */ - public listOfBookingRequestsGUI(Owner own) { + public listOfBookingRequestsGUI(Offer of) { setTitle("Adding requests"); - this.own = own; + this.off = of; try { init(); @@ -57,7 +57,7 @@ public class listOfBookingRequestsGUI extends JFrame { setContentPane(contentPane); contentPane.setLayout(null); - this.bookings= this.bookM.getAllBookings(own); + this.bookings= this.off.getBookings(); JLabel lblNewLabel = new JLabel(); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); lblNewLabel.setBounds(23, 41, 536, 33); @@ -117,7 +117,7 @@ public class listOfBookingRequestsGUI extends JFrame { row.add(book.getBookNumber()); row.add(book.isPaid()); row.add(book.getBookDate()); - row.add(book.getTelephone()); + row.add(book.getClient()); row.add(book.getOffer()); tableModel.addRow(row); } diff --git a/ruralHouses/src/gui/listOfOffers.java b/ruralHouses/src/gui/listOfOffers.java new file mode 100644 index 0000000..9ca4537 --- /dev/null +++ b/ruralHouses/src/gui/listOfOffers.java @@ -0,0 +1,124 @@ +package gui; + +import java.awt.Font; +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; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +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 { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + private Owner owner; + private BookingManager bookM = new BookingManager(); + private DefaultTableModel tableModel; + private Vector offers = new Vector(); + + /** + * Create the frame. + */ + public listOfOffers(Owner own) { + setTitle("Adding requests"); + this.owner = own; + try { + + init(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void init() throws Exception { + setBounds(100, 100, 600, 450); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + this.offers = this.owner.getAllOffers(); + JLabel lblNewLabel = new JLabel(); + lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); + lblNewLabel.setBounds(23, 41, 536, 33); + contentPane.add(lblNewLabel); + if (this.offers.isEmpty()) + lblNewLabel + .setText("There are not bookings to be confirmed or denied"); + else + lblNewLabel.setText("List of bookings:"); + 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; + + public boolean isCellEditable(int row, int column) { + return false; + }; + }; + scrollPane.setViewportView(table); + tableModel = new DefaultTableModel(null, new String[] { "Offer #", + "FirstDay", "LastDay", "Price" }); + + // 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) { + + } + } + }); + btnDenyAddition.setBounds(300, 396, 169, 25); + contentPane.add(btnDenyAddition); + Enumeration rhs = this.offers.elements(); + while (rhs.hasMoreElements()) { + Offer of = rhs.nextElement(); + Vector row = new Vector(); + row.add(of.getOfferNumber()); + row.add(of.getFirstDay()); + row.add(of.getLastDay()); + row.add(of.getPrice()); + tableModel.addRow(row); + + } + + } +} diff --git a/ruralHouses/src/gui/ownerAddittionRequests.java b/ruralHouses/src/gui/ownerAddittionRequests.java new file mode 100644 index 0000000..f72d1cc --- /dev/null +++ b/ruralHouses/src/gui/ownerAddittionRequests.java @@ -0,0 +1,128 @@ +package gui; + +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Enumeration; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.border.EmptyBorder; +import javax.swing.table.DefaultTableModel; + +import businessLogic.AccountManager; +import businessLogic.AdminManager; +import domain.Account; +import domain.Administrator; + +public class ownerAddittionRequests extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminManager am = new AdminManager(); + private Vector accounts; + /** + * Create the frame. + */ + public ownerAddittionRequests() { + setTitle("Adding requests"); + try { + this.accounts= am.getOwnerAdditionReuests(); + init(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void init() throws Exception { + setBounds(100, 100, 600, 450); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JLabel lblNewLabel = new JLabel(); + lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); + lblNewLabel.setBounds(23, 41, 536, 33); + contentPane.add(lblNewLabel); + if (accounts.isEmpty()) + lblNewLabel.setText("There are not owners to be added"); + else + lblNewLabel.setText("List of owners to be added:"); + 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; + + public boolean isCellEditable(int row, int column) { + return false; + }; + }; + scrollPane.setViewportView(table); + tableModel = new DefaultTableModel(null, new String[] { + "Name", "E-mail", "Bank Account" }); + + //Maybe there is a better way to avoid interaction. + //table.setEnabled(false); + table.setModel(tableModel); + + JButton btnNewButton = new JButton("Confirm Addition"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + AccountManager ama = new AccountManager(); + Account accou = accounts.get(table.getSelectedRow()); + //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that. + ama.addAccount(accou); + am.removeOwnerAdditionRequests(accou);; + Administrator.saveInstance(); + ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(accou)); + accounts.remove(accou); + } + } + }); + btnNewButton.setBounds(88, 396, 169, 25); + contentPane.add(btnNewButton); + + JButton btnDenyAddition = new JButton("Deny Addition"); + btnDenyAddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + Account acc = accounts.get(table.getSelectedRow()); + am.removeOwnerAdditionRequests(acc); + Administrator.saveInstance(); + ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(acc)); + accounts.remove(acc); + } + } + }); + btnDenyAddition.setBounds(300, 396, 169, 25); + contentPane.add(btnDenyAddition); + Enumeration en = accounts.elements(); + Account acc; + + while (en.hasMoreElements()) { + acc = en.nextElement(); + Vector row = new Vector(); + row.add(acc.getOwner().getName()); + row.add(acc.getOwner().getMailAccount()); + row.add(acc.getOwner().getBankAccount()); + tableModel.addRow(row); + } + + } +} -- 2.20.1