2019-10-10 17:13:30 +00:00
using Dapper ;
using System ;
using System.Collections.Generic ;
using System.Configuration ;
using System.Data ;
using System.Data.SQLite ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace QueueSys
{
2019-10-10 17:36:32 +00:00
public class CustomerView
2019-10-10 17:13:30 +00:00
{
public string customerName { get ; }
public string status { get ; }
public string timeElapsed { get ; }
}
2019-10-10 17:36:32 +00:00
public class EmployeeView
2019-10-10 17:13:30 +00:00
{
public int id { get ; }
public string customer_name { get ; set ; }
public int num_bags { get ; set ; }
public string employee { get ; set ; }
2019-10-11 22:28:31 +00:00
public int status { get ; set ; }
2019-10-10 17:13:30 +00:00
}
public class SqliteDataAccess
{
2019-10-10 17:36:32 +00:00
public static List < EmployeeView > LoadEmployeeView ( )
2019-10-10 17:13:30 +00:00
{
//A using statement protects us as a failsafe: it guarantees the connection to the
//database will be closed, even in event of an application or computer crash.
using ( IDbConnection cnn = new SQLiteConnection ( LoadConnectionString ( ) ) )
{
2019-10-11 22:28:31 +00:00
string strQuery = "SELECT id,customer_name,num_bags,employee,status FROM active_customers;" ;
2019-10-10 17:36:32 +00:00
var output = cnn . Query < EmployeeView > ( strQuery , new DynamicParameters ( ) ) ;
2019-10-10 17:13:30 +00:00
return output . ToList ( ) ;
}
}
2019-10-10 17:36:32 +00:00
public static List < CustomerView > LoadCustomerView ( )
2019-10-10 17:13:30 +00:00
{
using ( IDbConnection cnn = new SQLiteConnection ( LoadConnectionString ( ) ) )
{
2019-10-10 17:36:32 +00:00
string strQuery = "SELECT customer_name,status FROM active_customers;" ;
var output = cnn . Query < CustomerView > ( strQuery , new DynamicParameters ( ) ) ;
2019-10-10 17:13:30 +00:00
return output . ToList ( ) ;
}
}
2019-10-10 17:36:32 +00:00
public static void SaveCustomer ( EmployeeView customer )
2019-10-10 17:13:30 +00:00
{
2019-10-11 22:28:31 +00:00
using ( IDbConnection cnn = new SQLiteConnection ( LoadConnectionString ( ) ) )
{
string strQuery = "INSERT INTO active_customers (customer_name, num_bags, employee, status_id) VALUES (@customer_name, @num_bags, @employee, @status)" ;
cnn . Execute ( strQuery , customer ) ;
}
}
public static void ArchiveCustomer ( EmployeeView customer )
{
using ( IDbConnection cnn = new SQLiteConnection ( LoadConnectionString ( ) ) )
{
string strQuery = "INSERT INTO archive(id, customer_name,num_bags,employee,status,start_time) SELECT id,customer_name,num_bags,employee,status,start_time WHERE id=@id" ;
cnn . Execute ( strQuery , customer ) ;
// strQuery = "DELETE FROM active_customers WHERE id=@id";
// cnn.Execute(strQuery, customer);
}
2019-10-10 17:13:30 +00:00
}
private static string LoadConnectionString ( string id = "Default" )
{
return ConfigurationManager . ConnectionStrings [ id ] . ConnectionString ;
}
}
}