diff --git a/DB_Classes.cs b/DBClasses.cs similarity index 56% rename from DB_Classes.cs rename to DBClasses.cs index 21f76b7..ce7179c 100644 --- a/DB_Classes.cs +++ b/DBClasses.cs @@ -6,19 +6,18 @@ namespace CryptoCalc public interface IDBClasses { - string dbVariables { get; set; } - string variables { get; set; } + string DBVariables { get; set; } + string DBTableName { get; } - string DBVariables { get; } + string DBSaveDataString { get; } } - public class DB_Classes : IDBClasses + public class DBClasses : IDBClasses { - public virtual string dbVariables { get; set ; } - public virtual string variables { get; set; } - + #region Publics + public virtual string DBVariables { get; set; } public virtual string DBTableName => throw new NotImplementedException(); - public string DBVariables => $"({variables}) values ({dbVariables})"; + public string DBSaveDataString => $"({Regex.Replace(DBVariables, "@", "")}) values ({DBVariables})"; public int Index { get; set; } public int Year { get; set; } @@ -28,14 +27,31 @@ namespace CryptoCalc public int Minute { get; set; } public int Second { get; set; } public string DateTimeString { get; set; } + + #endregion + + #region Functions + + public void SaveDateTime() + { + 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(); + } + + #endregion + } - public class Transaction : DB_Classes + public class Transaction : DBClasses { #region Publics - public override string dbVariables { get => base.dbVariables; set => base.dbVariables = value; } - public override string variables { get => base.variables; set => base.variables = value; } + public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; } public override string DBTableName => "Transactions"; public string Currency { get; set; } @@ -54,13 +70,7 @@ namespace CryptoCalc public Transaction(string _currency, float _amount, string _type) { - 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(); + SaveDateTime(); Currency = _currency; Amount = _amount; TransactionType = _type; @@ -73,13 +83,7 @@ namespace CryptoCalc 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(); + SaveDateTime(); Currency = _currency; Amount = _amount; TransactionType = _type; @@ -97,23 +101,21 @@ namespace CryptoCalc private void SetDBStrings() { - dbVariables = - $"@{nameof(Year)}," - + $"@{nameof(Month)}," - + $"@{nameof(Day)}," - + $"@{nameof(Hour)}," - + $"@{nameof(Minute)}," - + $"@{nameof(Second)}," - + $"@{nameof(DateTimeString)}," - + $"@{nameof(Currency)}," - + $"@{nameof(Amount)}," - + $"@{nameof(TransactionType)}," - + $"@{nameof(FeeCurrency)}," - + $"@{nameof(FeeAmount)}," - + $"@{nameof(Platform)}," - + $"@{nameof(Note)}"; - - variables = Regex.Replace(dbVariables, "@", ""); + DBVariables = + $"@{nameof(Year)}," + + $"@{nameof(Month)}," + + $"@{nameof(Day)}," + + $"@{nameof(Hour)}," + + $"@{nameof(Minute)}," + + $"@{nameof(Second)}," + + $"@{nameof(DateTimeString)}," + + $"@{nameof(Currency)}," + + $"@{nameof(Amount)}," + + $"@{nameof(TransactionType)}," + + $"@{nameof(FeeCurrency)}," + + $"@{nameof(FeeAmount)}," + + $"@{nameof(Platform)}," + + $"@{nameof(Note)}"; } public string FullInfo => $"{ Index.ToString() } { DateTimeString } { Currency } { Amount } { TransactionType }"; @@ -122,11 +124,10 @@ namespace CryptoCalc } - public class Wallet : DB_Classes + public class Wallet : DBClasses { #region Publics - public override string dbVariables { get => base.dbVariables; set => base.dbVariables = value; } - public override string variables { get => base.variables; set => base.variables = value; } + public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; } public override string DBTableName => "Wallets"; public int CreationYear { get; set; } @@ -147,6 +148,7 @@ namespace CryptoCalc public Wallet(int _year, int _month, int _day, string _platform, string _name, string _currency, float _balance, int _default, string _note) { + SaveDateTime(); CreationYear = _year; CreationMonth = _month; CreationDay = _day; @@ -166,25 +168,23 @@ namespace CryptoCalc private void SetDBStrings() { - dbVariables = - $"@{nameof(Year)}, " + - $"@{nameof(Month)}," + - $"@{nameof(Day)}," + - $"@{nameof(Hour)}," + - $"@{nameof(Minute)}," + - $"@{nameof(Second)}," + - $"@{nameof(DateTimeString)}," + - $"@{nameof(CreationYear)}," + - $"@{nameof(CreationMonth)}," + - $"@{nameof(CreationDay)}," + - $"@{nameof(Platform)}," + - $"@{nameof(Name)}," + - $"@{nameof(Currency)}," + - $"@{nameof(Balance)}," + - $"@{nameof(DefaultWallet)}," + - $"@{nameof(Notes)}"; - - variables = Regex.Replace(dbVariables, "@", ""); + DBVariables = + $"@{nameof(Year)}," + + $"@{nameof(Month)}," + + $"@{nameof(Day)}," + + $"@{nameof(Hour)}," + + $"@{nameof(Minute)}," + + $"@{nameof(Second)}," + + $"@{nameof(DateTimeString)}," + + $"@{nameof(CreationYear)}," + + $"@{nameof(CreationMonth)}," + + $"@{nameof(CreationDay)}," + + $"@{nameof(Platform)}," + + $"@{nameof(Name)}," + + $"@{nameof(Currency)}," + + $"@{nameof(Balance)}," + + $"@{nameof(DefaultWallet)}," + + $"@{nameof(Notes)}"; } //public string FullInfo => $"{ Index.ToString() } { DateTimeString } { Currency } { Amount } { TransactionType }"; diff --git a/DBInteraction.cs b/DBInteraction.cs index 6e4cf70..281c893 100644 --- a/DBInteraction.cs +++ b/DBInteraction.cs @@ -5,21 +5,21 @@ using System.Data; using System.Data.SQLite; using System.Diagnostics; using System.Linq; -using static CryptoCalc.DB_Classes; +using static CryptoCalc.DBClasses; namespace CryptoCalc { public class DBInteraction { - public static void SaveData(ref T _data) where T : DB_Classes + public static void SaveData(ref T _data) where T : DBClasses { if (_data is null) { throw new ArgumentNullException(nameof(_data)); } using IDbConnection cnn = new SQLiteConnection(Util.GetConnectionString(_data.DBTableName)); - cnn.Execute($"insert into {_data.DBTableName} {_data.DBVariables}", _data); + cnn.Execute($"insert into {_data.DBTableName} {_data.DBSaveDataString}", _data); Debug.WriteLine($"Saved {_data.DBTableName} DB data"); } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 4264682..3a71886 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Windows; using System.Diagnostics; -using static CryptoCalc.DB_Classes; +using static CryptoCalc.DBClasses; namespace CryptoCalc { @@ -49,13 +49,7 @@ namespace CryptoCalc private Transaction DummyTransaction() { Transaction t = new(); - t.Year = DateTime.Now.Year; - t.Month = DateTime.Now.Month; - t.Day = DateTime.Now.Day; - t.Hour = DateTime.Now.Hour; - t.Minute = DateTime.Now.Minute; - t.Second = DateTime.Now.Second; - t.DateTimeString = DateTime.Now.ToString(); + t.SaveDateTime(); t.Currency = "SOL"; t.Amount = Convert.ToSingle(30 * rand.NextDouble()); t.TransactionType = "BUY";