WIP: Adds several core models needed for functionality #24

Merged
yan-wah merged 10 commits from models into main 2022-04-16 04:48:19 -04:00
15 changed files with 1615 additions and 674 deletions
Showing only changes of commit fbb75a583d - Show all commits

View File

@@ -1,13 +1,13 @@
using System.Data.SQLite; using Ophelias.Models;
using Ophelias.Models; using System.Data.SQLite;
namespace Ophelias.Managers namespace Ophelias.Managers
{ {
internal class DatabaseManager : IDisposable internal class Database : IDisposable
{ {
internal SQLiteConnection con = new SQLiteConnection("DataSource=database.sqlite3;Version=3;"); internal SQLiteConnection con = new("DataSource=database.sqlite3;Version=3;");
internal DatabaseManager() internal Database()
{ {
Connect(); Connect();
} }
@@ -30,13 +30,14 @@ namespace Ophelias.Managers
[Penalty] INTEGER NOT NULL, [Penalty] INTEGER NOT NULL,
[Multiplier] INTEGER NOT NULL, [Multiplier] INTEGER NOT NULL,
[RefundAmount] INTEGER NOT NULL, [RefundAmount] INTEGER NOT NULL,
[AmountPaid] INTEGER NOT NULL,
[PayBy] TEXT NOT NULL, [PayBy] TEXT NOT NULL,
[LastPaid] TEXT 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,
[RoomNum] INTEGER NULL UNIQUE, [RoomNum] INTEGER NULL,
[GuestID] INTEGER NOT NULL, [GuestID] INTEGER NOT NULL,
[TransactionID] INTEGER NOT NULL UNIQUE, [TransactionID] INTEGER NOT NULL UNIQUE,
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)), [IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
@@ -71,23 +72,19 @@ namespace Ophelias.Managers
[DateSet] TEXT NOT NULL UNIQUE, [DateSet] TEXT NOT NULL UNIQUE,
[DefaultRate] INTEGER NULL UNIQUE CHECK ([DefaultRate] IN (1)));"; [DefaultRate] INTEGER NULL UNIQUE CHECK ([DefaultRate] IN (1)));";
using (SQLiteCommand cmd = con.CreateCommand()) using SQLiteCommand cmd = con.CreateCommand();
{
cmd.CommandText = tableCommands; cmd.CommandText = tableCommands;
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
}
internal void InitializeRoomsTable() internal void InitializeRoomsTable()
{ {
using (SQLiteCommand cmd = con.CreateCommand()) using SQLiteCommand cmd = con.CreateCommand();
{
for (int i = 1; i < 46; i++) for (int i = 1; i < 46; i++)
{ {
cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);"; cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
}
// Initialize Rooms // Initialize Rooms
@@ -104,32 +101,64 @@ namespace Ophelias.Managers
internal static string? UpdateTransaction(int Id, internal static string? UpdateTransaction(int Id,
double? Rate = null, double? Owed = null, double? Penalty = null, double? Rate = null, double? Owed = null, double? Penalty = null,
double? Multiplier = null, double? Refund = null, double? Multiplier = null, double? Refund = null,
DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null) DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null, double? AmountPaid = null)
{ {
List<string> queryComponents = new List<string>(); List<string> queryComponents = new();
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($"RefundAmount = @RefundAmount");
}
if (AmountPaid.HasValue)
{
queryComponents.Add($"AmountPaid = @AmountPaid");
}
if (PayBy.HasValue) if (PayBy.HasValue)
{
queryComponents.Add($"PayBy = @PayBy"); queryComponents.Add($"PayBy = @PayBy");
}
if (LastPaid.HasValue) if (LastPaid.HasValue)
{
queryComponents.Add($"LastPaid = @LastPaid"); queryComponents.Add($"LastPaid = @LastPaid");
}
if (PaidOn.HasValue) if (PaidOn.HasValue)
{
queryComponents.Add($"PaidOn = @PaidOn"); 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;
}
return query; return query;
} }
@@ -139,64 +168,124 @@ namespace Ophelias.Managers
ReservationStatus? Status = null, DateTime? CreationDate = null, DateTime? StartDate = null, DateTime? EndDate = null, ReservationStatus? Status = null, DateTime? CreationDate = null, DateTime? StartDate = null, DateTime? EndDate = null,
DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null) DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
{ {
List<string> QueryParts = new List<string>(); List<string> QueryParts = new();
string query = "UPDATE reservations SET"; string query = "UPDATE reservations SET";
if (RoomID.HasValue) if (RoomID.HasValue)
{
QueryParts.Add($"RoomID = @RID"); QueryParts.Add($"RoomID = @RID");
}
if (GuestID.HasValue) if (GuestID.HasValue)
{
QueryParts.Add($"GuestID = @GID"); QueryParts.Add($"GuestID = @GID");
}
if (TransactionID.HasValue) if (TransactionID.HasValue)
{
QueryParts.Add($"TransactionID = @TID"); QueryParts.Add($"TransactionID = @TID");
}
if (IsNoShow.HasValue) if (IsNoShow.HasValue)
{
QueryParts.Add($"IsNoShow = @IsNoShow"); QueryParts.Add($"IsNoShow = @IsNoShow");
}
if (Type.HasValue) if (Type.HasValue)
{
QueryParts.Add($"Type = @Type"); QueryParts.Add($"Type = @Type");
}
if (Status.HasValue) if (Status.HasValue)
{
QueryParts.Add($"Status = @Status"); QueryParts.Add($"Status = @Status");
}
if (CreationDate.HasValue) if (CreationDate.HasValue)
{
QueryParts.Add($"CreationDate = @CreationDate"); QueryParts.Add($"CreationDate = @CreationDate");
}
if (StartDate.HasValue) if (StartDate.HasValue)
{
QueryParts.Add($"StartDate = @StartDate"); QueryParts.Add($"StartDate = @StartDate");
}
if (EndDate.HasValue) if (EndDate.HasValue)
{
QueryParts.Add($"EndDate = @EndDate"); QueryParts.Add($"EndDate = @EndDate");
}
if (CheckIn.HasValue) if (CheckIn.HasValue)
{
QueryParts.Add($"CheckIn = @CheckIn"); QueryParts.Add($"CheckIn = @CheckIn");
}
if (CheckOut.HasValue) if (CheckOut.HasValue)
{
QueryParts.Add($"CheckOut = @CheckOut"); QueryParts.Add($"CheckOut = @CheckOut");
}
if (DateChanged.HasValue) if (DateChanged.HasValue)
{
QueryParts.Add($"DateChanged = @DateChanged"); 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? 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();
string query = "UPDATE guests SET"; string query = "UPDATE guests SET";
if (!string.IsNullOrEmpty(FirstName)) if (!string.IsNullOrEmpty(FirstName))
{
QueryParts.Add($"Fname = @Fname"); QueryParts.Add($"Fname = @Fname");
}
if (!string.IsNullOrEmpty(LastName)) if (!string.IsNullOrEmpty(LastName))
{
QueryParts.Add($"Lname = @Lname"); 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 = @CC"); QueryParts.Add($"CreditCard = @CC");
}
if (!string.IsNullOrEmpty(Expiration)) if (!string.IsNullOrEmpty(Expiration))
{
QueryParts.Add($"Expiration = @Expiry"); 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;
}
return query; return query;
} }

View File

@@ -0,0 +1,949 @@
using Ophelias.Models;
using System.Data.SQLite;
namespace Ophelias.Managers
{
internal static class Hotel
{
internal static int GetLastId(string tableName)
{
int LastId = 0;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
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 && !reader.IsDBNull(0))
{
LastId = reader.GetInt32(0);
}
}
}
return LastId;
}
internal static (List<(DateTime, int, string, string)>, List<int>) GetDailyOccupancy()
{
List<int> previousOccupancies = new();
List<(DateTime, int, string, string)> currentOccupancies = new();
using (Database Manager = new())
{
using SQLiteTransaction Transaction = Manager.con.BeginTransaction();
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT RoomNum, Lname, Fname, EndDate FROM reservations " +
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
"INNER JOIN rooms ON reservations.RoomNum = rooms.ID " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2);";
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
currentOccupancies.Add((reader.GetDateTime(3), reader.GetInt32(0), reader.GetString(1), reader.GetString(2)));
}
}
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT RoomNum FROM reservations " +
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
"INNER JOIN rooms ON reservations.RoomNum = rooms.ID " +
"WHERE DATE (@Date) = EndDate AND Status IN (@Status1);";
cmd.Parameters.AddWithValue("@Date", DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Ended);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
foreach (int item in reader.GetValues())
{
previousOccupancies.Add(item);
}
}
}
}
Transaction.Commit();
}
return (currentOccupancies, previousOccupancies);
}
internal static List<Reservation> GetDailyArrivals()
{
List<Reservation> reservations = new();
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT * FROM reservations " +
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
"WHERE DATE (@Date) = StartDate AND Status IN (@Status1,@Status2)" +
"ORDER BY Lname ASC;";
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Reservation? r;
Transaction? t;
Guest g;
int? RoomNumber = null;
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
if (reader.HasRows && !reader.IsDBNull(0))
{
if (reader[21].GetType() != typeof(DBNull))
{
LastPaid = reader.GetDateTime(21);
}
if (reader[22].GetType() != typeof(DBNull))
{
PaidOn = reader.GetDateTime(22);
}
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
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(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);
reservations.Add(r);
}
}
}
}
}
return reservations;
}
internal static (double, double, List<(DateTime, double)>) GetIncentiveTransactions()
{
double losses;
double totalLosses = 0;
int days = 30;
DateTime dt = DateTime.Now;
List<(DateTime, double)> dailyLosses = new();
using (Database Manager = new())
{
for (int i = 0; i < days; i++)
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT sum(((julianday(EndDate) - julianday(StartDate)) * transactions.Rate) - transactions.Owed) AS Loss " +
"FROM reservations " +
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND STATUS IN (@Status1,@Status2) AND Type = @Type";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
cmd.Parameters.AddWithValue("@Type", (int)ReservationType.Incentive);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
totalLosses += reader.GetDouble(0);
losses = reader.GetDouble(0);
}
else
{
losses = 0;
}
}
}
dailyLosses.Add((dt.AddDays(i), losses));
}
}
return (totalLosses, totalLosses / 30, dailyLosses);
}
internal static (List<(DateTime, double)>, double, double) GetExpectedIncomeCount()
{
double totalIncome = 0;
double income;
int days = 30;
DateTime dt = DateTime.Now;
List<(DateTime, double)> dailyIncomes = new();
using (Database Manager = new())
{
for (int i = 0; i < days; i++)
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT sum(transactions.Owed) FROM reservations " +
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status IN (@Status1,@Status2);";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
totalIncome += reader.GetDouble(0);
income = reader.GetDouble(0);
}
else
{
income = 0;
}
}
}
dailyIncomes.Add((dt.AddDays(i), income));
}
}
return (dailyIncomes, totalIncome, totalIncome / 30);
}
internal static (double, List<(DateTime, int, int, int, int, int)>) GetExpectedOccupancyCount()
{
double thirtyDayOcc = 0;
int days = 30;
DateTime dt = DateTime.Now;
List<(DateTime, int, int, int, int, int)> occData = new();
using (Database Manager = new())
{
for (int i = 0; i < days; i++)
{
int rooms, conventional, prepaid, sixty, incentive;
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) " +
"FROM reservations " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2);";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
thirtyDayOcc += reader.GetInt32(0);
rooms = reader.GetInt32(0);
}
else
{
rooms = 0;
}
}
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) " +
"FROM reservations " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 0;";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
conventional = reader.GetInt32(0);
}
else
{
conventional = 0;
}
}
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) " +
"FROM reservations " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 1;";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
prepaid = reader.GetInt32(0);
}
else
{
prepaid = 0;
}
}
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) " +
"FROM reservations " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 2;";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
sixty = reader.GetInt32(0);
}
else
{
sixty = 0;
}
}
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) " +
"FROM reservations " +
"WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2) AND Type = 3;";
cmd.Parameters.AddWithValue("@Date", dt.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
incentive = reader.GetInt32(0);
}
else
{
incentive = 0;
}
}
}
Transaction.Commit();
}
occData.Add((dt.AddDays(i), rooms, conventional, prepaid, sixty, incentive));
}
}
return (thirtyDayOcc / days, occData);
}
internal static (int, bool) AvgOccupancySpan(DateTime Start, DateTime End)
{
int thirtyDayOcc = 0;
bool maxCapacityInRange = false;
int days = (int)(End.Date - Start.Date).TotalDays;
using (Database Manager = new())
{
for (int i = 0; i < days; i++)
{
using SQLiteCommand cmd = Manager.con.CreateCommand();
cmd.CommandText = $@"SELECT COUNT(*)
FROM reservations
WHERE (DATE(@Date) BETWEEN StartDate AND EndDate) AND Status in (@Status1,@Status2);";
cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using SQLiteDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows && !reader.IsDBNull(0))
{
thirtyDayOcc += reader.GetInt32(0);
if (reader.GetInt32(0) == 45)
{
maxCapacityInRange = true;
}
}
}
}
return (thirtyDayOcc / days, maxCapacityInRange);
}
internal static Guest? GetGuestByEmail(string Email)
{
Guest? g = null;
using (Database Manager = new())
{
using SQLiteCommand cmd = Manager.con.CreateCommand();
cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
cmd.Parameters.AddWithValue("@Email", Email);
using SQLiteDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
string? CreditCard = null, Expiration = null, CCV = null;
if (reader[4].GetType() != typeof(DBNull))
{
CreditCard = reader[4].ToString();
}
if (reader[5].GetType() != typeof(DBNull))
{
Expiration = reader[5].ToString();
}
if (reader[6].GetType() != typeof(DBNull))
{
CCV = reader[6].ToString();
}
g = new(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), CreditCard, Expiration, CCV);
}
}
return g;
}
internal static Reservation? GetResByGuest(Guest g)
{
Reservation? r = null;
Transaction? t;
using (Database Manager = new())
{
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);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
if (reader[21].GetType() != typeof(DBNull))
{
LastPaid = reader.GetDateTime(21);
}
if (reader[22].GetType() != typeof(DBNull))
{
PaidOn = reader.GetDateTime(22);
}
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
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(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 TimeRefs? CanBeCheckedIn(string Email)
{
TimeRefs? status = null;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (0,1)";
cmd.Parameters.AddWithValue("@Email", Email);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
DateTime dt = reader.GetDateTime(8);
if (dt.Date == DateTime.Now.Date)
{
status = TimeRefs.OnTime;
}
else if (dt.Date > DateTime.Now.Date)
{
status = TimeRefs.Late;
}
else if (dt.Date < DateTime.Now.Date)
{
status = TimeRefs.Early;
}
}
else
{
status = null;
}
}
}
}
return status;
}
internal static double? GetBaseRate()
{
double? rate;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Rate FROM rates WHERE DefaultRate = 1;";
cmd.CommandText = query;
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
rate = reader.GetDouble(0);
}
else
{
rate = null;
}
}
}
}
return rate;
}
internal static bool GetBaseRateByDate(DateTime dt)
{
bool configured;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Rate FROM rates WHERE DateSet = @Date;";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Date", dt.ToString("yyyy-MM-dd"));
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
configured = true;
}
else
{
configured = false;
}
}
}
}
return configured;
}
internal static void SetBaseRate(double Rate, DateTime DateSet, bool? DefaultRate = null)
{
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = $"INSERT INTO rates (Rate, DateSet, DefaultRate) VALUES (@Rate, @DateSet, @DefaultRate);";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@DateSet", DateSet.ToString("yyyy-MM-dd"));
if (DefaultRate != null)
{
if (DefaultRate.Value == true)
{
cmd.Parameters.AddWithValue("@DefaultRate", Convert.ToInt32(DefaultRate));
}
else
{
cmd.Parameters.AddWithValue("@DefaultRate", null);
}
}
else
{
cmd.Parameters.AddWithValue("@DefaultRate", null);
}
cmd.ExecuteNonQuery();
}
}
}
internal static void UpdateBaseRate(double Rate, DateTime DateSet, bool? DefaultRate = null)
{
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
if (DefaultRate != null)
{
if (DefaultRate.Value == true)
{
cmd.CommandText = $"UPDATE rates SET rate = @Rate, defaultrate = @DefaultRate WHERE DateSet = @Date;";
cmd.Parameters.AddWithValue("@DefaultRate", Convert.ToInt32(DefaultRate));
}
else
{
cmd.CommandText = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
}
}
else
{
cmd.CommandText = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
}
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@Date", DateSet.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
}
internal static bool CheckBaseRate()
{
int? OldId = null;
bool Success = true;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Id FROM rates WHERE DefaultRate = 1;";
cmd.CommandText = query;
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
OldId = reader.GetInt32(0);
}
}
}
int? Id;
if (OldId != null)
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Id FROM rates WHERE DateSet = @Date;";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
Id = reader.GetInt32(0);
}
else
{
Id = null;
}
}
}
if (Id != null)
{
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.Parameters.AddWithValue("@OldID", OldId);
cmd.Parameters.AddWithValue("@ID", Id);
cmd.ExecuteNonQuery();
}
}
}
else
{
Success = false;
}
}
return Success;
}
internal static int? CheckInGuest(string Email, DateTime CheckIn)
{
int? RoomID = null;
using (Database Manager = new())
{
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE reservations SET RoomNum = (SELECT ID FROM rooms WHERE Occupied = 0 LIMIT 1), CheckIn = @Date " +
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NULL AND Status in (@SActive,@SChanged);";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.Parameters.AddWithValue("@Date", CheckIn.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE rooms SET Occupied = 1 " +
"WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
RoomID = (int)reader.GetValue(0);
}
}
}
Transaction.Commit();
}
}
return RoomID;
}
internal static bool GuestCurrentlyCheckedIn(string Email)
{
bool EntryFound;
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT * FROM reservations " +
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)) AND CheckIn IS NOT NULL";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
EntryFound = true;
}
else
{
EntryFound = false;
}
}
}
}
return EntryFound;
}
internal static void CheckOutGuest(string Email, DateTime CheckOut)
{
using (Database Manager = new())
{
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE rooms SET Occupied = 0 " +
"WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Ended);
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE reservations SET CheckOut = @Date, Status = @Status " +
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NOT NULL AND Status in (@SActive,@SChanged);";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Ended);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.Parameters.AddWithValue("@Date", CheckOut.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
Transaction.Commit();
}
}
return;
}
internal static List<Reservation> GetActiveSixtyDayRes()
{
List<Reservation> list = new();
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT * FROM reservations " +
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
"WHERE Type = @Type AND Status IN (@Status1,@Status2);";
cmd.Parameters.AddWithValue("@Type", (int)ReservationType.SixtyDayAdvance);
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Reservation? r;
Transaction? t;
Guest g;
int? RoomNumber = null;
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
if (reader.HasRows)
{
if (reader[21].GetType() != typeof(DBNull))
{
LastPaid = reader.GetDateTime(21);
}
if (reader[22].GetType() != typeof(DBNull))
{
PaidOn = reader.GetDateTime(22);
}
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
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(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);
list.Add(r);
}
}
}
}
}
return list;
}
internal static List<Reservation> GetPastDueReservations()
{
List<Reservation> list = new();
using (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT * FROM reservations " +
"INNER JOIN transactions ON reservations.TransactionID = transactions.ID " +
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
"WHERE DATE(@Date) > StartDate AND Status IN (@Status1,@Status2) AND CheckIn IS NULL;";
cmd.Parameters.AddWithValue("@Date", DateTime.Now.Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Reservation? r;
Transaction? t;
Guest g;
int? RoomNumber = null;
DateTime? CheckIn = null, CheckOut = null, DateChanged = null, LastPaid = null, PaidOn = null;
if (reader.HasRows)
{
if (reader[21].GetType() != typeof(DBNull))
{
LastPaid = reader.GetDateTime(21);
}
if (reader[22].GetType() != typeof(DBNull))
{
PaidOn = reader.GetDateTime(22);
}
t = new(reader.GetInt32(13), reader.GetDouble(14), reader.GetDouble(15), reader.GetDouble(17), reader.GetDateTime(20),
LastPaid: LastPaid, PaidOn: PaidOn, RefundAmount: reader.GetDouble(18), Penalty: reader.GetDouble(16), AmountPaid: reader.GetDouble(19));
g = new(reader.GetInt32(23), reader.GetString(24), reader.GetString(25), reader.GetString(26), reader.GetString(27), reader.GetString(28), reader.GetString(29));
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(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);
list.Add(r);
}
}
}
}
}
return list;
}
}
internal enum TimeRefs
{
OnTime,
Early,
Late
}
}

View File

@@ -1,424 +0,0 @@
using Ophelias.Models;
using System.Data.SQLite;
namespace Ophelias.Managers
{
internal static class HotelManager
{
internal static int GetLastId(string tableName)
{
int LastId = 0;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
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);
}
}
}
return LastId;
}
internal static List<int> DailyOccupancies(DateTime Date)
{
List<int> Occupancies = new List<int>();
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = $@"SELECT COUNT(*)
FROM reservations
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));
}
}
}
return Occupancies;
}
internal static (int, bool) AvgOccupancySpan(DateTime Start, DateTime End)
{
int thirtyDayOcc = 0;
bool maxCapacityInRange = false;
int days = (int)(End.Date - Start.Date).TotalDays;
using (DatabaseManager Manager = new DatabaseManager())
{
for (int i = 0; i < days; i++)
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = $@"SELECT COUNT(*)
FROM reservations
WHERE DATE(@Date)
BETWEEN @Start AND @End;";
cmd.Parameters.AddWithValue("@Date", Start.AddDays(i).Date.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@Start", Start);
cmd.Parameters.AddWithValue("@End", End);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
thirtyDayOcc += reader.GetInt32(0);
if (reader.GetInt32(0) == 45)
maxCapacityInRange = true;
}
}
}
}
}
return (thirtyDayOcc / days, maxCapacityInRange);
}
internal static Guest? GetGuestByEmail(string Email)
{
Guest? g = null;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = $"SELECT * FROM guests WHERE Email = @Email";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
string? CreditCard = null, Expiration = null, CCV = null;
if (reader[4].GetType() != typeof(DBNull))
CreditCard = reader[4].ToString();
if (reader[5].GetType() != typeof(DBNull))
Expiration = reader[5].ToString();
if (reader[6].GetType() != typeof(DBNull))
CCV = reader[6].ToString();
g = new Guest(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), CreditCard, Expiration, CCV);
}
}
}
}
return g;
}
internal static Reservation? GetResByGuest(Guest g)
{
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 TimeRefs? CanBeCheckedIn(string Email)
{
TimeRefs? status = null;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (0,1)";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
DateTime dt = reader.GetDateTime(8);
if (dt.Date == DateTime.Now.Date)
status = TimeRefs.OnTime;
else if (dt.Date > DateTime.Now.Date)
status = TimeRefs.Late;
else if (dt.Date < DateTime.Now.Date)
status = TimeRefs.Early;
} else
status = null;
}
}
}
return status;
}
internal static double? GetBaseRate()
{
double? rate;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Rate FROM rates WHERE DefaultRate = 1;";
cmd.CommandText = query;
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
rate = reader.GetDouble(0);
else
rate = null;
}
}
}
return rate;
}
internal static bool GetBaseRateByDate(DateTime dt)
{
bool configured;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Rate FROM rates WHERE DateSet = @Date;";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Date", dt.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
configured = true;
else
configured = false;
}
}
}
return configured;
}
internal static void SetBaseRate(double Rate, DateTime DateSet)
{
double rate;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = $"INSERT INTO rates (Rate, DateSet) VALUES (@Rate, @DateSet);";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@DateSet", DateSet.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
}
internal static void UpdateBaseRate(double Rate, DateTime DateSet)
{
double rate;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = $"UPDATE rates SET rate = @Rate WHERE DateSet = @Date;";
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@Date", DateSet.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
}
internal static void CheckBaseRate()
{
using (DatabaseManager Manager = new DatabaseManager())
{
int? OldId;
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string query = "SELECT Id FROM rates WHERE DefaultRate = 1;";
cmd.CommandText = query;
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
OldId = reader.GetInt32(0);
}
}
int? Id;
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
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())
{
reader.Read();
Id = reader.GetInt32(0);
}
}
if (Id != null)
{
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.Parameters.AddWithValue("@OldID", OldId);
cmd.Parameters.AddWithValue("@ID", Id);
cmd.ExecuteNonQuery();
}
}
}
}
internal static int? CheckInGuest(string Email, DateTime CheckIn)
{
int? RoomID = null;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE reservations SET RoomNum = (SELECT ID FROM rooms WHERE Occupied = 0 LIMIT 1), CheckIn = @Date " +
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NULL AND Status in (@SActive,@SChanged);";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.Parameters.AddWithValue("@Date", CheckIn.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE rooms SET Occupied = 1 " +
"WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))));";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged))";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
{
RoomID = (int)reader.GetValue(0);
}
}
}
Transaction.Commit();
}
}
return RoomID;
}
internal static bool GuestCurrentlyCheckedIn(string Email)
{
bool EntryFound;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "SELECT * FROM reservations " +
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)) AND CheckIn IS NOT NULL";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.ExecuteNonQuery();
using (SQLiteDataReader reader = cmd.ExecuteReader())
{
reader.Read();
if (reader.HasRows)
EntryFound = true;
else
EntryFound = false;
}
}
}
return EntryFound;
}
internal static void CheckOutGuest(string Email, DateTime CheckOut)
{
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteTransaction Transaction = Manager.con.BeginTransaction())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE rooms SET Occupied = 0 " +
"WHERE ID = (SELECT RoomNum FROM reservations WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email AND Status in (@SActive,@SChanged)));";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Ended);
cmd.ExecuteNonQuery();
}
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "UPDATE reservations SET RoomNum = NULL, CheckOut = @Date, Status = @Status " +
"WHERE GuestID = (SELECT ID FROM guests WHERE Email = @Email) AND RoomNum IS NOT NULL AND Status in (@SActive,@SChanged);";
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@Status", (int)ReservationStatus.Ended);
cmd.Parameters.AddWithValue("@SActive", (int)ReservationStatus.Active);
cmd.Parameters.AddWithValue("@SChanged", (int)ReservationStatus.Changed);
cmd.Parameters.AddWithValue("@Date", CheckOut.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
Transaction.Commit();
}
}
return;
}
internal static List<Reservation> GetActiveSixtyDayRes()
{
List<Reservation> list = new List<Reservation>();
return list;
}
}
internal enum TimeRefs
{
OnTime,
Early,
Late
}
}

View File

@@ -16,17 +16,17 @@ namespace Ophelias.Models
internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null) internal Guest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
{ {
int Id; int Id;
using (DatabaseManager Manager = new DatabaseManager()) using (Database Manager = new())
{ {
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using (SQLiteCommand cmd = Manager.con.CreateCommand())
{ {
cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " + cmd.CommandText = "INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) " +
"VALUES (@Fname, @Lname, @Email, @CC, @Expiry, @CCV);"; "VALUES (@Fname, @Lname, @Email, @CreditCard, @Expiry, @CCV);";
cmd.Parameters.AddWithValue("@Fname", FirstName); cmd.Parameters.AddWithValue("@Fname", FirstName);
cmd.Parameters.AddWithValue("@Lname", LastName); cmd.Parameters.AddWithValue("@Lname", LastName);
cmd.Parameters.AddWithValue("@Email", Email); cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@CreditCard", CreditCard); cmd.Parameters.AddWithValue("@CreditCard", CreditCard);
cmd.Parameters.AddWithValue("@Expiration", Expiration); cmd.Parameters.AddWithValue("@Expiry", Expiration);
cmd.Parameters.AddWithValue("@CCV", CCV); cmd.Parameters.AddWithValue("@CCV", CCV);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@@ -63,26 +63,41 @@ namespace Ophelias.Models
} }
internal void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null) 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 (Database Manager = new())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{ {
using SQLiteCommand cmd = Manager.con.CreateCommand();
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV); cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
}
if (FirstName != null) if (FirstName != null)
{
this.FirstName = FirstName; this.FirstName = FirstName;
}
if (LastName != null) if (LastName != null)
{
this.LastName = LastName; this.LastName = LastName;
if (FirstName != null) }
if (Email != null)
{
this.Email = Email; this.Email = Email;
}
if (CreditCard != null)
{
this.CreditCard = CreditCard; this.CreditCard = CreditCard;
if (FirstName != null) }
if (Expiration != null)
{
this.Expiration = Expiration; this.Expiration = Expiration;
if (FirstName != null) }
if (CCV != null)
{
this.CCV = CCV; 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;
@@ -96,7 +111,7 @@ namespace Ophelias.Models
internal GuestList() internal GuestList()
{ {
Guests = new List<Guest>(); Guests = new();
} }
} }
} }

View File

