Updateed some formatting and bug fixes
Fixed inconsistencies in queries that would result in errors because the parameters were missing. Updating a guest is an example that had this issue. After checking parameters should all be supplied where needed.
This commit is contained in:
@@ -51,9 +51,10 @@ namespace Ophelias.Managers
|
||||
using SQLiteDataReader reader = cmd.ExecuteReader(); // Create a new reader to read the SQL data
|
||||
while (reader.Read())
|
||||
{
|
||||
foreach (int item in reader.GetValues())
|
||||
foreach (var item in reader.GetValues())
|
||||
{
|
||||
previousOccupancies.Add(item);
|
||||
if (item.GetType().Equals(typeof(int)))
|
||||
previousOccupancies.Add((int)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -554,8 +555,12 @@ namespace Ophelias.Managers
|
||||
using (Database Manager = new()) // Opens a database connection
|
||||
{
|
||||
using SQLiteCommand cmd = Manager.con.CreateCommand(); // Creates a new command
|
||||
cmd.CommandText = $"SELECT * FROM reservation WHERE Email = @Email AND Status IN (@Status1,@Status2)";
|
||||
cmd.CommandText = "SELECT * FROM reservations " +
|
||||
"INNER JOIN guests ON reservations.GuestID = guests.ID " +
|
||||
"WHERE Email = @Email AND Status IN (@Status1,@Status2)";
|
||||
cmd.Parameters.AddWithValue("@Email", Email);
|
||||
cmd.Parameters.AddWithValue("@Status1", (int)ReservationStatus.Active);
|
||||
cmd.Parameters.AddWithValue("@Status2", (int)ReservationStatus.Changed);
|
||||
using SQLiteDataReader reader = cmd.ExecuteReader(); // Creates a new SQL data reader
|
||||
reader.Read();
|
||||
if (reader.HasRows)
|
||||
@@ -798,7 +803,7 @@ namespace Ophelias.Managers
|
||||
* occupied as a guest has been assigned it.
|
||||
*/
|
||||
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))));";
|
||||
"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);
|
||||
@@ -818,7 +823,7 @@ namespace Ophelias.Managers
|
||||
reader.Read();
|
||||
if (reader.HasRows)
|
||||
{
|
||||
RoomID = (int)reader.GetValue(0);
|
||||
RoomID = reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
Transaction.Commit(); // Commits the transaction
|
||||
|
||||
Reference in New Issue
Block a user