WIP: Adds several core models needed for functionality #24
@@ -27,30 +27,30 @@ namespace Ophelias.Managers
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
[Rate] INTEGER NOT NULL,
|
||||
[Owed] INTEGER NOT NULL,
|
||||
[Penalty] INTEGER NULL,
|
||||
[Penalty] INTEGER NOT NULL,
|
||||
[Multiplier] INTEGER NOT NULL,
|
||||
[RefundAmount] INTEGER NOT NULL,
|
||||
[PayBy] TEXT NOT NULL,
|
||||
[LastPaid] TEXXT NULL,
|
||||
[LastPaid] TEXT NULL,
|
||||
[PaidOn] TEXT NULL);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS [reservations] (
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
[RoomID] INTEGER NOT NULL,
|
||||
[GuestID] INTEGER NOT NULL,
|
||||
[TransactionID] INTEGER NOT NULL,
|
||||
[RoomNum] INTEGER NULL UNIQUE,
|
||||
[GuestID] INTEGER NOT NULL UNIQUE,
|
||||
[TransactionID] INTEGER NOT NULL UNIQUE,
|
||||
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
|
||||
[Type] INTEGER NOT NULL CHECK ([Type] IN (0,1,2,3)),
|
||||
[Status] INTEGER NOT NULL CHECK ([Status] IN (0,1,2,3)),
|
||||
[CreationDate] TEXT NOT NULL,
|
||||
[StartDate] TEXT NOT NULL,
|
||||
[EndDate] TEXT NOT NULL,
|
||||
[CheckIn] TEXT NOT NULL,
|
||||
[CheckOut] TEXT NOT NULL,
|
||||
[DateChanged] TEXT NOT NULL,
|
||||
FOREIGN KEY ([RoomID]) REFERENCES ROOMS(ID),
|
||||
FOREIGN KEY ([GuestID]) REFERENCES GUESTS(ID),
|
||||
FOREIGN KEY ([TransactionID]) REFERENCES TRANSACTIONS(ID));
|
||||
[CheckIn] TEXT NULL,
|
||||
[CheckOut] TEXT NULL,
|
||||
[DateChanged] TEXT NULL,
|
||||
FOREIGN KEY ([RoomNum]) REFERENCES rooms(ID),
|
||||
FOREIGN KEY ([GuestID]) REFERENCES guests(ID),
|
||||
FOREIGN KEY ([TransactionID]) REFERENCES transactions(ID));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS [guests] (
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -98,10 +98,6 @@ namespace Ophelias.Managers
|
||||
}
|
||||
}
|
||||
|
||||
internal static class DatabaseFunctions
|
||||
{
|
||||
|
||||
}
|
||||
internal static class QueryBuilder
|
||||
{
|
||||
|
||||
@@ -114,24 +110,24 @@ namespace Ophelias.Managers
|
||||
string query = "UPDATE transactions SET";
|
||||
|
||||
if (Rate.HasValue)
|
||||
queryComponents.Add($"Rate = {Rate}");
|
||||
queryComponents.Add($"Rate = @Rate");
|
||||
if (Owed.HasValue)
|
||||
queryComponents.Add($"Owed = {Owed}");
|
||||
queryComponents.Add($"Owed = @Owed");
|
||||
if (Penalty.HasValue)
|
||||
queryComponents.Add($"Penalty = {Penalty}");
|
||||
queryComponents.Add($"Penalty = @Penalty");
|
||||
if (Multiplier.HasValue)
|
||||
queryComponents.Add($"Multiplier = {Multiplier}");
|
||||
queryComponents.Add($"Multiplier = @Multiplier");
|
||||
if (Refund.HasValue)
|
||||
queryComponents.Add($"Refund = {Refund}");
|
||||
queryComponents.Add($"Refund = @Refund");
|
||||
if (PayBy.HasValue)
|
||||
queryComponents.Add($"PayBy = {PayBy.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
queryComponents.Add($"PayBy = @PayBy");
|
||||
if (LastPaid.HasValue)
|
||||
queryComponents.Add($"LastPaid = {LastPaid.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
queryComponents.Add($"LastPaid = @LastPaid");
|
||||
if (PaidOn.HasValue)
|
||||
queryComponents.Add($"PaidOn = {PaidOn.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
queryComponents.Add($"PaidOn = @PaidOn");
|
||||
|
||||
if (queryComponents.Count > 0)
|
||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {Id};";
|
||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = @ID;";
|
||||
else
|
||||
return null;
|
||||
|
||||
@@ -147,83 +143,58 @@ namespace Ophelias.Managers
|
||||
string query = "UPDATE reservations SET";
|
||||
|
||||
if (RoomID.HasValue)
|
||||
QueryParts.Add($"RoomID = {RoomID}");
|
||||
QueryParts.Add($"RoomID = @RID");
|
||||
if (GuestID.HasValue)
|
||||
QueryParts.Add($"GuestID = {GuestID}");
|
||||
QueryParts.Add($"GuestID = @GID");
|
||||
if (TransactionID.HasValue)
|
||||
QueryParts.Add($"TransactionID = {TransactionID}");
|
||||
QueryParts.Add($"TransactionID = @TID");
|
||||
if (IsNoShow.HasValue)
|
||||
QueryParts.Add($"IsNoShow = {Convert.ToInt32(IsNoShow)}");
|
||||
QueryParts.Add($"IsNoShow = @IsNoShow");
|
||||
if (Type.HasValue)
|
||||
QueryParts.Add($"Type = {(int)Type}");
|
||||
QueryParts.Add($"Type = @Type");
|
||||
if (Status.HasValue)
|
||||
QueryParts.Add($"Status = {(int)Status}");
|
||||
QueryParts.Add($"Status = @Status");
|
||||
if (CreationDate.HasValue)
|
||||
QueryParts.Add($"CreationDate = {CreationDate.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
QueryParts.Add($"CreationDate = @CreationDate");
|
||||
if (StartDate.HasValue)
|
||||
QueryParts.Add($"StartDate = {StartDate.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
QueryParts.Add($"StartDate = @StartDate");
|
||||
if (EndDate.HasValue)
|
||||
QueryParts.Add($"EndDate = {EndDate.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
QueryParts.Add($"EndDate = @EndDate");
|
||||
if (CheckIn.HasValue)
|
||||
QueryParts.Add($"CheckIn = {CheckIn.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
QueryParts.Add($"CheckIn = @CheckIn");
|
||||
if (CheckOut.HasValue)
|
||||
QueryParts.Add($"CheckOut = {CheckOut.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
QueryParts.Add($"CheckOut = @CheckOut");
|
||||
if (DateChanged.HasValue)
|
||||
QueryParts.Add($"DateChanged = {DateChanged.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
QueryParts.Add($"DateChanged = @DateChanged");
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
|
||||
else
|
||||
return null;
|
||||
|
||||
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)
|
||||
{
|
||||
List<string> QueryParts = new List<string>();
|
||||
string query = "UPDATE guests SET";
|
||||
|
||||
if (!string.IsNullOrEmpty(FirstName))
|
||||
QueryParts.Add($"Fname = '{FirstName}'");
|
||||
QueryParts.Add($"Fname = @Fname");
|
||||
if (!string.IsNullOrEmpty(LastName))
|
||||
QueryParts.Add($"Lname = '{LastName}'");
|
||||
QueryParts.Add($"Lname = @Lname");
|
||||
if (!string.IsNullOrEmpty(LastName))
|
||||
QueryParts.Add($"Email = '{Email}'");
|
||||
QueryParts.Add($"Email = @Email");
|
||||
if (!string.IsNullOrEmpty(CreditCard))
|
||||
QueryParts.Add($"CreditCard = '{CreditCard}'");
|
||||
QueryParts.Add($"CreditCard = @CC");
|
||||
if (!string.IsNullOrEmpty(Expiration))
|
||||
QueryParts.Add($"Expiration = '{Expiration}'");
|
||||
QueryParts.Add($"Expiration = @Expiry");
|
||||
if (!string.IsNullOrEmpty(CCV))
|
||||
QueryParts.Add($"CCV = '{CCV}'");
|
||||
QueryParts.Add($"CCV = @CCV");
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
|
||||
else
|
||||
return null;
|
||||
|
||||
|
||||
@@ -12,11 +12,13 @@ namespace Ophelias.Managers
|
||||
{
|
||||
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.Parameters.AddWithValue("@Table", tableName);
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.HasRows)
|
||||
LastId = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
@@ -32,12 +34,14 @@ namespace Ophelias.Managers
|
||||
{
|
||||
cmd.CommandText = $@"SELECT COUNT(*)
|
||||
FROM reservations
|
||||
WHERE DATE('{Date.Date.ToString("yyyy-MM-dd")}')
|
||||
WHERE DATE(@Date)
|
||||
BETWEEN StartDate AND EndDate;";
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.AddWithValue("@Date", Date.Date.ToString("yyyy-MM-dd"));
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.Read())
|
||||
Occupancies.Add(reader.GetInt32(0));
|
||||
}
|
||||
}
|
||||
@@ -47,7 +51,7 @@ namespace Ophelias.Managers
|
||||
internal static int AvgOccupancySpan(DateTime Start, DateTime End)
|
||||
{
|
||||
int thirtyDayOcc = 0;
|
||||
int days = (int)(Start.Date - End.Date).TotalDays;
|
||||
int days = (int)(End.Date - Start.Date).TotalDays;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
for (int i = 0; i < days; i++)
|
||||
@@ -56,12 +60,14 @@ namespace Ophelias.Managers
|
||||
{
|
||||
cmd.CommandText = $@"SELECT COUNT(*)
|
||||
FROM reservations
|
||||
WHERE DATE('{Start.AddDays(i).Date.ToString("yyyy-MM-dd")}')
|
||||
WHERE DATE(@Date)
|
||||
BETWEEN StartDate AND EndDate;";
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
if(reader.HasRows)
|
||||
thirtyDayOcc += reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
@@ -69,82 +75,6 @@ namespace Ophelias.Managers
|
||||
}
|
||||
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)
|
||||
{
|
||||
Guest? g = null;
|
||||
@@ -152,7 +82,8 @@ namespace Ophelias.Managers
|
||||
{
|
||||
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();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
@@ -173,9 +104,57 @@ namespace Ophelias.Managers
|
||||
}
|
||||
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 (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
@@ -186,7 +165,10 @@ namespace Ophelias.Managers
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.HasRows)
|
||||
rate = reader.GetDouble(0);
|
||||
else
|
||||
rate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,8 +181,10 @@ namespace Ophelias.Managers
|
||||
{
|
||||
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.Parameters.AddWithValue("@Rate", Rate);
|
||||
cmd.Parameters.AddWithValue("@DateSet", DateSet);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
@@ -224,8 +208,9 @@ namespace Ophelias.Managers
|
||||
int? Id;
|
||||
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.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
|
||||
cmd.ExecuteNonQuery();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
@@ -237,8 +222,10 @@ namespace Ophelias.Managers
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $@"UPDATE rates SET DefaultRate = NULL WHERE Id = {OldId};
|
||||
UPDATE rates SET DefaultRate = 1 WHERE Id = {Id}";
|
||||
cmd.CommandText = @"UPDATE rates SET DefaultRate = NULL WHERE Id = @OldID;
|
||||
UPDATE rates SET DefaultRate = 1 WHERE Id = @ID";
|
||||
cmd.Parameters.AddWithValue("@OldID", OldId);
|
||||
cmd.Parameters.AddWithValue("@ID", Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Ophelias.Models;
|
||||
using Ophelias.Managers;
|
||||
using System.Data.SQLite;
|
||||
|
||||
namespace Ophelias.Models
|
||||
{
|
||||
@@ -17,6 +13,44 @@ namespace Ophelias.Models
|
||||
internal string? CCV;
|
||||
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)
|
||||
{
|
||||
this.Id = Id;
|
||||
@@ -27,6 +61,28 @@ namespace Ophelias.Models
|
||||
this.Expiration = Expiration;
|
||||
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)
|
||||
{
|
||||
this.CreditCard = CreditCard;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Ophelias.Models
|
||||
internal class Reservation
|
||||
{
|
||||
internal int Id;
|
||||
internal Room Room;
|
||||
internal int? RoomNum;
|
||||
internal Guest Guest;
|
||||
internal Transaction Transaction;
|
||||
|
||||
@@ -26,10 +26,84 @@ namespace Ophelias.Models
|
||||
internal DateTime? CheckOut;
|
||||
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,
|
||||
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.RoomNum = RoomNum;
|
||||
this.Guest = Guest;
|
||||
this.Transaction = Transaction;
|
||||
this.IsNoShow = IsNoShow;
|
||||
@@ -57,23 +131,38 @@ namespace Ophelias.Models
|
||||
throw new Exception();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
DateTime _DateChanged = DateTime.Now.Date;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
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)
|
||||
throw new Exception();
|
||||
|
||||
Status = ReservationStatus.Cancelled;
|
||||
DateChanged = _DateChanged;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Ophelias.Models
|
||||
{
|
||||
internal class Room
|
||||
internal class @int
|
||||
{
|
||||
internal int Id;
|
||||
internal bool Occupied;
|
||||
|
||||
internal Room(int id)
|
||||
internal @int(int id)
|
||||
{
|
||||
Id = id;
|
||||
Occupied = false;
|
||||
@@ -20,11 +20,11 @@ namespace Ophelias.Models
|
||||
|
||||
internal class RoomList
|
||||
{
|
||||
internal List<Room> Rooms;
|
||||
internal List<@int> Rooms;
|
||||
|
||||
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? 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,
|
||||
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
||||
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
|
||||
@@ -51,6 +94,10 @@ namespace Ophelias.Models
|
||||
throw new Exception();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -75,6 +122,11 @@ namespace Ophelias.Models
|
||||
throw new Exception();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -92,6 +144,8 @@ namespace Ophelias.Models
|
||||
throw new Exception();
|
||||
|
||||
cmd.CommandText = query;
|
||||
cmd.Parameters.AddWithValue("@ID", Id);
|
||||
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
@@ -125,7 +179,7 @@ namespace Ophelias.Models
|
||||
}
|
||||
internal static double CalculateOwed(double Rate, int Days)
|
||||
{
|
||||
return Rate * (double)Days;
|
||||
return Rate * Days;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,56 @@ class Program
|
||||
{
|
||||
Reservation? activeReservation = 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() {
|
||||
Console.Write("What is your first name: ");
|
||||
string FirstName = "";
|
||||
@@ -40,21 +90,6 @@ class Program
|
||||
}
|
||||
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()
|
||||
{
|
||||
Console.Write("\nEnter your email address: ");
|
||||
@@ -67,8 +102,12 @@ class Program
|
||||
}
|
||||
activeGuest = HotelManager.GetGuestByEmail(email);
|
||||
if (activeGuest == null)
|
||||
{
|
||||
Console.WriteLine($"\nNo account was found with the email {email}.");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine($"\nYou have logged into {activeGuest.FirstName} {activeGuest.LastName} ({email}).");
|
||||
activeReservation = HotelManager.GetResByGuestAndDate(activeGuest);
|
||||
}
|
||||
void CreateNewGuestPrompt()
|
||||
{
|
||||
@@ -81,7 +120,7 @@ class Program
|
||||
if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y"))
|
||||
(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})");
|
||||
}
|
||||
void UpdateGuestInformation()
|
||||
@@ -136,7 +175,7 @@ class Program
|
||||
if (NewDetails.Count > 0)
|
||||
changes += string.Join("\n", NewDetails);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -153,7 +192,6 @@ class Program
|
||||
switch (Console.ReadLine())
|
||||
{
|
||||
case "Q": return;
|
||||
case "q": return;
|
||||
case "1": (NewFname, NewLname) = GetGuestName(); break;
|
||||
case "2": NewEmail = GetGuestEmail(); break;
|
||||
case "3": (NewCard, NewExpiry, NewCCV) = GetCreditCardInformation(); break;
|
||||
@@ -162,16 +200,9 @@ class Program
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
void CreateNewReservation()
|
||||
{
|
||||
if (activeGuest == null)
|
||||
Console.WriteLine("No guest is currently logged in, please login.");
|
||||
if (activeReservation != null)
|
||||
Console.WriteLine("");
|
||||
|
||||
string input = "";
|
||||
ReservationType SelectReservation()
|
||||
{
|
||||
string input = "";
|
||||
Console.Write("What kind of reservation would you like to make?\n" +
|
||||
"1. Conventional\n" +
|
||||
"2. Prepaid\n" +
|
||||
@@ -189,12 +220,13 @@ class Program
|
||||
}
|
||||
(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)
|
||||
while (true)
|
||||
{
|
||||
input = Console.ReadLine();
|
||||
if (DateTime.TryParse(input, out _StartDate))
|
||||
@@ -218,6 +250,53 @@ class Program
|
||||
}
|
||||
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()
|
||||
{
|
||||
if (activeGuest == null)
|
||||
{
|
||||
Console.WriteLine("No guest is currently logged in, please login.");
|
||||
return;
|
||||
}
|
||||
if (activeReservation != null)
|
||||
{
|
||||
Console.WriteLine("You currently have an active registration.");
|
||||
return;
|
||||
}
|
||||
if (HotelManager.GetBaseRate() == null)
|
||||
{
|
||||
Console.WriteLine("Unable to proceed with reservation due to no base rate being set. Please inform an employee.");
|
||||
return;
|
||||
}
|
||||
|
||||
string input;
|
||||
|
||||
ReservationType Type;
|
||||
DateTime StartDate;
|
||||
@@ -225,71 +304,126 @@ class Program
|
||||
|
||||
Type = SelectReservation();
|
||||
(StartDate, EndDate) = SelectDate();
|
||||
if (Type != ReservationType.SixtyDayAdvance &&
|
||||
(activeGuest.CreditCard == null || activeGuest.Expiration == null || activeGuest.CCV == null))
|
||||
while((Type != ReservationType.SixtyDayAdvance &&
|
||||
(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();
|
||||
}
|
||||
|
||||
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")}." +
|
||||
$"If these details are correct, enter YES to complete. If they are not enter...\n" +
|
||||
$"1. Change your reservation type\n" +
|
||||
$"2. Change your reservation dates\n" +
|
||||
$"If these details are correct, enter YES to complete. To cancel your reservation enter Q. Enter NO to edit your reservation.\n" +
|
||||
$": ");
|
||||
input = Console.ReadLine();
|
||||
if (input != "YES")
|
||||
while(input != "YES")
|
||||
{
|
||||
bool completed = false;
|
||||
if (input == "NO")
|
||||
{
|
||||
EditReservationPrompt();
|
||||
Console.Write("You're changes have been saved. Are you done with your changes?\n" +
|
||||
"Enter YES to finish, NO to continue editing, or Q to discard your reservation.\n" +
|
||||
": ");
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
else if (input == "Q")
|
||||
{
|
||||
Console.WriteLine("Reservation has been deleted.");
|
||||
return;
|
||||
} else
|
||||
{
|
||||
Console.WriteLine("Input must be YES, NO, or Q.\n: ");
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
|
||||
Console.WriteLine("Your reservation has been made.");
|
||||
}
|
||||
void UpdateReservation()
|
||||
{
|
||||
string input = "NO";
|
||||
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;
|
||||
}
|
||||
|
||||
Console.Write("Your current reservation details are:\n" +
|
||||
$"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")}\n" +
|
||||
$"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")}\n");
|
||||
DateTime? _StartDate = null, _EndDate = null;
|
||||
do
|
||||
{
|
||||
Console.Write("Would you like to edit any information, enter Q to exit and complete your reservation?\n" +
|
||||
"1. Reservation type\n" +
|
||||
"2. Reservation dates\n" +
|
||||
"Enter 1 or 2: ");
|
||||
switch (Console.ReadLine())
|
||||
if (input == "NO")
|
||||
{
|
||||
case "Q": completed = true; break;
|
||||
case "q": completed = true; break;
|
||||
case "1": SelectReservation(); break;
|
||||
case "2": SelectDate(); break;
|
||||
default: break;
|
||||
}
|
||||
} while (!completed);
|
||||
}
|
||||
HotelManager.CreateReservation(activeGuest, Type, DateTime.Now.Date, StartDate, EndDate);
|
||||
}
|
||||
(string?, string?, string?) GetCreditCardInformation()
|
||||
(_StartDate, _EndDate) = SelectDate();
|
||||
if (_StartDate.HasValue && _EndDate.HasValue)
|
||||
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.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.WriteLine("Your changes have been discarded.");
|
||||
return;
|
||||
}
|
||||
Console.Write("What is your credit card expiration date (MM/yy): ");
|
||||
string CardExpiration = "";
|
||||
while (!Validation.ValidateExpirationDate(CardExpiration))
|
||||
else
|
||||
{
|
||||
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.WriteLine("Input must be YES, NO, or Q.");
|
||||
Console.Write(": ");
|
||||
}
|
||||
Console.Write("What is your credit card CCV: ");
|
||||
string CCV = "";
|
||||
while (!Validation.ValidateCCV(CCV))
|
||||
input = Console.ReadLine();
|
||||
} while (input != "YES");
|
||||
if (_StartDate != null && _EndDate != null)
|
||||
{
|
||||
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: ");
|
||||
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(
|
||||
"\nWelcome to the Ophelias Oasis Hotel Registration System!\n" +
|
||||
@@ -304,8 +438,8 @@ class Program
|
||||
{
|
||||
case "help": help(); break;
|
||||
case "reservation create": CreateNewReservation(); break;
|
||||
case "reservation update": break;
|
||||
case "reservation cancel": break;
|
||||
case "reservation update": UpdateReservation(); break;
|
||||
case "reservation cancel": CancelReservation(); break;
|
||||
case "account create": CreateNewGuestPrompt(); break;
|
||||
case "account update": UpdateGuestInformation(); break;
|
||||
case "account login": GuestLogin(); break;
|
||||
@@ -321,16 +455,50 @@ class Program
|
||||
{
|
||||
Console.WriteLine(
|
||||
"Report Commands:\n" +
|
||||
"\treservation create\n" +
|
||||
"\treservation update\n" +
|
||||
"\tgenerate daily report - Generates a daily report on expected occupancy, room income, and incentive losses.\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" +
|
||||
"Account Commands:" +
|
||||
"\taccount create\n" +
|
||||
"\taccount update\n" +
|
||||
"Management Commands:" +
|
||||
"\tcheckin guest - Checks in a guest and assigns them a room.\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"
|
||||
);
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user