Updades for DB Interaction
Gathered DB classes in one script Added wallet DB Added connection string function
This commit is contained in:
parent
dcfd4ba6e7
commit
671cdfbf12
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="Default" connectionString="Data Source = ./data.db;version=3" providerName="System.Data.SqlClient"/>
|
<add name="data" connectionString="Data Source = ./data.db;version=3" providerName="System.Data.SqlClient"/>
|
||||||
|
<add name="wallet" connectionString="Data Source = ./wallet.db;version=3" providerName="System.Data.SqlClient"/>
|
||||||
</connectionStrings>
|
</connectionStrings>
|
||||||
</configuration>
|
</configuration>
|
|
@ -1,47 +1,40 @@
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using static CryptoCalc.DB_Classes;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CryptoCalc
|
namespace CryptoCalc
|
||||||
{
|
{
|
||||||
public class DBInteraction
|
public class DBInteraction
|
||||||
{
|
{
|
||||||
public static void SaveTransaction(Transaction transaction)
|
public static void SaveTransaction(RawData _rawData)
|
||||||
{
|
{
|
||||||
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString());
|
if (_rawData is null)
|
||||||
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);
|
{
|
||||||
|
throw new ArgumentNullException(nameof(_rawData));
|
||||||
|
}
|
||||||
|
using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString("data"));
|
||||||
|
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)", _rawData);
|
||||||
Debug.WriteLine("Saved DB data");
|
Debug.WriteLine("Saved DB data");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Transaction> LoadTransactions()
|
public static List<RawData> LoadTransactions()
|
||||||
{
|
{
|
||||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString());
|
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("data"));
|
||||||
var output = _connection.Query<Transaction>("select * from RawData", new DynamicParameters());
|
var output = _connection.Query<RawData>("select * from RawData", new DynamicParameters());
|
||||||
Debug.WriteLine("Loaded DB data");
|
Debug.WriteLine("Loaded DB data");
|
||||||
return output.ToList();
|
return output.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Transaction> LoadTransactionsOfCurrency(string _currency)
|
public static List<RawData> LoadTransactionsOfCurrency(string _currency)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(_currency);
|
Debug.WriteLine($"Fetching all {_currency} transactions from Database");
|
||||||
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString());
|
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("data"));
|
||||||
return connection.Query<Transaction>($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList();
|
return connection.Query<RawData>($"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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace CryptoCalc
|
||||||
|
{
|
||||||
|
public class DB_Classes
|
||||||
|
{
|
||||||
|
public class Transaction
|
||||||
|
{
|
||||||
|
public Transaction() { }
|
||||||
|
public Transaction(string _currency, float _amount, string _type, string _feeCurrency, float _feeAmount)
|
||||||
|
{
|
||||||
|
Year = DateTime.Now.Year;
|
||||||
|
Month = DateTime.Now.Month;
|
||||||
|
Day = DateTime.Now.Day;
|
||||||
|
Hour = DateTime.Now.Hour;
|
||||||
|
Minute = DateTime.Now.Minute;
|
||||||
|
Second = DateTime.Now.Second;
|
||||||
|
DateTimeString = DateTime.Now.ToString();
|
||||||
|
Currency = _currency;
|
||||||
|
Amount = _amount;
|
||||||
|
TransactionType = _type;
|
||||||
|
FeeCurrency = _feeCurrency;
|
||||||
|
FeeAmount = _feeAmount;
|
||||||
|
Service = "";
|
||||||
|
Comment = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Index { get; set; }
|
||||||
|
public int Year { get; set; }
|
||||||
|
public int Month { get; set; }
|
||||||
|
public int Day { get; set; }
|
||||||
|
public int Hour { get; set; }
|
||||||
|
public int Minute { get; set; }
|
||||||
|
public int Second { get; set; }
|
||||||
|
public string DateTimeString { get; set; }
|
||||||
|
public string Currency { get; set; }
|
||||||
|
public float Amount { get; set; }
|
||||||
|
public string TransactionType { get; set; }
|
||||||
|
public string FeeCurrency { get; set; }
|
||||||
|
public float FeeAmount { get; set; }
|
||||||
|
public string Service { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
|
||||||
|
//Functions
|
||||||
|
public string FullInfo => $"{ Index.ToString() } { DateTimeString } { Currency } { Amount } { TransactionType }";
|
||||||
|
|
||||||
|
}
|
||||||
|
public class RawData
|
||||||
|
{
|
||||||
|
public RawData(){}
|
||||||
|
public RawData(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 Date_Year { get; set; }
|
||||||
|
public int Date_Month { get; set; }
|
||||||
|
public int Date_Day { get; set; }
|
||||||
|
public int Time_Hour { get; set; }
|
||||||
|
public int Time_Minute { get; set; }
|
||||||
|
public int Time_Second { get; set; }
|
||||||
|
public string DateTimeString { get; set; }
|
||||||
|
public string CryptoCurrency { get; set; }
|
||||||
|
public float Amount { get; set; }
|
||||||
|
public string TransactionType { get; set; }
|
||||||
|
public string Service { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
public string FullInfo => $"{ Index.ToString() } { DateTimeString } { CryptoCurrency } { Amount } { TransactionType }";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,9 +12,6 @@
|
||||||
<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"/>
|
<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"/>
|
<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 x:Name="transactionsFoundListBox" Margin="27,66,337,24">
|
||||||
<ListBox.DataContext>
|
|
||||||
<local:Transaction/>
|
|
||||||
</ListBox.DataContext>
|
|
||||||
</ListBox>
|
</ListBox>
|
||||||
<TextBox x:Name="currencyText" HorizontalAlignment="Left" Margin="89,21,0,0" Text="ETH" TextWrapping="Wrap" VerticalAlignment="Top" Width="75" Height="22"/>
|
<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"/>
|
<Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="210,20,0,0" VerticalAlignment="Top" Click="searchButton_Click" Height="25"/>
|
||||||
|
|
|
@ -1,26 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Navigation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using static CryptoCalc.DB_Classes;
|
||||||
|
|
||||||
namespace CryptoCalc
|
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 List<RawData> transactions = new();
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
@ -33,33 +22,29 @@ namespace CryptoCalc
|
||||||
}
|
}
|
||||||
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
DBInteraction.SaveTransaction(new Transaction(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text));
|
DBInteraction.SaveTransaction(new RawData(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 (Transaction x in transactions)
|
foreach (RawData 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());
|
|
||||||
}
|
}
|
||||||
private void searchButton_Click(object sender, RoutedEventArgs e)
|
private void searchButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
|
||||||
transactionsFoundListBox.Items.Clear();
|
transactionsFoundListBox.Items.Clear();
|
||||||
foreach (Transaction x in transactions)
|
foreach (RawData x in transactions)
|
||||||
{
|
{
|
||||||
transactionsFoundListBox.Items.Add(x.FullInfo);
|
transactionsFoundListBox.Items.Add(x.FullInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private RawData DummyTransaction()
|
||||||
|
|
||||||
private Transaction DummyTransaction()
|
|
||||||
{
|
{
|
||||||
Transaction t = new();
|
RawData t = new();
|
||||||
t.Date_Year = DateTime.Now.Year;
|
t.Date_Year = DateTime.Now.Year;
|
||||||
t.Date_Month = DateTime.Now.Month;
|
t.Date_Month = DateTime.Now.Month;
|
||||||
t.Date_Day = DateTime.Now.Day;
|
t.Date_Day = DateTime.Now.Day;
|
||||||
|
@ -70,10 +55,9 @@ namespace CryptoCalc
|
||||||
t.CryptoCurrency = "SOL";
|
t.CryptoCurrency = "SOL";
|
||||||
t.Amount = Convert.ToSingle(30 * rand.NextDouble());
|
t.Amount = Convert.ToSingle(30 * rand.NextDouble());
|
||||||
t.TransactionType = "DEPOSIT";
|
t.TransactionType = "DEPOSIT";
|
||||||
t.Service = "MiraiEx";
|
t.Service = "Firi";
|
||||||
t.Comment = "Test";
|
t.Comment = "Test";
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace CryptoCalc
|
|
||||||
{
|
|
||||||
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 Date_Year { get; set; }
|
|
||||||
public int Date_Month { get; set; }
|
|
||||||
public int Date_Day { get; set; }
|
|
||||||
public int Time_Hour { get; set; }
|
|
||||||
public int Time_Minute { get; set; }
|
|
||||||
public int Time_Second { get; set; }
|
|
||||||
public string DateTimeString { get; set; }
|
|
||||||
public string CryptoCurrency { get; set; }
|
|
||||||
public float Amount { get; set; }
|
|
||||||
public string TransactionType { get; set; }
|
|
||||||
public string Service { get; set; }
|
|
||||||
public string Comment { get; set; }
|
|
||||||
public string FullInfo => $"{ Index.ToString() } { DateTimeString } { CryptoCurrency } { Amount } { TransactionType }";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
9
Util.cs
9
Util.cs
|
@ -1,13 +1,8 @@
|
||||||
using System;
|
using System.Configuration;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Configuration;
|
|
||||||
|
|
||||||
namespace CryptoCalc
|
namespace CryptoCalc
|
||||||
{
|
{
|
||||||
public static class Util
|
public class Util
|
||||||
{
|
{
|
||||||
public static string GetConnectionString(string name = "Default")
|
public static string GetConnectionString(string name = "Default")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue