diff --git a/App.config b/App.config index d64670c..657cbdc 100644 --- a/App.config +++ b/App.config @@ -1,6 +1,7 @@  - + + \ No newline at end of file diff --git a/DBInteraction.cs b/DBInteraction.cs index bc76824..e9c3246 100644 --- a/DBInteraction.cs +++ b/DBInteraction.cs @@ -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 LoadTransactions() + public static List LoadTransactions() { - using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString()); - var output = _connection.Query("select * from RawData", new DynamicParameters()); + using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("data")); + var output = _connection.Query("select * from RawData", new DynamicParameters()); Debug.WriteLine("Loaded DB data"); return output.ToList(); } - public static List LoadTransactionsOfCurrency(string _currency) + public static List LoadTransactionsOfCurrency(string _currency) { - Debug.WriteLine(_currency); - using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString()); - return connection.Query($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList(); - //var output = connection.Query($"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($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList(); } } } diff --git a/DB_Classes.cs b/DB_Classes.cs new file mode 100644 index 0000000..1721396 --- /dev/null +++ b/DB_Classes.cs @@ -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 }"; + + } + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml index e4a8251..84ff7c7 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -12,9 +12,6 @@