Finishes major documentation, bug fixes, and small optimizations
This commit is contained in:
@@ -5,6 +5,14 @@ namespace Ophelias.Managers
|
||||
{
|
||||
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 Database()
|
||||
@@ -22,6 +30,11 @@ namespace Ophelias.Managers
|
||||
}
|
||||
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 =
|
||||
@"CREATE TABLE IF NOT EXISTS [transactions] (
|
||||
[ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -79,17 +92,21 @@ namespace Ophelias.Managers
|
||||
|
||||
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();
|
||||
for (int i = 1; i < 46; i++)
|
||||
for (int i = 0; i < 45; i++)
|
||||
{
|
||||
cmd.CommandText = $"INSERT INTO ROOMS (Occupied) VALUES (0);";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Initialize Rooms
|
||||
|
||||
}
|
||||
public void Dispose()
|
||||
public void Dispose() // Needed to support "using"
|
||||
{
|
||||
Close();
|
||||
}
|
||||
@@ -97,12 +114,20 @@ namespace Ophelias.Managers
|
||||
|
||||
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,
|
||||
double? Rate = null, double? Owed = null, double? Penalty = null,
|
||||
double? Multiplier = null, double? Refund = 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();
|
||||
string query = "UPDATE transactions SET";
|
||||
|
||||
@@ -151,7 +176,7 @@ namespace Ophelias.Managers
|
||||
queryComponents.Add($"PaidOn = @PaidOn");
|
||||
}
|
||||
|
||||
if (queryComponents.Count > 0)
|
||||
if (queryComponents.Count >= 0)
|
||||
{
|
||||
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,
|
||||
DateTime? CheckIn = null, DateTime? CheckOut = null, DateTime? DateChanged = null)
|
||||
{
|
||||
/*
|
||||
* Builds an update query string for the reservation model
|
||||
*/
|
||||
List<string> QueryParts = new();
|
||||
string query = "UPDATE reservations SET";
|
||||
|
||||
@@ -231,7 +259,7 @@ namespace Ophelias.Managers
|
||||
QueryParts.Add($"DateChanged = @DateChanged");
|
||||
}
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
if (QueryParts.Count >= 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
/*
|
||||
* Builds an update query string for the guest model
|
||||
*/
|
||||
List<string> QueryParts = new();
|
||||
string query = "UPDATE guests SET";
|
||||
|
||||
@@ -278,7 +309,7 @@ namespace Ophelias.Managers
|
||||
QueryParts.Add($"CCV = @CCV");
|
||||
}
|
||||
|
||||
if (QueryParts.Count > 0)
|
||||
if (QueryParts.Count >= 0)
|
||||
{
|
||||
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:
|
||||
* Returns to the main loop for choosing either the Guest or Admin flow.
|
||||
*/
|
||||
Hotel.CheckBaseRate();
|
||||
string? input = Console.ReadLine();
|
||||
switch (input)
|
||||
{
|
||||
@@ -1309,6 +1310,7 @@ internal class Program
|
||||
* Q or Q:
|
||||
* Returns to the main loop for choosing either the Guest or Admin flow.
|
||||
*/
|
||||
Hotel.CheckBaseRate();
|
||||
string? input = Console.ReadLine();
|
||||
switch (input)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user