From: camjan Date: Thu, 21 May 2015 10:41:31 +0000 (+0200) Subject: Separate DB almost fixed X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/3db0928331c5d4caaa16db7b63df6617c7bcb480 Separate DB almost fixed --- diff --git a/ruralHouses client/src/gui/DeleteOfferGUI.java b/ruralHouses client/src/gui/DeleteOfferGUI.java index d9f5ab8..2f9dda7 100644 --- a/ruralHouses client/src/gui/DeleteOfferGUI.java +++ b/ruralHouses client/src/gui/DeleteOfferGUI.java @@ -43,8 +43,7 @@ public class DeleteOfferGUI extends JFrame { */ public DeleteOfferGUI(Owner o) { try { - hm = (HouseInterface) Naming - .lookup(___IntNames.HouseManager); + hm = (HouseInterface) Naming.lookup(___IntNames.HouseManager); } catch (Exception e1) { System.out.println("Error accessing remote authentication: " + e1.toString()); @@ -53,7 +52,7 @@ public class DeleteOfferGUI extends JFrame { Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0); } catch (RemoteException e1) { e1.printStackTrace(); - } + } setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); @@ -64,7 +63,8 @@ public class DeleteOfferGUI extends JFrame { comboBox_1 = new JComboBox(); comboBox_1.setBounds(101, 76, 314, 20); - Vector vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers(); + Vector vo = ((RuralHouse) comboBox.getSelectedItem()) + .getAllOffers(); comboBox_1.removeAllItems(); for (Offer of : vo) { comboBox_1.addItem(of); @@ -82,7 +82,8 @@ public class DeleteOfferGUI extends JFrame { @Override public void itemStateChanged(ItemEvent arg0) { - Vector vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers(); + Vector vo = ((RuralHouse) comboBox.getSelectedItem()) + .getAllOffers(); comboBox_1.removeAllItems(); for (Offer of : vo) { comboBox_1.addItem(of); @@ -92,7 +93,31 @@ public class DeleteOfferGUI extends JFrame { } }); + comboBox_1.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent arg0) { + if (((Offer) comboBox_1.getSelectedItem()).isBooked()) { + feedback.setText("This offer is already booked."); + btnDelete.setEnabled(false); + } + + } + + }); + comboBox_1.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent arg0) { + if (comboBox_1.getSelectedItem() != null) { + if (!((Offer) comboBox_1.getSelectedItem()).isBooked()) { + feedback.setText(""); + btnDelete.setEnabled(true); + } + } + } + + }); rdbtnIAmSure.addItemListener(new ItemListener() { @Override @@ -119,11 +144,14 @@ public class DeleteOfferGUI extends JFrame { contentPane.add(lblOffer); contentPane.add(comboBox); contentPane.add(comboBox_1); - + feedback = new JLabel(""); feedback.setBounds(140, 178, 202, 23); contentPane.add(feedback); - + if (((Offer) comboBox_1.getSelectedItem()).isBooked()) { + feedback.setText("This offer is already booked."); + btnDelete.setEnabled(false); + } btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionListenerButton(arg0); @@ -138,13 +166,12 @@ public class DeleteOfferGUI extends JFrame { Offer toDel = (Offer) comboBox_1.getSelectedItem(); OfferInterface oM = null; try { - oM = (OfferInterface) Naming - .lookup(___IntNames.OfferManager); + oM = (OfferInterface) Naming.lookup(___IntNames.OfferManager); } catch (Exception e1) { System.out.println("Error accessing remote authentication: " + e1.toString()); } - + try { oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel); comboBox_1.removeItem(toDel); @@ -154,6 +181,6 @@ public class DeleteOfferGUI extends JFrame { feedback.setText("Imposible to delete the offer"); e1.printStackTrace(); } - + } } diff --git a/ruralHouses client/src/gui/HouseFeaturesGUI.java b/ruralHouses client/src/gui/HouseFeaturesGUI.java index 39d0bc9..c4bb654 100644 --- a/ruralHouses client/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses client/src/gui/HouseFeaturesGUI.java @@ -301,6 +301,7 @@ public class HouseFeaturesGUI extends JFrame { Vector book = null; try { if (table.getRowCount() != 0) { + row = table.getSelectedRow(); Client cl = new Client(nameField.getText(), mailField.getText(), telIn.getText()); book = bookingM.createBooking(rh, offers.get(row) diff --git a/ruralHouses client/src/gui/ModifyOfferGUI.java b/ruralHouses client/src/gui/ModifyOfferGUI.java index 1f082d0..73230bb 100644 --- a/ruralHouses client/src/gui/ModifyOfferGUI.java +++ b/ruralHouses client/src/gui/ModifyOfferGUI.java @@ -26,9 +26,9 @@ import javax.swing.JLabel; import javax.swing.JTextField; import com.toedter.calendar.JCalendar; + import common.HouseInterface; import common.OfferInterface; - import configuration.___IntNames; import domain.Offer; import domain.Owner; @@ -252,7 +252,28 @@ public class ModifyOfferGUI extends JFrame { } } }); - + if(((Offer) comboBox_o.getSelectedItem()).isBooked()){ + jLabel5.setText("This offer is already booked."); + jButton1.setEnabled(false); + } + comboBox_o.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent arg0) { + if(((Offer) comboBox_o.getSelectedItem()).isBooked()){ + jLabel5.setText("This offer is already booked."); + jButton1.setEnabled(false); + } + } + }); + comboBox_o.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent arg0) { + if(!((Offer) comboBox_o.getSelectedItem()).isBooked()){ + jLabel5.setText("");; + jButton1.setEnabled(true); + } + } + }); this.getContentPane().add(jCalendar2, null); this.getContentPane().add(jCalendar1, null); this.getContentPane().add(jLabel5, null); diff --git a/ruralHouses client/src/gui/listOfBookingRequestsGUI.java b/ruralHouses client/src/gui/listOfBookingRequestsGUI.java index aab2736..025c1fe 100644 --- a/ruralHouses client/src/gui/listOfBookingRequestsGUI.java +++ b/ruralHouses client/src/gui/listOfBookingRequestsGUI.java @@ -113,19 +113,11 @@ public class listOfBookingRequestsGUI extends JFrame { } catch (RemoteException e1) { e1.printStackTrace(); } - int rows = table.getModel().getRowCount(); - for(int i = rows - 1; i >=0; i--){ + int rows = table.getModel().getRowCount(); + for (int i = rows - 1; i >= 0; i--) { ((DefaultTableModel) table.getModel()).removeRow(i); } - Vector row = new Vector(); - row.add(book.getBookNumber()); - row.add(book.getBookDate()); - row.add(book.getClient().getName()); - row.add(book.getClient().getMailAccount()); - row.add(book.getClient().getTelephone()); - tableModel.addRow(row); - btnNewButton.setEnabled(false); - btnDenyAddition.setEnabled(false); + } } diff --git a/ruralHouses client/src/gui/listOfOffers.java b/ruralHouses client/src/gui/listOfOffers.java index 4d065bb..3674c59 100644 --- a/ruralHouses client/src/gui/listOfOffers.java +++ b/ruralHouses client/src/gui/listOfOffers.java @@ -21,7 +21,6 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import common.HouseInterface; -import common.OfferInterface; import configuration.___IntNames; import domain.Offer; @@ -111,7 +110,6 @@ public class listOfOffers extends JFrame { @Override public void mouseClicked(MouseEvent arg0) { int row = table.getSelectedRow(); - System.out.println(row); listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row)); feat.setVisible(true); } diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index 0233811..c2b624c 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -59,6 +59,8 @@ public class HouseManager extends UnicastRemoteObject implements HouseInterface return this.dbMngr.getRuralHouses( ow, name ,town, nBed, nKit, nBath, nPark, nLiv); } + + } diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 403c916..a424473 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -516,7 +516,14 @@ public class DB4oManager { public Vector getRuralHouses(Owner ow, String name, String town, int nBed, int nKit, int nBath, int nPark, int nLiv) { HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark); - RuralHouse rh = new RuralHouse(name, ow, null, town, fea); + RuralHouse rh; + if (ow != null) { + Owner own = new Owner(ow.getName(), ow.getBankAccount(), + ow.getMailAccount()); + rh = new RuralHouse(name, own, null, town, fea); + }else{ + rh = new RuralHouse(name, ow, null, town, fea); + } if (c.isDatabaseLocal() == false) openSDB(); else @@ -632,7 +639,9 @@ public class DB4oManager { try { Offer of = (Offer) db.queryByExample( - new Offer(0, o.getRuralHouse(), null, null, 0)).get(0); + new Offer(o.getOfferNumber(), new RuralHouse(o + .getRuralHouse().getHouseName(), null, null, null, + null), null, null, 0)).get(0); Booking proto = new Booking(0, of, null, null); ObjectSet result = db.queryByExample(proto); return new Vector(result); diff --git a/ruralHousesDB/src/dataAccess/DB4oManager.java b/ruralHousesDB/src/dataAccess/DB4oManager.java index 1c6bdba..ea6bc69 100644 --- a/ruralHousesDB/src/dataAccess/DB4oManager.java +++ b/ruralHousesDB/src/dataAccess/DB4oManager.java @@ -4,6 +4,8 @@ package dataAccess; public class DB4oManager { + private static DB4oManagerAux theDB4oManagerAux; + class DB4oManagerAux { int bookingNumber; int offerNumber;