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" ?>
|
||||
<configuration>
|
||||
<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>
|
||||
</configuration>
|
|
@ -1,47 +1,40 @@
|
|||
using Dapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static CryptoCalc.DB_Classes;
|
||||
|
||||
namespace CryptoCalc
|
||||
{
|
||||
public class DBInteraction
|
||||
{
|
||||
public static void SaveTransaction(Transaction transaction)
|
||||
public static void SaveTransaction(RawData _rawData)
|
||||
{
|
||||
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);
|
||||
if (_rawData is null)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
public static List<Transaction> LoadTransactions()
|
||||
public static List<RawData> LoadTransactions()
|
||||
{
|
||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString());
|
||||
var output = _connection.Query<Transaction>("select * from RawData", new DynamicParameters());
|
||||
using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("data"));
|
||||
var output = _connection.Query<RawData>("select * from RawData", new DynamicParameters());
|
||||
Debug.WriteLine("Loaded DB data");
|
||||
return output.ToList();
|
||||
}
|
||||
|
||||
public static List<Transaction> LoadTransactionsOfCurrency(string _currency)
|
||||
public static List<RawData> LoadTransactionsOfCurrency(string _currency)
|
||||
{
|
||||
Debug.WriteLine(_currency);
|
||||
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString());
|
||||
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;
|
||||
Debug.WriteLine($"Fetching all {_currency} transactions from Database");
|
||||
using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("data"));
|
||||
return connection.Query<RawData>($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"/>
|
||||
<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"/>
|
||||
|
|
|
@ -1,26 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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.IO;
|
||||
using static CryptoCalc.DB_Classes;
|
||||
|
||||
namespace CryptoCalc
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly Random rand = new();
|
||||
private List<Transaction> transactions = new();
|
||||
private List<RawData> transactions = new();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
|
@ -33,33 +22,29 @@ namespace CryptoCalc
|
|||
}
|
||||
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)
|
||||
{
|
||||
transactions = DBInteraction.LoadTransactions();
|
||||
foreach (Transaction x in transactions)
|
||||
foreach (RawData x in transactions)
|
||||
{
|
||||
Debug.WriteLine($"{x.DateTimeString} *** {x.CryptoCurrency} - {x.Amount}");
|
||||
|
||||
}
|
||||
//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)
|
||||
foreach (RawData x in transactions)
|
||||
{
|
||||
transactionsFoundListBox.Items.Add(x.FullInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Transaction DummyTransaction()
|
||||
private RawData DummyTransaction()
|
||||
{
|
||||
Transaction t = new();
|
||||
RawData t = new();
|
||||
t.Date_Year = DateTime.Now.Year;
|
||||
t.Date_Month = DateTime.Now.Month;
|
||||
t.Date_Day = DateTime.Now.Day;
|
||||
|
@ -68,12 +53,11 @@ namespace CryptoCalc
|
|||
t.Time_Second = DateTime.Now.Second;
|
||||
t.DateTimeString = DateTime.Now.ToString();
|
||||
t.CryptoCurrency = "SOL";
|
||||
t.Amount = Convert.ToSingle(30*rand.NextDouble());
|
||||
t.Amount = Convert.ToSingle(30 * rand.NextDouble());
|
||||
t.TransactionType = "DEPOSIT";
|
||||
t.Service = "MiraiEx";
|
||||
t.Service = "Firi";
|
||||
t.Comment = "Test";
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Configuration;
|
||||
using System.Configuration;
|
||||
|
||||
namespace CryptoCalc
|
||||
{
|
||||
public static class Util
|
||||
public class Util
|
||||
{
|
||||
public static string GetConnectionString(string name = "Default")
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue