diff --git a/App.config b/App.config
index 657cbdc..924c79d 100644
--- a/App.config
+++ b/App.config
@@ -1,7 +1,8 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/DBInteraction.cs b/DBInteraction.cs
index e9c3246..6829d1c 100644
--- a/DBInteraction.cs
+++ b/DBInteraction.cs
@@ -11,29 +11,53 @@ namespace CryptoCalc
{
public class DBInteraction
{
- public static void SaveTransaction(RawData _rawData)
+
+ public static void SaveData(ref T _data) where T : IDBClasses
{
- if (_rawData is null)
+ if (_data is null)
{
- throw new ArgumentNullException(nameof(_rawData));
+ throw new ArgumentNullException(nameof(_data));
}
- 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");
+ using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(_data.DBTableName));
+ cnn.Execute($"insert into {_data.DBTableName} {_data.DBVariables}", _data);
+ Debug.WriteLine($"Saved {_data.DBTableName} DB data");
}
+
+ //public static void SaveTransaction(RawData _data)
+ //{
+ // if (_data is null)
+ // {
+ // throw new ArgumentNullException(nameof(_data));
+ // }
+ // using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(_data.DBTableName));
+ // cnn.Execute($"insert into {_data.DBTableName} (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)", _data);
+ // Debug.WriteLine("Saved DB data");
+ //}
+ //public static void SaveNewWallet(Wallet _data)
+ //{
+ // if (_data is null)
+ // {
+ // throw new ArgumentNullException(nameof(_data));
+ // }
+ // using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(_data.DBTableName));
+ // cnn.Execute($"insert into {_data.DBTableName} (wCreationYear, wCreationMonth, wCreationDay, wPlatform, wName, wCurrency, wBalance, wDefaultWallet, wNotes) values (@wCreationYear, @wCreationMonth, @wCreationDay, @wPlatform, @wName, @wCurrency, @wBalance, @wDefaultWallet, @wNotes)", _data);
+ // //cnn.Execute("insert into RawData (wCreationYear, wCreationMonth, wCreationDay, wPlatform, wName, wCurrency, wBalance, wDefaultWallet, wNotes) values ()", _walletData);
+ // Debug.WriteLine("Saved Wallet");
+ //}
public static List LoadTransactions()
{
- using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("data"));
+ using IDbConnection _connection = new SQLiteConnection(Util.GetConnectionString("RawData"));
var output = _connection.Query("select * from RawData", new DynamicParameters());
Debug.WriteLine("Loaded DB data");
return output.ToList();
- }
+ }
+
public static List LoadTransactionsOfCurrency(string _currency)
{
Debug.WriteLine($"Fetching all {_currency} transactions from Database");
- using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("data"));
+ using IDbConnection connection = new SQLiteConnection(Util.GetConnectionString("RawData"));
return connection.Query($"select * from RawData where CryptoCurrency = '{ _currency }'").ToList();
}
}
diff --git a/DB_Classes.cs b/DB_Classes.cs
index 7229171..2ad75b0 100644
--- a/DB_Classes.cs
+++ b/DB_Classes.cs
@@ -2,58 +2,71 @@
namespace CryptoCalc
{
+
+ public interface IDBClasses
+ {
+ string DBTableName { get; }
+ string DBVariables { get; }
+ }
+
public class DB_Classes
{
- public class Transaction
+ public class Transaction : IDBClasses
{
#region Constructors
+
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 = "";
+ tYear = DateTime.Now.Year;
+ tMonth = DateTime.Now.Month;
+ tDay = DateTime.Now.Day;
+ tHour = DateTime.Now.Hour;
+ tMinute = DateTime.Now.Minute;
+ tSecond = DateTime.Now.Second;
+ tDateTimeString = DateTime.Now.ToString();
+ tCurrency = _currency;
+ tAmount = _amount;
+ tTransactionType = _type;
+ tFeeCurrency = _feeCurrency;
+ tFeeAmount = _feeAmount;
+ tPlatform = "";
+ tNote = "";
}
#endregion
#region Publics
+ public string DBTableName => "Transactions";
+
+ public string DBVariables => "(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)";
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; }
+ public int tYear { get; set; }
+ public int tMonth { get; set; }
+ public int tDay { get; set; }
+ public int tHour { get; set; }
+ public int tMinute { get; set; }
+ public int tSecond { get; set; }
+ public string tDateTimeString { get; set; }
+ public string tCurrency { get; set; }
+ public float tAmount { get; set; }
+ public string tTransactionType { get; set; }
+ public string tFeeCurrency { get; set; }
+ public float tFeeAmount { get; set; }
+ public string tPlatform { get; set; }
+ public string tNote { get; set; }
#endregion
+
#region Functions
- public string FullInfo => $"{ Index.ToString() } { DateTimeString } { Currency } { Amount } { TransactionType }";
+
+ public string FullInfo => $"{ Index.ToString() } { tDateTimeString } { tCurrency } { tAmount } { tTransactionType }";
#endregion
}
- public class RawData
+ public class RawData : IDBClasses
{
#region Contructors
public RawData() { }
@@ -77,6 +90,8 @@ namespace CryptoCalc
#region Publics
+ public string DBTableName => "RawData";
+ public string DBVariables => "(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)";
public int Index { get; set; }
public int Date_Year { get; set; }
public int Date_Month { get; set; }
@@ -100,8 +115,10 @@ namespace CryptoCalc
}
- public class Wallet
+ public class Wallet : IDBClasses
{
+
+
#region Constructors
public Wallet()
{
@@ -138,6 +155,9 @@ namespace CryptoCalc
#endregion
#region Publics
+ public string DBTableName => "Wallets";
+
+ public string DBVariables => "(wCreationYear, wCreationMonth, wCreationDay, wPlatform, wName, wCurrency, wBalance, wDefaultWallet, wNotes) values (@wCreationYear, @wCreationMonth, @wCreationDay, @wPlatform, @wName, @wCurrency, @wBalance, @wDefaultWallet, @wNotes)";
public int Index { get; set; }
public int wCreationYear { get; set; }
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 866e300..3808592 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -18,11 +18,14 @@ namespace CryptoCalc
private void saveButton_Click(object sender, RoutedEventArgs e)
{
- DBInteraction.SaveTransaction(DummyTransaction());
+ RawData rd = DummyTransaction();
+ DBInteraction.SaveData(ref rd);
}
+
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
{
- DBInteraction.SaveTransaction(new RawData(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text));
+ RawData rd = new(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text);
+ DBInteraction.SaveData(ref rd);
}
private void readButton_click(object sender, RoutedEventArgs e)
diff --git a/transactions.db b/transactions.db
new file mode 100644
index 0000000..8ec933f
Binary files /dev/null and b/transactions.db differ
diff --git a/wallet.db b/wallet.db
index 016fa24..30a84f8 100644
Binary files a/wallet.db and b/wallet.db differ