From 0a5fa3e4022511cee285f464baf6b24bb9ed4728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B2=E8=8F=AF?= <42814579+yunwah@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:55:38 -0400 Subject: [PATCH] Updateed some formatting and bug fixes Fixed inconsistencies in queries that would result in errors because the parameters were missing. Updating a guest is an example that had this issue. After checking parameters should all be supplied where needed. --- OpheliasOasis/Managers/Hotel.cs | 15 ++++++++++----- OpheliasOasis/Models/Guest.cs | 1 + OpheliasOasis/Program.cs | 14 ++++++++++++++ OpheliasOasis/Reporting/Accommodation.cs | 6 +++--- OpheliasOasis/Reporting/Management.cs | 14 +++++++------- OpheliasOasis/Reporting/Operational.cs | 2 +- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/OpheliasOasis/Managers/Hotel.cs b/OpheliasOasis/Managers/Hotel.cs index 2f0fe26..a518feb 100644 --- a/OpheliasOasis/Managers/Hotel.cs +++ b/OpheliasOasis/Managers/Hotel.cs @@ -51,9 +51,10 @@ namespace Ophelias.Managers using SQLiteDataReader reader = cmd.ExecuteReader(); // Create a new reader to read the SQL data while (reader.Read()) { - foreach (int item in reader.GetValues()) + foreach (var item in reader.GetValues()) { - previousOccupancies.Add(item); + if (item.GetType().Equals(typeof(int))) + previousOccupancies.Add((int)item); } } } @@ -554,8 +555,12 @@ namespace Ophelias.Managers using (Database Manager = new()) // Opens a database connection { using SQLiteCommand cmd = Manager.con.CreateCommand(); // Creates a new command - cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (@Status1,@Status2)"; + cmd.CommandText = "SELECT * FROM reservations " + + "INNER JOIN guests ON reservations.GuestID = guests.ID " + + "WHERE Email = @Email AND Status IN (@Status1,@Status2)"; cmd.Parameters.AddWithValue("@Email", Email); + cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active); + cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed); using SQLiteDataReader reader = cmd.ExecuteReader(); // Creates a new SQL data reader reader.Read(); if (reader.HasRows) @@ -798,7 +803,7 @@ namespace Ophelias.Managers * occupied as a guest has been assigned it. */ cmd.CommandText = "UPDATE rooms SET Occupied = 1 " + - "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));"; + "WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));"; cmd.Parameters.AddWithValue("@Email", Email); cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active); cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed); @@ -818,7 +823,7 @@ namespace Ophelias.Managers reader.Read(); if (reader.HasRows) { - RoomID = (int)reader.GetValue(0); + RoomID = reader.GetInt32(0); } } Transaction.Commit(); // Commits the transaction diff --git a/OpheliasOasis/Models/Guest.cs b/OpheliasOasis/Models/Guest.cs index 9dc015b..498eab5 100644 --- a/OpheliasOasis/Models/Guest.cs +++ b/OpheliasOasis/Models/Guest.cs @@ -80,6 +80,7 @@ namespace Ophelias.Models { using SQLiteCommand cmd = Manager.con.CreateCommand(); // Creates a new command that will be executed in the database cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV); + cmd.Parameters.AddWithValue("@Id", Id); cmd.Parameters.AddWithValue("@Fname", FirstName); cmd.Parameters.AddWithValue("@Lname", LastName); cmd.Parameters.AddWithValue("@Email", Email); diff --git a/OpheliasOasis/Program.cs b/OpheliasOasis/Program.cs index d8928e8..e74b171 100644 --- a/OpheliasOasis/Program.cs +++ b/OpheliasOasis/Program.cs @@ -576,6 +576,19 @@ internal class Program Console.WriteLine("You currently do not have an active registration."); return; } + if (activeReservation.StartDate.Date < DateTime.Now.Date && activeReservation.CheckIn == null) + { + Console.WriteLine("Your reservation is no longer valid, it has been cancelled. You may be charged based on your reservation type."); + activeReservation.CancelReservation(); + activeReservation = null; + return; + } + if (activeReservation.CheckIn != null) + { + Console.WriteLine("You can't update a reservation that has been checked in."); + return; + } + Console.Write("Your current reservation details are:\n" + $"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")}\n" + @@ -711,6 +724,7 @@ internal class Program } activeReservation.CancelReservation(); Console.WriteLine("Your reservation has been cancelled because you failed to pay within the payment period."); + activeReservation = null; return; } } diff --git a/OpheliasOasis/Reporting/Accommodation.cs b/OpheliasOasis/Reporting/Accommodation.cs index 59d93ea..2c13581 100644 --- a/OpheliasOasis/Reporting/Accommodation.cs +++ b/OpheliasOasis/Reporting/Accommodation.cs @@ -15,10 +15,10 @@ namespace Ophelias.Reporting { string report = $"ACCOMMODATION BILL - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + $"Name: {r.Guest.LastName}, {r.Guest.FirstName}\n" + - $"Arrival Date: {r.StartDate}\n" + - $"Departure Date: {r.EndDate}\n" + + $"Arrival Date: {r.StartDate.Date.ToString("yyyy-MM-dd")}\n" + + $"Departure Date: {r.EndDate.Date.ToString("yyyy-MM-dd")}\n" + $"Length of Stay: {(int)(r.EndDate.Date - r.StartDate.Date).TotalDays} days\n" + - $"Charged: ${r.Transaction.Owed}\n\n"; + $"Charged: ${Math.Round(r.Transaction.Owed, 2)}\n\n"; File.AppendAllText(Path.GetFullPath("AccommodationBills.txt"), report); } } diff --git a/OpheliasOasis/Reporting/Management.cs b/OpheliasOasis/Reporting/Management.cs index ea4b6d4..8d8730d 100644 --- a/OpheliasOasis/Reporting/Management.cs +++ b/OpheliasOasis/Reporting/Management.cs @@ -27,7 +27,7 @@ namespace Ophelias.Reporting string report = $"EXPECTED 30 DAY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + $"Date\tRooms Filled\tConventional\tPrepaid\t60-Day\tIncentive\n" + $"{string.Join("\n", entries)}\n" + // Combine entries at this location in the string - $"Average Occupancy Rate: {average}\n\n"; + $"Average Occupancy Rate: {Math.Round(average, 2)}\n\n"; File.AppendAllText(Path.GetFullPath("ExpectedOccupancy.txt"), report); // Write to file } @@ -40,13 +40,13 @@ namespace Ophelias.Reporting List entries = new(); foreach (var x in items) // Build a list of entries { - entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}"); + entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{Math.Round(x.Item2, 2)}"); } string report = $"EXPECTED 30 DAY INCOME REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + $"Date\tIncome\n" + $"{string.Join("\n", entries)}\n" + // Combine entries at this location in the string - $"Average Income: {average}\n" + - $"Total Income: {totalIncome}\n\n"; + $"Average Income: {Math.Round(average, 2)}\n" + + $"Total Income: {Math.Round(totalIncome, 2)}\n\n"; File.AppendAllText(Path.GetFullPath("ExpectedIncome.txt"), report); // Write to file } @@ -59,13 +59,13 @@ namespace Ophelias.Reporting List entries = new(); foreach (var x in items) // Build a list of entries { - entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}"); + entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{Math.Round(x.Item2, 2)}"); } string report = $"EXPECTED 30 DAY LOSSES (TO INCENTIVE) REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + $"Date\tLosses\n" + $"{string.Join("\n", entries)}\n" + // Combine entries at this location in the string - $"Average Losses (Due to incentive): {average}\n" + - $"Total Losses (Due to incentive): {totalLosses}\n\n"; + $"Average Losses (Due to incentive): {Math.Round(average, 2)}\n" + + $"Total Losses (Due to incentive): {Math.Round(totalLosses, 2)}\n\n"; File.AppendAllText(Path.GetFullPath("IncentiveLosses.txt"), report); // Write to file } diff --git a/OpheliasOasis/Reporting/Operational.cs b/OpheliasOasis/Reporting/Operational.cs index 51b1711..8a296b8 100644 --- a/OpheliasOasis/Reporting/Operational.cs +++ b/OpheliasOasis/Reporting/Operational.cs @@ -36,7 +36,7 @@ namespace Ophelias.Reporting roominfo = r.RoomNum.Value.ToString(); } - entries.Add($"{r.Guest.LastName}, {r.Guest.FirstName}\t{r.Type}\t{roominfo}\t{r.EndDate}"); + entries.Add($"{r.Guest.LastName}, {r.Guest.FirstName}\t{r.Type}\t{roominfo}\t{r.EndDate.Date.ToString("yyyy-MM-dd")}"); } string report = $"DAILY ARRIVAL REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" + $"Last, First\tType\tRoom\tDeparture\n" +