diff --git a/QueueSys/SqliteDataAccess.cs b/QueueSys/SqliteDataAccess.cs index 89f428f..65f972a 100644 --- a/QueueSys/SqliteDataAccess.cs +++ b/QueueSys/SqliteDataAccess.cs @@ -39,6 +39,11 @@ namespace QueueSys public string status { get; set; } } + public class endTimeModel + { + public string end_time { get; set; } + } + public class SqliteDataAccess { public List LoadEmployeeView() @@ -90,7 +95,21 @@ namespace QueueSys { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { - string strQuery = "INSERT INTO archive(id, customer_name,num_bags,employee,status_id,start_time) SELECT id,customer_name,num_bags,employee,status_id,start_time FROM active_customers WHERE id=@id"; + //Check to see if the customer already has an end_time + string strQuery = "SELECT end_time FROM active_customers WHERE id=@id"; + + List etm = new List(); + var output = cnn.Query(strQuery, new { id = customer.id }); + etm = output.ToList(); + + if(etm[0].end_time != null) + { + strQuery = "INSERT INTO archive(id, customer_name,num_bags,employee,status_id,start_time,end_time) SELECT id,customer_name,num_bags,employee,status_id,start_time,end_time FROM active_customers WHERE id=@id"; + } + else + { + strQuery = "INSERT INTO archive(id, customer_name,num_bags,employee,status_id,start_time) SELECT id,customer_name,num_bags,employee,status_id,start_time FROM active_customers WHERE id=@id"; + } cnn.Execute(strQuery, customer); strQuery = "DELETE FROM active_customers WHERE id=@id"; @@ -118,6 +137,28 @@ namespace QueueSys } } + public void UpdateEndTime(int customer_id_in, string trans) + { + using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) + { + switch(trans) + { + case "add": + { + string strQuery = "UPDATE active_customers SET end_time = datetime() WHERE id=@customer_id"; + cnn.Execute(strQuery, new { customer_id = customer_id_in }); + break; + } + case "remove": + { + string strQuery = "UPDATE active_customers SET end_time = NULL WHERE id=@customer_id"; + cnn.Execute(strQuery, new { customer_id = customer_id_in }); + break; + } + } + } + } + public List QueryReports() { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))