Begun integration of models and managers
The HotelManager class now has been connected to some aspects of the command line interface and is functioning for a few cases such as logging in as a specific guest via email, chaging a guests information and creating a new guest account. This was implemented first over the reservation system to test and implement something on a smaller scale. Furthermore, the reservation depends on an existing guest account since a Guest ID needs to be linked to the reservation that is created. Other changes include redesigning, tweaking/ adjusting, and/ or fixing of other modules that have not yet been implemented or are partially implemented.
This commit is contained in:
@@ -31,6 +31,7 @@ namespace Ophelias.Managers
|
||||
[Multiplier] INTEGER NOT NULL,
|
||||
[RefundAmount] INTEGER NOT NULL,
|
||||
[PayBy] TEXT NOT NULL,
|
||||
[LastPaid] TEXXT NULL,
|
||||
[PaidOn] TEXT NULL);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS [reservations] (
|
||||
@@ -55,8 +56,8 @@ namespace Ophelias.Managers
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
[Fname] TEXT NOT NULL,
|
||||
[Lname] TEXT NOT NULL,
|
||||
[Email] TEXT NOT NULL,
|
||||
[CreditCard] TEXT NULL,
|
||||
[Email] TEXT NOT NULL UNIQUE,
|
||||
[CreditCard] TEXT NULL UNIQUE,
|
||||
[Expiration] TEXT NULL,
|
||||
[CCV] TEXT NULL);
|
||||
|
||||
@@ -67,7 +68,8 @@ namespace Ophelias.Managers
|
||||
CREATE TABLE IF NOT EXISTS [rates] (
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
[Rate] INTEGER NOT NULL,
|
||||
[DateSet] TEXT NOT NULL);";
|
||||
[DateSet] TEXT NOT NULL UNIQUE,
|
||||
[DefaultRate] INTEGER NULL UNIQUE CHECK ([DefaultRate] IN (1)));";
|
||||
|
||||
using (SQLiteCommand cmd = con.CreateCommand())
|
||||
{
|
||||
@@ -103,10 +105,10 @@ namespace Ophelias.Managers
|
||||
internal static class QueryBuilder
|
||||
{
|
||||
|
||||
internal static string? UpdateTransaction(int id,
|
||||
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? PaidOn = null)
|
||||
DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null)
|
||||
{
|
||||
List<string> queryComponents = new List<string>();
|
||||
string query = "UPDATE transactions SET";
|
||||
@@ -122,82 +124,110 @@ namespace Ophelias.Managers
|
||||
if (Refund.HasValue)
|
||||
queryComponents.Add($"Refund = {Refund}");
|
||||
if (PayBy.HasValue)
|
||||
queryComponents.Add($"PaidBy = {PayBy.Value.ToString("yyyy-MM-dd")}");
|
||||
queryComponents.Add($"PayBy = {PayBy.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (LastPaid.HasValue)
|
||||
queryComponents.Add($"LastPaid = {LastPaid.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (PaidOn.HasValue)
|
||||
queryComponents.Add($"PaidOn = {PaidOn.Value.ToString("yyyy-MM-dd")}");
|
||||
queryComponents.Add($"PaidOn = {PaidOn.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
|
||||
if (queryComponents.Count == 0)
|
||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
|
||||
if (queryComponents.Count > 0)
|
||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {Id};";
|
||||
else
|
||||
return null;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
internal static string? UpdateReservation(int id,
|
||||
int? roomid = null, int? guestid = null, int? transactionid = null, bool? isnoshow = null, ReservationType? type = null,
|
||||
ReservationStatus? status = null, DateTime? creationdate = null, DateTime? startdate = null, DateTime? enddate = null,
|
||||
DateTime? checkin = null, DateTime? checkout = null, DateTime? datechanged = null)
|
||||
internal static string? UpdateReservation(int Id,
|
||||
int? RoomID = null, int? GuestID = null, int? TransactionID = null, bool? IsNoShow = null, ReservationType? Type = null,
|
||||
ReservationStatus? Status = null, DateTime? CreationDate = null, DateTime? StartDate = null, DateTime? EndDate = null,
|
||||
DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
|
||||
{
|
||||
List<string> queryComponents = new List<string>();
|
||||
List<string> QueryParts = new List<string>();
|
||||
string query = "UPDATE reservations SET";
|
||||
|
||||
if (roomid.HasValue)
|
||||
queryComponents.Add($"RoomID = {roomid}");
|
||||
if (guestid.HasValue)
|
||||
queryComponents.Add($"GuestID = {guestid}");
|
||||
if (transactionid.HasValue)
|
||||
queryComponents.Add($"TransactionID = {transactionid}");
|
||||
if (isnoshow.HasValue)
|
||||
queryComponents.Add($"IsNoShow = {Convert.ToInt32(isnoshow)}");
|
||||
if (type.HasValue)
|
||||
queryComponents.Add($"Type = {(int)type}");
|
||||
if (status.HasValue)
|
||||
queryComponents.Add($"Type = {(int)status}");
|
||||
if (creationdate.HasValue)
|
||||
queryComponents.Add($"CreationDate = {creationdate.Value.ToString("yyyy-MM-dd")}");
|
||||
if (startdate.HasValue)
|
||||
queryComponents.Add($"StartDate = {startdate.Value.ToString("yyyy-MM-dd")}");
|
||||
if (enddate.HasValue)
|
||||
queryComponents.Add($"EndDate = {enddate.Value.ToString("yyyy-MM-dd")}");
|
||||
if (checkin.HasValue)
|
||||
queryComponents.Add($"CheckIn = {checkin.Value.ToString("yyyy-MM-dd")}");
|
||||
if (checkout.HasValue)
|
||||
queryComponents.Add($"CheckOut = {checkout.Value.ToString("yyyy-MM-dd")}");
|
||||
if (datechanged.HasValue)
|
||||
queryComponents.Add($"CheckOut = {datechanged.Value.ToString("yyyy-MM-dd")}");
|
||||
if (RoomID.HasValue)
|
||||
QueryParts.Add($"RoomID = {RoomID}");
|
||||
if (GuestID.HasValue)
|
||||
QueryParts.Add($"GuestID = {GuestID}");
|
||||
if (TransactionID.HasValue)
|
||||
QueryParts.Add($"TransactionID = {TransactionID}");
|
||||
if (IsNoShow.HasValue)
|
||||
QueryParts.Add($"IsNoShow = {Convert.ToInt32(IsNoShow)}");
|
||||
if (Type.HasValue)
|
||||
QueryParts.Add($"Type = {(int)Type}");
|
||||
if (Status.HasValue)
|
||||
QueryParts.Add($"Status = {(int)Status}");
|
||||
if (CreationDate.HasValue)
|
||||
QueryParts.Add($"CreationDate = {CreationDate.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (StartDate.HasValue)
|
||||
QueryParts.Add($"StartDate = {StartDate.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (EndDate.HasValue)
|
||||
QueryParts.Add($"EndDate = {EndDate.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (CheckIn.HasValue)
|
||||
QueryParts.Add($"CheckIn = {CheckIn.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (CheckOut.HasValue)
|
||||
QueryParts.Add($"CheckOut = {CheckOut.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
if (DateChanged.HasValue)
|
||||
QueryParts.Add($"DateChanged = {DateChanged.Value.Date.ToString("yyyy-MM-dd")}");
|
||||
|
||||
if (queryComponents.Count == 0)
|
||||
query += " " + string.Join(", ", queryComponents) + " " + $"WHERE ID = {id};";
|
||||
if (QueryParts.Count > 0)
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
|
||||
else
|
||||
return null;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
internal static string CreateTransaction(double Rate, double Owed, double Penalty,
|
||||
double Multiplier, double Refund, bool isLate,
|
||||
bool PaidOff, DateTime PaidBy, DateTime? PaidOn = null)
|
||||
internal static string CreateTransaction(double Rate, double Owed,
|
||||
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
||||
DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
|
||||
{
|
||||
|
||||
return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, Refund, IsLate, PaidOff, PaidBy, PaidOn)
|
||||
VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {isLate}, {PaidOff}, {PaidBy}, {PaidOn});";
|
||||
return @$"INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn)
|
||||
VALUES ({Rate}, {Owed}, {Penalty}, {Multiplier}, {Refund}, {PayBy}, {PayBy}, {PaidOn});";
|
||||
}
|
||||
|
||||
internal static string CreateReservation(int roomid, int guestid, int transactionid, bool isnoshow, ReservationType type,
|
||||
internal static string CreateReservation(int guestid, int transactionid, ReservationType type,
|
||||
ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
|
||||
DateTime checkin, DateTime checkout, DateTime datechanged)
|
||||
DateTime? checkin = null, DateTime? checkout = null, DateTime? datechanged = null, bool? isnoshow = false)
|
||||
{
|
||||
return @$"INSERT INTO reservations (RoomID, GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
|
||||
VALUES ({roomid}, {guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
|
||||
return @$"INSERT INTO reservations (GuestID, TransactionID, IsNoShow, Type, Status, CreationDate, StartDate, EndDate, CheckIn, CheckOut, DateChanged)
|
||||
VALUES ({guestid}, {transactionid}, {isnoshow}, {status}, {creationdate}, {startdate}, {enddate}, {checkin}, {checkout}, {datechanged});";
|
||||
}
|
||||
|
||||
internal static string CreateGuest(string FirstName, string LastName, string Email, string? CreditCard, string? Expiration, string? CCV)
|
||||
{
|
||||
if (CreditCard != null && Expiration != null && CCV != null)
|
||||
return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ({FirstName}, {LastName}, {Email});";
|
||||
return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ('{FirstName}', '{LastName}', '{Email}', '{CreditCard}', '{Expiration}', '{CCV}');";
|
||||
else
|
||||
return $@"INSERT INTO guests (Fname, Lname, Email, CreditCard, Expiration, CCV) VALUES ({FirstName}, {LastName}, {Email}, {CreditCard}, {Expiration}, {CCV});";
|
||||
return $@"INSERT INTO guests (Fname, Lname, Email) VALUES ('{FirstName}', '{LastName}', '{Email}');";
|
||||
}
|
||||
|
||||
internal static string? UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||
{
|
||||
List<string> QueryParts = new List<string>();
|
||||
string query = "UPDATE guests SET";
|
||||
|
||||
if (!string.IsNullOrEmpty(FirstName))
|
||||
QueryParts.Add($"Fname = '{FirstName}'");
|
||||
if (!string.IsNullOrEmpty(LastName))
|
||||
QueryParts.Add($"Lname = '{LastName}'");
|
||||
if (!string.IsNullOrEmpty(LastName))
|
||||
QueryParts.Add($"Email = '{Email}'");
|
||||
if (!string.IsNullOrEmpty(CreditCard))
|
||||
QueryParts.Add($"CreditCard = '{CreditCard}'");
|
||||
if (!string.IsNullOrEmpty(Expiration))
|
||||
QueryParts.Add($"Expiration = '{Expiration}'");
|
||||
if (!string.IsNullOrEmpty(CCV))
|
||||
QueryParts.Add($"CCV = '{CCV}'");
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
query += " " + string.Join(", ", QueryParts) + " " + $"WHERE ID = {Id};";
|
||||
else
|
||||
return null;
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Ophelias.Models;
|
||||
using Ophelias.Models;
|
||||
using System.Data.SQLite;
|
||||
|
||||
namespace Ophelias.Managers
|
||||
@@ -12,107 +7,117 @@ namespace Ophelias.Managers
|
||||
{
|
||||
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=\"{tableName}\";";
|
||||
cmd.ExecuteNonQuery();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
lastId = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lastId;
|
||||
}
|
||||
internal static int GetThirtyDayOccupancy(DateTime start)
|
||||
{
|
||||
int thirtyDayOcc;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand()) {
|
||||
cmd.CommandText = $@"SELECT COUNT(*)
|
||||
FROM reservations
|
||||
WHERE StartDate => date({start.ToString("yyyy-MM-dd")})
|
||||
AND EndDate <= date({start.AddDays(30).ToString("yyyy-MM-dd")});";
|
||||
cmd.ExecuteNonQuery();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
thirtyDayOcc = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return thirtyDayOcc;
|
||||
}
|
||||
internal static int CreateReservation(int roomid, int guestid, int transactionid, bool isnoshow, ReservationType type,
|
||||
ReservationStatus status, DateTime creationdate, DateTime startdate, DateTime enddate,
|
||||
DateTime checkin, DateTime checkout, DateTime datechanged)
|
||||
{
|
||||
int id;
|
||||
int LastId = 0;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = QueryBuilder.CreateReservation(roomid, guestid, transactionid, isnoshow, type,
|
||||
status, creationdate, startdate, enddate,
|
||||
checkin, checkout, datechanged);
|
||||
cmd.CommandText = $"SELECT SEQ FROM sqlite_sequence WHERE name='{tableName}';";
|
||||
cmd.ExecuteNonQuery();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
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.Date.ToString("yyyy-MM-dd")}')
|
||||
BETWEEN StartDate AND EndDate;";
|
||||
cmd.ExecuteNonQuery();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
Occupancies.Add(reader.GetInt32(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Occupancies;
|
||||
}
|
||||
internal static int AvgOccupancySpan(DateTime Start, DateTime End)
|
||||
{
|
||||
int thirtyDayOcc = 0;
|
||||
int days = (int)(Start.Date - End.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('{Start.AddDays(i).Date.ToString("yyyy-MM-dd")}')
|
||||
BETWEEN StartDate AND EndDate;";
|
||||
cmd.ExecuteNonQuery();
|
||||
using (SQLiteDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
reader.Read();
|
||||
thirtyDayOcc += reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return thirtyDayOcc / days;
|
||||
}
|
||||
internal static Reservation CreateReservation(Guest Guest, ReservationType Type,
|
||||
DateTime CreationDate, DateTime StartDate, DateTime EndDate, ReservationStatus Status = ReservationStatus.Active)
|
||||
{
|
||||
int id; double Multiplier;
|
||||
switch (Type)
|
||||
{
|
||||
case ReservationType.Conventional: Multiplier = TxFunctions.ConventionalFee; break;
|
||||
case ReservationType.Prepaid: Multiplier = TxFunctions.PrepaidFee; break;
|
||||
case ReservationType.Incentive: Multiplier = TxFunctions.IncentiveFee(StartDate, EndDate); break;
|
||||
case ReservationType.SixtyDayAdvance: Multiplier = TxFunctions.SixtyDayFee; break;
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
Transaction t = CreateTransaction(
|
||||
Rate: GetBaseRate(),
|
||||
Owed: TxFunctions.CalculateOwed(GetBaseRate(), (int)(StartDate.Date - EndDate.Date).TotalDays),
|
||||
Multiplier: Multiplier,
|
||||
PayBy: TxFunctions.GetPayByDate(Type, StartDate, EndDate)
|
||||
);
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = QueryBuilder.CreateReservation(Guest.Id, t.Id, Type,
|
||||
Status, CreationDate, StartDate, EndDate);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
id = (int)Manager.con.LastInsertRowId;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
internal static void ChangeReservationDates(Reservation r, Transaction t, DateTime start, DateTime end)
|
||||
{
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
string? query = QueryBuilder.UpdateReservation(id: r.Id, startdate: start, enddate: end, datechanged: DateTime.Now);
|
||||
|
||||
if (query == null)
|
||||
throw new Exception();
|
||||
|
||||
query += QueryBuilder.UpdateTransaction(id: r.TransactionId, Multiplier: 1.1);
|
||||
cmd.CommandText = query;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
return new Reservation(id, Guest, t, Type, Status, CreationDate, StartDate, EndDate);
|
||||
}
|
||||
internal static Transaction CreateTransaction(double Rate, double Owed, double Penalty,
|
||||
double Multiplier, double Refund, bool isLate,
|
||||
bool PaidOff, DateTime PaidBy, DateTime? PaidOn = null)
|
||||
internal static Transaction CreateTransaction(double Rate, double Owed,
|
||||
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
|
||||
DateTime? PaidOn = null, double Refund = 0, double Penalty = 0)
|
||||
{
|
||||
int Id;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Penalty, Multiplier, Refund, isLate, PaidOff, PaidBy, PaidOn);
|
||||
cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy,Refund: Refund, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
Id = (int)Manager.con.LastInsertRowId;
|
||||
}
|
||||
return new Transaction(Id, Rate, Owed, Penalty, Multiplier, Refund, PaidBy, PaidOn);
|
||||
return new Transaction(Id, Rate, Owed, Multiplier, Penalty: Penalty, RefundAmount: Refund, PayBy: PayBy, PaidOn: PaidOn);
|
||||
}
|
||||
internal static int CheckInGuest(DateTime CheckIn)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
internal static int CheckOutGuest(DateTime CheckOut)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
internal static Guest CreateGuest(string FirstName, string LastName, string Email, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||
{
|
||||
string query = QueryBuilder.CreateGuest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
||||
|
||||
int Id;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
@@ -125,9 +130,127 @@ namespace Ophelias.Managers
|
||||
}
|
||||
|
||||
if (CreditCard != null && Expiration != null && CCV != null)
|
||||
return new Guest(FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
||||
return new Guest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
||||
else
|
||||
return new Guest(FirstName, LastName, Email);
|
||||
return new Guest(Id, FirstName, LastName, Email);
|
||||
}
|
||||
internal static void UpdateGuest(int Id, string? FirstName = null, string? LastName = null, string? Email = null, string? CreditCard = null, string? Expiration = null, string? CCV = null)
|
||||
{
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = QueryBuilder.UpdateGuest(Id, FirstName, LastName, Email, CreditCard, Expiration, CCV);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static Guest? GetGuestByEmail(string Email)
|
||||
{
|
||||
Guest? g = null;
|
||||
using (DatabaseManager Manager = new DatabaseManager())
|
||||
{
|
||||
using (SQLiteCommand cmd = Manager.con.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT * FROM guests WHERE 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 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();
|
||||
rate = reader.GetDouble(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rate;
|
||||
}
|
||||
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.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 = {DateTime.Now.Date.ToString("yyyy-MM-dd")};";
|
||||
cmd.CommandText = query;
|
||||
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.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static int CheckInGuest(DateTime CheckIn)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
internal static int CheckOutGuest(DateTime CheckOut)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user