|
@@ -9,6 +9,7 @@ |
9 |
9 |
|
import java.util.Date; |
10 |
10 |
|
import java.util.Enumeration; |
11 |
11 |
|
import java.util.Vector; |
|
12 |
+ |
|
12 |
13 |
|
import javax.swing.JButton; |
13 |
14 |
|
import javax.swing.JFrame; |
14 |
15 |
|
import javax.swing.JLabel; |
|
@@ -23,6 +24,7 @@ |
23 |
24 |
|
|
24 |
25 |
|
import businessLogic.BookingManager; |
25 |
26 |
|
import domain.Booking; |
|
27 |
+ |
import domain.Client; |
26 |
28 |
|
import domain.Offer; |
27 |
29 |
|
import domain.RuralHouse; |
28 |
30 |
|
|
|
@@ -53,6 +55,10 @@ |
53 |
55 |
|
private JTextField telIn; |
54 |
56 |
|
private int row; |
55 |
57 |
|
private JLabel labelPhone; |
|
58 |
+ |
private JLabel lblName; |
|
59 |
+ |
private JTextField nameField; |
|
60 |
+ |
private JLabel lblEmail; |
|
61 |
+ |
private JTextField mailField; |
56 |
62 |
|
|
57 |
63 |
|
/** |
58 |
64 |
|
* Create the frame. |
|
@@ -62,7 +68,7 @@ |
62 |
68 |
|
final Date LastDay) { |
63 |
69 |
|
this.rh = RH; |
64 |
70 |
|
this.getContentPane().setLayout(null); |
65 |
|
- |
setBounds(100, 100, 500, 583); |
|
71 |
+ |
setBounds(100, 100, 500, 700); |
66 |
72 |
|
contentPane = new JPanel(); |
67 |
73 |
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
68 |
74 |
|
setContentPane(contentPane); |
|
@@ -171,7 +177,7 @@ |
171 |
177 |
|
scrollPane.setViewportView(table); |
172 |
178 |
|
|
173 |
179 |
|
JButton btnBookSelected = new JButton("Book SelectedOffer"); |
174 |
|
- |
btnBookSelected.setBounds(238, 505, 178, 23); |
|
180 |
+ |
btnBookSelected.setBounds(238, 614, 178, 23); |
175 |
181 |
|
contentPane.add(btnBookSelected); |
176 |
182 |
|
|
177 |
183 |
|
btnBookSelected.addActionListener(new ActionListener() { |
|
@@ -189,11 +195,11 @@ |
189 |
195 |
|
contentPane.add(lblNewLabel); |
190 |
196 |
|
|
191 |
197 |
|
JLabel lblNewLabel_1 = new JLabel("Telephone num:"); |
192 |
|
- |
lblNewLabel_1.setBounds(10, 509, 83, 14); |
|
198 |
+ |
lblNewLabel_1.setBounds(10, 618, 83, 14); |
193 |
199 |
|
contentPane.add(lblNewLabel_1); |
194 |
200 |
|
|
195 |
201 |
|
telIn = new JTextField(); |
196 |
|
- |
telIn.setBounds(99, 505, 129, 20); |
|
202 |
+ |
telIn.setBounds(103, 615, 129, 20); |
197 |
203 |
|
contentPane.add(telIn); |
198 |
204 |
|
telIn.setColumns(10); |
199 |
205 |
|
|
|
@@ -201,6 +207,24 @@ |
201 |
207 |
|
labelPhone.setBounds(238, 252, 178, 14); |
202 |
208 |
|
contentPane.add(labelPhone); |
203 |
209 |
|
|
|
210 |
+ |
lblName = new JLabel("Name:"); |
|
211 |
+ |
lblName.setBounds(10, 516, 46, 14); |
|
212 |
+ |
contentPane.add(lblName); |
|
213 |
+ |
|
|
214 |
+ |
nameField = new JTextField(); |
|
215 |
+ |
nameField.setBounds(103, 513, 178, 20); |
|
216 |
+ |
contentPane.add(nameField); |
|
217 |
+ |
nameField.setColumns(10); |
|
218 |
+ |
|
|
219 |
+ |
lblEmail = new JLabel("E-mail:"); |
|
220 |
+ |
lblEmail.setBounds(10, 565, 46, 14); |
|
221 |
+ |
contentPane.add(lblEmail); |
|
222 |
+ |
|
|
223 |
+ |
mailField = new JTextField(); |
|
224 |
+ |
mailField.setBounds(103, 562, 178, 20); |
|
225 |
+ |
contentPane.add(mailField); |
|
226 |
+ |
mailField.setColumns(10); |
|
227 |
+ |
|
204 |
228 |
|
table.addMouseListener(new MouseAdapter() { |
205 |
229 |
|
@Override |
206 |
230 |
|
public void mouseClicked(MouseEvent arg0) { |
|
@@ -210,7 +234,8 @@ |
210 |
234 |
|
Enumeration<Offer> rhs = rh.getAllOffers().elements(); |
211 |
235 |
|
while (rhs.hasMoreElements()) { |
212 |
236 |
|
Offer of = rhs.nextElement(); |
213 |
|
- |
if (of.getBookings().size()==1&&of.getBookings().get(0).isAccepted()) { |
|
237 |
+ |
if (of.getBookings() == null |
|
238 |
+ |
|| !(of.getBookings().size() == 1 && of.isBooked())) { |
214 |
239 |
|
Vector<Object> row = new Vector<Object>(); |
215 |
240 |
|
row.add(of.getOfferNumber()); |
216 |
241 |
|
row.add(of.getFirstDay()); |
|
@@ -251,25 +276,32 @@ |
251 |
276 |
|
|
252 |
277 |
|
private void jButton_ActionPerformed(ActionEvent arg0) { |
253 |
278 |
|
BookingManager bookingM = new BookingManager(); |
254 |
|
- |
// RegExp to see if telephone number is correct??TODO |
255 |
|
- |
if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) { |
|
279 |
+ |
|
|
280 |
+ |
if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}") |
|
281 |
+ |
&& mailField |
|
282 |
+ |
.getText() |
|
283 |
+ |
.matches( |
|
284 |
+ |
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$") |
|
285 |
+ |
&& !nameField.getText().isEmpty()) { |
256 |
286 |
|
labelPhone.setText(""); |
257 |
|
- |
Booking book = null; |
|
287 |
+ |
Vector<Booking> book = null; |
258 |
288 |
|
try { |
259 |
|
- |
if (table.getRowCount() != 0) |
|
289 |
+ |
if (table.getRowCount() != 0) { |
|
290 |
+ |
Client cl = new Client(nameField.getText(), |
|
291 |
+ |
mailField.getText(), telIn.getText()); |
260 |
292 |
|
book = bookingM.createBooking(rh, rh.offers.get(row) |
261 |
|
- |
.getFirstDay(), rh.offers.get(row).getLastDay(), |
262 |
|
- |
telIn.getText()); |
|
293 |
+ |
.getFirstDay(), rh.offers.get(row).getLastDay(),cl); |
|
294 |
+ |
} |
263 |
295 |
|
} catch (Exception e) { |
264 |
296 |
|
e.printStackTrace(); |
265 |
297 |
|
} |
266 |
298 |
|
if (book != null) { |
267 |
299 |
|
BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow( |
268 |
|
- |
book); |
|
300 |
+ |
book.lastElement()); |
269 |
301 |
|
confirmWindow.setVisible(true); |
270 |
302 |
|
} |
271 |
303 |
|
} else { |
272 |
|
- |
labelPhone.setText("Phone format is wrong"); |
|
304 |
+ |
labelPhone.setText("Bad formatted data."); |
273 |
305 |
|
|
274 |
306 |
|
} |
275 |
307 |
|
} |