SQL interaction update

Using only Query method
+ text input cleanup
This commit is contained in:
Stedd 2022-02-12 16:09:37 +01:00
parent 8e777e9330
commit 4007190be3
3 changed files with 21 additions and 23 deletions

View File

@ -14,7 +14,7 @@ namespace CryptoCalc
{ {
if (data is null) if (data is null)
{ {
throw new ArgumentNullException(nameof(data)); throw new ArgumentNullException(nameof(data), "No data passed to SQL");
} }
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBName)); using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(data.DBName));
@ -25,26 +25,14 @@ namespace CryptoCalc
public class GenericDB<T> where T : DBClasses public class GenericDB<T> where T : DBClasses
{ {
public IEnumerable<T> QueryData(T data, string query)
public IEnumerable<T> LoadAllData(T data)
{ {
if (data.DBTableName is null) if (data is null)
{ {
throw new ArgumentNullException(nameof(data.DBTableName)); throw new ArgumentNullException(nameof(data), "DBclass is null");
} }
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(data.DBName)); using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(data.DBName));
return _connection.Query<T>($"select * from {data.DBTableName}", new DynamicParameters());
}
public IEnumerable<T> QueryData(T data, string query)
{
if (data.DBTableName is null)
{
throw new ArgumentNullException(nameof(data.DBTableName));
}
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString(data.DBTableName));
return _connection.Query<T>($"{query}", new DynamicParameters()); return _connection.Query<T>($"{query}", new DynamicParameters());
} }
} }

View File

@ -14,7 +14,7 @@
<Button x:Name="saveWalletButton" Content="Save Random Wallet" Margin="0,120,37,0" Click="saveWalletButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239" Height="38" VerticalAlignment="Top"/> <Button x:Name="saveWalletButton" Content="Save Random Wallet" Margin="0,120,37,0" Click="saveWalletButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239" Height="38" VerticalAlignment="Top"/>
<Button x:Name="readButton" Content="PrintToConsole" Margin="0,53,37,0" Click="readButton_click" FontSize="20" Height="36" VerticalAlignment="Top" HorizontalAlignment="Right" Width="239"/> <Button x:Name="readButton" Content="PrintToConsole" Margin="0,53,37,0" Click="readButton_click" FontSize="20" Height="36" VerticalAlignment="Top" HorizontalAlignment="Right" Width="239"/>
<Button x:Name="saveButton_fromInput" Content="Save Data" Margin="0,0,37,10" VerticalAlignment="Bottom" Height="39" Click="saveButtonFromInput_Click" FontSize="20" HorizontalAlignment="Right" Width="239"/> <Button x:Name="saveButton_fromInput" Content="Save Data" Margin="0,0,37,10" VerticalAlignment="Bottom" Height="39" Click="saveButtonFromInput_Click" FontSize="20" HorizontalAlignment="Right" Width="239"/>
<TextBox x:Name="inputCurrency" Margin="0,0,60,125" TextWrapping="Wrap" Text="BTC" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120"/> <TextBox x:Name="inputCurrency" Margin="0,0,60,125" TextWrapping="Wrap" Text="BTC" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120" LostFocus="inputCurrency_LostFocus"/>
<Label x:Name="label" Content="Currency" HorizontalAlignment="Right" Margin="0,0,185,125" Width="69" Height="27" VerticalAlignment="Bottom"/> <Label x:Name="label" Content="Currency" HorizontalAlignment="Right" Margin="0,0,185,125" Width="69" Height="27" VerticalAlignment="Bottom"/>
<TextBox x:Name="inputAmount" Margin="0,0,60,94" TextWrapping="Wrap" Text="1,3141592" LostFocus="inputAmount_LostFocus" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120"/> <TextBox x:Name="inputAmount" Margin="0,0,60,94" TextWrapping="Wrap" Text="1,3141592" LostFocus="inputAmount_LostFocus" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120"/>
<Label x:Name="label_Copy" Content="Amount" HorizontalAlignment="Right" Margin="0,0,185,94" Width="69" Height="27" VerticalAlignment="Bottom"/> <Label x:Name="label_Copy" Content="Amount" HorizontalAlignment="Right" Margin="0,0,185,94" Width="69" Height="27" VerticalAlignment="Bottom"/>
@ -22,7 +22,7 @@
<Label x:Name="label_Copy1" Content="Type" HorizontalAlignment="Right" Margin="0,0,185,62" Width="69" Height="27" VerticalAlignment="Bottom"/> <Label x:Name="label_Copy1" Content="Type" HorizontalAlignment="Right" Margin="0,0,185,62" Width="69" Height="27" VerticalAlignment="Bottom"/>
<Label x:Name="currencyLablel" Content="Currency" HorizontalAlignment="Left" Margin="27,16,0,0" VerticalAlignment="Top" Height="32"/> <Label x:Name="currencyLablel" Content="Currency" HorizontalAlignment="Left" Margin="27,16,0,0" VerticalAlignment="Top" Height="32"/>
<ListBox x:Name="transactionsFoundListBox" Margin="27,66,331,10"/> <ListBox x:Name="transactionsFoundListBox" Margin="27,66,331,10"/>
<TextBox x:Name="currencyText" HorizontalAlignment="Left" Margin="89,21,0,0" Text="SOL" TextWrapping="Wrap" VerticalAlignment="Top" Width="75" Height="22"/> <TextBox x:Name="currencyText" HorizontalAlignment="Left" Margin="89,21,0,0" Text="SOL" TextWrapping="Wrap" VerticalAlignment="Top" Width="75" Height="22" LostFocus="currencyText_LostFocus"/>
<Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="169,20,0,0" VerticalAlignment="Top" Click="searchButton_Click" Height="25" Width="55"/> <Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="169,20,0,0" VerticalAlignment="Top" Click="searchButton_Click" Height="25" Width="55"/>
</Grid> </Grid>
</TabItem> </TabItem>