@@ -27,7 +27,7 @@ namespace Ophelias.Models
internal Rates() internal Rates()
{ {
BaseRates = new List<BaseRate>(); BaseRates = new();
} }
} }
} }

View File

@@ -1,7 +1,4 @@
using System; using Ophelias.Managers;
using System.Collections.Generic;
using System.Linq;
using Ophelias.Managers;
using System.Data.SQLite; using System.Data.SQLite;
namespace Ophelias.Models namespace Ophelias.Models
@@ -39,23 +36,27 @@ namespace Ophelias.Models
case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break; case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
default: throw new NotImplementedException(); default: throw new NotImplementedException();
} }
double? BaseRate = HotelManager.GetBaseRate(); double? BaseRate = Hotel.GetBaseRate();
if (BaseRate == null) { if (BaseRate == null)
{
throw new NotImplementedException(); throw new NotImplementedException();
} }
Transaction Transaction = new Transaction( Transaction Transaction = new(
Rate: (double)BaseRate, Rate: (double)BaseRate,
Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays, Multiplier), Owed: TxFunctions.CalculateOwed((double)BaseRate, (int)(EndDate.Date - StartDate.Date).TotalDays, Multiplier),
Multiplier: Multiplier, Multiplier: Multiplier,
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate) PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
); );
using (DatabaseManager Manager = new DatabaseManager()) using (Database Manager = new())
{ {
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using (SQLiteCommand cmd = Manager.con.CreateCommand())
{ {
if (RoomNum != null) if (RoomNum != null)
{
this.RoomNum = RoomNum; this.RoomNum = RoomNum;
}
cmd.CommandText = cmd.CommandText =
"INSERT INTO reservations (RoomNum, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged) " + "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);"; "VALUES (@RoomNum, @GuestID, @TransactionID, @IsNoShow, @Type, @Status, @CreationDate, @StartDate, @EndDate, @CheckIn, @CheckOut, @DateChanged);";
@@ -69,17 +70,31 @@ namespace Ophelias.Models
cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@StartDate", StartDate.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@EndDate", EndDate.ToString("yyyy-MM-dd"));
if (CheckIn.HasValue) if (CheckIn.HasValue)
{
cmd.Parameters.AddWithValue("@CheckIn", CheckIn.Value.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@CheckIn", CheckIn.Value.ToString("yyyy-MM-dd"));
}
else else
{
cmd.Parameters.AddWithValue("@CheckIn", CheckIn); cmd.Parameters.AddWithValue("@CheckIn", CheckIn);
}
if (CheckOut.HasValue) if (CheckOut.HasValue)
{
cmd.Parameters.AddWithValue("@CheckOut", CheckOut.Value.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@CheckOut", CheckOut.Value.ToString("yyyy-MM-dd"));
}
else else
{
cmd.Parameters.AddWithValue("@CheckOut", CheckOut); cmd.Parameters.AddWithValue("@CheckOut", CheckOut);
}
if (DateChanged.HasValue) if (DateChanged.HasValue)
{
cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@DateChanged", DateChanged.Value.ToString("yyyy-MM-dd"));
}
else else
{
cmd.Parameters.AddWithValue("@DateChanged", DateChanged); cmd.Parameters.AddWithValue("@DateChanged", DateChanged);
}
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@@ -121,14 +136,16 @@ namespace Ophelias.Models
this.StartDate = StartDate; this.StartDate = StartDate;
this.EndDate = EndDate; this.EndDate = EndDate;
DateChanged = DateTime.Now.Date; DateChanged = DateTime.Now.Date;
using (DatabaseManager Manager = new DatabaseManager()) using (Database Manager = new())
{ {
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using (SQLiteCommand cmd = Manager.con.CreateCommand())
{ {
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Changed, StartDate: this.StartDate, EndDate: this.EndDate, DateChanged: DateChanged); string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Changed, StartDate: this.StartDate, EndDate: this.EndDate, DateChanged: DateChanged);
if (query == null) if (query == null)
{
throw new Exception(); throw new Exception();
}
cmd.CommandText = query; cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id); cmd.Parameters.AddWithValue("@ID", Id);
@@ -139,22 +156,27 @@ namespace Ophelias.Models
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
} }
double? BaseRate = HotelManager.GetBaseRate(); double? BaseRate = Hotel.GetBaseRate();
if (BaseRate == null) if (BaseRate == null)
{
throw new ArgumentNullException(nameof(BaseRate)); throw new ArgumentNullException(nameof(BaseRate));
}
Transaction.UpdateTransactionFees((double)BaseRate, TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate)); Transaction.UpdateTransactionFees((double)BaseRate, TxFunctions.Changed, TxFunctions.GetPayByDate(Type, this.StartDate, this.EndDate));
} }
internal void CancelReservation() internal void CancelReservation()
{ {
DateTime _DateChanged = DateTime.Now.Date; DateTime _DateChanged = DateTime.Now.Date;
using (DatabaseManager Manager = new DatabaseManager()) using (Database Manager = new())
{ {
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using (SQLiteCommand cmd = Manager.con.CreateCommand())
{ {
string? query = QueryBuilder.UpdateReservation(Id: Id, Status: ReservationStatus.Cancelled, DateChanged: _DateChanged); 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; Status = ReservationStatus.Cancelled;
DateChanged = _DateChanged; DateChanged = _DateChanged;

View File

@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ophelias.Models
{
internal class @int
{
internal int Id;
internal bool Occupied;
internal @int(int id)
{
Id = id;
Occupied = false;
}
}
internal class RoomList
{
internal List<@int> Rooms;
internal RoomList()
{
Rooms = new List<@int>();
}
}
}

View File

@@ -1,53 +1,58 @@
using System; using Ophelias.Managers;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ophelias.Models;
using Ophelias.Managers;
using System.Data.SQLite; using System.Data.SQLite;
namespace Ophelias.Models namespace Ophelias.Models
{ {
internal class Transaction internal class Transaction
{ {
internal int Id { get; set; } internal int Id;
internal double Rate { get; set; } internal double Rate;
internal double Owed { get; set; } internal double Owed;
internal double Penalty { get; set; } internal double Penalty;
internal double Multiplier { get; set; } internal double Multiplier;
internal double RefundAmount { get; set; } internal double RefundAmount;
internal DateTime PayBy { get; set; } internal double AmountPaid;
internal DateTime? LastPaid { get; set; } = null; internal DateTime PayBy;
internal DateTime? PaidOn { get; set; } = null; internal DateTime? LastPaid = null;
internal DateTime? PaidOn = null;
internal Transaction(double Rate, double Owed, internal Transaction(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, double AmountPaid = 0)
{ {
int Id; int Id;
using (DatabaseManager Manager = new DatabaseManager()) using (Database Manager = new())
{ {
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using (SQLiteCommand cmd = Manager.con.CreateCommand())
{ {
cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn) " + cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, AmountPaid, PayBy, LastPaid, PaidOn) " +
"VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @PayBy, @LastPaid, @PaidOn)"; "VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @AmountPaid, @PayBy, @LastPaid, @PaidOn)";
cmd.Parameters.AddWithValue("@Rate", Rate); cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@Owed", Owed); cmd.Parameters.AddWithValue("@Owed", Owed);
cmd.Parameters.AddWithValue("@Multiplier", Multiplier); cmd.Parameters.AddWithValue("@Multiplier", Multiplier);
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount); cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
cmd.Parameters.AddWithValue("@AmountPaid", AmountPaid);
cmd.Parameters.AddWithValue("@Penalty", Penalty); cmd.Parameters.AddWithValue("@Penalty", Penalty);
cmd.Parameters.AddWithValue("@PayBy", PayBy.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@PayBy", PayBy.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@LastPaid", LastPaid); cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
cmd.Parameters.AddWithValue("@PaidOn", PaidOn); cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
if (LastPaid != null) if (LastPaid != null)
{
cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
}
else else
{
cmd.Parameters.AddWithValue("@LastPaid", LastPaid); cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
}
if (PaidOn != null) if (PaidOn != null)
{
cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
}
else else
{
cmd.Parameters.AddWithValue("@PaidOn", PaidOn); cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
}
//cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy, Refund: RefundAmount, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn); //cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy, Refund: RefundAmount, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
@@ -60,13 +65,14 @@ namespace Ophelias.Models
this.Penalty = Penalty; this.Penalty = Penalty;
this.Multiplier = Multiplier; this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount; this.RefundAmount = RefundAmount;
this.AmountPaid = AmountPaid;
this.PayBy = PayBy; this.PayBy = PayBy;
this.LastPaid = LastPaid; this.LastPaid = LastPaid;
this.PaidOn = PaidOn; 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, double AmountPaid = 0)
{ {
this.Id = Id; this.Id = Id;
this.Rate = Rate; this.Rate = Rate;
@@ -74,6 +80,7 @@ namespace Ophelias.Models
this.Penalty = Penalty; this.Penalty = Penalty;
this.Multiplier = Multiplier; this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount; this.RefundAmount = RefundAmount;
this.AmountPaid = AmountPaid;
this.PayBy = PayBy; this.PayBy = PayBy;
this.LastPaid = LastPaid; this.LastPaid = LastPaid;
this.PaidOn = PaidOn; this.PaidOn = PaidOn;
@@ -84,14 +91,14 @@ namespace Ophelias.Models
this.Rate = Rate; this.Rate = Rate;
this.Multiplier = Multiplier; this.Multiplier = Multiplier;
this.PayBy = PayBy; this.PayBy = PayBy;
using (DatabaseManager Manager = new DatabaseManager()) using Database Manager = new();
{ using SQLiteCommand cmd = Manager.con.CreateCommand();
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateTransaction(Id: Id, Rate: this.Rate, Multiplier: this.Multiplier, PayBy: this.PayBy); string? query = QueryBuilder.UpdateTransaction(Id: Id, Rate: this.Rate, Multiplier: this.Multiplier, PayBy: this.PayBy);
if (query == null) if (query == null)
{
throw new Exception(); throw new Exception();
}
cmd.CommandText = query; cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id); cmd.Parameters.AddWithValue("@ID", Id);
@@ -100,48 +107,56 @@ namespace Ophelias.Models
cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd")); cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
}
}
internal void Pay(double Amount) internal void Pay(double Amount)
{ {
if (Amount <= 0) if (Amount <= 0)
{
return; return;
}
LastPaid = DateTime.Now; LastPaid = DateTime.Now;
Owed -= Amount; AmountPaid += Amount;
if (Owed < 0) if (Owed - AmountPaid < 0)
RefundAmount = Math.Abs(Owed); {
else if (Owed == 0) RefundAmount = Math.Abs(Owed - Amount);
}
if (Owed - AmountPaid <= 0)
{
PaidOn = DateTime.Now; PaidOn = DateTime.Now;
using (DatabaseManager Manager = new DatabaseManager()) }
{
using (SQLiteCommand cmd = Manager.con.CreateCommand()) using Database Manager = new();
{ using SQLiteCommand cmd = Manager.con.CreateCommand();
string? query = QueryBuilder.UpdateTransaction(Id: Id, Owed: Owed, Refund: RefundAmount, LastPaid: LastPaid, PaidOn: PaidOn); string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount, AmountPaid: AmountPaid, LastPaid: LastPaid, PaidOn: PaidOn);
if (query == null) if (query == null)
{
throw new Exception(); throw new Exception();
}
cmd.CommandText = query; cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id); cmd.Parameters.AddWithValue("@ID", Id);
cmd.Parameters.AddWithValue("@Owed", Owed);
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount); cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
cmd.Parameters.AddWithValue("@LastPaid", LastPaid); cmd.Parameters.AddWithValue("@AmountPaid", AmountPaid);
cmd.Parameters.AddWithValue("@PaidOn", PaidOn); cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
if(!PaidOn.HasValue)
throw new Exception();
cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
}
}
internal void Refund() internal void Refund()
{ {
AmountPaid -= RefundAmount;
RefundAmount = 0; RefundAmount = 0;
using (DatabaseManager Manager = new DatabaseManager()) using Database Manager = new();
{ using SQLiteCommand cmd = Manager.con.CreateCommand();
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount); string? query = QueryBuilder.UpdateTransaction(Id: Id, Refund: RefundAmount);
if (query == null) if (query == null)
{
throw new Exception(); throw new Exception();
}
cmd.CommandText = query; cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id); cmd.Parameters.AddWithValue("@ID", Id);
@@ -149,8 +164,6 @@ namespace Ophelias.Models
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
} }
}
}
internal static class TxFunctions internal static class TxFunctions
{ {
@@ -161,9 +174,12 @@ namespace Ophelias.Models
internal static double IncentiveFee(DateTime Start, DateTime End) internal static double IncentiveFee(DateTime Start, DateTime End)
{ {
int thirtyDayOcc; int thirtyDayOcc;
(thirtyDayOcc, _) = HotelManager.AvgOccupancySpan(Start, End); (thirtyDayOcc, _) = Hotel.AvgOccupancySpan(Start, End);
if ((double)(thirtyDayOcc / 45.0) <= 0.6) if ((double)(thirtyDayOcc / 45.0) <= 0.6)
{
return 0.80; return 0.80;
}
return 1.0; return 1.0;
} }
internal static DateTime GetPayByDate(ReservationType Type, DateTime StartDate, DateTime EndDate) internal static DateTime GetPayByDate(ReservationType Type, DateTime StartDate, DateTime EndDate)
@@ -179,7 +195,7 @@ namespace Ophelias.Models
} }
internal static double CalculateOwed(double Rate, int Days, double Multiplier) internal static double CalculateOwed(double Rate, int Days, double Multiplier)
{ {
return Rate * Days * Multiplier; return Math.Round(Rate * Days * Multiplier);
} }
@@ -190,7 +206,7 @@ namespace Ophelias.Models
internal TransactionList() internal TransactionList()
{ {
Transactions = new List<Transaction>(); Transactions = new();
} }
} }
} }

View File

@@ -1,9 +1,10 @@
using Ophelias.Models; using Ophelias.Expressions;
using Ophelias.Managers; using Ophelias.Managers;
using Ophelias.Expressions; using Ophelias.Models;
using Ophelias.Reporting;
using System.Data.SQLite; using System.Data.SQLite;
class Program internal class Program
{ {
private static string GetGuestEmail() private static string GetGuestEmail()
{ {
@@ -13,8 +14,10 @@ class Program
{ {
Email = Console.ReadLine(); Email = Console.ReadLine();
if (!Validation.ValidateEmail(Email)) if (!Validation.ValidateEmail(Email))
{
Console.Write("Please enter a valid email: "); Console.Write("Please enter a valid email: ");
} }
}
return Email; return Email;
} }
@@ -46,49 +49,69 @@ class Program
{ {
CreditCard = Console.ReadLine().Trim().Replace("\t", ""); CreditCard = Console.ReadLine().Trim().Replace("\t", "");
if (CreditCard == "q" || CreditCard == "Q") if (CreditCard == "q" || CreditCard == "Q")
{
return (null, null, null); return (null, null, null);
}
if (!Validation.ValidateCreditCard(CreditCard)) if (!Validation.ValidateCreditCard(CreditCard))
{
Console.Write("Please enter a valid credit card. If your card is expired, enter Q to cancel: "); 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): "); Console.Write("What is your credit card expiration date (MM/yy): ");
string CardExpiration = ""; string CardExpiration = "";
while (!Validation.ValidateExpirationDate(CardExpiration)) while (!Validation.ValidateExpirationDate(CardExpiration))
{ {
CardExpiration = Console.ReadLine().Trim().Replace("\t", ""); CardExpiration = Console.ReadLine().Trim().Replace("\t", "");
if (CardExpiration == "q" || CardExpiration == "Q") if (CardExpiration == "q" || CardExpiration == "Q")
{
return (null, null, null); return (null, null, null);
}
if (!Validation.ValidateExpirationDate(CardExpiration)) if (!Validation.ValidateExpirationDate(CardExpiration))
{
Console.Write("Please enter a valid expiration date. If your card is expired, enter Q to cancel: "); 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: "); Console.Write("What is your credit card CCV: ");
string CCV = ""; string CCV = "";
while (!Validation.ValidateCCV(CCV)) while (!Validation.ValidateCCV(CCV))
{ {
CCV = Console.ReadLine().Trim().Replace("\t", ""); CCV = Console.ReadLine().Trim().Replace("\t", "");
if (CCV == "q" || CCV == "Q") if (CCV == "q" || CCV == "Q")
{
return (null, null, null); return (null, null, null);
}
if (!Validation.ValidateCCV(CCV)) if (!Validation.ValidateCCV(CCV))
{
Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: "); Console.Write("Please enter a valid credit card CCV. If your card is expired, enter Q to cancel: ");
} }
}
return (CreditCard, CardExpiration, CCV); 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 = "";
while (FirstName.Length == 0) while (FirstName.Length == 0)
{ {
FirstName = Console.ReadLine(); FirstName = Console.ReadLine();
if (FirstName == "") if (FirstName == "")
{
Console.Write("What is your first name: "); Console.Write("What is your first name: ");
} }
}
Console.Write("What is your last name: "); Console.Write("What is your last name: ");
string LastName = ""; string LastName = "";
while (LastName.Length == 0) while (LastName.Length == 0)
{ {
LastName = Console.ReadLine(); LastName = Console.ReadLine();
if (LastName == "") if (LastName == "")
{
Console.Write("What is your last name: "); Console.Write("What is your last name: ");
} }
}
return (FirstName, LastName); return (FirstName, LastName);
} }
void GuestLogin() void GuestLogin()
@@ -99,16 +122,18 @@ class Program
{ {
email = Console.ReadLine(); email = Console.ReadLine();
if (!Validation.ValidateEmail(email)) if (!Validation.ValidateEmail(email))
{
Console.Write("Please enter a valid email: "); Console.Write("Please enter a valid email: ");
} }
activeGuest = HotelManager.GetGuestByEmail(email); }
activeGuest = Hotel.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; 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.GetResByGuest(activeGuest); activeReservation = Hotel.GetResByGuest(activeGuest);
} }
void CreateNewGuestPrompt() void CreateNewGuestPrompt()
{ {
@@ -118,10 +143,25 @@ class Program
string? CreditCard = null; string? CreditCard = null;
string? CardExpiration = null; string? CardExpiration = null;
string? CCV = null; string? CCV = null;
if (Console.ReadLine().Equals("y") || Console.ReadLine().Equals("Y")) while (true)
{
string input = Console.ReadLine();
if (input.Equals("y") || input.Equals("Y"))
{
(CreditCard, CardExpiration, CCV) = GetCreditCardInformation(); (CreditCard, CardExpiration, CCV) = GetCreditCardInformation();
break;
}
else if (input.Equals("n") || input.Equals("N"))
{
break;
}
else
{
Console.Write("Input must be Y, y or N, n: ");
}
}
activeGuest = new Guest(FirstName, LastName, Email, CreditCard: CreditCard, Expiration: CardExpiration, CCV: CCV); activeGuest = new(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()
@@ -142,7 +182,7 @@ class Program
return; return;
} }
string changes = ""; string changes = "";
List<string> NewDetails = new List<string>(); List<string> NewDetails = new();
if (!string.IsNullOrEmpty(NewFname)) if (!string.IsNullOrEmpty(NewFname))
{ {
NewDetails.Add($"\tFirst Name: {activeGuest.FirstName} -> {NewFname}"); NewDetails.Add($"\tFirst Name: {activeGuest.FirstName} -> {NewFname}");
@@ -174,7 +214,10 @@ class Program
activeGuest.CCV = NewCCV; activeGuest.CCV = NewCCV;
} }
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}");
activeGuest.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV); activeGuest.UpdateGuest(activeGuest.Id, NewFname, NewLname, NewEmail, NewCard, NewExpiry, NewCCV);
return; return;
@@ -214,7 +257,10 @@ class Program
{ {
input = Console.ReadLine(); input = Console.ReadLine();
if (input == "1" || input == "2" || input == "3" || input == "4") if (input == "1" || input == "2" || input == "3" || input == "4")
{
break; break;
}
Console.Write("Please enter either 1, 2, 3, or 4: "); Console.Write("Please enter either 1, 2, 3, or 4: ");
} }
return (ReservationType)(Convert.ToInt32(input) - 1); return (ReservationType)(Convert.ToInt32(input) - 1);
@@ -223,7 +269,7 @@ class Program
{ {
if (Type == ReservationType.Prepaid) if (Type == ReservationType.Prepaid)
{ {
if ((Date - DateTime.Now).TotalDays < 90) if ((int)(Date - DateTime.Now).TotalDays < 90)
{ {
Console.WriteLine("Prepaid reservations must be made 90 days in advance."); Console.WriteLine("Prepaid reservations must be made 90 days in advance.");
} }
@@ -234,7 +280,7 @@ class Program
} }
else if (Type == ReservationType.SixtyDayAdvance) else if (Type == ReservationType.SixtyDayAdvance)
{ {
if ((Date - DateTime.Now).TotalDays < 60) if ((int)(Date - DateTime.Now).TotalDays < 60)
{ {
Console.WriteLine("Sixty-days-in-advance reservations must be made 60 days in advance."); Console.WriteLine("Sixty-days-in-advance reservations must be made 60 days in advance.");
} }
@@ -260,13 +306,19 @@ class Program
{ {
input = Console.ReadLine(); input = Console.ReadLine();
if (DateTime.TryParse(input, out _StartDate) && _StartDate >= DateTime.Now) if (DateTime.TryParse(input, out _StartDate) && _StartDate >= DateTime.Now)
{
break; break;
}
if (_StartDate <= DateTime.Now) if (_StartDate <= DateTime.Now)
{
Console.Write("Start date cannot be before current date. Please enter a valid date (2021-12-31): "); Console.Write("Start date cannot be before current date. Please enter a valid date (2021-12-31): ");
}
else else
{
Console.Write("Please enter a valid date (2021-12-31): "); Console.Write("Please enter a valid date (2021-12-31): ");
} }
}
Console.Write("When would you like to end your stay.\n" + 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" + "Your date input should be in in the following format - yyyy-MM-dd. Example: (2021-12-31)?\n" +
"Input a date (2021-12-31): "); "Input a date (2021-12-31): ");
@@ -274,13 +326,19 @@ class Program
{ {
input = Console.ReadLine(); input = Console.ReadLine();
if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate) if (DateTime.TryParse(input, out _EndDate) && _EndDate > _StartDate)
{
break; break;
}
if (_EndDate < _StartDate) if (_EndDate < _StartDate)
{
Console.Write("End date must be after start date. Please enter a valid date (2021-12-31): "); Console.Write("End date must be after start date. Please enter a valid date (2021-12-31): ");
}
else else
{
Console.Write("Please enter a valid date (2021-12-31): "); Console.Write("Please enter a valid date (2021-12-31): ");
} }
}
return (_StartDate.Date, _EndDate.Date); return (_StartDate.Date, _EndDate.Date);
} }
@@ -293,7 +351,10 @@ class Program
bool maxCapacity = false; bool maxCapacity = false;
(StartDate, EndDate) = Dates(); (StartDate, EndDate) = Dates();
if (StartDate == null || EndDate == null) if (StartDate == null || EndDate == null)
(_, maxCapacity) = HotelManager.AvgOccupancySpan(StartDate, EndDate); {
(_, maxCapacity) = Hotel.AvgOccupancySpan(StartDate, EndDate);
}
if (!maxCapacity) if (!maxCapacity)
{ {
if (!CheckReservationRestrictions(StartDate, Type)) if (!CheckReservationRestrictions(StartDate, Type))
@@ -306,7 +367,8 @@ class Program
Console.WriteLine("Aborting reservation changes."); Console.WriteLine("Aborting reservation changes.");
return (null, null); return (null, null);
} }
} else }
else
{ {
break; break;
} }
@@ -342,13 +404,18 @@ class Program
case "2": (NewStartDate, NewEndDate) = SelectDate(NewType); break; case "2": (NewStartDate, NewEndDate) = SelectDate(NewType); break;
case "S": case "S":
if (NewStartDate == null || NewEndDate == null) if (NewStartDate == null || NewEndDate == null)
{
return; return;
}
while (CheckReservationRestrictions((DateTime)NewStartDate, NewType)) while (CheckReservationRestrictions((DateTime)NewStartDate, NewType))
{ {
(NewStartDate, NewEndDate) = SelectDate(NewType); (NewStartDate, NewEndDate) = SelectDate(NewType);
if (NewStartDate == null || NewEndDate == null) if (NewStartDate == null || NewEndDate == null)
{
return; return;
} }
}
completed = true; completed = true;
(activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, (DateTime)NewStartDate, (DateTime)NewEndDate); (activeReservation.Type, activeReservation.StartDate, activeReservation.EndDate) = (NewType, (DateTime)NewStartDate, (DateTime)NewEndDate);
break; break;
@@ -368,7 +435,7 @@ class Program
Console.WriteLine("You currently have an active registration."); Console.WriteLine("You currently have an active registration.");
return; return;
} }
if (HotelManager.GetBaseRate() == null) if (Hotel.GetBaseRate() == null)
{ {
Console.WriteLine("Unable to proceed with reservation due to no base rate being set. Please inform an employee."); Console.WriteLine("Unable to proceed with reservation due to no base rate being set. Please inform an employee.");
return; return;
@@ -388,14 +455,18 @@ class Program
return; return;
} }
while((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" + 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" + "If you are unable to provide one, enter Q to quit or hit enter to continue.\n" +
": "); ": ");
input = Console.ReadLine(); input = Console.ReadLine();
if (input == "Q") if (input == "Q")
{
return; return;
}
GetCreditCardInformation(); GetCreditCardInformation();
} }
@@ -404,13 +475,14 @@ class Program
$"If these details are correct, enter YES to complete. To cancel your reservation enter Q.\n" + $"If these details are correct, enter YES to complete. To cancel your reservation enter Q.\n" +
$": "); $": ");
input = Console.ReadLine(); input = Console.ReadLine();
while(input != "YES") while (input != "YES")
{ {
if (input == "Q") if (input == "Q")
{ {
Console.WriteLine("Reservation has been deleted."); Console.WriteLine("Reservation has been deleted.");
return; return;
} else }
else
{ {
Console.Write("Input must be YES or Q.\n: "); Console.Write("Input must be YES or Q.\n: ");
input = Console.ReadLine(); input = Console.ReadLine();
@@ -418,9 +490,13 @@ class Program
} }
if (Type == ReservationType.Prepaid) if (Type == ReservationType.Prepaid)
{ {
activeReservation = new Reservation(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value); activeReservation = new(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
activeReservation.Transaction.Pay(activeReservation.Transaction.Owed); activeReservation.Transaction.Pay(activeReservation.Transaction.Owed);
} }
else
{
activeReservation = new(activeGuest, Type, DateTime.Now.Date, StartDate.Value, EndDate.Value);
}
Console.WriteLine("Your reservation has been made."); Console.WriteLine("Your reservation has been made.");
} }
void UpdateReservation() void UpdateReservation()
@@ -447,13 +523,17 @@ class Program
{ {
(_StartDate, _EndDate) = SelectDate(activeReservation.Type); (_StartDate, _EndDate) = SelectDate(activeReservation.Type);
if (_StartDate.HasValue && _EndDate.HasValue) if (_StartDate.HasValue && _EndDate.HasValue)
{
Console.Write("Your new reservation details are:\n" + Console.Write("Your new reservation details are:\n" +
$"\tStarts on: {activeReservation.StartDate.ToString("yyyy-MM-dd")} -> {_StartDate.Value.ToString("yyyy-MM-dd")}\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"); $"\tEnds on: {activeReservation.EndDate.ToString("yyyy-MM-dd")} -> {_EndDate.Value.ToString("yyyy-MM-dd")}\n");
}
Console.Write("Are you done with your changes?\n" + Console.Write("Are you done with your changes?\n" +
"Enter YES to finish and save, NO to continue editing.\n" + "Enter YES to finish and save, NO to continue editing.\n" +
": "); ": ");
} else if (input == "Q") }
else if (input == "Q")
{ {
Console.WriteLine("Your changes have been discarded."); Console.WriteLine("Your changes have been discarded.");
return; return;
@@ -489,13 +569,14 @@ class Program
"You may be charged depending on your reservation.\n" + "You may be charged depending on your reservation.\n" +
"Enter YES to confirm or NO to exit: "); "Enter YES to confirm or NO to exit: ");
input = Console.ReadLine(); input = Console.ReadLine();
while(input != "YES") while (input != "YES")
{ {
if (input == "NO") if (input == "NO")
{ {
Console.Write("Reservation has not been cancelled."); Console.Write("Reservation has not been cancelled.");
return; return;
} else }
else
{ {
Console.Write("Your input must be YES or NO: "); Console.Write("Your input must be YES or NO: ");
Console.ReadLine(); Console.ReadLine();
@@ -514,7 +595,7 @@ class Program
{ {
string? input = Console.ReadLine(); string? input = Console.ReadLine();
switch(input) switch (input)
{ {
case "help": help(); break; case "help": help(); break;
case "reservation create": CreateNewReservation(); break; case "reservation create": CreateNewReservation(); break;
@@ -535,9 +616,9 @@ class Program
{ {
Console.WriteLine( Console.WriteLine(
"Report Commands:\n" + "Report Commands:\n" +
"\tgenerate daily report - Generates a daily report on expected occupancy, room income, and incentive losses.\n" + "\tgenerate management report - Generates a daily management report on expected occupancy, room income, and incentive losses.\n" +
"\tgenerate operational report - Generates a report of daily arrivals and occupancy.\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" + "\tgenerate accommodation bills - Generates an accommodation bill that will be handed to guests upon checkout.\n" +
"\treservation cancel\n" + "\treservation cancel\n" +
"Management Commands:" + "Management Commands:" +
"\nnotify pending payments - Generates and emails 60 day advance reservations that they must pay for their reservation or it will be cancelled." + "\nnotify pending payments - Generates and emails 60 day advance reservations that they must pay for their reservation or it will be cancelled." +
@@ -578,9 +659,26 @@ class Program
{ {
if (FixedDate != null) if (FixedDate != null)
{ {
HotelManager.SetBaseRate(Convert.ToDouble(amount), (DateTime)FixedDate); if (Hotel.GetBaseRateByDate((DateTime)FixedDate))
Console.WriteLine($"A base rate of {amount} has been set and will take effect on {FixedDate.Value.ToString("yyyy-MM-dd")}."); {
} else Console.Write("There is already a base rate configured for this date.\n" +
"If you are entering a new rate because one was not configured and got this error, type YES.\n" +
"Would you like to overwrite it (YES)? If not enter anything to continue.\n" +
": ");
if (Console.ReadLine() == "YES")
{
Hotel.UpdateBaseRate(Convert.ToDouble(amount), FixedDate.Value.Date, DefaultRate: true);
return true;
}
}
else
{
Hotel.SetBaseRate(Convert.ToDouble(amount), (DateTime)FixedDate, true);
}
Console.WriteLine($"A base rate of {amount} has been set and will take effect immediately.");
}
else
{ {
DateTime StartDate; DateTime StartDate;
Console.Write("When would you like the new rate to take effect.\n" + Console.Write("When would you like the new rate to take effect.\n" +
@@ -590,28 +688,31 @@ class Program
{ {
input = Console.ReadLine(); input = Console.ReadLine();
if (DateTime.TryParse(input, out StartDate)) if (DateTime.TryParse(input, out StartDate))
{
if (StartDate.Date <= DateTime.Now.Date) if (StartDate.Date <= DateTime.Now.Date)
{ {
Console.WriteLine("Base rate must be configured for a future night. Not the same day or past."); Console.WriteLine("Base rate must be configured for a future night. Not the same day or past.");
} }
else if (HotelManager.GetBaseRateByDate(StartDate)) else if (Hotel.GetBaseRateByDate(StartDate))
{ {
Console.Write("There is already a base rate configured for this date.\n" + Console.Write("There is already a base rate configured for this date.\n" +
"Would you like to overwrite it (YES)? If not enter anything to continue." + "Would you like to overwrite it (YES)? If not enter anything to continue." +
": "); ": ");
if(Console.ReadLine() == "YES") if (Console.ReadLine() == "YES")
{ {
HotelManager.UpdateBaseRate(Convert.ToDouble(amount), StartDate.Date); Hotel.UpdateBaseRate(Convert.ToDouble(amount), StartDate.Date);
return true; return true;
} }
} else }
else
{ {
break; break;
} }
}
Console.Write("Please enter a valid date (2021-12-31): "); Console.Write("Please enter a valid date (2021-12-31): ");
} }
HotelManager.SetBaseRate(Convert.ToDouble(amount), StartDate); Hotel.SetBaseRate(Convert.ToDouble(amount), StartDate);
Console.WriteLine($"A base rate of {amount} has been set and will take effect on {DateTime.Now.Date.ToString("yyyy-MM-dd")}."); Console.WriteLine($"A base rate of {amount} has been set and will take effect on {DateTime.Now.Date.ToString("yyyy-MM-dd")}.");
} }
return true; return true;
@@ -625,13 +726,14 @@ class Program
return false; return false;
} }
if (HotelManager.GetBaseRate() == null) if (Hotel.GetBaseRate() == null)
{ {
Console.Write("No base rate has been configured. " + Console.Write("No base rate has been configured. " +
"You must set one for the current date.\n" + "You must set one for the current date.\n" +
"Enter new rate: "); "Enter new rate: ");
while (!SetRatePrompt(DateTime.Now.Date)) { } while (!SetRatePrompt(DateTime.Now.Date)) { }
} else }
else
{ {
Console.Write("What is the value of the rate you would like to set.\n" + Console.Write("What is the value of the rate you would like to set.\n" +
"Enter new rate: "); "Enter new rate: ");
@@ -641,8 +743,8 @@ class Program
void CheckIn() void CheckIn()
{ {
string Email = GetGuestEmail(); string Email = GetGuestEmail();
TimeRefs? status = HotelManager.CanBeCheckedIn(Email); TimeRefs? status = Hotel.CanBeCheckedIn(Email);
Guest? g = HotelManager.GetGuestByEmail(Email); Guest? g = Hotel.GetGuestByEmail(Email);
if (g == null) if (g == null)
{ {
Console.WriteLine("No guest with that email exists."); Console.WriteLine("No guest with that email exists.");
@@ -656,17 +758,22 @@ class Program
if (status.Value == TimeRefs.OnTime) if (status.Value == TimeRefs.OnTime)
{ {
int? RoomID = HotelManager.CheckInGuest(Email, DateTime.Now.Date); int? RoomID = Hotel.CheckInGuest(Email, DateTime.Now.Date);
if (RoomID != null) if (RoomID != null)
{
Console.WriteLine($"Guest has been checked in, their room number is {RoomID}."); Console.WriteLine($"Guest has been checked in, their room number is {RoomID}.");
} }
}
else if (status.Value == TimeRefs.Late) else if (status.Value == TimeRefs.Late)
{ {
Console.WriteLine("Since the reservation was not checked in on the date scheduled, it has been cancelled. The guest will be charged the \"no show\" penalty."); Console.WriteLine("Since the reservation was not checked in on the date scheduled, it has been cancelled. The guest will be charged the \"no show\" penalty.");
Reservation? r = HotelManager.GetResByGuest(g); Reservation? r = Hotel.GetResByGuest(g);
if (r == null) if (r == null)
{
throw new Exception(); throw new Exception();
}
r.CancelReservation(); r.CancelReservation();
} }
@@ -679,16 +786,97 @@ class Program
void CheckOut() void CheckOut()
{ {
string Email = GetGuestEmail(); string Email = GetGuestEmail();
if (HotelManager.GuestCurrentlyCheckedIn(Email)) if (Hotel.GuestCurrentlyCheckedIn(Email))
{ {
HotelManager.CheckOutGuest(Email, DateTime.Now.Date); Reservation r = Hotel.GetResByGuest(Hotel.GetGuestByEmail(Email));
if (r.Type == ReservationType.Incentive || r.Type == ReservationType.Conventional)
{
r.Transaction.Pay(r.Transaction.Owed);
}
Hotel.CheckOutGuest(Email, DateTime.Now.Date);
Console.WriteLine($"Guest has been checked out."); Console.WriteLine($"Guest has been checked out.");
} else }
else
{ {
Console.WriteLine($"Can't checkout a guest that hasn't been checked in."); Console.WriteLine($"Can't checkout a guest that hasn't been checked in.");
} }
return; return;
} }
void NotifyOutstandingPayments()
{
List<Reservation> activeSixtyRes = Hotel.GetActiveSixtyDayRes();
foreach (Reservation r in activeSixtyRes)
{
int days = (int)(r.StartDate.Date - DateTime.Now.Date).TotalDays - 30;
if (days < 0)
{
r.CancelReservation();
}
else if (days <= 15)
{
Email e = new(r.Guest.Email);
e.Send();
}
}
if (File.Exists("Emails.txt"))
{
FileInfo f = new("Emails.txt");
Console.WriteLine($"Emails have been written and appended to {f.FullName}");
}
}
void GenerateManagementReports()
{
var w = Hotel.GetExpectedOccupancyCount();
Management.CalculateExpectedOccupancy(w.Item2, w.Item1);
if (File.Exists("ExpectedOccupancy.txt"))
{
FileInfo f = new("ExpectedOccupancy.txt");
Console.WriteLine($"Expected occupancy has been written and appended to {f.FullName}");
}
var x = Hotel.GetExpectedIncomeCount();
Management.CalculateExpectedIncome(x.Item1, x.Item2, x.Item3);
if (File.Exists("ExpectedIncome.txt"))
{
FileInfo f = new("ExpectedIncome.txt");
Console.WriteLine($"Expected income has been written and appended to {f.FullName}");
}
var y = Hotel.GetIncentiveTransactions();
Management.CalculateIncentiveLosses(y.Item3, y.Item1, y.Item2);
if (File.Exists("IncentiveLosses.txt"))
{
FileInfo f = new("IncentiveLosses.txt");
Console.WriteLine($"Incentive losses have been written and appended to {f.FullName}");
}
}
void GenerateAccommodationBills()
{
List<Reservation> reservations = Hotel.GetDailyArrivals();
Accommodation.GenerateAccommodationBills(reservations);
if (File.Exists("AccommodationBills.txt"))
{
FileInfo f = new("AccommodationBills.txt");
Console.WriteLine($"Accommodation bills have been written and appended to {f.FullName}");
}
}
void GenerateOperationalReports()
{
List<Reservation> reservations = Hotel.GetDailyArrivals();
Operational.FetchDailyArriavals(reservations);
if (File.Exists("DailyArrivals.txt"))
{
FileInfo f = new("DailyArrivals.txt");
Console.WriteLine($"Daily arrivals have been written and appended to {f.FullName}");
}
var x = Hotel.GetDailyOccupancy();
Operational.FetchDailyOccupancy(x.Item1, x.Item2);
if (File.Exists("DailyOccupancy.txt"))
{
FileInfo f = new("DailyOccupancy.txt");
Console.WriteLine($"Daily occupancy has been written and appended to {f.FullName}");
}
}
Console.Write( Console.Write(
"\nWelcome to the Ophelias Oasis Hotel Management System!\n" + "\nWelcome to the Ophelias Oasis Hotel Management System!\n" +
@@ -701,10 +889,10 @@ class Program
switch (input) switch (input)
{ {
case "help": help(); break; case "help": help(); break;
case "generate daily report": break; case "generate management report": GenerateManagementReports(); break;
case "generate operational report": break; case "generate operational report": GenerateOperationalReports(); break;
case "generate accomodation bills": break; case "generate accommodation bills": GenerateAccommodationBills(); break;
case "notify pending payments": break; case "notify pending payments": NotifyOutstandingPayments(); break;
case "issue penalties": break; case "issue penalties": break;
case "checkin guest": CheckIn(); break; case "checkin guest": CheckIn(); break;
case "checkout guest": CheckOut(); break; case "checkout guest": CheckOut(); break;
@@ -716,18 +904,22 @@ class Program
} }
} }
static void Main()
private static void Main()
{ {
HotelManager.CheckBaseRate();
if (!File.Exists("database.sqlite3") || new FileInfo("database.sqlite3").Length == 0) if (!File.Exists("database.sqlite3") || new FileInfo("database.sqlite3").Length == 0)
{ {
SQLiteConnection.CreateFile("database.sqlite3"); SQLiteConnection.CreateFile("database.sqlite3");
using (DatabaseManager Manager = new DatabaseManager()) using (Database Manager = new())
{ {
Manager.InitializeTables(); Manager.InitializeTables();
Manager.InitializeRoomsTable(); Manager.InitializeRoomsTable();
} }
} }
if (!Hotel.CheckBaseRate())
{
Console.WriteLine("No base rate is configured. As a result reservations cannot be made until one is configured.");
}
bool run = true; bool run = true;
while (run) while (run)
@@ -738,7 +930,7 @@ class Program
"2. Customer/ Guest\n" + "2. Customer/ Guest\n" +
": " ": "
); );
switch(Console.ReadLine().ToUpper()) switch (Console.ReadLine().ToUpper())
{ {
case "1": AdminMode(); break; case "1": AdminMode(); break;
case "2": GuestMode(); break; case "2": GuestMode(); break;

View File

@@ -0,0 +1,20 @@
using Ophelias.Models;
namespace Ophelias.Reporting
{
internal static class Accommodation
{
internal static void GenerateAccommodationBills(List<Reservation> reservations)
{
foreach (Reservation? r in reservations)
{
string report = $"ACCOMMODATION BILL - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Name: {r.Guest.LastName}, {r.Guest.FirstName}\n" +
$"Arrival Date: {r.StartDate}\n" +
$"Departure Date: {r.EndDate}\n" +
$"Length of Stay: {(int)(r.EndDate.Date - r.StartDate.Date).TotalDays} days\n" +
$"Charged: ${r.Transaction.Owed}\n\n";
File.AppendAllText(Path.GetFullPath("AccommodationBills.txt"), report);
}
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ophelias.Reporting
{
internal class Accomodation
{
}
}

View File

@@ -1,12 +1,24 @@
using System; namespace Ophelias.Reporting
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ophelias.Reporting
{ {
internal class Email internal class Email
{ {
private readonly string to;
private readonly string subject = "Your payment is due soon!";
private readonly string body = "Hello valued customer, this is a reminder that your payment for your reservation is due soon, please login to the system and pay for your reservation. If you do not it will be canceled.";
private readonly string from = "no-reply@ophelias.oasis";
internal Email(string to)
{
this.to = to;
}
internal void Send()
{
File.AppendAllText(Path.GetFullPath("Emails.txt"),
$"TO: {to}\n" +
$"FROM: {from}\n" +
$"SUBJECT: {subject}\n" +
$"MESSAGE: {body}\n" +
$"\n");
}
} }
} }

View File

@@ -1,12 +1,54 @@
using System; using Ophelias.Models;
using System.Collections.Generic; using Ophelias.Managers;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ophelias.Reporting namespace Ophelias.Reporting
{ {
internal class Management internal static class Management
{ {
internal static void CalculateExpectedOccupancy(List<(DateTime, int, int, int, int, int)> items, double average)
{
List<string> entries = new();
foreach (var x in items)
{
entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}\t{x.Item3}\t{x.Item4}\t{x.Item5}\t{x.Item6}");
}
string report = $"EXPECTED 30 DAY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Date\tRooms Filled\tConventional\tPrepaid\t60-Day\tIncentive\n" +
$"{string.Join("\n", entries)}\n" +
$"Average Occupancy Rate: {average}\n\n";
File.AppendAllText(Path.GetFullPath("ExpectedOccupancy.txt"), report);
}
internal static void CalculateExpectedIncome(List<(DateTime, double)> items, double totalIncome, double average)
{
List<string> entries = new();
foreach (var x in items)
{
entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}");
}
string report = $"EXPECTED 30 DAY INCOME REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Date\tIncome\n" +
$"{string.Join("\n", entries)}\n" +
$"Average Income: {average}\n" +
$"Total Income: {totalIncome}\n\n";
File.AppendAllText(Path.GetFullPath("ExpectedIncome.txt"), report);
}
internal static void CalculateIncentiveLosses(List<(DateTime, double)> items, double totalLosses, double average)
{
List<string> entries = new();
foreach (var x in items)
{
entries.Add($"{x.Item1.Date.ToString("yyyy-MM-dd")}\t{x.Item2}");
}
string report = $"EXPECTED 30 DAY LOSSES (TO INCENTIVE) REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Date\tLosses\n" +
$"{string.Join("\n", entries)}\n" +
$"Average Losses (Due to incentive): {average}\n" +
$"Total Losses (Due to incentive): {totalLosses}\n\n";
File.AppendAllText(Path.GetFullPath("IncentiveLosses.txt"), report);
}
} }
} }

View File

@@ -1,12 +1,62 @@
using System; using Ophelias.Models;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ophelias.Reporting namespace Ophelias.Reporting
{ {
internal class Operational internal static class Operational
{ {
internal static void FetchDailyArriavals(List<Reservation> reservations)
{
List<string> entries = new();
foreach (Reservation r in reservations)
{
string roominfo;
if (!r.RoomNum.HasValue)
{
roominfo = "N/A";
}
else
{
roominfo = r.RoomNum.Value.ToString();
}
entries.Add($"{r.Guest.LastName}, {r.Guest.FirstName}\t{r.Type}\t{roominfo}\t{r.EndDate}");
}
string report = $"DAILY ARRIVAL REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"Last, First\tType\tRoom\tDeparture" +
$"{string.Join("\n", entries)}\n\n";
File.AppendAllText(Path.GetFullPath("DailyArrivals.txt"), report);
}
internal static void FetchDailyOccupancy(List<(DateTime, int, string, string)> cop, List<int> pop)
{
List<string> entries = new();
foreach (var c in cop)
{
string lastOccupied;
string sameDayLeave = "";
if (pop.Contains(c.Item2))
{
lastOccupied = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
} else
{
lastOccupied = "N/A";
}
if(DateTime.Now.Date == c.Item1.Date)
{
sameDayLeave = "*";
}
entries.Add($"{c.Item2}\t{lastOccupied}\t{sameDayLeave}{c.Item3}, {c.Item4}");
}
string report = $"DAILY OCCUPANCY REPORT - GENERATED ON {DateTime.Now.Date.ToString("yyyy-MM-dd")}\n" +
$"An * means that the guest is leaving the same day.\n" +
$"Room #\tPrev. Occupied\tCurrent Occupant\n" +
$"{string.Join("\n", entries)}\n\n";
File.AppendAllText(Path.GetFullPath("DailyOccupancy.txt"), report);
}
} }
} }

View File

@@ -11,10 +11,10 @@ namespace Ophelias.Expressions
{ {
internal static class Expressions internal static class Expressions
{ {
internal static Regex CardRx = new Regex(@"^[0-9]{16}$", RegexOptions.Compiled); internal static Regex CardRx = new(@"^[0-9]{16}$", RegexOptions.Compiled);
internal static Regex ExpriationRx = new Regex(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled); internal static Regex ExpriationRx = new(@"^(0?[1-9]|1[012])/2[0-9]{1}$", RegexOptions.Compiled);
internal static Regex CCVRx = new Regex(@"^[0-9]{3}$", RegexOptions.Compiled); internal static Regex CCVRx = new(@"^[0-9]{3}$", RegexOptions.Compiled);
internal static Regex MoneyRx = new Regex(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled); internal static Regex MoneyRx = new(@"^(\d+\.\d{2}|\d+)$", RegexOptions.Compiled);
} }
internal static class Validation internal static class Validation
{ {
@@ -41,7 +41,7 @@ namespace Ophelias.Expressions
} }
internal static bool ValidateEmail(string email) internal static bool ValidateEmail(string email)
{ {
EmailAddressAttribute EmailChecker = new EmailAddressAttribute(); EmailAddressAttribute EmailChecker = new();
return EmailChecker.IsValid(email); return EmailChecker.IsValid(email);
} }
internal static bool ValidateCCV(string CCV) internal static bool ValidateCCV(string CCV)