Merge branch 'GenericGetDBData'
This commit is contained in:
commit
3f833429c8
|
@ -16,40 +16,37 @@ namespace CryptoCalc
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(data));
|
throw new ArgumentNullException(nameof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
|
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
|
||||||
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
||||||
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());
|
|
||||||
Debug.WriteLine("Loaded DB data");
|
|
||||||
return output.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public IEnumerable<T> LoadAllData(string tableName)
|
||||||
public static List<Transaction> LoadTransactionsOfCurrency(string currency)
|
|
||||||
{
|
{
|
||||||
if (currency is null)
|
if (tableName is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(currency));
|
throw new ArgumentNullException(nameof(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.WriteLine($"Fetching all {currency} transactions from Database");
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
||||||
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("Transactions"));
|
return _connection.Query<T>($"select * from {tableName}", new DynamicParameters());
|
||||||
return connection.Query<Transaction>($"select * from Transactions where Currency = '{ currency.ToUpper() }'")
|
}
|
||||||
.ToList();
|
|
||||||
|
public IEnumerable<T> QueryData(string tableName, string query)
|
||||||
|
{
|
||||||
|
if (tableName is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
||||||
|
return _connection.Query<T>($"{query}", new DynamicParameters());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,12 @@ 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();
|
|
||||||
|
private DBInteraction.GenericDB<Transaction> transactionDB = new();
|
||||||
|
private DBInteraction.GenericDB<Wallet> walletDB = new();
|
||||||
|
|
||||||
|
private Transaction genericT = new();
|
||||||
|
private Wallet genericW = new();
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
@ -17,32 +22,34 @@ namespace CryptoCalc
|
||||||
|
|
||||||
private void saveButton_Click(object sender, RoutedEventArgs e)
|
private void saveButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Transaction dummy = DummyTransaction();
|
genericT = DummyTransaction();
|
||||||
DBInteraction.SaveData(ref dummy);
|
DBInteraction.SaveData(ref genericT);
|
||||||
}
|
}
|
||||||
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
|
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Wallet dummy = DummyWallet();
|
genericW = DummyWallet();
|
||||||
DBInteraction.SaveData(ref dummy);
|
DBInteraction.SaveData(ref genericW);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Transaction rd = new(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text);
|
genericT = new(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text);
|
||||||
DBInteraction.SaveData(ref rd);
|
DBInteraction.SaveData(ref genericT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readButton_click(object sender, RoutedEventArgs e)
|
private void readButton_click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactions = DBInteraction.LoadTransactions();
|
IEnumerable <Transaction> transactions = transactionDB.LoadAllData(genericT.DBTableName);
|
||||||
foreach (Transaction x in transactions)
|
foreach (Transaction t in transactions)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{x.GetLocalTimeFromUnixTime(x.UnixTime)} *** {x.Currency} - {x.Amount}");
|
Debug.WriteLine($"{t.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void searchButton_Click(object sender, RoutedEventArgs e)
|
private void searchButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
string query = $"SELECT * from {genericT.DBTableName} WHERE {nameof(genericT.Currency)}=\'{currencyText.Text}\'";
|
||||||
|
IEnumerable<Transaction> transactions = transactionDB.QueryData(genericT.DBTableName, query);
|
||||||
|
//transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
||||||
transactionsFoundListBox.Items.Clear();
|
transactionsFoundListBox.Items.Clear();
|
||||||
foreach (Transaction x in transactions)
|
foreach (Transaction x in transactions)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +57,12 @@ namespace CryptoCalc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private IEnumerable<Transaction> ReadTransactionFromDB()
|
||||||
|
//{
|
||||||
|
// Transaction t = new();
|
||||||
|
// return transactionDB.LoadAllData(t.DBTableName);
|
||||||
|
//}
|
||||||
|
|
||||||
private Transaction DummyTransaction()
|
private Transaction DummyTransaction()
|
||||||
{
|
{
|
||||||
Transaction t = new();
|
Transaction t = new();
|
||||||
|
|
Loading…
Reference in New Issue