forked from janaghoniem/Bus-Ticket-Booking-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooking.java
2226 lines (1835 loc) · 94.3 KB
/
Booking.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package project.trial;
/**
*
* @author Nouran
*/
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Random;
import java.io.FileNotFoundException;
import java.io.Serializable;
import javafx.scene.control.ComboBox;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import project.trial.Trips.Destination;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
public class Booking implements manages<Booking>, Serializable {
public static final HashMap<Integer, Booking> book = new HashMap<>();
public static boolean goFired = false;
public static Booking currentBooking;
private transient ComboBox<Trips> tripComboBox;
private transient Spinner<Integer> ticketsSpinner;
private transient List<Trips> filteredTrips;
double windowWidth = 600;
double windowHeight = 400;
String tolocation;
LocalDate selectedDate;
static String file = "View Bookings";
String fromlocation;
int numberOfTickets;
int buttonClickCount = 0;
private int booking_id;
private int guest_id;
private String guestPassword;
private int trip_id;
private String guest_Name;
private int total_price;
private String license_plate;
private static int receptionist_id;
private LocalDateTime booking_time;
private int no_of_tickets;
private static final long serialVersionUID = 1L;
Destination fromDestination;
String fromBusStop;
LocalDateTime departureDateTime;
private Destination toDestination;
private String toBusStop;
private LocalDateTime arrivalDateTime;
String searchValue;
private transient Scene scene1;
private transient Scene scene4;
private transient Scene scene6;
private transient VBox bookingsVBox = new VBox(10);
private transient HBox bookingHBox = new HBox(10);
private transient Image backgroundImage = new Image("file:/home/jana/Downloads/Project(6).png");
private transient BackgroundSize backgroundSize = new BackgroundSize(windowWidth, windowHeight, false, false, true, true);
private transient BackgroundImage background = new BackgroundImage(
backgroundImage,
BackgroundRepeat.NO_REPEAT,
BackgroundRepeat.NO_REPEAT,
BackgroundPosition.DEFAULT,
backgroundSize
);
//empty constructor
public Booking() {
}
//constructor
public Booking(int booking_id, int guest_id, String guest_Name, String guestPassword, int trip_id,String fromDestination, String fromBusStop, LocalDateTime DepartureDateTime,String toDestination, String toBusStop, LocalDateTime arrivalDateTime,double total_price, String license_plate, int receptionist_id, int no_of_tickets,LocalDateTime booking_time) {
this.guest_id = guest_id;
this.guestPassword = guestPassword;
this.trip_id = trip_id;
this.guest_Name = guest_Name;
this.total_price = (int) total_price;
this.license_plate = license_plate;
this.receptionist_id = receptionist_id;
this.booking_id = booking_id;
this.no_of_tickets = no_of_tickets;
this.booking_time = booking_time;
}
//setters and getters
public int getBooking_id() {
return booking_id;
}
public void setBooking_id(int booking_id) {
this.booking_id = booking_id;
}
public static HashMap<Integer, Booking> getBook() {
return book;
}
public int getTrip_id() {
return trip_id;
}
public void setTrip_id(int trip_id) {
this.trip_id = trip_id;
}
public String getGuest_Name() {
return guest_Name;
}
public void setGuest_Name(String guest_Name) {
this.guest_Name = guest_Name;
}
public int getGuest_id() {
return guest_id;
}
public LocalDateTime getBooking_time() {
return booking_time;
}
public void setBooking_time(LocalDateTime now) {
this.booking_time = LocalDateTime.now();
}
public void setGuest_id(int guest_id) {
this.guest_id = guest_id;
}
public String getGuestPassword() {
return guestPassword;
}
public void setGuestPassword(String guestPassword) {
this.guestPassword = guestPassword;
}
public int getTotal_price() {
return total_price;
}
public void setTotal_price(int total_price) {
this.total_price = total_price;
}
public String getLicense_plate() {
return license_plate;
}
public void setLicense_plate(String license_plate) {
this.license_plate = license_plate;
}
public static int getReceptionist_id() {
return receptionist_id;
}
public static void setReceptionist_id(int receptionist_id) {
Booking.receptionist_id = receptionist_id;
}
public String getSearchValue() {
return searchValue;
}
public void setSearchValue(String searchValue) {
this.searchValue = searchValue;
}
public Destination getFromDestination() {
return fromDestination;
}
public void setFromDestination(Destination fromDestination) {
this.fromDestination = fromDestination;
}
public Destination getToDestination() {
return toDestination;
}
public void setToDestination(Destination toDestination) {
this.toDestination = toDestination;
}
public LocalDateTime getDepartureDateTime() {
return departureDateTime;
}
public String getTolocation() {
return tolocation;
}
public void setTolocation(String tolocation) {
this.tolocation = tolocation;
}
public String getFromlocation() {
return fromlocation;
}
public void setFromlocation(String fromlocation) {
this.fromlocation = fromlocation;
}
public LocalDate getSelectedDate() {
return selectedDate;
}
public void setSelectedDate(LocalDate selectedDate) {
this.selectedDate = selectedDate;
}
public static Booking getCurrentBooking() {
return currentBooking;
}
public static void setCurrentBooking(Booking currentBooking) {
Booking.currentBooking = currentBooking;
}
public int getNumberOfTickets() {
return numberOfTickets;
}
public void setNumberOfTickets(int numberOfTickets) {
this.numberOfTickets = numberOfTickets;
}
public void setDepartureDateTime(LocalDateTime departureDateTime) {
this.departureDateTime = departureDateTime;
}
public String getFromBusStop() {
return fromBusStop;
}
public void setFromBusStop(String fromBusStop) {
this.fromBusStop = fromBusStop;
}
public String getToBusStop() {
return toBusStop;
}
public void setToBusStop(String toBusStop) {
this.toBusStop = toBusStop;
}
public LocalDateTime getArrivalDateTime() {
return arrivalDateTime;
}
public void setArrivalDateTime(LocalDateTime arrivalDateTime) {
this.arrivalDateTime = arrivalDateTime;
}
@Override
public void add() {
System.out.println("--Add--");
try {
if (!book.containsKey(booking_id)) {
if (false == Vehicle.newBooking(getTrip_id(), (int) getNumberOfTickets())) {
System.out.println("Sorry cant book! Try to look for another available trip");
} else {
book.put(booking_id, this);
System.out.println(book);
String file = "View Bookings";
saveToFile();
viewFile();
}
} else {
throw new RuntimeException("This booking already exists with the id :" + booking_id);
}
} catch (IllegalStateException e) {
System.err.println("Error in adding booking " + e.getMessage());
}
}
@Override
public String toString() {
return "Booking{" +
"guest_id=" + guest_id +
", guest_Name='" + guest_Name + '\'' +
", guestPassword='" + guestPassword + '\'' +
", trip_id=" + trip_id +
", fromDestination='" + fromDestination + '\'' +
", fromBusStop='" + fromBusStop + '\'' +
", DepartureDateTime=" + departureDateTime +
", toDestination='" + toDestination + '\'' +
", toBusStop='" + toBusStop + '\'' +
", arrivalDateTime=" + arrivalDateTime +
", total_price=" + total_price +
", license_plate='" + license_plate + '\'' +
", receptionist_id=" + receptionist_id +
", no_of_tickets=" + numberOfTickets +
", booking_time=" + booking_time +
'}';
}
//remove
@Override
public void remove() {
System.out.println("--remove--");
Vehicle v = new Vehicle();
book.remove(booking_id);
v.cancelBooking(booking_id, no_of_tickets);
System.out.println("Your booking has been successfully deleted.");
String file = "View Bookings";
saveToFile();
viewFile();
}
public static void saveToFile() {
int i = 0;
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file))) {
for (Booking bb : book.values()) {
System.out.println(bb.booking_id);
out.writeObject(bb);
i++;
}
System.out.println("number of objects written into file: " + i);
} catch (IOException e) {
System.out.println("File error: " + e);
}
}
public static void readFromFile() {
int i = 0;
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) {
while (true) {
try {
Booking books = (Booking) in.readObject();
book.put(books.booking_id, books);
i++;
} catch (EOFException e) {
// End of file reached
System.out.println("number of bookings read from file into hashmap: " + i);
break;
} catch (ClassNotFoundException | IOException e) {
System.out.println("Error reading object: " + e);
break;
}
}
} catch (IOException e) {
System.out.println("File error: " + e);
}
}
public void viewFile() {
String file = "B";
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
for (Booking booking : book.values()) {
writer.write(booking.toString());
writer.newLine();
}
System.out.println("Booking data successfully saved to file.");
} catch (IOException e) {
System.err.println("Failed to save booking data to file! " + e.getMessage());
}
}
public static int generateBookingId() {
Random random = new Random();
int maxAttempts = 1000;
for (int attempt = 1; attempt <= maxAttempts; attempt++) {
int generatedId = Integer.parseInt("11" + String.format("%03d", random.nextInt(1000)));
if (!book.containsKey(generatedId)) {
return generatedId;
}
}
throw new RuntimeException("Unable to generate a unique booking ID after multiple attempts.");
}
public static int calculate_payment(int trip_id, int no_of_tickets) {
try {
if (no_of_tickets < 0) {
throw new IllegalArgumentException("The number inserted is below zero (Negative). Please try to insert a valid value.");
}
Trips trip = Trips.TripsMap.get(trip_id);
int total_price = (int) (no_of_tickets * trip.getPrice());
return total_price;
} catch (IllegalArgumentException e) {
System.err.println("Error in payment calculation! Please try again: " + e.getMessage());
return 0;
} catch (RuntimeException e) {
System.err.println("Error: " + e.getMessage());
return 0;
}
}
@Override
public void edit() //partially implemented
{
Alert editBookingAlert1 = new Alert(Alert.AlertType.NONE);
editBookingAlert1.setTitle("Confirmation");
editBookingAlert1.setHeaderText("Do You Want To Edit Number of tickets: " + getTotal_price());
ButtonType yesButton1 = new ButtonType("Yes", ButtonBar.ButtonData.YES);
ButtonType cancelButton1 = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
editBookingAlert1.getButtonTypes().setAll(yesButton1, cancelButton1);
Optional<ButtonType> result1 = editBookingAlert1.showAndWait();
if (result1.isPresent() && result1.get() == yesButton1) {
Alert editBookingAlert2 = new Alert(Alert.AlertType.NONE);
editBookingAlert2.setTitle("Edit Number of tickets");
Spinner<Integer> spinner = new Spinner<>(1, 10, 1);
VBox alertContent2 = new VBox(10);
Label ticketsLabel = new Label("Number of Tickets:");
Label totalPriceLabel = new Label("Total Price: $" + Booking.calculate_payment(getTrip_id(), 1));
spinner.valueProperty().addListener((observable, oldValue, newValue) -> {
int editNumberOfTickets = spinner.getValue();
double editTotal = Booking.calculate_payment(getTrip_id(), editNumberOfTickets);
ticketsLabel.setText("Number of Tickets: " + editNumberOfTickets);
totalPriceLabel.setText("Total Price: $" + editTotal);
});
alertContent2.getChildren().addAll(ticketsLabel, spinner, totalPriceLabel);
editBookingAlert2.getDialogPane().setContent(alertContent2);
ButtonType yesButton2 = new ButtonType("Yes", ButtonBar.ButtonData.YES);
ButtonType cancelButton2 = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
editBookingAlert2.getButtonTypes().setAll(yesButton2, cancelButton2);
Optional<ButtonType> result2 = editBookingAlert2.showAndWait();
if (result2.isPresent() && result2.get() == yesButton2) {
int editNumberOfTickets = spinner.getValue();
setTotal_price((editNumberOfTickets));
//Vehicle v= new Vehicle();
//if(v.AvailibilityMap.get(trip.getTrip_id())>editNumberOfTickets)
//{
setTotal_price(Booking.calculate_payment(getTrip_id(), editNumberOfTickets));
System.out.println("Yes button clicked in the second alert");
System.out.println(book);
Booking.getBook().put(booking_id, this);
saveToFile();
viewFile();
//}else{ System.out.println("sorry all seats are booked");};
} else {
System.out.println("Cancel button clicked in the second alert");
}
} else {
System.out.println("Cancel button clicked in the first alert");
}
}
public static Scene createPrimaryStage(Stage primaryStage) throws FileNotFoundException {
BorderPane root = new BorderPane();
root.setStyle("-fx-background-color: #292525; -fx-background-image: url('file:/home/jana/Downloads/Project(1).jpg'); -fx-background-size: cover;");
// Image
Image i = new Image(new FileInputStream("/home/jana/Downloads/review.png"));
ImageView iv = new ImageView(i);
iv.setFitHeight(150);
iv.setFitWidth(150);
Label description = new Label("Generate Guest's Login Information.");
description.setTextFill(Color.web("#ffb000"));
description.setFont(Font.font("Helvetica World", FontWeight.BOLD, 30));
Label fnamelbl = new Label("Full Name:");
fnamelbl.setTextFill(Color.web("#ffb000"));
fnamelbl.setFont(Font.font("Helvetica World", FontWeight.BOLD, 25));
TextField fnametf = new TextField();
fnametf.setMinSize(300, 60); // Adjust the size as needed
fnametf.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-border-width: 4px; -fx-text-fill: #ffb000; -fx-font-size: 18px;");
// GridPane
GridPane gridpane = new GridPane();
gridpane.add(fnamelbl, 0, 0);
gridpane.add(fnametf, 1, 0);
// Buttons
Button generate = new Button("Generate");
generate.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
generate.setPrefWidth(300);
generate.setFont(Font.font("Helvetica World", FontWeight.BOLD, 24)); // Increase the font size
generate.setOnMouseEntered(eh ->
{
generate.setCursor(Cursor.HAND);
generate.setStyle("-fx-background-color: transparent; -fx-border-color: white; -fx-border-radius: 5px; -fx-text-fill: white; -fx-border-width: 4px;");
});
// non-hover event
generate.setOnMouseExited(eh ->
{
generate.setCursor(Cursor.DEFAULT);
generate.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
});
Button startBookingbtn = new Button("Start Booking");
startBookingbtn.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
startBookingbtn.setPrefWidth(300);
startBookingbtn.setFont(Font.font("Helvetica World", FontWeight.BOLD, 24));
startBookingbtn.setOnMouseEntered(eh ->
{
startBookingbtn.setCursor(Cursor.HAND);
startBookingbtn.setStyle("-fx-background-color: transparent; -fx-border-color: white; -fx-border-radius: 5px; -fx-text-fill: white; -fx-border-width: 4px;");
});
// non-hover event
startBookingbtn.setOnMouseExited(eh ->
{
startBookingbtn.setCursor(Cursor.DEFAULT);
startBookingbtn.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
});
// VBox
VBox vbox = new VBox();
vbox.setMinSize(600, 600);
Button existingGuest = new Button("Existing Guest");
existingGuest.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
existingGuest.setPrefWidth(300);
existingGuest.setFont(Font.font("Helvetica World", FontWeight.BOLD, 24)); // Increase the font size
existingGuest.setOnMouseEntered(eh ->
{
existingGuest.setCursor(Cursor.HAND);
existingGuest.setStyle("-fx-background-color: transparent; -fx-border-color: white; -fx-border-radius: 5px; -fx-text-fill: white; -fx-border-width: 4px;");
});
// non-hover event
existingGuest.setOnMouseExited(eh ->
{
existingGuest.setCursor(Cursor.DEFAULT);
existingGuest.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
});
Button newGuest = new Button("New Guest");
newGuest.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
newGuest.setPrefWidth(300);
newGuest.setFont(Font.font("Helvetica World", FontWeight.BOLD, 24)); // Increase the font size
newGuest.setOnMouseEntered(eh ->
{
newGuest.setCursor(Cursor.HAND);
newGuest.setStyle("-fx-background-color: transparent; -fx-border-color: white; -fx-border-radius: 5px; -fx-text-fill: white; -fx-border-width: 4px;");
});
// non-hover event
newGuest.setOnMouseExited(eh ->
{
newGuest.setCursor(Cursor.DEFAULT);
newGuest.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
});
VBox buttons = new VBox();
buttons.getChildren().addAll(iv, description, newGuest, existingGuest);
buttons.setMinSize(600, 600);
// Function to validate the name
// Scene settings
startBookingbtn.setOnAction(e -> {
try {
System.out.println("Button 1 clicked");
primaryStage.setScene(currentBooking.chooseTrip(primaryStage));
} catch (FileNotFoundException ex) {
Logger.getLogger(Booking.class.getName()).log(Level.SEVERE, null, ex);
}
});
gridpane.setAlignment(Pos.CENTER);
gridpane.setHgap(40);
gridpane.setVgap(25);
vbox.setSpacing(50);
vbox.setAlignment(Pos.CENTER);
buttons.setSpacing(30);
buttons.setAlignment(Pos.CENTER);
// StackPane
StackPane stackpane = new StackPane();
Rectangle rectangle = new Rectangle(700, 600);
rectangle.setArcWidth(20);
rectangle.setArcHeight(20);
rectangle.setFill(Color.rgb(10,12,38, 0.5));
rectangle.setStyle("-fx-border-radius: 5px;");
stackpane.getChildren().addAll(rectangle, buttons);
Label GID = new Label("Guest ID");
GID.setTextFill(Color.web("#ffb000"));
GID.setFont(Font.font("Helvetica World", FontWeight.BOLD, 25));
TextField gid = new TextField();
gid.setMinSize(300, 60); // Adjust the size as needed
gid.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-border-width: 4px; -fx-text-fill: #ffb000; -fx-font-size: 18px;");
GridPane eg = new GridPane();
eg.add(GID, 0, 0);
eg.add(gid, 1, 0);
eg.setHgap(40);
eg.setVgap(25);
eg.setAlignment(Pos.CENTER);
Button go = new Button("Go");
go.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
go.setPrefWidth(300);
go.setFont(Font.font("Helvetica World", FontWeight.BOLD, 24)); // Increase the font size
go.setOnMouseEntered(eh ->
{
go.setCursor(Cursor.HAND);
go.setStyle("-fx-background-color: transparent; -fx-border-color: white; -fx-border-radius: 5px; -fx-text-fill: white; -fx-border-width: 4px;");
});
// non-hover event
go.setOnMouseExited(eh ->
{
go.setCursor(Cursor.DEFAULT);
go.setStyle("-fx-background-color: transparent; -fx-border-color: #ffb000; -fx-border-radius: 5px; -fx-text-fill: #ffb000; -fx-border-width: 4px;");
});
newGuest.setOnAction(eh ->
{
stackpane.getChildren().clear();
vbox.getChildren().addAll(iv, description, gridpane, generate);
stackpane.getChildren().addAll(rectangle, vbox);
});
existingGuest.setOnAction(eh ->
{
stackpane.getChildren().clear();
vbox.getChildren().clear();
vbox.getChildren().addAll(iv, description, eg, go);
stackpane.getChildren().addAll(rectangle, vbox);
});
go.setOnAction(eh ->
{
if(!gid.getText().isEmpty())
{
goFired = true;
generate.fire();
}
});
generate.setOnAction((ActionEvent event) -> {
String enteredName = fnametf.getText().trim();
Label gNamelbl = new Label("Guest Name:");
gNamelbl.setTextFill(Color.web("white"));
gNamelbl.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gIDlbl = new Label("Guest ID:");
gIDlbl.setTextFill(Color.web("white"));
gIDlbl.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gPasslbl = new Label("Guest Password:");
gPasslbl.setTextFill(Color.web("white"));
gPasslbl.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gBookingIDlbl = new Label("Booking ID:");
gBookingIDlbl.setTextFill(Color.web("white"));
gBookingIDlbl.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
if(goFired == true)
{
Booking boo = new Booking();
boo.setGuest_Name(Guest.guests.get(Integer.parseInt(gid.getText())).Name);
boo.setGuestPassword(Guest.guests.get(Integer.parseInt(gid.getText())).Password);
boo.setGuest_id(Guest.guests.get(Integer.parseInt(gid.getText())).ID);
boo.setBooking_id(boo.generateBookingId());
boo.setBooking_time(LocalDateTime.now());
currentBooking = boo;
System.out.println(currentBooking.booking_id);
System.out.println( boo.getBooking_id());
Label gName = new Label(boo.getGuest_Name());
gName.setTextFill(Color.web("#ffb000"));
gName.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gID = new Label("" + boo.getGuest_id());
gID.setTextFill(Color.web("#ffb000"));
gID.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gPass = new Label(boo.getGuestPassword());
gPass.setTextFill(Color.web("#ffb000"));
gPass.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gBookingID = new Label("" + boo.getBooking_id());
gBookingID.setTextFill(Color.web("#ffb000"));
gBookingID.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
description.setText("Guest's Information");
gridpane.getChildren().clear();
gridpane.add(gNamelbl, 0, 0);
gridpane.add(gName, 1, 0);
gridpane.add(gIDlbl, 0, 1);
gridpane.add(gID, 1, 1);
gridpane.add(gPasslbl, 0, 2);
gridpane.add(gPass, 1, 2);
gridpane.add(gBookingIDlbl, 0, 3);
gridpane.add(gBookingID, 1, 3);
vbox.getChildren().clear();
vbox.getChildren().addAll(iv, description, gridpane, startBookingbtn);
}
else{
// Check if the name is empty
if (enteredName.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(null);
alert.setContentText("Name Field cannot be empty. Please enter your name.");
alert.showAndWait();
} else if (!isValidName(enteredName)) {
// Check if the name contains only alphabets and spaces
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(null);
alert.setContentText("Invalid name. Please enter a valid name with only alphabets and spaces.");
alert.showAndWait();
} else {
// If all validations pass, proceed with setting the information
Booking boo = new Booking();
boo.setGuest_Name(enteredName);
boo.setGuestPassword(Admin.generateGuestPassword());
boo.setGuest_id(Admin.generateGuestId());
boo.setBooking_id(boo.generateBookingId());
boo.setBooking_time(LocalDateTime.now());
Guest g = new Guest(boo.getGuest_id(), boo.getGuestPassword(), enteredName);
currentBooking = boo;
System.out.println(currentBooking.booking_id);
System.out.println( boo.getBooking_id());
Label gName = new Label(boo.getGuest_Name());
gName.setTextFill(Color.web("#ffb000"));
gName.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gID = new Label("" + boo.getGuest_id());
gID.setTextFill(Color.web("#ffb000"));
gID.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gPass = new Label(boo.getGuestPassword());
gPass.setTextFill(Color.web("#ffb000"));
gPass.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
Label gBookingID = new Label("" + boo.getBooking_id());
gBookingID.setTextFill(Color.web("#ffb000"));
gBookingID.setFont(Font.font("Helvetica World", FontWeight.BOLD, 20));
description.setText("Guest's Information");
gridpane.getChildren().clear();
gridpane.add(gNamelbl, 0, 0);
gridpane.add(gName, 1, 0);
gridpane.add(gIDlbl, 0, 1);
gridpane.add(gID, 1, 1);
gridpane.add(gPasslbl, 0, 2);
gridpane.add(gPass, 1, 2);
gridpane.add(gBookingIDlbl, 0, 3);
gridpane.add(gBookingID, 1, 3);
vbox.getChildren().clear();
vbox.getChildren().addAll(iv, description, gridpane, startBookingbtn);
}
}
});
// Adding items to the page
root.setCenter(stackpane);
Region centerRegion = (Region) root.getCenter();
centerRegion.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
Scene scene = new Scene(root, Screen.getPrimary().getVisualBounds().getWidth(), Screen.getPrimary().getVisualBounds().getHeight());
primaryStage.setTitle("Bus-Ticket Booking System - Generate Guest Information");
// Stage settings
return scene;
}
private static boolean isValidName(String name) {
return name.matches("^[a-zA-Z\\s]+$");
}
@Override
public void search() {
int count = 0;
bookingsVBox.getChildren().clear();
for (Booking book : Booking.getBook().values()) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedArrivalDateTime = book.getArrivalDateTime() != null ?
book.getArrivalDateTime().format(formatter) : "N/A";
String formattedDepartureDateTime = book.getDepartureDateTime() != null ?
book.getDepartureDateTime().format(formatter) : "N/A";
String formattedBookingTime = book.getBooking_time() != null ?
book.getBooking_time().format(formatter) : "N/A";
String stringTrip = String.format("%s %s %s %s %s %d %.2f %s %s %s %s %s",
book.getFromBusStop(),
book.getToBusStop(),
book.getFromDestination(),
book.getToDestination(),
book.getLicense_plate(),
book.getBooking_id(),
book.getTotal_price(),
formattedArrivalDateTime,
formattedDepartureDateTime,
book.getGuest_Name(),
formattedBookingTime,
book.getReceptionist_id()
);
if (stringTrip.toLowerCase().contains(searchValue.toLowerCase())) {
bookingHBox.setAlignment(Pos.CENTER);
Button editButton = new Button("Edit");
Button deleteButton = new Button("Delete");
Label bookingIdLabel = new Label(Integer.toString(book.getBooking_id()));
Label guestNameLabel = new Label(book.getGuest_Name());
Label guestIdLabel = new Label(Integer.toString(book.getGuest_id()));
Label tripIdLabel = new Label(Integer.toString(book.getTrip_id()));
Label ticketsLabel = new Label(Integer.toString(book.getNumberOfTickets()));
Label priceLabel = new Label(Double.toString(book.getTotal_price()));
Label toDestinationLabel = new Label(String.valueOf(book.getToDestination()));
Label fromBusStopLabel = new Label(book.getFromBusStop());
Label toBusStopLabel = new Label(book.getToBusStop());
Label departureLabel = new Label(formattedDepartureDateTime);
Label arrivalLabel = new Label(formattedArrivalDateTime);
Label vehicleIdLabel = new Label(book.getLicense_plate());
Label bookingTimeLabel = new Label(formattedBookingTime);
Label Reception= new Label(Integer.toString(Booking.getReceptionist_id()));
bookingHBox.getChildren().addAll(
bookingIdLabel ,guestNameLabel,guestIdLabel,tripIdLabel,ticketsLabel, fromBusStopLabel, toBusStopLabel, departureLabel,
arrivalLabel, vehicleIdLabel, priceLabel, editButton, deleteButton,bookingTimeLabel,Reception
);
bookingsVBox.getChildren().add(bookingHBox);
editButton.setOnAction(event -> {
book.edit();
ticketsLabel.setText((Integer.toString(book.getNumberOfTickets())));
priceLabel.setText(Double.toString(book.getTotal_price()));
}
);
deleteButton.setOnAction(event -> {
book.remove();
System.out.println(book);
VBox parentVBox = (VBox) bookingHBox.getParent();
parentVBox.getChildren().remove(bookingHBox);
});
count++;
}
}
if (count == 0) {
Label noResultsLabel = new Label("No matching trips found.");
bookingsVBox.getChildren().add(noResultsLabel);
}
}
public Scene ExistingBookings(Stage primaryStage) throws FileNotFoundException {
GridPane root1 = new GridPane();
root1.setStyle("-fx-background-color: #292525; -fx-background-image: url('file:/home/jana/Downloads/Project(6).jpg'); -fx-background-size: cover;");
scene4 = new Scene(root1, Screen.getPrimary().getVisualBounds().getWidth(), Screen.getPrimary().getVisualBounds().getHeight());
root1.setAlignment(Pos.TOP_CENTER);
root1.setHgap(10);
root1.setVgap(10);
root1.setPadding(new Insets(20));
Label lbl24 = new Label("Manage Bookings");
lbl24.setTextFill(Color.WHITE);
lbl24.setStyle("-fx-font-family: 'Helvetica World'; -fx-font-size: 35; -fx-font-weight: bold;");
Label lbl25 = new Label("Search:");
lbl25.setTextFill(Color.WHITE);
lbl25.setStyle("-fx-font-family: 'Helvetica World'; -fx-font-size: 19; -fx-font-weight: bold;");
TextField txt1 = new TextField("");
txt1.setPromptText("Search Users");
txt1.setStyle("-fx-font-size: 15; -fx-background-color: rgba(0, 0, 0, 0); -fx-text-fill: #ffb000; -fx-border-color: #ffb000; -fx-border-width: 3px");
txt1.setMaxWidth(800);
txt1.setMinWidth(800);
Button btn8 = new Button("cancel search");
btn8.setStyle("-fx-font-size: 15; -fx-background-color: #ffb000; -fx-text-fill: #0a0c26;");
Button backBtn = new Button("Back");
backBtn.setStyle("-fx-font-size: 15; -fx-background-color: #ffb000; -fx-text-fill: #0a0c26;");
Button exitBtn = new Button("Exit");
exitBtn.setStyle("-fx-font-size: 15; -fx-background-color: #ffb000; -fx-text-fill: #0a0c26;");
exitBtn.setOnAction(e -> primaryStage.close());
root1.add(exitBtn, 3, 3);
backBtn.setOnAction(e -> {
primaryStage.setScene(Receptionist.homepage);
readFromFile();
});
txt1.setOnKeyPressed(eh -> {
searchValue = txt1.getText().trim();
search();
});
Button deleteAllBtn = new Button("Delete All");
deleteAllBtn.setStyle("-fx-font-size: 15; -fx-background-color: #ffb000; -fx-text-fill: #0a0c26;");
deleteAllBtn.setOnAction(eh -> {
Alert confirmationAlert = new Alert(Alert.AlertType.CONFIRMATION);
confirmationAlert.setTitle("Confirmation");
confirmationAlert.setHeaderText("Delete All Bookings");
confirmationAlert.setContentText("Are you sure you want to delete all bookings?");
Optional<ButtonType> result = confirmationAlert.showAndWait();