Finishes major documentation, bug fixes, and small optimizations
This commit is contained in:
@@ -5,6 +5,14 @@ namespace Ophelias.Managers
|
|||||||
{
|
{
|
||||||
internal class Database : IDisposable
|
internal class Database : IDisposable
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* This class provides some basic functions that
|
||||||
|
* mirror SQLite. The reason for this class is to include
|
||||||
|
* some functions on it that typically would be separate.
|
||||||
|
* In another world, these functions could be of another
|
||||||
|
* static class as they don't really serve a purpose other
|
||||||
|
* than a one-time use if the database needs initialization.
|
||||||
|
*/
|
||||||
internal SQLiteConnection con = new("DataSource=database.sqlite3;Version=3;");
|
internal SQLiteConnection con = new("DataSource=database.sqlite3;Version=3;");
|
||||||
|
|
||||||
internal Database()
|
internal Database()
|
||||||
@@ -22,6 +30,11 @@ namespace Ophelias.Managers
|
|||||||
}
|
}
|
||||||
internal void InitializeTables()
|
internal void InitializeTables()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* This string is used to create the tables used by the models
|
||||||
|
* and the database functions. For more details, see the formatting
|
||||||
|
* string below as it has been organized in such a way there it is readable.
|
||||||
|
*/
|
||||||
string tableCommands =
|
string tableCommands =
|
||||||
@"CREATE TABLE IF NOT EXISTS [transactions] (
|
@"CREATE TABLE IF NOT EXISTS [transactions] (
|
||||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -79,17 +92,21 @@ namespace Ophelias.Managers
|
|||||||
|
|
||||||
internal void InitializeRoomsTable()
|
internal void InitializeRoomsTable()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* This is a one off initialization function to intialize
|
||||||
|
* a list of 45 rooms. The design specification called
|
||||||
|
* for a static 45 rooms that were not configurable hence
|
||||||
|
* it being hardcoded here for now. Ideally this is moved
|
||||||
|
* out to config file.
|
||||||
|
*/
|
||||||
using SQLiteCommand cmd = con.CreateCommand();
|
using SQLiteCommand cmd = con.CreateCommand();
|
||||||
for (int i = 1; i < 46; i++)
|
for (int i = 0; i < 45; i++)
|
||||||
{
|
{
|
||||||
cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
|
cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Rooms
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose() // Needed to support "using"
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
@@ -97,12 +114,20 @@ namespace Ophelias.Managers
|
|||||||
|
|
||||||
internal static class QueryBuilder
|
internal static class QueryBuilder
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* This class is for building update query strings. To prevent SQL injection
|
||||||
|
* on dynamically built strings, the inputs are now used as null check values,
|
||||||
|
* rather than as null check values that get set if they exist. Parameters are
|
||||||
|
* now used in their place which prevent SQL injection.
|
||||||
|
*/
|
||||||
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, double? AmountPaid = null)
|
DateTime? PayBy = null, DateTime? LastPaid = null, DateTime? PaidOn = null, double? AmountPaid = null)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Builds an update query string for the transaction model
|
||||||
|
*/
|
||||||
List<string> queryComponents = new();
|
List<string> queryComponents = new();
|
||||||
string query = "UPDATE transactions SET";
|
string query = "UPDATE transactions SET";
|
||||||
|
|
||||||
@@ -151,7 +176,7 @@ namespace Ophelias.Managers
|
|||||||
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;";
|
||||||
}
|
}
|
||||||
@@ -168,6 +193,9 @@ 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)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Builds an update query string for the reservation model
|
||||||
|
*/
|
||||||
List<string> QueryParts = new();
|
List<string> QueryParts = new();
|
||||||
string query = "UPDATE reservations SET";
|
string query = "UPDATE reservations SET";
|
||||||
|
|
||||||
@@ -231,7 +259,7 @@ namespace Ophelias.Managers
|
|||||||
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;";
|
||||||
}
|
}
|
||||||
@@ -245,6 +273,9 @@ namespace Ophelias.Managers
|
|||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Builds an update query string for the guest model
|
||||||
|
*/
|
||||||
List<string> QueryParts = new();
|
List<string> QueryParts = new();
|
||||||
string query = "UPDATE guests SET";
|
string query = "UPDATE guests SET";
|
||||||
|
|
||||||
@@ -278,7 +309,7 @@ namespace Ophelias.Managers
|
|||||||
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;";
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -850,6 +850,7 @@ internal class Program
|
|||||||
* Q and q:
|
* Q and q:
|
||||||
* Returns to the main loop for choosing either the Guest or Admin flow.
|
* Returns to the main loop for choosing either the Guest or Admin flow.
|
||||||
*/
|
*/
|
||||||
|
Hotel.CheckBaseRate();
|
||||||
string? input = Console.ReadLine();
|
string? input = Console.ReadLine();
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
@@ -1309,6 +1310,7 @@ internal class Program
|
|||||||
* Q or Q:
|
* Q or Q:
|
||||||
* Returns to the main loop for choosing either the Guest or Admin flow.
|
* Returns to the main loop for choosing either the Guest or Admin flow.
|
||||||
*/
|
*/
|
||||||
|
Hotel.CheckBaseRate();
|
||||||
string? input = Console.ReadLine();
|
string? input = Console.ReadLine();
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user