View File

@ -36,7 +36,8 @@ namespace CryptoCalc
private void readButton_click(object sender, RoutedEventArgs e) private void readButton_click(object sender, RoutedEventArgs e)
{ {
IEnumerable <Transaction> transactions = transactionDB.LoadAllData(genericT); string query = $"select * from {genericT.DBTableName}";
IEnumerable <Transaction> transactions = transactionDB.QueryData(genericT, query);
foreach (Transaction t in transactions) foreach (Transaction t in transactions)
{ {
Debug.WriteLine($"{t.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}"); Debug.WriteLine($"{t.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
@ -71,11 +72,11 @@ namespace CryptoCalc
w.SaveUnixTimeNow(); w.SaveUnixTimeNow();
w.UnixTimeCreated = w.GetUnixTime(new DateTime(rand.Next(2011, DateTime.Now.Year), rand.Next(1,12), rand.Next(1, 28))); w.UnixTimeCreated = w.GetUnixTime(new DateTime(rand.Next(2011, DateTime.Now.Year), rand.Next(1,12), rand.Next(1, 28)));
w.Platform = "Ledger"; w.Platform = "Ledger";
w.Name = "TestWallet"; w.Name = "DefaultBTCWallet";
w.Currency = "SOL"; w.Currency = "BTC";
w.Balance = Convert.ToSingle(30 * rand.NextDouble()); w.Balance = Convert.ToSingle(30 * rand.NextDouble());
w.DefaultWallet = 0; w.DefaultWallet = 1;
w.Note = "Test"; w.Note = "Main BTC Wallet";
return w; return w;
} }
@ -85,5 +86,14 @@ namespace CryptoCalc
inputAmount.Text = inputAmount.Text.Replace(".", ","); inputAmount.Text = inputAmount.Text.Replace(".", ",");
} }
private void currencyText_LostFocus(object sender, RoutedEventArgs e)
{
currencyText.Text = currencyText.Text.ToUpper();
}
private void inputCurrency_LostFocus(object sender, RoutedEventArgs e)
{
inputCurrency.Text = inputCurrency.Text.ToUpper();
}
} }
} }