Generic SQL interaction working
This commit is contained in:
parent
5bcb0df7df
commit
38c160968a
|
@ -16,6 +16,7 @@ namespace CryptoCalc
|
|||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
|
||||
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
|
||||
cnn.Execute($"insert into {data.DBTableName} {data.DBSaveDataString}", data);
|
||||
Debug.WriteLine($"Saved {data.DBTableName} DB data");
|
||||
|
@ -35,6 +36,17 @@ namespace CryptoCalc
|
|||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(tableName));
|
||||
return _connection.Query<T>($"select * from {tableName}", new DynamicParameters());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,12 @@ namespace CryptoCalc
|
|||
{
|
||||
private readonly Random rand = new();
|
||||
|
||||
private DBInteraction.GenericDB<Transaction> transactionDB = new();
|
||||
private DBInteraction.GenericDB<Wallet> walletDB = new();
|
||||
|
||||
private Transaction genericT = new();
|
||||
private Wallet genericW = new();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -16,46 +22,46 @@ namespace CryptoCalc
|
|||
|
||||
private void saveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Transaction dummy = DummyTransaction();
|
||||
DBInteraction.SaveData(ref dummy);
|
||||
genericT = DummyTransaction();
|
||||
DBInteraction.SaveData(ref genericT);
|
||||
}
|
||||
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Wallet dummy = DummyWallet();
|
||||
DBInteraction.SaveData(ref dummy);
|
||||
genericW = DummyWallet();
|
||||
DBInteraction.SaveData(ref genericW);
|
||||
}
|
||||
|
||||
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Transaction rd = new(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text);
|
||||
DBInteraction.SaveData(ref rd);
|
||||
genericT = new(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text);
|
||||
DBInteraction.SaveData(ref genericT);
|
||||
}
|
||||
|
||||
private void readButton_click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
IEnumerable <Transaction> transactions = ReadTransactionFromDB();
|
||||
foreach (Transaction x in transactions)
|
||||
IEnumerable <Transaction> transactions = transactionDB.LoadAllData(genericT.DBTableName);
|
||||
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)
|
||||
{
|
||||
//IEnumerable<Transaction> transactions = ReadTransactionFromDB("Currency");
|
||||
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();
|
||||
//foreach (Transaction x in transactions)
|
||||
//{
|
||||
// transactionsFoundListBox.Items.Add(x.FullInfo);
|
||||
//}
|
||||
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 IEnumerable<Transaction> ReadTransactionFromDB()
|
||||
//{
|
||||
// Transaction t = new();
|
||||
// return transactionDB.LoadAllData(t.DBTableName);
|
||||
//}
|
||||
|
||||
private Transaction DummyTransaction()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue