Finishes the guest part of the models and UI integration
This commit branch has been muddled with changes that are out of scope and cover more than just the models. Specifically it includes completion of basic guest related models, database access, command line interface integration and preventing SQL injection. Total summary of changes: **IMPORTANT CHANGE: All queries are now parameterized to prevent SQL injections. Prior versions are subject to it since the strings were built. - HotelManager This class is used to provide database operations that are outside of scope from a given model. Furthermore if there is no model to work off of, such as creating a new model based off an existing entry, these functions live outside of the model since it makes no sense for models to contain functions where it would retrieve itself with no context. Realistically this could be placed in an empty constructor and address itself, however, for now this functionality has been moved off the model since it is a one use and is not guaranteed to generate a guest. Some functionality for the coming employee management functions are already in there since they share overlap with the guest module. Specifically GetBaseRate for checking and getting the base rate. - DatabaseManager This class has mostly migrated functionality out or switch to parameterized query generation to prevent SQL injections. - Guest, Reservation, and Transaction Classes Migrated functionality to create the database entry and a new entry of guest upon creation as well as update them. - Program (Terminal app) Fully integrated the guest module. Has not undergone extensive testing but does work as of this commit.
This commit is contained in:
@@ -27,30 +27,30 @@ namespace Ophelias.Managers
|
|||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
[Rate] INTEGER NOT NULL,
|
[Rate] INTEGER NOT NULL,
|
||||||
[Owed] INTEGER NOT NULL,
|
[Owed] INTEGER NOT NULL,
|
||||||
[Penalty] INTEGER NULL,
|
[Penalty] INTEGER NOT NULL,
|
||||||
[Multiplier] INTEGER NOT NULL,
|
[Multiplier] INTEGER NOT NULL,
|
||||||
[RefundAmount] INTEGER NOT NULL,
|
[RefundAmount] INTEGER NOT NULL,
|
||||||
[PayBy] TEXT NOT NULL,
|
[PayBy] TEXT NOT NULL,
|
||||||
[LastPaid] TEXXT NULL,
|
[LastPaid] TEXT NULL,
|
||||||
[PaidOn] TEXT NULL);
|
[PaidOn] TEXT NULL);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS [reservations] (
|
CREATE TABLE IF NOT EXISTS [reservations] (
|
||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
[RoomID] INTEGER NOT NULL,
|
[RoomNum] INTEGER NULL UNIQUE,
|
||||||
[GuestID] INTEGER NOT NULL,
|
[GuestID] INTEGER NOT NULL UNIQUE,
|
||||||
[TransactionID] INTEGER NOT NULL,
|
[TransactionID] INTEGER NOT NULL UNIQUE,
|
||||||
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
|
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
|
||||||
[Type] INTEGER NOT NULL CHECK ([Type] IN (0,1,2,3)),
|
[Type] INTEGER NOT NULL CHECK ([Type] IN (0,1,2,3)),
|
||||||
[Status] INTEGER NOT NULL CHECK ([Status] IN (0,1,2,3)),
|
[Status] INTEGER NOT NULL CHECK ([Status] IN (0,1,2,3)),
|
||||||
[CreationDate] TEXT NOT NULL,
|
[CreationDate] TEXT NOT NULL,
|
||||||
[StartDate] TEXT NOT NULL,
|
[StartDate] TEXT NOT NULL,
|
||||||
[EndDate] TEXT NOT NULL,
|
[EndDate] TEXT NOT NULL,
|
||||||
[CheckIn] TEXT NOT NULL,
|
[CheckIn] TEXT NULL,
|
||||||
[CheckOut] TEXT NOT NULL,
|
[CheckOut] TEXT NULL,
|
||||||
[DateChanged] TEXT NOT NULL,
|
[DateChanged] TEXT NULL,
|
||||||
FOREIGN KEY ([RoomID]) REFERENCES ROOMS(ID),
|
FOREIGN KEY ([RoomNum]) REFERENCES rooms(ID),
|
||||||
FOREIGN KEY ([GuestID]) REFERENCES GUESTS(ID),
|
FOREIGN KEY ([GuestID]) REFERENCES guests(ID),
|
||||||
FOREIGN KEY ([TransactionID]) REFERENCES TRANSACTIONS(ID));
|
FOREIGN KEY ([TransactionID]) REFERENCES transactions(ID));
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS [guests] (
|
CREATE TABLE IF NOT EXISTS [guests] (
|
||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -98,10 +98,6 @@ namespace Ophelias.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class DatabaseFunctions
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
internal static class QueryBuilder
|
internal static class QueryBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -114,24 +110,24 @@ namespace Ophelias.Managers
|
|||||||
string query = "UPDATE transactions SET";
|
string query = "UPDATE transactions SET";
|
||||||
|
|
||||||
if (Rate.HasValue)
|
if (Rate.HasValue)
|
||||||
queryComponents.Add($"Rate = {Rate}");
|
queryComponents.Add($"Rate = @Rate");
|
||||||
if (Owed.HasValue)
|
if (Owed.HasValue)
|
||||||
queryComponents.Add($"Owed = {Owed}");
|
queryComponents.Add($"Owed = @Owed");
|
||||||
if (Penalty.HasValue)
|
if (Penalty.HasValue)
|
||||||
queryComponents.Add($"Penalty = {Penalty}");
|
queryComponents.Add($"Penalty = @Penalty");
|
||||||
if (Multiplier.HasValue)
|
if (Multiplier.HasValue)
|
||||||
queryComponents.Add($"Multiplier = {Multiplier}");
|
queryComponents.Add($"Multiplier = @Multiplier");
|
||||||
if (Refund.HasValue)
|
if (Refund.HasValue)
|
||||||
queryComponents.Add($"Refund = {Refund}");
|
queryComponents.Add($"Refund = @Refund");
|
||||||
if (PayBy.HasValue)
|
if (PayBy.HasValue)
|
||||||
queryComponents.Add($"PayBy = {PayBy.Value.Date.ToString("yyyy-MM-dd")}");
|
queryComponents.Add($"PayBy = @PayBy");
|
||||||
if (LastPaid.HasValue)
|
if (LastPaid.HasValue)
|
||||||
queryComponents.Add($"LastPaid = {LastPaid.Value.Date.ToString("yyyy-MM-dd")}");
|
queryComponents.Add($"LastPaid = @LastPaid");
|
||||||
if (PaidOn.HasValue)
|
if (PaidOn.HasValue)
|
||||||
queryComponents.Add($"PaidOn = {PaidOn.Value.Date.ToString("yyyy-MM-dd")}");
|
queryComponents.Add($"PaidOn = @PaidOn");
|
||||||
|
|
||||||
if (queryComponents.Count > 0)
|
if (queryComponents.Count > 0)
|
||||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {Id};";
|
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = @ID;";
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -147,83 +143,58 @@ namespace Ophelias.Managers
|
|||||||
string query = "UPDATE reservations SET";
|
string query = "UPDATE reservations SET";
|
||||||
|
|
||||||
if (RoomID.HasValue)
|
if (RoomID.HasValue)
|
||||||
QueryParts.Add($"RoomID = {RoomID}");
|
QueryParts.Add($"RoomID = @RID");
|
||||||
if (GuestID.HasValue)
|
if (GuestID.HasValue)
|
||||||
QueryParts.Add($"GuestID = {GuestID}");
|
QueryParts.Add($"GuestID = @GID");
|
||||||
if (TransactionID.HasValue)
|
if (TransactionID.HasValue)
|
||||||
QueryParts.Add($"TransactionID = {TransactionID}");
|
QueryParts.Add($"TransactionID = @TID");
|
||||||
if (IsNoShow.HasValue)
|
if (IsNoShow.HasValue)
|
||||||
QueryParts.Add($"IsNoShow = {Convert.ToInt32(IsNoShow)}");
|
QueryParts.Add($"IsNoShow = @IsNoShow");
|
||||||
if (Type.HasValue)
|
if (Type.HasValue)
|
||||||
QueryParts.Add($"Type = {(int)Type}");
|
QueryParts.Add($"Type = @Type");
|
||||||
if (Status.HasValue)
|
if (Status.HasValue)
|
||||||
QueryParts.Add($"Status = {(int)Status}");
|
QueryParts.Add($"Status = @Status");
|
||||||
if (CreationDate.HasValue)
|
if (CreationDate.HasValue)
|
||||||
QueryParts.Add($"CreationDate = {CreationDate.Value.Date.ToString("yyyy-MM-dd")}");
|
QueryParts.Add($"CreationDate = @CreationDate");
|
||||||
if (StartDate.HasValue)
|
if (StartDate.HasValue)
|
||||||
QueryParts.Add($"StartDate = {StartDate.Value.Date.ToString("yyyy-MM-dd")}");
|
QueryParts.Add($"StartDate = @StartDate");
|
||||||
if (EndDate.HasValue)
|
if (EndDate.HasValue)
|
||||||
QueryParts.Add($"EndDate = {EndDate.Value.Date.ToString("yyyy-MM-dd")}");
|
QueryParts.Add($"EndDate = @EndDate");
|
||||||
if (CheckIn.HasValue)
|
if (CheckIn.HasValue)
|
||||||
QueryParts.Add($"CheckIn = {CheckIn.Value.Date.ToString("yyyy-MM-dd")}");
|
QueryParts.Add($"CheckIn = @CheckIn");
|
||||||
if (CheckOut.HasValue)
|
if (CheckOut.HasValue)
|
||||||
QueryParts.Add($"CheckOut = {CheckOut.Value.Date.ToString("yyyy-MM-dd")}");
|
QueryParts.Add($"CheckOut = @CheckOut");
|
||||||
if (DateChanged.HasValue)
|
if (DateChanged.HasValue)
|
||||||
QueryParts.Add($"DateChanged = {DateChanged.Value.Date.ToString("yyyy-MM-dd")}");
|
QueryParts.Add($"DateChanged = @DateChanged");
|
||||||
|
|
||||||
if (QueryParts.Count > 0)
|
if (QueryParts.Count > 0)
|
||||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
|
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string CreateTransaction(double Rate, double Owed,
|
|
||||||
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
|
||||||
DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn)
|
|
||||||
VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {PayBy}, {PayBy}, {PaidOn});";
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string CreateReservation(int guestid, int transactionid, ReservationType type,
|
|
||||||
ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
|
|
||||||
DateTime? checkin = null, DateTime? checkout = null, DateTime? datechanged = null, bool? isnoshow = false)
|
|
||||||
{
|
|
||||||
return @$"INSERT INTO reservations (GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
|
|
||||||
VALUES ({guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string CreateGuest(string FirstName, string LastName, string Email, string? CreditCard, string? Expiration, string? CCV)
|
|
||||||
{
|
|
||||||
if (CreditCard != null && Expiration != null && CCV != null)
|
|
||||||
return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ('{FirstName}', '{LastName}', '{Email}', '{CreditCard}', '{Expiration}', '{CCV}');";
|
|
||||||
else
|
|
||||||
return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ('{FirstName}', '{LastName}', '{Email}');";
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string? UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
internal static string? UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||||
{
|
{
|
||||||
List<string> QueryParts = new List<string>();
|
List<string> QueryParts = new List<string>();
|
||||||
string query = "UPDATE guests SET";
|
string query = "UPDATE guests SET";
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(FirstName))
|
if (!string.IsNullOrEmpty(FirstName))
|
||||||
QueryParts.Add($"Fname = '{FirstName}'");
|
QueryParts.Add($"Fname = @Fname");
|
||||||
if (!string.IsNullOrEmpty(LastName))
|
if (!string.IsNullOrEmpty(LastName))
|
||||||
QueryParts.Add($"Lname = '{LastName}'");
|
QueryParts.Add($"Lname = @Lname");
|
||||||
if (!string.IsNullOrEmpty(LastName))
|
if (!string.IsNullOrEmpty(LastName))
|
||||||
QueryParts.Add($"Email = '{Email}'");
|
QueryParts.Add($"Email = @Email");
|
||||||
if (!string.IsNullOrEmpty(CreditCard))
|
if (!string.IsNullOrEmpty(CreditCard))
|
||||||
QueryParts.Add($"CreditCard = '{CreditCard}'");
|
QueryParts.Add($"CreditCard = @CC");
|
||||||
if (!string.IsNullOrEmpty(Expiration))
|
if (!string.IsNullOrEmpty(Expiration))
|
||||||
QueryParts.Add($"Expiration = '{Expiration}'");
|
QueryParts.Add($"Expiration = @Expiry");
|
||||||
if (!string.IsNullOrEmpty(CCV))
|
if (!string.IsNullOrEmpty(CCV))
|
||||||
QueryParts.Add($"CCV = '{CCV}'");
|
QueryParts.Add($"CCV = @CCV");
|
||||||
|
|
||||||
if (QueryParts.Count > 0)
|
if (QueryParts.Count > 0)
|
||||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
|
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name='{tableName}';";
|
cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name=@Table;";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.AddWithValue("@Table", tableName);
|
||||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
reader.Read();
|
reader.Read();
|
||||||
LastId = reader.GetInt32(0);
|
if (reader.HasRows)
|
||||||
|
LastId = reader.GetInt32(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,13 +34,15 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
cmd.CommandText = $@"SELECT COUNT(*)
|
cmd.CommandText = $@"SELECT COUNT(*)
|
||||||
FROM reservations
|
FROM reservations
|
||||||
WHERE DATE('{Date.Date.ToString("yyyy-MM-dd")}')
|
WHERE DATE(@Date)
|
||||||
BETWEEN StartDate AND EndDate;";
|
BETWEEN StartDate AND EndDate;";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.AddWithValue("@Date", Date.Date.ToString("yyyy-MM-dd"));
|
||||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
reader.Read();
|
reader.Read();
|
||||||
Occupancies.Add(reader.GetInt32(0));
|
if (reader.Read())
|
||||||
|
Occupancies.Add(reader.GetInt32(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +51,7 @@ namespace Ophelias.Managers
|
|||||||
internal static int AvgOccupancySpan(DateTime Start, DateTime End)
|
internal static int AvgOccupancySpan(DateTime Start, DateTime End)
|
||||||
{
|
{
|
||||||
int thirtyDayOcc = 0;
|
int thirtyDayOcc = 0;
|
||||||
int days = (int)(Start.Date - End.Date).TotalDays;
|
int days = (int)(End.Date - Start.Date).TotalDays;
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
{
|
{
|
||||||
for (int i = 0; i < days; i++)
|
for (int i = 0; i < days; i++)
|
||||||
@@ -56,95 +60,21 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
cmd.CommandText = $@"SELECT COUNT(*)
|
cmd.CommandText = $@"SELECT COUNT(*)
|
||||||
FROM reservations
|
FROM reservations
|
||||||
WHERE DATE('{Start.AddDays(i).Date.ToString("yyyy-MM-dd")}')
|
WHERE DATE(@Date)
|
||||||
BETWEEN StartDate AND EndDate;";
|
BETWEEN StartDate AND EndDate;";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
||||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
reader.Read();
|
reader.Read();
|
||||||
thirtyDayOcc += reader.GetInt32(0);
|
if(reader.HasRows)
|
||||||
|
thirtyDayOcc += reader.GetInt32(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return thirtyDayOcc / days;
|
return thirtyDayOcc / days;
|
||||||
}
|
}
|
||||||
internal static Reservation CreateReservation(Guest Guest, ReservationType Type,
|
|
||||||
DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active)
|
|
||||||
{
|
|
||||||
int id; double Multiplier;
|
|
||||||
switch (Type)
|
|
||||||
{
|
|
||||||
case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
|
|
||||||
case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
|
|
||||||
case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
|
|
||||||
case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
|
|
||||||
default: throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
Transaction t = CreateTransaction(
|
|
||||||
Rate: GetBaseRate(),
|
|
||||||
Owed: TxFunctions.CalculateOwed(GetBaseRate(), (int)(StartDate.Date - EndDate.Date).TotalDays),
|
|
||||||
Multiplier: Multiplier,
|
|
||||||
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
|
|
||||||
);
|
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
||||||
{
|
|
||||||
cmd.CommandText = QueryBuilder.CreateReservation(Guest.Id, t.Id, Type,
|
|
||||||
Status, CreationDate, StartDate, EndDate);
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
id = (int)Manager.con.LastInsertRowId;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Reservation(id, Guest, t, Type, Status, CreationDate, StartDate, EndDate);
|
|
||||||
}
|
|
||||||
internal static Transaction CreateTransaction(double Rate, double Owed,
|
|
||||||
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
|
||||||
DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
|
|
||||||
{
|
|
||||||
int Id;
|
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
||||||
{
|
|
||||||
cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy,Refund: Refund, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
Id = (int)Manager.con.LastInsertRowId;
|
|
||||||
}
|
|
||||||
return new Transaction(Id, Rate, Owed, Multiplier, Penalty: Penalty, RefundAmount: Refund, PayBy: PayBy, PaidOn: PaidOn);
|
|
||||||
}
|
|
||||||
internal static Guest CreateGuest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
|
||||||
{
|
|
||||||
int Id;
|
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
||||||
{
|
|
||||||
cmd.CommandText = QueryBuilder.CreateGuest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
Id = (int)Manager.con.LastInsertRowId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CreditCard != null && Expiration != null && CCV != null)
|
|
||||||
return new Guest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
|
||||||
else
|
|
||||||
return new Guest(Id, FirstName, LastName, Email);
|
|
||||||
}
|
|
||||||
internal static void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
|
||||||
{
|
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
|
||||||
{
|
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
|
||||||
{
|
|
||||||
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal static Guest? GetGuestByEmail(string Email)
|
internal static Guest? GetGuestByEmail(string Email)
|
||||||
{
|
{
|
||||||
Guest? g = null;
|
Guest? g = null;
|
||||||
@@ -152,7 +82,8 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = $"SELECT * FROM guests WHERE email = '{Email}'";
|
cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
|
||||||
|
cmd.Parameters.AddWithValue("@Email", Email);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@@ -173,9 +104,57 @@ namespace Ophelias.Managers
|
|||||||
}
|
}
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
internal static double GetBaseRate()
|
internal static Reservation? GetResByGuestAndDate(Guest g)
|
||||||
{
|
{
|
||||||
double rate;
|
Reservation? r = null;
|
||||||
|
Transaction? t;
|
||||||
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
|
{
|
||||||
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
|
{
|
||||||
|
int? RoomNumber = null;
|
||||||
|
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
|
||||||
|
|
||||||
|
cmd.CommandText = @"SELECT * FROM reservations
|
||||||
|
INNER JOIN transactions ON reservations.TransactionID = transactions.ID
|
||||||
|
WHERE GuestID = @GuestID AND Status = @Status;";
|
||||||
|
cmd.Parameters.AddWithValue("@GuestID", g.Id);
|
||||||
|
cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Active);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
|
{
|
||||||
|
reader.Read();
|
||||||
|
if (reader.HasRows)
|
||||||
|
{
|
||||||
|
if (reader[20].GetType() != typeof(DBNull))
|
||||||
|
LastPaid = reader.GetDateTime(20);
|
||||||
|
if (reader[21].GetType() != typeof(DBNull))
|
||||||
|
PaidOn = reader.GetDateTime(21);
|
||||||
|
t = new Transaction(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(19),
|
||||||
|
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16));
|
||||||
|
|
||||||
|
if (reader[1].GetType() != typeof(DBNull))
|
||||||
|
RoomNumber = reader.GetInt32(1);
|
||||||
|
if (reader[10].GetType() != typeof(DBNull))
|
||||||
|
CheckIn = reader.GetDateTime(10);
|
||||||
|
if (reader[11].GetType() != typeof(DBNull))
|
||||||
|
CheckOut = reader.GetDateTime(11);
|
||||||
|
if (reader[12].GetType() != typeof(DBNull))
|
||||||
|
DateChanged = reader.GetDateTime(12);
|
||||||
|
|
||||||
|
r = new Reservation(reader.GetInt32(0), g, t, (ReservationType)reader.GetInt32(5), (ReservationStatus)reader.GetInt32(6),
|
||||||
|
reader.GetDateTime(7), reader.GetDateTime(8), reader.GetDateTime(9), RoomNum: RoomNumber, IsNoShow: reader.GetBoolean(4),
|
||||||
|
CheckIn: CheckIn, CheckOut: CheckOut, DateChanged: DateChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
internal static double? GetBaseRate()
|
||||||
|
{
|
||||||
|
double? rate;
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
{
|
{
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
@@ -186,7 +165,10 @@ namespace Ophelias.Managers
|
|||||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
reader.Read();
|
reader.Read();
|
||||||
rate = reader.GetDouble(0);
|
if (reader.HasRows)
|
||||||
|
rate = reader.GetDouble(0);
|
||||||
|
else
|
||||||
|
rate = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,8 +181,10 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
{
|
{
|
||||||
string query = $"INSERT INTO rates (Rate, DateSet) VALUES ({Rate}, {DateSet});";
|
string query = $"INSERT INTO rates (Rate, DateSet) VALUES (@Rate, @DateSet);";
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@Rate", Rate);
|
||||||
|
cmd.Parameters.AddWithValue("@DateSet", DateSet);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,8 +208,9 @@ namespace Ophelias.Managers
|
|||||||
int? Id;
|
int? Id;
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
{
|
{
|
||||||
string query = $"SELECT Id FROM rates WHERE DateSet = {DateTime.Now.Date.ToString("yyyy-MM-dd")};";
|
string query = "SELECT Id FROM rates WHERE DateSet = @Date;";
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@@ -237,8 +222,10 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = $@"UPDATE rates SET DefaultRate = NULL WHERE Id = {OldId};
|
cmd.CommandText = @"UPDATE rates SET DefaultRate = NULL WHERE Id = @OldID;
|
||||||
UPDATE rates SET DefaultRate = 1 WHERE Id = {Id}";
|
UPDATE rates SET DefaultRate = 1 WHERE Id = @ID";
|
||||||
|
cmd.Parameters.AddWithValue("@OldID", OldId);
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Id);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
using System;
|
using Ophelias.Managers;
|
||||||
using System.Collections.Generic;
|
using System.Data.SQLite;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Ophelias.Models;
|
|
||||||
|
|
||||||
namespace Ophelias.Models
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
@@ -17,6 +13,44 @@ namespace Ophelias.Models
|
|||||||
internal string? CCV;
|
internal string? CCV;
|
||||||
internal string? Expiration;
|
internal string? Expiration;
|
||||||
|
|
||||||
|
internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||||
|
{
|
||||||
|
int Id;
|
||||||
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
|
{
|
||||||
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " +
|
||||||
|
"VALUES (@Fname, @Lname, @Email, @CC, @Expiry, @CCV);";
|
||||||
|
cmd.Parameters.AddWithValue("@Fname", FirstName);
|
||||||
|
cmd.Parameters.AddWithValue("@Lname", LastName);
|
||||||
|
cmd.Parameters.AddWithValue("@Email", Email);
|
||||||
|
cmd.Parameters.AddWithValue("@CreditCard", CreditCard);
|
||||||
|
cmd.Parameters.AddWithValue("@Expiration", Expiration);
|
||||||
|
cmd.Parameters.AddWithValue("@CCV", CCV);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
Id = (int)Manager.con.LastInsertRowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CreditCard != null && Expiration != null && CCV != null)
|
||||||
|
{
|
||||||
|
this.Id = Id;
|
||||||
|
this.FirstName = FirstName;
|
||||||
|
this.LastName = LastName;
|
||||||
|
this.Email = Email;
|
||||||
|
this.CreditCard = CreditCard;
|
||||||
|
this.Expiration = Expiration;
|
||||||
|
this.CCV = CCV;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Id = Id;
|
||||||
|
this.FirstName = FirstName;
|
||||||
|
this.LastName = LastName;
|
||||||
|
this.Email = Email;
|
||||||
|
}
|
||||||
|
}
|
||||||
internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
internal Guest(int Id, string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||||
{
|
{
|
||||||
this.Id = Id;
|
this.Id = Id;
|
||||||
@@ -27,6 +61,28 @@ namespace Ophelias.Models
|
|||||||
this.Expiration = Expiration;
|
this.Expiration = Expiration;
|
||||||
this.CCV = CCV;
|
this.CCV = CCV;
|
||||||
}
|
}
|
||||||
|
internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||||
|
{
|
||||||
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
|
{
|
||||||
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FirstName != null)
|
||||||
|
this.FirstName = FirstName;
|
||||||
|
if (LastName != null)
|
||||||
|
this.LastName = LastName;
|
||||||
|
if (FirstName != null)
|
||||||
|
this.Email = Email;
|
||||||
|
this.CreditCard = CreditCard;
|
||||||
|
if (FirstName != null)
|
||||||
|
this.Expiration = Expiration;
|
||||||
|
if (FirstName != null)
|
||||||
|
this.CCV = CCV;
|
||||||
|
}
|
||||||
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
|
internal void SetCreditCardInformation(string CreditCard, string Expiration, string CCV)
|
||||||
{
|
{
|
||||||
this.CreditCard = CreditCard;
|
this.CreditCard = CreditCard;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Ophelias.Models
|
|||||||
internal class Reservation
|
internal class Reservation
|
||||||
{
|
{
|
||||||
internal int Id;
|
internal int Id;
|
||||||
internal Room Room;
|
internal int? RoomNum;
|
||||||
internal Guest Guest;
|
internal Guest Guest;
|
||||||
internal Transaction Transaction;
|
internal Transaction Transaction;
|
||||||
|
|
||||||
@@ -26,10 +26,84 @@ namespace Ophelias.Models
|
|||||||
internal DateTime? CheckOut;
|
internal DateTime? CheckOut;
|
||||||
internal DateTime? DateChanged;
|
internal DateTime? DateChanged;
|
||||||
|
|
||||||
|
internal Reservation(Guest Guest, ReservationType Type,
|
||||||
|
DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active,
|
||||||
|
bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null, int? RoomNum = null)
|
||||||
|
{
|
||||||
|
int Id; double Multiplier;
|
||||||
|
switch (Type)
|
||||||
|
{
|
||||||
|
case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
|
||||||
|
case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
|
||||||
|
case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
|
||||||
|
case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
|
||||||
|
default: throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
double? BaseRate = HotelManager.GetBaseRate();
|
||||||
|
if (BaseRate == null) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction Transaction = new Transaction(
|
||||||
|
Rate: (double)BaseRate,
|
||||||
|
Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays),
|
||||||
|
Multiplier: Multiplier,
|
||||||
|
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
|
||||||
|
);
|
||||||
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
|
{
|
||||||
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
|
{
|
||||||
|
if (RoomNum != null)
|
||||||
|
this.RoomNum = RoomNum;
|
||||||
|
cmd.CommandText =
|
||||||
|
"INSERT INTO reservations (RoomNum, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged) " +
|
||||||
|
"VALUES (@RoomNum, @GuestID, @TransactionID, @IsNoShow, @Type, @Status, @CreationDate, @StartDate, @EndDate, @CheckIn, @CheckOut, @DateChanged);";
|
||||||
|
cmd.Parameters.AddWithValue("@RoomNum", RoomNum);
|
||||||
|
cmd.Parameters.AddWithValue("@GuestID", Guest.Id);
|
||||||
|
cmd.Parameters.AddWithValue("@TransactionID", Transaction.Id);
|
||||||
|
cmd.Parameters.AddWithValue("@IsNoShow", Convert.ToInt32(IsNoShow));
|
||||||
|
cmd.Parameters.AddWithValue("@Type", (int)Type);
|
||||||
|
cmd.Parameters.AddWithValue("@Status", (int)Status);
|
||||||
|
cmd.Parameters.AddWithValue("@CreationDate", CreationDate.ToString("yyyy-MM-dd"));
|
||||||
|
cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
|
||||||
|
cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
|
||||||
|
if (CheckIn.HasValue)
|
||||||
|
cmd.Parameters.AddWithValue("@CheckIn", CheckIn.Value.ToString("yyyy-MM-dd"));
|
||||||
|
else
|
||||||
|
cmd.Parameters.AddWithValue("@CheckIn", CheckIn);
|
||||||
|
if (CheckOut.HasValue)
|
||||||
|
cmd.Parameters.AddWithValue("@CheckOut", CheckOut.Value.ToString("yyyy-MM-dd"));
|
||||||
|
else
|
||||||
|
cmd.Parameters.AddWithValue("@CheckOut", CheckOut);
|
||||||
|
if (DateChanged.HasValue)
|
||||||
|
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
|
||||||
|
else
|
||||||
|
cmd.Parameters.AddWithValue("@DateChanged", DateChanged);
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
Id = (int)Manager.con.LastInsertRowId;
|
||||||
|
}
|
||||||
|
this.Id = Id;
|
||||||
|
this.RoomNum = RoomNum;
|
||||||
|
this.Guest = Guest;
|
||||||
|
this.Transaction = Transaction;
|
||||||
|
this.IsNoShow = IsNoShow;
|
||||||
|
this.Type = Type;
|
||||||
|
this.Status = Status;
|
||||||
|
this.CreationDate = CreationDate;
|
||||||
|
this.StartDate = StartDate;
|
||||||
|
this.EndDate = EndDate;
|
||||||
|
this.CheckIn = CheckIn;
|
||||||
|
this.CheckOut = CheckOut;
|
||||||
|
this.DateChanged = DateChanged;
|
||||||
|
}
|
||||||
internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
|
internal Reservation(int Id, Guest Guest, Transaction Transaction, ReservationType Type, ReservationStatus Status,
|
||||||
DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
|
DateTime CreationDate, DateTime StartDate, DateTime EndDate, bool IsNoShow = false, DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null, int? RoomNum = null)
|
||||||
{
|
{
|
||||||
this.Id = Id;
|
this.Id = Id;
|
||||||
|
this.RoomNum = RoomNum;
|
||||||
this.Guest = Guest;
|
this.Guest = Guest;
|
||||||
this.Transaction = Transaction;
|
this.Transaction = Transaction;
|
||||||
this.IsNoShow = IsNoShow;
|
this.IsNoShow = IsNoShow;
|
||||||
@@ -57,23 +131,38 @@ namespace Ophelias.Models
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Id);
|
||||||
|
cmd.Parameters.AddWithValue("@Status", Status);
|
||||||
|
cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
|
||||||
|
cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
|
||||||
|
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Transaction.UpdateTransactionFees(HotelManager.GetBaseRate(), TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
|
double? BaseRate = HotelManager.GetBaseRate();
|
||||||
|
if (BaseRate == null)
|
||||||
|
throw new ArgumentNullException(nameof(BaseRate));
|
||||||
|
Transaction.UpdateTransactionFees((double)BaseRate, TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
|
||||||
}
|
}
|
||||||
internal void CancelReservation()
|
internal void CancelReservation()
|
||||||
{
|
{
|
||||||
|
DateTime _DateChanged = DateTime.Now.Date;
|
||||||
using (DatabaseManager Manager = new DatabaseManager())
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
{
|
{
|
||||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
{
|
{
|
||||||
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: DateTime.Now.Date);
|
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: _DateChanged);
|
||||||
|
|
||||||
if (query == null)
|
if (query == null)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
|
Status = ReservationStatus.Cancelled;
|
||||||
|
DateChanged = _DateChanged;
|
||||||
|
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Id);
|
||||||
|
cmd.Parameters.AddWithValue("@Status", Status);
|
||||||
|
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Ophelias.Models
|
namespace Ophelias.Models
|
||||||
{
|
{
|
||||||
internal class Room
|
internal class @int
|
||||||
{
|
{
|
||||||
internal int Id;
|
internal int Id;
|
||||||
internal bool Occupied;
|
internal bool Occupied;
|
||||||
|
|
||||||
internal Room(int id)
|
internal @int(int id)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Occupied = false;
|
Occupied = false;
|
||||||
@@ -20,11 +20,11 @@ namespace Ophelias.Models
|
|||||||
|
|
||||||
internal class RoomList
|
internal class RoomList
|
||||||
{
|
{
|
||||||
internal List<Room> Rooms;
|
internal List<@int> Rooms;
|
||||||
|
|
||||||
internal RoomList()
|
internal RoomList()
|
||||||
{
|
{
|
||||||
Rooms = new List<Room>();
|
Rooms = new List<@int>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,49 @@ namespace Ophelias.Models
|
|||||||
internal DateTime? LastPaid { get; set; } = null;
|
internal DateTime? LastPaid { get; set; } = null;
|
||||||
internal DateTime? PaidOn { get; set; } = null;
|
internal DateTime? PaidOn { get; set; } = null;
|
||||||
|
|
||||||
|
internal Transaction(double Rate, double Owed,
|
||||||
|
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
||||||
|
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
|
||||||
|
{
|
||||||
|
int Id;
|
||||||
|
using (DatabaseManager Manager = new DatabaseManager())
|
||||||
|
{
|
||||||
|
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn) " +
|
||||||
|
"VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @PayBy, @LastPaid, @PaidOn)";
|
||||||
|
cmd.Parameters.AddWithValue("@Rate", Rate);
|
||||||
|
cmd.Parameters.AddWithValue("@Owed", Owed);
|
||||||
|
cmd.Parameters.AddWithValue("@Multiplier", Multiplier);
|
||||||
|
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
|
||||||
|
cmd.Parameters.AddWithValue("@Penalty", Penalty);
|
||||||
|
cmd.Parameters.AddWithValue("@PayBy", PayBy.ToString("yyyy-MM-dd"));
|
||||||
|
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
|
||||||
|
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
|
||||||
|
if (LastPaid != null)
|
||||||
|
cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
|
||||||
|
else
|
||||||
|
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
|
||||||
|
if (PaidOn != null)
|
||||||
|
cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
|
||||||
|
else
|
||||||
|
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
|
||||||
|
|
||||||
|
//cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy, Refund: RefundAmount, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
Id = (int)Manager.con.LastInsertRowId;
|
||||||
|
}
|
||||||
|
this.Id = Id;
|
||||||
|
this.Rate = Rate;
|
||||||
|
this.Owed = Owed;
|
||||||
|
this.Penalty = Penalty;
|
||||||
|
this.Multiplier = Multiplier;
|
||||||
|
this.RefundAmount = RefundAmount;
|
||||||
|
this.PayBy = PayBy;
|
||||||
|
this.LastPaid = LastPaid;
|
||||||
|
this.PaidOn = PaidOn;
|
||||||
|
}
|
||||||
internal Transaction(int Id, double Rate, double Owed,
|
internal Transaction(int Id, double Rate, double Owed,
|
||||||
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
||||||
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
|
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
|
||||||
@@ -51,6 +94,10 @@ namespace Ophelias.Models
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Id);
|
||||||
|
cmd.Parameters.AddWithValue("@Rate", this.Rate);
|
||||||
|
cmd.Parameters.AddWithValue("@Multiplier", this.Multiplier);
|
||||||
|
cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +122,11 @@ namespace Ophelias.Models
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Id);
|
||||||
|
cmd.Parameters.AddWithValue("@Owed", Owed);
|
||||||
|
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
|
||||||
|
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
|
||||||
|
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,6 +144,8 @@ namespace Ophelias.Models
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
cmd.CommandText = query;
|
cmd.CommandText = query;
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Id);
|
||||||
|
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,7 +179,7 @@ namespace Ophelias.Models
|
|||||||
}
|
}
|
||||||
internal static double CalculateOwed(double Rate, int Days)
|
internal static double CalculateOwed(double Rate, int Days)
|
||||||
{
|
{
|
||||||
return Rate * (double)Days;
|
return Rate * Days;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,56 @@ class Program
|
|||||||
{
|
{
|
||||||
Reservation? activeReservation = null;
|
Reservation? activeReservation = null;
|
||||||
Guest? activeGuest = null;
|
Guest? activeGuest = null;
|
||||||
|
void help()
|
||||||
|
{
|
||||||
|
Console.WriteLine(
|
||||||
|
"Reservation Commands:\n" +
|
||||||
|
"\treservation create - Create a new reservation.\n" +
|
||||||
|
"\treservation update - Update your active reservation.\n" +
|
||||||
|
"\treservation cancel - Cancel a reservation.\n" +
|
||||||
|
"Account Commands:\n" +
|
||||||
|
"\taccount create - Create a new guest account.\n" +
|
||||||
|
"\taccount update - Update your account information.\n" +
|
||||||
|
"\taccount login - Log into your guest account." +
|
||||||
|
"Enter Q to quit.\n"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(string?, string?, string?) GetCreditCardInformation()
|
||||||
|
{
|
||||||
|
Console.Write("What is your credit card number: ");
|
||||||
|
string CreditCard = "";
|
||||||
|
while (!Validation.ValidateCreditCard(CreditCard))
|
||||||
|
{
|
||||||
|
CreditCard = Console.ReadLine().Trim().Replace("\t", "");
|
||||||
|
if (CreditCard == "q" || CreditCard == "Q")
|
||||||
|
return (null, null, null);
|
||||||
|
if (!Validation.ValidateCreditCard(CreditCard))
|
||||||
|
Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
|
||||||
|
}
|
||||||
|
Console.Write("What is your credit card expiration date (MM/yy): ");
|
||||||
|
string CardExpiration = "";
|
||||||
|
while (!Validation.ValidateExpirationDate(CardExpiration))
|
||||||
|
{
|
||||||
|
CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
|
||||||
|
if (CardExpiration == "q" || CardExpiration == "Q")
|
||||||
|
return (null, null, null);
|
||||||
|
if (!Validation.ValidateExpirationDate(CardExpiration))
|
||||||
|
Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
|
||||||
|
}
|
||||||
|
Console.Write("What is your credit card CCV: ");
|
||||||
|
string CCV = "";
|
||||||
|
while (!Validation.ValidateCCV(CCV))
|
||||||
|
{
|
||||||
|
CCV = Console.ReadLine().Trim().Replace("\t", "");
|
||||||
|
if (CCV == "q" || CCV == "Q")
|
||||||
|
return (null, null, null);
|
||||||
|
if (!Validation.ValidateCCV(CCV))
|
||||||
|
Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
|
||||||
|
}
|
||||||
|
return (CreditCard, CardExpiration, CCV);
|
||||||
|
}
|
||||||
(string, string) GetGuestName() {
|
(string, string) GetGuestName() {
|
||||||
Console.Write("What is your first name: ");
|
Console.Write("What is your first name: ");
|
||||||
string FirstName = "";
|
string FirstName = "";
|
||||||
@@ -40,21 +90,6 @@ class Program
|
|||||||
}
|
}
|
||||||
return Email;
|
return Email;
|
||||||
}
|
}
|
||||||
void help()
|
|
||||||
{
|
|
||||||
Console.WriteLine(
|
|
||||||
"Reservation Commands:\n" +
|
|
||||||
"\treservation create - Create a new reservation.\n" +
|
|
||||||
"\treservation update - Update your active reservation.\n" +
|
|
||||||
"\treservation cancel - Cancel a reservation.\n" +
|
|
||||||
"Account Commands:\n" +
|
|
||||||
"\taccount create - Create a new guest account.\n" +
|
|
||||||
"\taccount update - Update your account information.\n" +
|
|
||||||
"\taccount login - Log into your guest account." +
|
|
||||||
"Enter Q to quit.\n"
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
void GuestLogin()
|
void GuestLogin()
|
||||||
{
|
{
|
||||||
Console.Write("\nEnter your email address: ");
|
Console.Write("\nEnter your email address: ");
|
||||||
@@ -67,8 +102,12 @@ class Program
|
|||||||
}
|
}
|
||||||
activeGuest = HotelManager.GetGuestByEmail(email);
|
activeGuest = HotelManager.GetGuestByEmail(email);
|
||||||
if (activeGuest == null)
|
if (activeGuest == null)
|
||||||
|
{
|
||||||
Console.WriteLine($"\nNo account was found with the email {email}.");
|
Console.WriteLine($"\nNo account was found with the email {email}.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
|
Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
|
||||||
|
activeReservation = HotelManager.GetResByGuestAndDate(activeGuest);
|
||||||
}
|
}
|
||||||
void CreateNewGuestPrompt()
|
void CreateNewGuestPrompt()
|
||||||
{
|
{
|
||||||
@@ -81,7 +120,7 @@ class Program
|
|||||||
if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
|
if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
|
||||||
(CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
|
(CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
|
||||||
|
|
||||||
activeGuest = HotelManager.CreateGuest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
|
activeGuest = new Guest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV);
|
||||||
Console.Write($"You are now logged in as {FirstName} {LastName} ({Email})");
|
Console.Write($"You are now logged in as {FirstName} {LastName} ({Email})");
|
||||||
}
|
}
|
||||||
void UpdateGuestInformation()
|
void UpdateGuestInformation()
|
||||||
@@ -136,7 +175,7 @@ class Program
|
|||||||
if (NewDetails.Count > 0)
|
if (NewDetails.Count > 0)
|
||||||
changes += string.Join("\n", NewDetails);
|
changes += string.Join("\n", NewDetails);
|
||||||
Console.WriteLine($"The following changes have been made:\n {changes}");
|
Console.WriteLine($"The following changes have been made:\n {changes}");
|
||||||
HotelManager.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
|
activeGuest.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +192,6 @@ class Program
|
|||||||
switch (Console.ReadLine())
|
switch (Console.ReadLine())
|
||||||
{
|
{
|
||||||
case "Q": return;
|
case "Q": return;
|
||||||
case "q": return;
|
|
||||||
case "1": (NewFname, NewLname) = GetGuestName(); break;
|
case "1": (NewFname, NewLname) = GetGuestName(); break;
|
||||||
case "2": NewEmail = GetGuestEmail(); break;
|
case "2": NewEmail = GetGuestEmail(); break;
|
||||||
case "3": (NewCard, NewExpiry, NewCCV) = GetCreditCardInformation(); break;
|
case "3": (NewCard, NewExpiry, NewCCV) = GetCreditCardInformation(); break;
|
||||||
@@ -162,134 +200,230 @@ class Program
|
|||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
ReservationType SelectReservation()
|
||||||
|
{
|
||||||
|
string input = "";
|
||||||
|
Console.Write("What kind of reservation would you like to make?\n" +
|
||||||
|
"1. Conventional\n" +
|
||||||
|
"2. Prepaid\n" +
|
||||||
|
"3. 60 Day Advance\n" +
|
||||||
|
"4. Incentive\n" +
|
||||||
|
"Input a number: ");
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
input = Console.ReadLine();
|
||||||
|
if (input == "1" || input == "2" || input == "3" || input == "4")
|
||||||
|
break;
|
||||||
|
Console.Write("Please enter either 1, 2, 3, or 4: ");
|
||||||
|
}
|
||||||
|
return (ReservationType)Convert.ToInt32(input);
|
||||||
|
}
|
||||||
|
(DateTime, DateTime) SelectDate()
|
||||||
|
{
|
||||||
|
string input = "";
|
||||||
|
DateTime _StartDate;
|
||||||
|
DateTime _EndDate;
|
||||||
|
Console.Write("When would you like to begin your stay.\n" +
|
||||||
|
"Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
|
||||||
|
"Input a date (2021-12-31): ");
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
input = Console.ReadLine();
|
||||||
|
if (DateTime.TryParse(input, out _StartDate))
|
||||||
|
break;
|
||||||
|
|
||||||
|
Console.Write("Please enter a valid date (2021-12-31): ");
|
||||||
|
}
|
||||||
|
Console.Write("When would you like to end your stay.\n" +
|
||||||
|
"Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
|
||||||
|
"Input a date (2021-12-31): ");
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
input = Console.ReadLine();
|
||||||
|
if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (_EndDate < _StartDate)
|
||||||
|
Console.Write("End date cannot be before start date. Please enter a valid date (2021-12-31): ");
|
||||||
|
else
|
||||||
|
Console.Write("Please enter a valid date (2021-12-31): ");
|
||||||
|
}
|
||||||
|
return (_StartDate.Date, _EndDate.Date);
|
||||||
|
}
|
||||||
|
void EditReservationPrompt()
|
||||||
|
{
|
||||||
|
string input;
|
||||||
|
DateTime NewStartDate = activeReservation.StartDate, NewEndDate = activeReservation.EndDate;
|
||||||
|
ReservationType NewType = activeReservation.Type;
|
||||||
|
|
||||||
|
bool completed = false;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.Write("What information would you like to edit?\n" +
|
||||||
|
"If not and you wish to cancel, enter Q to exit. If you want to save and complete your changes, enter S.\n" +
|
||||||
|
"1. Reservation type\n" +
|
||||||
|
"2. Reservation dates\n" +
|
||||||
|
"Enter 1 or 2: ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
switch (input)
|
||||||
|
{
|
||||||
|
case "Q": Console.WriteLine("Changes have has been deleted."); return;
|
||||||
|
case "1": NewType = SelectReservation(); break;
|
||||||
|
case "2": (NewStartDate, NewEndDate) = SelectDate(); break;
|
||||||
|
case "S":
|
||||||
|
completed = true;
|
||||||
|
(activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, NewStartDate, NewEndDate);
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
} while (!completed);
|
||||||
|
}
|
||||||
void CreateNewReservation()
|
void CreateNewReservation()
|
||||||
{
|
{
|
||||||
if (activeGuest == null)
|
if (activeGuest == null)
|
||||||
|
{
|
||||||
Console.WriteLine("No guest is currently logged in, please login.");
|
Console.WriteLine("No guest is currently logged in, please login.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (activeReservation != null)
|
if (activeReservation != null)
|
||||||
Console.WriteLine("");
|
|
||||||
|
|
||||||
string input = "";
|
|
||||||
ReservationType SelectReservation()
|
|
||||||
{
|
{
|
||||||
Console.Write("What kind of reservation would you like to make?\n" +
|
Console.WriteLine("You currently have an active registration.");
|
||||||
"1. Conventional\n" +
|
return;
|
||||||
"2. Prepaid\n" +
|
|
||||||
"3. 60 Day Advance\n" +
|
|
||||||
"4. Incentive\n" +
|
|
||||||
"Input a number: ");
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
input = Console.ReadLine();
|
|
||||||
if (input == "1" || input == "2" || input == "3" || input == "4")
|
|
||||||
break;
|
|
||||||
Console.Write("Please enter either 1, 2, 3, or 4: ");
|
|
||||||
}
|
|
||||||
return (ReservationType)Convert.ToInt32(input);
|
|
||||||
}
|
}
|
||||||
(DateTime, DateTime) SelectDate()
|
if (HotelManager.GetBaseRate() == null)
|
||||||
{
|
{
|
||||||
DateTime _StartDate;
|
Console.WriteLine("Unable to proceed with reservation due to no base rate being set. Please inform an employee.");
|
||||||
DateTime _EndDate;
|
return;
|
||||||
Console.Write("When would you like to begin your stay.\n" +
|
|
||||||
"Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
|
|
||||||
"Input a date (2021-12-31): ");
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
input = Console.ReadLine();
|
|
||||||
if (DateTime.TryParse(input, out _StartDate))
|
|
||||||
break;
|
|
||||||
|
|
||||||
Console.Write("Please enter a valid date (2021-12-31): ");
|
|
||||||
}
|
|
||||||
Console.Write("When would you like to end your stay.\n" +
|
|
||||||
"Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
|
|
||||||
"Input a date (2021-12-31): ");
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
input = Console.ReadLine();
|
|
||||||
if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (_EndDate < _StartDate)
|
|
||||||
Console.Write("End date cannot be before start date. Please enter a valid date (2021-12-31): ");
|
|
||||||
else
|
|
||||||
Console.Write("Please enter a valid date (2021-12-31): ");
|
|
||||||
}
|
|
||||||
return (_StartDate.Date, _EndDate.Date);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string input;
|
||||||
|
|
||||||
ReservationType Type;
|
ReservationType Type;
|
||||||
DateTime StartDate;
|
DateTime StartDate;
|
||||||
DateTime EndDate;
|
DateTime EndDate;
|
||||||
|
|
||||||
Type = SelectReservation();
|
Type = SelectReservation();
|
||||||
(StartDate, EndDate) = SelectDate();
|
(StartDate, EndDate) = SelectDate();
|
||||||
if (Type != ReservationType.SixtyDayAdvance &&
|
while((Type != ReservationType.SixtyDayAdvance &&
|
||||||
(activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))
|
(activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))) {
|
||||||
|
Console.Write("The reservation type you chose requires you to specify your credit card.\n" +
|
||||||
|
"If you are unable to provide one, enter Q to quit or hit enter to continue.\n" +
|
||||||
|
": ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
if (input == "Q")
|
||||||
|
return;
|
||||||
GetCreditCardInformation();
|
GetCreditCardInformation();
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Thank you for filling out your reservation details. Currently you have made a {Type}" +
|
Console.Write($"Thank you for filling out your reservation details. Currently you have made a {Type} " +
|
||||||
$"reservation and are scheduled to stay from {StartDate.ToString("yyyy-MM-dd")} to {EndDate.ToString("yyyy-MM-dd")}." +
|
$"reservation and are scheduled to stay from {StartDate.ToString("yyyy-MM-dd")} to {EndDate.ToString("yyyy-MM-dd")}." +
|
||||||
$"If these details are correct, enter YES to complete. If they are not enter...\n" +
|
$"If these details are correct, enter YES to complete. To cancel your reservation enter Q. Enter NO to edit your reservation.\n" +
|
||||||
$"1. Change your reservation type\n" +
|
|
||||||
$"2. Change your reservation dates\n" +
|
|
||||||
$": ");
|
$": ");
|
||||||
input = Console.ReadLine();
|
input = Console.ReadLine();
|
||||||
if (input != "YES")
|
while(input != "YES")
|
||||||
{
|
{
|
||||||
bool completed = false;
|
if (input == "NO")
|
||||||
do
|
|
||||||
{
|
{
|
||||||
Console.Write("Would you like to edit any information, enter Q to exit and complete your reservation?\n" +
|
EditReservationPrompt();
|
||||||
"1. Reservation type\n" +
|
Console.Write("You're changes have been saved. Are you done with your changes?\n" +
|
||||||
"2. Reservation dates\n" +
|
"Enter YES to finish, NO to continue editing, or Q to discard your reservation.\n" +
|
||||||
"Enter 1 or 2: ");
|
": ");
|
||||||
switch (Console.ReadLine())
|
input = Console.ReadLine();
|
||||||
{
|
}
|
||||||
case "Q": completed = true; break;
|
else if (input == "Q")
|
||||||
case "q": completed = true; break;
|
{
|
||||||
case "1": SelectReservation(); break;
|
Console.WriteLine("Reservation has been deleted.");
|
||||||
case "2": SelectDate(); break;
|
return;
|
||||||
default: break;
|
} else
|
||||||
}
|
{
|
||||||
} while (!completed);
|
Console.WriteLine("Input must be YES, NO, or Q.\n: ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HotelManager.CreateReservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
|
activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
|
||||||
|
Console.WriteLine("Your reservation has been made.");
|
||||||
}
|
}
|
||||||
(string?, string?, string?) GetCreditCardInformation()
|
void UpdateReservation()
|
||||||
{
|
{
|
||||||
Console.Write("What is your credit card number: ");
|
string input = "NO";
|
||||||
string CreditCard = "";
|
if (activeGuest == null)
|
||||||
while (!Validation.ValidateCreditCard(CreditCard))
|
|
||||||
{
|
{
|
||||||
CreditCard = Console.ReadLine().Trim().Replace("\t", "");
|
Console.WriteLine("No guest is currently logged in, please login.");
|
||||||
if (CreditCard == "q" || CreditCard == "Q")
|
return;
|
||||||
return (null, null, null);
|
|
||||||
if (!Validation.ValidateCreditCard(CreditCard))
|
|
||||||
Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: ");
|
|
||||||
}
|
}
|
||||||
Console.Write("What is your credit card expiration date (MM/yy): ");
|
if (activeReservation == null)
|
||||||
string CardExpiration = "";
|
|
||||||
while (!Validation.ValidateExpirationDate(CardExpiration))
|
|
||||||
{
|
{
|
||||||
CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
|
Console.WriteLine("You currently do not have an active registration.");
|
||||||
if (CardExpiration == "q" || CardExpiration == "Q")
|
return;
|
||||||
return (null, null, null);
|
|
||||||
if (!Validation.ValidateExpirationDate(CardExpiration))
|
|
||||||
Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: ");
|
|
||||||
}
|
}
|
||||||
Console.Write("What is your credit card CCV: ");
|
|
||||||
string CCV = "";
|
Console.Write("Your current reservation details are:\n" +
|
||||||
while (!Validation.ValidateCCV(CCV))
|
$"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")}\n" +
|
||||||
|
$"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")}\n");
|
||||||
|
DateTime? _StartDate = null, _EndDate = null;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
CCV = Console.ReadLine().Trim().Replace("\t", "");
|
if (input == "NO")
|
||||||
if (CCV == "q" || CCV == "Q")
|
{
|
||||||
return (null, null, null);
|
(_StartDate, _EndDate) = SelectDate();
|
||||||
if (!Validation.ValidateCCV(CCV))
|
if (_StartDate.HasValue && _EndDate.HasValue)
|
||||||
Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
|
Console.Write("Your new reservation details are:\n" +
|
||||||
|
$"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")} -> {_StartDate.Value.ToString("yyyy-MM-dd")}\n" +
|
||||||
|
$"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")} -> {_EndDate.Value.ToString("yyyy-MM-dd")}\n");
|
||||||
|
Console.Write("Are you done with your changes?\n" +
|
||||||
|
"Enter YES to finish and save, NO to continue editing.\n" +
|
||||||
|
": ");
|
||||||
|
} else if (input == "Q")
|
||||||
|
{
|
||||||
|
Console.WriteLine("Your changes have been discarded.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Input must be YES, NO, or Q.");
|
||||||
|
Console.Write(": ");
|
||||||
|
}
|
||||||
|
input = Console.ReadLine();
|
||||||
|
} while (input != "YES");
|
||||||
|
if (_StartDate != null && _EndDate != null)
|
||||||
|
{
|
||||||
|
activeReservation.ChangeReservationDates((DateTime)_StartDate, (DateTime)_EndDate);
|
||||||
|
Console.WriteLine("Your changes have been saved.");
|
||||||
}
|
}
|
||||||
return (CreditCard, CardExpiration, CCV);
|
return;
|
||||||
|
}
|
||||||
|
void CancelReservation()
|
||||||
|
{
|
||||||
|
if (activeGuest == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("No guest is currently logged in, please login.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (activeReservation == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You currently do not have an active registration.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string input;
|
||||||
|
Console.Write("Would you like to cancel your reservation?\n" +
|
||||||
|
"You may be charged depending on your reservation.\n" +
|
||||||
|
"Enter YES to confirm or NO to exit: ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
while(input != "YES")
|
||||||
|
{
|
||||||
|
if (input == "NO")
|
||||||
|
{
|
||||||
|
Console.Write("Reservation has not been cancelled.");
|
||||||
|
return;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
Console.Write("Your input must be YES or NO: ");
|
||||||
|
Console.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activeReservation.CancelReservation();
|
||||||
|
activeReservation = null;
|
||||||
|
Console.Write("Reservation has been cancelled, you may be charged based on your reservation.");
|
||||||
}
|
}
|
||||||
Console.Write(
|
Console.Write(
|
||||||
"\nWelcome to the Ophelias Oasis Hotel Registration System!\n" +
|
"\nWelcome to the Ophelias Oasis Hotel Registration System!\n" +
|
||||||
@@ -304,8 +438,8 @@ class Program
|
|||||||
{
|
{
|
||||||
case "help": help(); break;
|
case "help": help(); break;
|
||||||
case "reservation create": CreateNewReservation(); break;
|
case "reservation create": CreateNewReservation(); break;
|
||||||
case "reservation update": break;
|
case "reservation update": UpdateReservation(); break;
|
||||||
case "reservation cancel": break;
|
case "reservation cancel": CancelReservation(); break;
|
||||||
case "account create": CreateNewGuestPrompt(); break;
|
case "account create": CreateNewGuestPrompt(); break;
|
||||||
case "account update": UpdateGuestInformation(); break;
|
case "account update": UpdateGuestInformation(); break;
|
||||||
case "account login": GuestLogin(); break;
|
case "account login": GuestLogin(); break;
|
||||||
@@ -321,16 +455,50 @@ class Program
|
|||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Report Commands:\n" +
|
"Report Commands:\n" +
|
||||||
"\treservation create\n" +
|
"\tgenerate daily report - Generates a daily report on expected occupancy, room income, and incentive losses.\n" +
|
||||||
"\treservation update\n" +
|
"\tgenerate operational report - Generates a report of daily arrivals and occupancy.\n" +
|
||||||
|
"\tgenerate accomodation bills - Generates an accomodation bill that will be handed to guests upon checkout.\n" +
|
||||||
"\treservation cancel\n" +
|
"\treservation cancel\n" +
|
||||||
"Account Commands:" +
|
"Management Commands:" +
|
||||||
"\taccount create\n" +
|
"\tcheckin guest - Checks in a guest and assigns them a room.\n" +
|
||||||
"\taccount update\n" +
|
"\tcheckout guest - Checks out a guest and removes their room assignment.\n" +
|
||||||
|
"\tbaserate set - Sets a new base rate to begin after a specified date.\n" +
|
||||||
"Enter Q to quit.\n"
|
"Enter Q to quit.\n"
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetFutureBaseRate()
|
||||||
|
{
|
||||||
|
if (HotelManager.GetBaseRate() == null)
|
||||||
|
{
|
||||||
|
Console.Write("No base rate has been configured. " +
|
||||||
|
"You must set one for the current date.\n" +
|
||||||
|
"Enter new rate: ");
|
||||||
|
Console.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
|
string? input = Console.ReadLine();
|
||||||
|
switch (input)
|
||||||
|
{
|
||||||
|
case "help": help(); break;
|
||||||
|
case "generate daily report": break;
|
||||||
|
case "generate operational report": break;
|
||||||
|
case "generate accomodation bills": break;
|
||||||
|
case "reservation cancel": break;
|
||||||
|
case "checkin guest": break;
|
||||||
|
case "checkout guest": break;
|
||||||
|
case "baserate set": break;
|
||||||
|
case "Q": return;
|
||||||
|
default: Console.WriteLine("Unknown command, enter help for more inforamtion."); break;
|
||||||
|
}
|
||||||
|
Console.Write("\nCommand: ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user