Added query for currency type
Added save with input from textboxes
Following tutorial: https://www.youtube.com/watch?v=Et2khGnrIqc
This commit is contained in:
Stedd 2021-10-13 23:28:55 +02:00
parent 10cea5f42c
commit dcfd4ba6e7
4 changed files with 80 additions and 20 deletions

View File

@ -11,8 +11,15 @@ using System.Threading.Tasks;
namespace CryptoCalc namespace CryptoCalc
{ {
class DBInteraction public class DBInteraction
{ {
public static void SaveTransaction(Transaction transaction)
{
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString());
cnn.Execute("insert into RawData (Date_Year, Date_Month, Date_Day, Time_Hour, Time_Minute, Time_Second, DateTimeString, CryptoCurrency, Amount, TransactionType, Service, Comment) values (@Date_Year, @Date_Month, @Date_Day, @Time_Hour, @Time_Minute, @Time_Second, @DateTimeString, @CryptoCurrency, @Amount, @TransactionType, @Service, @Comment)", transaction);
Debug.WriteLine("Saved DB data");
}
public static List<Transaction> LoadTransactions() public static List<Transaction> LoadTransactions()
{ {
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString()); using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString());
@ -21,11 +28,20 @@ namespace CryptoCalc
return output.ToList(); return output.ToList();
} }
public static void SaveTransaction(Transaction transaction) public static List<Transaction> LoadTransactionsOfCurrency(string _currency)
{ {
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString()); Debug.WriteLine(_currency);
cnn.Execute("insert into RawData (Date_Year, Date_Month, Date_Day, Time_Hour, Time_Minute, Time_Second, DateTimeString, CryptoCurrency, Amount, TransactionType, Service, Comment) values (@Date_Year, @Date_Month, @Date_Day, @Time_Hour, @Time_Minute, @Time_Second, @DateTimeString, @CryptoCurrency, @Amount, @TransactionType, @Service, @Comment)", transaction); using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString());
Debug.WriteLine("Saved DB data"); return connection.Query<Transaction>($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList();
//var output = connection.Query<Transaction>($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList();
//Debug.WriteLine(output);
//foreach (Transaction x in output)
//{
// Debug.WriteLine($"{x.DateTimeString} {x.CryptoCurrency} - {x.Amount}");
//}
//return output;
} }
} }
} }

View File

