Generic load data working
This commit is contained in:
parent
b6b4dc0cea
commit
5bcb0df7df
|
@ -21,35 +21,20 @@ namespace CryptoCalc
|
|||
Debug.WriteLine($"Saved {data.DBTableName} DB data");
|
||||
}
|
||||
|
||||
//public static List<T> _LoadTransactions()
|
||||
//{
|
||||
// using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("RawData"));
|
||||
// var output = _connection.Query<T>("select * from RawData", new DynamicParameters());
|
||||
// Debug.WriteLine("Loaded DB data");
|
||||
// return output.ToList();
|
||||
//}
|
||||
|
||||
|
||||
public static List<Transaction> LoadTransactions()
|
||||
public class GenericDB<T> where T : DBClasses
|
||||
{
|
||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("Transactions"));
|
||||
IEnumerable<Transaction> output = _connection.Query<Transaction>("select * from Transactions", new DynamicParameters());
|
||||
Debug.WriteLine("Loaded DB data");
|
||||
return output.ToList();
|
||||
|
||||
public IEnumerable<T> LoadAllData(string tableName)
|
||||
{
|
||||
if (tableName is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tableName));
|
||||
}
|
||||
|
||||
|
||||
public static List<Transaction> LoadTransactionsOfCurrency(string currency)
|
||||
{
|
||||
if (currency is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(currency));
|
||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
||||
return _connection.Query<T>($"select * from {tableName}", new DynamicParameters());
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Fetching all {currency} transactions from Database");
|
||||
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("Transactions"));
|
||||
return connection.Query<Transaction>($"select * from Transactions where Currency = '{ currency.ToUpper() }'")
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace CryptoCalc
|
|||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly Random rand = new();
|
||||
private List<Transaction> transactions = new();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
|
@ -34,7 +33,7 @@ namespace CryptoCalc
|
|||
|
||||
private void readButton_click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
transactions = DBInteraction.LoadTransactions();
|
||||
IEnumerable <Transaction> transactions = ReadTransactionFromDB();
|
||||
foreach (Transaction x in transactions)
|
||||
{
|
||||
Debug.WriteLine($"{x.GetLocalTimeFromUnixTime(x.UnixTime)} *** {x.Currency} - {x.Amount}");
|
||||
|
@ -42,12 +41,20 @@ namespace CryptoCalc
|
|||
}
|
||||
private void searchButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
||||
transactionsFoundListBox.Items.Clear();
|
||||
foreach (Transaction x in transactions)
|
||||
{
|
||||
transactionsFoundListBox.Items.Add(x.FullInfo);
|
||||
//IEnumerable<Transaction> transactions = ReadTransactionFromDB("Currency");
|
||||
//transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
||||
//transactionsFoundListBox.Items.Clear();
|
||||
//foreach (Transaction x in transactions)
|
||||
//{
|
||||
// transactionsFoundListBox.Items.Add(x.FullInfo);
|
||||
//}
|
||||
}
|
||||
|
||||
private IEnumerable<Transaction> ReadTransactionFromDB()
|
||||
{
|
||||
Transaction t = new();
|
||||
DBInteraction.GenericDB<Transaction> db = new();
|
||||
return db.LoadAllData(t.DBTableName);
|
||||
}
|
||||
|
||||
private Transaction DummyTransaction()
|
||||
|
|
Loading…
Reference in New Issue