Finishes the guest part of the models and UI integration

This commit branch has been muddled with changes that are out of scope
and cover more than just the models. Specifically it includes
completion of basic guest related models, database access, command line interface
integration and preventing SQL injection.

Total summary of changes:

**IMPORTANT CHANGE: All queries are now parameterized to prevent SQL
injections. Prior versions are subject to it since the strings were
built.

- HotelManager
This class is used to provide database operations that are outside of
scope from a given model. Furthermore if there is no model to work off
of, such as creating a new model based off an existing entry, these
functions live outside of the model since it makes no sense for models
to contain functions where it would retrieve itself with no context.
Realistically this could be placed in an empty constructor and address
itself, however, for now this functionality has been moved off the model
since it is a one use and is not guaranteed to generate a guest. Some
functionality for the coming employee management functions are already
in there since they share overlap with the guest module. Specifically
GetBaseRate for checking and getting the base rate.

- DatabaseManager
This class has mostly migrated functionality out or switch to
parameterized query generation to prevent SQL injections.

- Guest, Reservation, and Transaction Classes
Migrated functionality to create the database entry and a new entry of
guest upon creation as well as update them.

- Program (Terminal app)
Fully integrated the guest module. Has not undergone extensive testing
but does work as of this commit.
This commit is contained in:
雲華
2022-04-15 02:29:55 -04:00
parent 8764c2e57c
commit 34bebca414
7 changed files with 621 additions and 296 deletions

View File

@@ -21,6 +21,49 @@ namespace Ophelias.Models
internal DateTime? LastPaid { get; set; } = null;
internal DateTime? PaidOn { get; set; } = null;
internal Transaction(double Rate, double Owed,
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
{
int Id;
using (DatabaseManager Manager = new DatabaseManager())
{
using (SQLiteCommand cmd = Manager.con.CreateCommand())
{
cmd.CommandText = "INSERT INTO transactions (Rate, Owed, Penalty, Multiplier, RefundAmount, PayBy, LastPaid, PaidOn) " +
"VALUES (@Rate, @Owed, @Penalty, @Multiplier, @RefundAmount, @PayBy, @LastPaid, @PaidOn)";
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@Owed", Owed);
cmd.Parameters.AddWithValue("@Multiplier", Multiplier);
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
cmd.Parameters.AddWithValue("@Penalty", Penalty);
cmd.Parameters.AddWithValue("@PayBy", PayBy.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
if (LastPaid != null)
cmd.Parameters.AddWithValue("@LastPaid", LastPaid.Value.ToString("yyyy-MM-dd"));
else
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
if (PaidOn != null)
cmd.Parameters.AddWithValue("@PaidOn", PaidOn.Value.ToString("yyyy-MM-dd"));
else
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
//cmd.CommandText = QueryBuilder.CreateTransaction(Rate, Owed, Multiplier, PayBy, Refund: RefundAmount, Penalty: Penalty, LastPaid: LastPaid, PaidOn: PaidOn);
cmd.ExecuteNonQuery();
}
Id = (int)Manager.con.LastInsertRowId;
}
this.Id = Id;
this.Rate = Rate;
this.Owed = Owed;
this.Penalty = Penalty;
this.Multiplier = Multiplier;
this.RefundAmount = RefundAmount;
this.PayBy = PayBy;
this.LastPaid = LastPaid;
this.PaidOn = PaidOn;
}
internal Transaction(int Id, double Rate, double Owed,
double Multiplier, DateTime PayBy, DateTime? LastPaid = null,
DateTime? PaidOn = null, double RefundAmount = 0, double Penalty = 0)
@@ -51,6 +94,10 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id);
cmd.Parameters.AddWithValue("@Rate", this.Rate);
cmd.Parameters.AddWithValue("@Multiplier", this.Multiplier);
cmd.Parameters.AddWithValue("@PayBy", this.PayBy.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
}
}
@@ -75,6 +122,11 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id);
cmd.Parameters.AddWithValue("@Owed", Owed);
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
cmd.Parameters.AddWithValue("@LastPaid", LastPaid);
cmd.Parameters.AddWithValue("@PaidOn", PaidOn);
cmd.ExecuteNonQuery();
}
}
@@ -92,6 +144,8 @@ namespace Ophelias.Models
throw new Exception();
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@ID", Id);
cmd.Parameters.AddWithValue("@RefundAmount", RefundAmount);
cmd.ExecuteNonQuery();
}
}
@@ -125,7 +179,7 @@ namespace Ophelias.Models
}
internal static double CalculateOwed(double Rate, int Days)
{
return Rate * (double)Days;
return Rate * Days;
}