@ -5,10 +5,25 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CryptoCalc" xmlns:local="clr-namespace:CryptoCalc"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="784" Width="800">
<Grid> <Grid>
<Button x:Name="saveButton" Content="Save" HorizontalAlignment="Left" Margin="518,0,0,289" VerticalAlignment="Bottom" Height="100" Width="239" Click="saveButton_Click" FontSize="20"/> <Button x:Name="saveButton" Content="Save Random" HorizontalAlignment="Left" Margin="518,0,0,672" VerticalAlignment="Bottom" Height="30" Width="239" Click="saveButton_Click" FontSize="20"/>
<Button x:Name="readButton" Content="Read" HorizontalAlignment="Left" Margin="518,0,0,156" VerticalAlignment="Bottom" Height="100" Width="239" Click="readButton_click" FontSize="20"/> <Button x:Name="readButton" Content="PrintToConsole" HorizontalAlignment="Left" Margin="518,0,0,616" VerticalAlignment="Bottom" Height="40" Width="239" Click="readButton_click" FontSize="20"/>
<Button x:Name="saveButton_fromInput" Content="Save Data" HorizontalAlignment="Left" Margin="518,0,0,24" VerticalAlignment="Bottom" Height="30" Width="239" Click="saveButtonFromInput_Click" FontSize="20"/>
<Label x:Name="currencyLablel" Content="Currency" HorizontalAlignment="Left" Margin="27,16,0,0" VerticalAlignment="Top" Height="32"/>
<ListBox x:Name="transactionsFoundListBox" Margin="27,66,337,24">
<ListBox.DataContext>
<local:Transaction/>
</ListBox.DataContext>
</ListBox>
<TextBox x:Name="currencyText" HorizontalAlignment="Left" Margin="89,21,0,0" Text="ETH" TextWrapping="Wrap" VerticalAlignment="Top" Width="75" Height="22"/>
<Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="210,20,0,0" VerticalAlignment="Top" Click="searchButton_Click" Height="25"/>
<TextBox x:Name="inputCurrency" HorizontalAlignment="Left" Margin="578,550,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="27" Text="BTC"/>
<Label x:Name="label" Content="Currency" HorizontalAlignment="Left" Margin="504,550,0,0" VerticalAlignment="Top" Height="27" Width="69"/>
<TextBox x:Name="inputAmount" HorizontalAlignment="Left" Margin="578,581,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="27" Text="1"/>
<Label x:Name="label_Copy" Content="Amount" HorizontalAlignment="Left" Margin="504,581,0,0" VerticalAlignment="Top" Height="27" Width="69"/>
<TextBox x:Name="inputType" HorizontalAlignment="Left" Margin="578,613,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="27" Text="DEPOSIT"/>
<Label x:Name="label_Copy1" Content="Type" HorizontalAlignment="Left" Margin="504,613,0,0" VerticalAlignment="Top" Height="27" Width="69"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -17,11 +17,6 @@ using System.IO;
namespace CryptoCalc namespace CryptoCalc
{ {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private readonly Random rand = new(); private readonly Random rand = new();
@ -34,21 +29,35 @@ namespace CryptoCalc
private void saveButton_Click(object sender, RoutedEventArgs e) private void saveButton_Click(object sender, RoutedEventArgs e)
{ {
DBInteraction.SaveTransaction(dummyTransaction()); DBInteraction.SaveTransaction(DummyTransaction());
}
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
{
DBInteraction.SaveTransaction(new Transaction(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text));
} }
private void readButton_click(object sender, RoutedEventArgs e) private void readButton_click(object sender, RoutedEventArgs e)
{ {
transactions = DBInteraction.LoadTransactions(); transactions = DBInteraction.LoadTransactions();
foreach (var x in transactions) foreach (Transaction x in transactions)
{ {
Debug.WriteLine($"{x.DateTimeString} *** {x.CryptoCurrency} - {x.Amount}"); Debug.WriteLine($"{x.DateTimeString} *** {x.CryptoCurrency} - {x.Amount}");
} }
//Debug.WriteLine(DateTime.Now.Minute.ToString()); //Debug.WriteLine(DateTime.Now.Minute.ToString());
} }
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);
}
}
private Transaction dummyTransaction()
private Transaction DummyTransaction()
{ {
Transaction t = new(); Transaction t = new();
t.Date_Year = DateTime.Now.Year; t.Date_Year = DateTime.Now.Year;
@ -58,12 +67,13 @@ namespace CryptoCalc
t.Time_Minute = DateTime.Now.Minute; t.Time_Minute = DateTime.Now.Minute;
t.Time_Second = DateTime.Now.Second; t.Time_Second = DateTime.Now.Second;
t.DateTimeString = DateTime.Now.ToString(); t.DateTimeString = DateTime.Now.ToString();
t.CryptoCurrency = "ETH"; t.CryptoCurrency = "SOL";
t.Amount = (float)rand.NextDouble(); t.Amount = Convert.ToSingle(30*rand.NextDouble());
t.TransactionType = "WITHDRAWAL"; t.TransactionType = "DEPOSIT";
t.Service = "MiraiEx"; t.Service = "MiraiEx";
t.Comment = "Test"; t.Comment = "Test";
return t; return t;
} }
} }
} }

View File

@ -8,6 +8,23 @@ namespace CryptoCalc
{ {
public class Transaction public class Transaction
{ {
public Transaction(){}
public Transaction(string _currency, float _amount, string _type)
{
Date_Year = DateTime.Now.Year;
Date_Month = DateTime.Now.Month;
Date_Day = DateTime.Now.Day;
Time_Hour = DateTime.Now.Hour;
Time_Minute = DateTime.Now.Minute;
Time_Second = DateTime.Now.Second;
DateTimeString = DateTime.Now.ToString();
CryptoCurrency = _currency;
Amount = _amount;
TransactionType = _type;
Service = "";
Comment = "";
}
public int Index { get; set; } public int Index { get; set; }
public int Date_Year { get; set; } public int Date_Year { get; set; }
public int Date_Month { get; set; } public int Date_Month { get; set; }
@ -19,7 +36,9 @@ namespace CryptoCalc
public string CryptoCurrency { get; set; } public string CryptoCurrency { get; set; }
public float Amount { get; set; } public float Amount { get; set; }
public string TransactionType { get; set; } public string TransactionType { get; set; }
public string Service{ get; set; } public string Service { get; set; }
public string Comment { get; set; } public string Comment { get; set; }
public string FullInfo => $"{ Index.ToString() } { DateTimeString } { CryptoCurrency } { Amount } { TransactionType }";
} }
} }