First major version of the project
This finishes the first iteration of the project. Reports have been tested and are functional in terms of writing out and outputting some form of text. There are still a few bugs here and there that are found but ultimately this commit is so testing can begin. Since the changes are too large to individually summarize, here is the generalization: Reports have been integrated into the admin mode. They write out to text files rather than export to say email or a printer as it was not to be considered for this version. The files are appended too and exist in the debug director of the project. I made this easier to find by outputting where the files were output to after running the report. Other changes included some bug fixes, optimizations, and a few bit of automatic cleanup. This may lead to sylistic inconsistencies. Documentation will come in a later commit.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
using System.Data.SQLite;
|
||||
using Ophelias.Models;
|
||||
using Ophelias.Models;
|
||||
using System.Data.SQLite;
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -30,13 +30,14 @@ namespace Ophelias.Managers
|
||||
[Penalty] INTEGER NOT NULL,
|
||||
[Multiplier] INTEGER NOT NULL,
|
||||
[RefundAmount] INTEGER NOT NULL,
|
||||
[AmountPaid] INTEGER NOT NULL,
|
||||
[PayBy] TEXT NOT NULL,
|
||||
[LastPaid] TEXT NULL,
|
||||
[PaidOn] TEXT NULL);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS [reservations] (
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
[RoomNum] INTEGER NULL UNIQUE,
|
||||
[RoomNum] INTEGER NULL,
|
||||
[GuestID] INTEGER NOT NULL,
|
||||
[TransactionID] INTEGER NOT NULL UNIQUE,
|
||||
[IsNoShow] BOOLEAN NOT NULL CHECK ([IsNoShow] IN (0,1)),
|
||||
@@ -71,22 +72,18 @@ namespace Ophelias.Managers
|
||||
[DateSet] TEXT NOT NULL UNIQUE,
|
||||
[DefaultRate] INTEGER NULL UNIQUE CHECK ([DefaultRate] IN (1)));";
|
||||
|
||||
using (SQLiteCommand cmd = con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = tableCommands;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
using SQLiteCommand cmd = con.CreateCommand();
|
||||
cmd.CommandText = tableCommands;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
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.ExecuteNonQuery();
|
||||
}
|
||||
cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Initialize Rooms
|
||||
@@ -104,32 +101,64 @@ namespace Ophelias.Managers
|
||||
internal static string? UpdateTransaction(int Id,
|
||||
double? Rate = null, double? Owed = null, double? Penalty = 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";
|
||||
|
||||
if (Rate.HasValue)
|
||||
{
|
||||
queryComponents.Add($"Rate = @Rate");
|
||||
}
|
||||
|
||||
if (Owed.HasValue)
|
||||
{
|
||||
queryComponents.Add($"Owed = @Owed");
|
||||
}
|
||||
|
||||
if (Penalty.HasValue)
|
||||
{
|
||||
queryComponents.Add($"Penalty = @Penalty");
|
||||
}
|
||||
|
||||
if (Multiplier.HasValue)
|
||||
{
|
||||
queryComponents.Add($"Multiplier = @Multiplier");
|
||||
}
|
||||
|
||||
if (Refund.HasValue)
|
||||
queryComponents.Add($"Refund = @Refund");
|
||||
{
|
||||
queryComponents.Add($"RefundAmount = @RefundAmount");
|
||||
}
|
||||
|
||||
if (AmountPaid.HasValue)
|
||||
{
|
||||
queryComponents.Add($"AmountPaid = @AmountPaid");
|
||||
}
|
||||
|
||||
if (PayBy.HasValue)
|
||||
{
|
||||
queryComponents.Add($"PayBy = @PayBy");
|
||||
}
|
||||
|
||||
if (LastPaid.HasValue)
|
||||
{
|
||||
queryComponents.Add($"LastPaid = @LastPaid");
|
||||
}
|
||||
|
||||
if (PaidOn.HasValue)
|
||||
{
|
||||
queryComponents.Add($"PaidOn = @PaidOn");
|
||||
}
|
||||
|
||||
if (queryComponents.Count > 0)
|
||||
{
|
||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = @ID;";
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
@@ -139,64 +168,124 @@ namespace Ophelias.Managers
|
||||
ReservationStatus? Status = null, DateTime? CreationDate = null, DateTime? StartDate = null, DateTime? EndDate = 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";
|
||||
|
||||
if (RoomID.HasValue)
|
||||
{
|
||||
QueryParts.Add($"RoomID = @RID");
|
||||
}
|
||||
|
||||
if (GuestID.HasValue)
|
||||
{
|
||||
QueryParts.Add($"GuestID = @GID");
|
||||
}
|
||||
|
||||
if (TransactionID.HasValue)
|
||||
{
|
||||
QueryParts.Add($"TransactionID = @TID");
|
||||
}
|
||||
|
||||
if (IsNoShow.HasValue)
|
||||
{
|
||||
QueryParts.Add($"IsNoShow = @IsNoShow");
|
||||
}
|
||||
|
||||
if (Type.HasValue)
|
||||
{
|
||||
QueryParts.Add($"Type = @Type");
|
||||
}
|
||||
|
||||
if (Status.HasValue)
|
||||
{
|
||||
QueryParts.Add($"Status = @Status");
|
||||
}
|
||||
|
||||
if (CreationDate.HasValue)
|
||||
{
|
||||
QueryParts.Add($"CreationDate = @CreationDate");
|
||||
}
|
||||
|
||||
if (StartDate.HasValue)
|
||||
{
|
||||
QueryParts.Add($"StartDate = @StartDate");
|
||||
}
|
||||
|
||||
if (EndDate.HasValue)
|
||||
{
|
||||
QueryParts.Add($"EndDate = @EndDate");
|
||||
}
|
||||
|
||||
if (CheckIn.HasValue)
|
||||
{
|
||||
QueryParts.Add($"CheckIn = @CheckIn");
|
||||
}
|
||||
|
||||
if (CheckOut.HasValue)
|
||||
{
|
||||
QueryParts.Add($"CheckOut = @CheckOut");
|
||||
}
|
||||
|
||||
if (DateChanged.HasValue)
|
||||
{
|
||||
QueryParts.Add($"DateChanged = @DateChanged");
|
||||
}
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
{
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
List<string> QueryParts = new List<string>();
|
||||
List<string> QueryParts = new();
|
||||
string query = "UPDATE guests SET";
|
||||
|
||||
if (!string.IsNullOrEmpty(FirstName))
|
||||
{
|
||||
QueryParts.Add($"Fname = @Fname");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(LastName))
|
||||
{
|
||||
QueryParts.Add($"Lname = @Lname");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(LastName))
|
||||
{
|
||||
QueryParts.Add($"Email = @Email");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(CreditCard))
|
||||
{
|
||||
QueryParts.Add($"CreditCard = @CC");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Expiration))
|
||||
{
|
||||
QueryParts.Add($"Expiration = @Expiry");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(CCV))
|
||||
{
|
||||
QueryParts.Add($"CCV = @CCV");
|
||||
}
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
{
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = @ID;";
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
949
OpheliasOasis/Managers/Hotel.cs
Normal file
949
OpheliasOasis/Managers/Hotel.cs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user