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");
|
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 class GenericDB<T> where T : DBClasses
|
||||||
public static List<Transaction> LoadTransactions()
|
|
||||||
{
|
{
|
||||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("Transactions"));
|
|
||||||
IEnumerable<Transaction> output = _connection.Query<Transaction>("select * from Transactions", new DynamicParameters());
|
public IEnumerable<T> LoadAllData(string tableName)
|
||||||
Debug.WriteLine("Loaded DB data");
|
{
|
||||||
return output.ToList();
|
if (tableName is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
||||||
public static List<Transaction> LoadTransactionsOfCurrency(string currency)
|
return _connection.Query<T>($"select * from {tableName}", new DynamicParameters());
|
||||||
{
|
|
||||||
if (currency is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(currency));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private readonly Random rand = new();
|
private readonly Random rand = new();
|
||||||
private List<Transaction> transactions = new();
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
@ -34,7 +33,7 @@ namespace CryptoCalc
|
||||||
|
|
||||||
private void readButton_click(object sender, RoutedEventArgs e)
|
private void readButton_click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactions = DBInteraction.LoadTransactions();
|
IEnumerable <Transaction> transactions = ReadTransactionFromDB();
|
||||||
foreach (Transaction x in transactions)
|
foreach (Transaction x in transactions)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{x.GetLocalTimeFromUnixTime(x.UnixTime)} *** {x.Currency} - {x.Amount}");
|
Debug.WriteLine($"{x.GetLocalTimeFromUnixTime(x.UnixTime)} *** {x.Currency} - {x.Amount}");
|
||||||
|
@ -42,12 +41,20 @@ namespace CryptoCalc
|
||||||
}
|
}
|
||||||
private void searchButton_Click(object sender, RoutedEventArgs e)
|
private void searchButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
//IEnumerable<Transaction> transactions = ReadTransactionFromDB("Currency");
|
||||||
transactionsFoundListBox.Items.Clear();
|
//transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
||||||
foreach (Transaction x in transactions)
|
//transactionsFoundListBox.Items.Clear();
|
||||||
{
|
//foreach (Transaction x in transactions)
|
||||||
transactionsFoundListBox.Items.Add(x.FullInfo);
|
//{
|
||||||
|
// 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()
|
private Transaction DummyTransaction()
|
||||||
|
|
Loading…
Reference in New Issue