-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotelSystem.cs
1280 lines (1219 loc) · 37.1 KB
/
HotelSystem.cs
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
using System.Xml.Serialization;
using System;
using System.IO;
[Serializable]
public class IOFiles
{
public void RoomsFile(List<Room> rooms = null)
{
if (rooms == null)
{
rooms = new List<Room>
{
new Room(442, "Single", 25, true),
new Room(102, "Double", 30, true),
new Room(506, "Double", 32, false),
new Room(702, "Suit", 40, true),
new Room(333, "Double", 34, true)
};
}
FileStream RoomsData = new FileStream("RoomsFile.txt", FileMode.Create, FileAccess.Write);
XmlSerializer serializer = new XmlSerializer(typeof(List<Room>));
serializer.Serialize(RoomsData, rooms);
RoomsData.Close();
}
public void GuestFile()
{
List<Guest> guests = new List<Guest>
{
new Guest("12345", "Omar", "11", 05215, 450),
new Guest("12546", "Khaled", "22", 01459, 550),
new Guest("16556", "Salma", "33", 04122, 660),
new Guest("18730", "Ahmad", "44", 02250, 720)
};
FileStream GuestsData = new FileStream("GuestsFile.txt", FileMode.Create, FileAccess.Write);
XmlSerializer serializer = new XmlSerializer(typeof(List<Guest>));
serializer.Serialize(GuestsData, guests);
GuestsData.Close();
}
public void ReservationFile()
{
FileStream ReservationData = new FileStream("ReservationFile.txt", FileMode.Create, FileAccess.Write);
List<Reservation> Reservation = new List<Reservation>();
XmlSerializer serializer = new XmlSerializer(typeof(List<Reservation>));
serializer.Serialize(ReservationData, Reservation);
ReservationData.Close();
}
public void ServiceFile()
{
FileStream ServiceData = new FileStream("ServiceFile.txt", FileMode.Create, FileAccess.Write);
List<Service> services = new List<Service>();
XmlSerializer serializer = new XmlSerializer(typeof(List<Service>));
serializer.Serialize(ServiceData, services);
ServiceData.Close();
}
public void PaymentFile()
{
FileStream PaymentData = new FileStream("PaymentFile.txt", FileMode.Create, FileAccess.Write);
List<Payment> payments = new List<Payment>();
XmlSerializer serializer = new XmlSerializer(typeof(List<Payment>));
serializer.Serialize(PaymentData, payments);
PaymentData.Close();
}
}
[Serializable]
public class Guest
{
public Guest(string ID, string Name, string Password, double PhoneNumber, double BankBalance)
{
this.ID = ID;
this.Name = Name;
this.Password = Password;
this.BankBalance = BankBalance;
this.PhoneNumber = PhoneNumber;
}
public Guest(string ID, string Password)
{
this.ID = ID;
this.Password = Password;
}
public Guest() { }
public string ID { get; set; }
public string Name { get; set; }
public string Password { get; set; }
public double PhoneNumber { get; set; }
public double BankBalance { get; set; }
public override string ToString()
{
return "Your name is : " + Name +
"\nYour ID is : " + ID +
"\nYour Phone Number is : " + PhoneNumber +
"\nYour Bank Balance is : " + BankBalance;
}
public void GuestFunctions(Guest guest)
{
bool exitGuestMenu = false;
while (!exitGuestMenu)
{
Console.WriteLine("\n");
Console.WriteLine("You're here to? Please Select a number...\n\n\n" +
"[1] Reserve a room\n" +
"[2] Check-In\n" +
"[3] Request a service\n" +
"[4] Check-Out\n" +
"[5] Pay for a reservation\n" +
"[6] Pay for a service\n" +
"[7] Log-Out");
Console.Write("Enter your choice : ");
int KindofUsage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
HotelSystem HS0 = new HotelSystem();
Reservation RS0 = new Reservation();
Service RV0 = new Service();
switch (KindofUsage)
{
case 1:
Reservation R0 = RS0.StartNewReservation(guest);
if (R0 != null)
{
HS0.AddReservation(R0);
}
break;
case 2:
string id0 = guest.ID;
Console.WriteLine(RS0.CheckInReservation(id0));
break;
case 3:
string id1 = guest.ID;
RV0.RequestAService(id1);
break;
case 4:
string id2 = guest.ID;
Console.WriteLine(RS0.CheckOutReservation(id2));
break;
case 5:
Payment PY0 = new Payment();
PY0.PayForReservation(guest);
break;
case 6:
Payment PY1 = new Payment();
PY1.PayForService(guest);
break;
case 7:
HS0.LogoutG();
exitGuestMenu = true;
break;
default:
Console.WriteLine("Try Again");
break;
}
}
}
public override bool Equals(object obj)
{
if (obj is Guest guest)
{
return ID == guest.ID && Password == guest.Password;
}
return false;
}
}
[Serializable]
public class Manager
{
public string ID
{
get;
set;
}
private string Password
{
get;
set;
}
public void ManagerFunctions()
{
bool exitManagerMenu = false;
while (!exitManagerMenu)
{
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
Console.WriteLine("You're here to? Pleas Select a number...\n\n\n" +
"[1] View all guests \n" +
"[2] View all reservations \n" +
"[3] View all services\n" +
"[4] View all payments \n" +
"[5] View all rooms\n" +
"[6] Update room information\n" +
"[7] Generate profit report\n" +
"[8] Log-Out");
Console.Write("Enter your choice : ");
int KindofUsage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
HotelSystem HS0 = new HotelSystem();
switch (KindofUsage)
{
case 1:
HS0.ViewAllGuests();
break;
case 2:
HS0.ViewAllReservations();
break;
case 3:
HS0.ViewAllServices();
break;
case 4:
HS0.ViewAllPayments();
break;
case 5:
HS0.ViewAllRooms();
break;
case 6:
Room RM0 = new Room();
RM0.UpdateRoomInfo();
break;
case 7:
Payment PY0 = new Payment();
PY0.GenerationOfProfitReport();
break;
case 8:
HS0.LogoutM();
exitManagerMenu = true;
break;
default:
Console.WriteLine("Try Again");
break;
}
}
}
}
[Serializable]
public class Service : Guest
{
public string SID { get; set; }
public int Notes { get; set; }
private string[] description = { "Car-Rental", "Kids-Zone" };
public string Description { get; set; }
public string GenerateUnique4DigitIDNumber()
{
HotelSystem hotelSystem = new HotelSystem();
List<Service> services = hotelSystem.LoadServicesFromFile();
int servicesCounter = services.Count;
servicesCounter++;
return servicesCounter.ToString("D4");
}
public Service RequestAService(string guestID)
{
Console.WriteLine("What Service do you want to get?");
int j = 1;
foreach (string option in description)
{
Console.WriteLine("[" + j + "]" + " " + option);
j++;
}
Console.Write("Enter your choice : ");
int op = Convert.ToInt32(Console.ReadLine());
if (op == 1)
{
Description = description[0];
Console.Write("Enter the number of rental days : ");
int notes = Convert.ToInt32(Console.ReadLine());
this.Notes = notes;
}
else if (op == 2)
{
Description = description[1];
Console.Write("Enter the number of kids : ");
int notes = Convert.ToInt32(Console.ReadLine());
this.Notes = notes;
}
else
{
Console.WriteLine("Enter Available service");
return null;
}
SID = GenerateUnique4DigitIDNumber();
this.ID = guestID;
HotelSystem HSS = new HotelSystem();
HSS.SaveServiceToFile(this);
string totalAmount = CalculateServiceAmount();
string amountString = totalAmount.Split(':')[1].Trim();
int amount;
double TA = Convert.ToDouble(amountString);
Payment payment = new Payment();
payment.CreateAndSavePaymentRecord("Service", TA, guestID);
Console.WriteLine($"Your service is confirmed.\nService ID: {this.SID}.\nYour bill number is: {payment.BillNumber}.\nYour bill amount is: {payment.TotalAmount}");
return this;
}
public string CalculateServiceAmount()
{
int TotalServiceAmount;
if (Description == description[0])
{
TotalServiceAmount = 10 * this.Notes;
return "Your service will cost : " + TotalServiceAmount;
}
else if (Description == description[1])
{
TotalServiceAmount = 5 * this.Notes;
return "Your service will cost : " + TotalServiceAmount;
}
return "Select valid option";
}
}
[Serializable]
public class Payment : Reservation
{
public string BillNumber
{
get;
set;
}
public double TotalAmount
{
get;
set;
}
public string PaymentSource
{
get;
set;
}
public string PaymentStatus
{
get;
set;
}
public Payment()
{
}
public bool IsbalancePayable(double TotalAmount, Guest g)
{
double Balance = g.BankBalance;
return TotalAmount <= Balance;
}
public void CreateAndSavePaymentRecord(string paymentSource, double totalAmount, string guestID)
{
this.BillNumber = GenerateUniqueBillNumber().ToString();
this.PaymentSource = paymentSource;
this.TotalAmount = totalAmount;
this.PaymentStatus = "not paid";
this.ID = guestID;
HotelSystem hotelSystem = new HotelSystem();
hotelSystem.AddPayment(this);
}
public string GenerateUniqueBillNumber()
{
HotelSystem hotelSystem = new HotelSystem();
List<Payment> payments = hotelSystem.LoadPaymentsFromFile();
int paymentCounter = payments.Count;
paymentCounter++;
return paymentCounter.ToString("D4");
}
public void PayForReservation(Guest guest)
{
HotelSystem hotelSystem = new HotelSystem();
List<Payment> payments = hotelSystem.LoadPaymentsFromFile();
var unpaidPayments = payments.Where(p => p.PaymentSource == "Reservation" && p.ID == guest.ID && p.PaymentStatus == "not paid").ToList();
if (unpaidPayments.Count == 0)
{
Console.WriteLine("No unpaid reservations found for the logged-in guest.");
return;
}
Console.WriteLine("Your unpaid reservations:");
foreach (Payment payment in unpaidPayments)
{
Console.WriteLine($"Bill Number: {payment.BillNumber}, Amount: {payment.TotalAmount}");
}
Console.Write("Enter the bill number to pay for: ");
string billNumber = Console.ReadLine();
var selectedPayment = unpaidPayments.FirstOrDefault(p => p.BillNumber == billNumber);
if (selectedPayment == null)
{
Console.WriteLine("Invalid bill number.");
return;
}
if (!IsbalancePayable(selectedPayment.TotalAmount, guest))
{
Console.WriteLine("Insufficient bank balance.");
return;
}
guest.BankBalance -= selectedPayment.TotalAmount;
selectedPayment.PaymentStatus = "paid";
hotelSystem.UpdateGuestInFile(guest);
hotelSystem.UpdatePaymentInFile(selectedPayment);
Console.WriteLine("Payment successful. Your reservation payment status is now 'paid'.");
}
public void PayForService(Guest guest)
{
HotelSystem hotelSystem = new HotelSystem();
List<Payment> payments = hotelSystem.LoadPaymentsFromFile();
var unpaidPayments = payments.Where(p => p.PaymentSource == "Service" && p.ID == guest.ID && p.PaymentStatus == "not paid").ToList();
if (unpaidPayments.Count == 0)
{
Console.WriteLine("No unpaid services found for the logged-in guest.");
return;
}
Console.WriteLine("Your unpaid services:");
foreach (Payment payment in unpaidPayments)
{
Console.WriteLine($"Bill Number: {payment.BillNumber}, Amount: {payment.TotalAmount}");
}
Console.Write("Enter the bill number to pay for: ");
string billNumber = Console.ReadLine();
var selectedPayment = unpaidPayments.FirstOrDefault(p => p.BillNumber == billNumber);
if (selectedPayment == null)
{
Console.WriteLine("Invalid bill number.");
return;
}
if (!IsbalancePayable(selectedPayment.TotalAmount, guest))
{
Console.WriteLine("Insufficient bank balance.");
return;
}
guest.BankBalance -= selectedPayment.TotalAmount;
selectedPayment.PaymentStatus = "paid";
hotelSystem.UpdateGuestInFile(guest);
hotelSystem.UpdatePaymentInFile(selectedPayment);
Console.WriteLine("Payment successful. Your service payment status is now 'paid'.");
}
public void GenerationOfProfitReport()
{
double totalRoomReservations = 0;
double totalCarRental = 0;
double totalKidsZone = 0;
HotelSystem HSP = new HotelSystem();
List<Payment> payments = HSP.LoadPaymentsFromFile();
var paidPayments = payments.Where(p => p.PaymentStatus == "paid").ToList();
foreach (Payment payment in paidPayments)
{
switch (payment.PaymentSource)
{
case "Reservation":
totalRoomReservations += payment.TotalAmount;
break;
case "Car-Rental":
totalCarRental += payment.TotalAmount;
break;
case "Kids-Zone":
totalKidsZone += payment.TotalAmount;
break;
}
}
Console.WriteLine("Profit Report:");
Console.WriteLine($"Total from Room Reservations: {totalRoomReservations}");
Console.WriteLine($"Total from Car Rental: {totalCarRental}");
Console.WriteLine($"Total from Kids Zone: {totalKidsZone}");
}
}
[Serializable]
public class Room : Guest
{
public int Number
{
get;
set;
}
public string Type
{
get;
set;
}
public double PricePerDay
{
get;
set;
}
public bool AvailabilityStatus
{
get;
set;
}
public Room(int Number, string Type, double PricePerDay, bool AvailabilityStatus)
{
this.Number = Number;
this.Type = Type;
this.PricePerDay = PricePerDay;
this.AvailabilityStatus = AvailabilityStatus;
}
public Room() { }
public void UpdateRoomInfo()
{
HotelSystem hotelSystem = new HotelSystem();
List<Room> rooms = hotelSystem.LoadRoomsFromFile();
Console.WriteLine("Available rooms:");
foreach (Room room in rooms)
{
Console.WriteLine($"Room Number: {room.Number}, Type: {room.Type}, Price per Day: {room.PricePerDay}");
}
Console.Write("Enter the room number to update: ");
int roomNumber = Convert.ToInt32(Console.ReadLine());
Room selectedRoom = rooms.FirstOrDefault(r => r.Number == roomNumber);
if (selectedRoom == null)
{
Console.WriteLine("Invalid room number.");
return;
}
Console.Write("Enter new type: ");
string newType = Console.ReadLine();
Console.Write("Enter new price per day: ");
double newPrice = Convert.ToDouble(Console.ReadLine());
selectedRoom.Type = newType;
selectedRoom.PricePerDay = newPrice;
using (FileStream RoomsDataSave = new FileStream("RoomsFile.txt", FileMode.Create, FileAccess.Write))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Room>));
serializer.Serialize(RoomsDataSave, rooms);
}
Console.WriteLine("Room information updated successfully.");
}
public bool AvailableRoomsOnly()
{
List<Room> list;
HotelSystem hS = new HotelSystem();
list = hS.LoadRoomsFromFile();
List<Room> AvailableRooms = new List<Room>();
foreach (Room i in list)
{
if (i.AvailabilityStatus)
{
AvailableRooms.Add(i);
}
}
int j = 1;
foreach (Room room in AvailableRooms)
{
Console.Write("[" + j + "]");
Console.WriteLine($" Room Number: {room.Number}, Room Type: {room.Type}");
j++;
}
Console.Write("Enter your choice : ");
string y0 = Console.ReadLine();
int y1 = Convert.ToInt32(y0);
Room RTBU = AvailableRooms[y1 - 1];
RTBU.AvailabilityStatus = false;
for (int i = 0; i < list.Count; i++)
{
if (list[i].Number == RTBU.Number)
{
list[i] = RTBU;
break;
}
}
IOFiles io = new IOFiles();
io.RoomsFile(list);
if (y0 != null)
{
return true;
}
return false;
}
}
[Serializable]
public class Reservation : Room
{
private static readonly string[] MealOptions = { "Break-fast", "Break-fast and Lunch", "Full-Board" };
public string RID { get; set; }
public DateTime CheckInDate { get; set; }
public DateTime CheckOutDate { get; set; }
public string MealOption { get; set; }
public string ReservationStatus { get; set; }
public Reservation(string RID, DateTime CheckInDate, DateTime CheckOutDate, string MealOption, string ReservationStatus, int Number, string Type, double PricePerDay, bool AvailabilityStatus) :
base(Number, Type, PricePerDay, AvailabilityStatus)
{
this.RID = RID;
this.CheckInDate = CheckInDate;
this.CheckOutDate = CheckOutDate;
this.MealOption = MealOption;
this.ReservationStatus = ReservationStatus;
}
public Reservation() { }
public string GenerateUnique4DigitIDNumber()
{
HotelSystem hotelSystem = new HotelSystem();
List<Reservation> reservations = hotelSystem.LoadReservationsFromFile();
int reservationCounter = reservations.Count;
reservationCounter++;
return reservationCounter.ToString("D4");
}
public Reservation StartNewReservation(Guest guest)
{
Console.WriteLine("Choose the appropriate room for your stay : ");
HotelSystem hotelSystem = new HotelSystem();
List<Room> availableRooms = hotelSystem.LoadRoomsFromFile().Where(r => r.AvailabilityStatus).ToList();
if (availableRooms.Count == 0)
{
Console.WriteLine("No available rooms.");
return null;
}
int roomIndex = 1;
foreach (Room room in availableRooms)
{
Console.WriteLine($"[{roomIndex}] Room Number: {room.Number}, Type: {room.Type}, Price per Day: {room.PricePerDay}");
roomIndex++;
}
Console.Write("Enter the number of the room you want to reserve: ");
int selectedRoomIndex = Convert.ToInt32(Console.ReadLine()) - 1;
if (selectedRoomIndex < 0 || selectedRoomIndex >= availableRooms.Count)
{
Console.WriteLine("Invalid room selection.");
return null;
}
Room selectedRoom = availableRooms[selectedRoomIndex];
Console.Write("Please enter your Check-In date (yyyy-MM-dd): ");
string checkInInput = Console.ReadLine();
DateTime checkInDate;
while (!DateTime.TryParseExact(checkInInput, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out checkInDate))
{
Console.WriteLine("Invalid date format. Please enter the date in the format yyyy-MM-dd.");
checkInInput = Console.ReadLine();
}
Console.Write("Please enter your Check-Out date (yyyy-MM-dd): ");
string checkOutInput = Console.ReadLine();
DateTime checkOutDate;
while (!DateTime.TryParseExact(checkOutInput, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out checkOutDate) || checkOutDate <= checkInDate)
{
Console.WriteLine("Invalid date format or Check-Out date must be later than Check-In date. Please enter a valid date.");
checkOutInput = Console.ReadLine();
}
Console.WriteLine("Select the meal option that suits you best : ");
int i = 1;
foreach (string option in MealOptions)
{
Console.WriteLine("[" + i + "] " + option);
i++;
}
Console.Write("Enter your choice : ");
int mealOptionIndex = Convert.ToInt32(Console.ReadLine());
while (mealOptionIndex < 1 || mealOptionIndex > MealOptions.Length)
{
Console.WriteLine("Invalid choice. Enter Available meal option.");
mealOptionIndex = Convert.ToInt32(Console.ReadLine());
}
string mealOption = MealOptions[mealOptionIndex - 1];
this.RID = GenerateUnique4DigitIDNumber();
this.CheckInDate = checkInDate;
this.CheckOutDate = checkOutDate;
this.MealOption = mealOption;
this.ReservationStatus = "Confirmed";
this.ID = guest.ID;
this.Number = selectedRoom.Number;
this.Type = selectedRoom.Type;
this.PricePerDay = selectedRoom.PricePerDay;
this.AvailabilityStatus = selectedRoom.AvailabilityStatus;
hotelSystem.AddReservation(this);
double totalAmount = CalculateReservationAmount();
Payment payment = new Payment();
payment.CreateAndSavePaymentRecord("Reservation", totalAmount, guest.ID);
selectedRoom.AvailabilityStatus = false;
hotelSystem.UpdateRoomFile(selectedRoom);
Console.WriteLine($"Your reservation is confirmed.\nReservation ID: {this.RID}.\nYour bill number is: {payment.BillNumber}.\nYour bill amount is: {payment.TotalAmount}");
return this;
}
public double CalculateReservationAmount()
{
TimeSpan residenceDays = this.CheckOutDate - this.CheckInDate;
int days = residenceDays.Days;
Console.WriteLine($"Your reservation is for {days} days.");
double amount = days * this.PricePerDay;
if (this.MealOption == MealOptions[0])
{
amount = amount;
}
else if (this.MealOption == MealOptions[1])
{
amount = 1.2 * amount;
}
else if (this.MealOption == MealOptions[2])
{
amount = 1.4 * amount;
}
if (this.CheckInDate == new DateTime(2025, 1, 2) ||
this.CheckInDate == new DateTime(2025, 4, 22) ||
this.CheckInDate == new DateTime(2025, 10, 10))
{
amount = ApplyDiscount(amount);
}
return amount;
}
public double ApplyDiscount(double amount)
{
Console.WriteLine("Congrats! You've got a discount!");
double FinalAmount = amount * 0.6;
return FinalAmount;
}
public string CheckInReservation(string guestID)
{
HotelSystem hotelSystem = new HotelSystem();
List<Reservation> reservations = hotelSystem.LoadReservationsFromFile();
List<Reservation> confirmedReservations = reservations
.Where(r => r.ID == guestID && r.ReservationStatus == "Confirmed")
.ToList();
if (confirmedReservations.Count == 0)
{
return "No confirmed reservations found for the logged-in guest.";
}
Console.WriteLine("Your confirmed reservations:");
for (int i = 0; i < confirmedReservations.Count; i++)
{
Console.WriteLine($"[{i + 1}] Reservation ID: {confirmedReservations[i].RID}, Check-in Date: {confirmedReservations[i].CheckInDate}, Check-out Date: {confirmedReservations[i].CheckOutDate}");
}
Console.Write("Enter the reservation ID to check-in: ");
string reservationID = Console.ReadLine();
Reservation selectedReservation = confirmedReservations.FirstOrDefault(r => r.RID == reservationID);
if (selectedReservation == null)
{
return "Invalid reservation ID.";
}
selectedReservation.ReservationStatus = "Checked-in";
hotelSystem.UpdateReservationInFile(selectedReservation);
return "Check-in successful. Your reservation status is now 'Checked-in'.";
}
public string CheckOutReservation(string guestID)
{
HotelSystem hotelSystem = new HotelSystem();
List<Reservation> reservations = hotelSystem.LoadReservationsFromFile();
List<Reservation> checkedInReservations = reservations
.Where(r => r.ID == guestID && r.ReservationStatus == "Checked-in")
.ToList();
if (checkedInReservations.Count == 0)
{
return "No checked-in reservations found for the logged-in guest.";
}
Console.WriteLine("Your checked-in reservations:");
for (int i = 0; i < checkedInReservations.Count; i++)
{
Console.WriteLine($"[{i + 1}] Reservation ID: {checkedInReservations[i].RID}, Room Number: {checkedInReservations[i].Number}, Check-in Date: {checkedInReservations[i].CheckInDate}, Check-out Date: {checkedInReservations[i].CheckOutDate}");
}
Console.Write("Enter the reservation ID to check-out: ");
string reservationID = Console.ReadLine();
Reservation selectedReservation = checkedInReservations.FirstOrDefault(r => r.RID == reservationID);
if (selectedReservation == null)
{
return "Invalid reservation ID.";
}
selectedReservation.ReservationStatus = "Checked-out";
Room room = hotelSystem.LoadRoomsFromFile().FirstOrDefault(r => r.Number == selectedReservation.Number);
if (room != null)
{
room.AvailabilityStatus = true;
hotelSystem.SaveRoomToFile(room);
}
hotelSystem.UpdateReservationInFile(selectedReservation);
return "Check-out successful. Your reservation status is now 'Checked-out'.";
}
}
[Serializable]
public class HotelSystem
{
private List<Guest> Guests;
private List<Room> Rooms;
private List<Reservation> Reservations;
private List<Payment> Payments;
private List<Service> Services;
private IOFiles ioFiles;
public HotelSystem()
{
ioFiles = new IOFiles();
ReloadData();
}
public void ReloadData()
{
if (!File.Exists("RoomsFile.txt") || new FileInfo("RoomsFile.txt").Length == 0)
{
ioFiles.RoomsFile();
}
Rooms = LoadRoomsFromFile();
if (!File.Exists("GuestsFile.txt") || new FileInfo("GuestsFile.txt").Length == 0)
{
ioFiles.GuestFile();
}
Guests = LoadGuestsFromFile();
if (!File.Exists("ReservationFile.txt") || new FileInfo("ReservationFile.txt").Length == 0)
{
ioFiles.ReservationFile();
}
Reservations = LoadReservationsFromFile();
if (!File.Exists("ServiceFile.txt") || new FileInfo("ServiceFile.txt").Length == 0)
{
ioFiles.ServiceFile();
}
Services = LoadServicesFromFile();
if (!File.Exists("PaymentFile.txt") || new FileInfo("PaymentFile.txt").Length == 0)
{
ioFiles.PaymentFile();
}
Payments = LoadPaymentsFromFile();
}
public void ViewAllGuests()
{
if (Guests != null && Guests.Count > 0)
{
int v = 1;
foreach (Guest guest in Guests)
{
Console.Write("[" + v + "]");
Console.WriteLine(
$" Guest Name : {guest.Name}," +
$" Guest Phone-Number : {guest.PhoneNumber}," +
$" Guest National-ID : {guest.ID}," +
$" Guest Bank-Balance : {guest.BankBalance}," +
$" Guest Password : {guest.Password}"
);
v++;
}
}
else
{
Console.WriteLine("No Guests Yet");
}
}
public void ViewAllServices()
{
if (Services != null && Services.Count > 0)
{
int v = 1;
foreach (Service service in Services)
{
Console.Write("[" + v + "]");
Console.WriteLine(
$" Service ID : {service.SID}," +
$" Service Description : {service.Description}," +
$" Service Notes : {service.Notes}," +
$" Guest's national ID (who order this service) : {service.ID}"
);
v++;
}
}
else
{
Console.WriteLine("No Services Yet");
}
}
public void ViewAllPayments()
{
if (Payments != null && Payments.Count > 0)
{
int v = 1;
foreach (Payment payment in Payments)
{
Console.Write("[" + v + "]");
Console.WriteLine(
$" Bill Number : {payment.BillNumber}," +
$" Payment Source : {payment.PaymentSource}," +
$" Payment Status : {payment.PaymentStatus}," +
$" Total Amount : {payment.TotalAmount}," +
$" Guest's national ID (who made this payment) : {payment.ID}"
);
v++;
}
}
else
{
Console.WriteLine("No Payments Yet");
}
}
public void ViewAllReservations()
{
if (Reservations != null && Reservations.Count > 0)
{
int v = 1;
foreach (Reservation reservation in Reservations)
{
Console.Write("[" + v + "]");
Console.WriteLine(
$" Reservation ID : {reservation.RID}," +
$" Check-in Date : {reservation.CheckInDate}," +
$" Check-out Date : {reservation.CheckOutDate}," +
$" Reservation Status : {reservation.ReservationStatus}," +
$" Meals Option : {reservation.MealOption}," +
$" Guest's national ID (who reserved this room) : {reservation.ID}," +
$" Room Number : {reservation.Number}"
);
v++;
}
}
else
{
Console.WriteLine("No Reservations Yet");
}
}
public void ViewAllRooms()
{
if (Rooms != null && Rooms.Count > 0)
{
int v = 1;
foreach (Room room in Rooms)
{
Console.Write("[" + v + "]");
Console.WriteLine(
$" Room Number: {room.Number}," +
$" Room Type: {room.Type}," +
$" Room Price-per Day: {room.PricePerDay}," +
$" Room Availability Status: {room.AvailabilityStatus}"
);
v++;
}
}
else
{
Console.WriteLine("No Rooms Yet");
}
}
public void UpdateReservationInFile(Reservation updatedReservation)
{
List<Reservation> reservations = LoadReservationsFromFile();
int i = reservations.FindIndex(r => r.RID == updatedReservation.RID);
if (i != -1)
{
reservations[i] = updatedReservation;
using (FileStream ReservationsDataSave = new FileStream("ReservationFile.txt", FileMode.Create, FileAccess.Write))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Reservation>));
serializer.Serialize(ReservationsDataSave, reservations);
}
}
}
public void UpdateRoomFile(Room updatedRoom)
{
List<Room> rooms = LoadRoomsFromFile();
int roomIndex = rooms.FindIndex(r => r.Number == updatedRoom.Number);
if (roomIndex != -1)
{
rooms[roomIndex] = updatedRoom;
using (FileStream RoomsDataSave = new FileStream("RoomsFile.txt", FileMode.Create, FileAccess.Write))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Room>));
serializer.Serialize(RoomsDataSave, rooms);
}
}
}
public void UpdateGuestInFile(Guest updatedGuest)
{
List<Guest> guests = LoadGuestsFromFile();
int i = guests.FindIndex(g => g.ID == updatedGuest.ID);
if (i != -1)
{
guests[i] = updatedGuest;
using (FileStream GuestsDataSave = new FileStream("GuestsFile.txt", FileMode.Create, FileAccess.Write))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Guest>));
serializer.Serialize(GuestsDataSave, guests);
}
}
}
public void UpdatePaymentInFile(Payment updatedPayment)
{
List<Payment> payments = LoadPaymentsFromFile();
int i = payments.FindIndex(p => p.BillNumber == updatedPayment.BillNumber);
if (i != -1)
{
payments[i] = updatedPayment;
using (FileStream PaymentsDataSave = new FileStream("PaymentFile.txt", FileMode.Create, FileAccess.Write))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Payment>));
serializer.Serialize(PaymentsDataSave, payments);
}
}
}