From 6d8bf44077b332bf4395abcdc43fc4a88e00b9f6 Mon Sep 17 00:00:00 2001 From: Stedd Date: Sun, 13 Feb 2022 13:49:44 +0100 Subject: [PATCH] Save as string test This did not work well --- DBClasses.cs | 23 ++++++++++++----------- MainWindow.xaml.cs | 5 +++-- Util.cs | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/DBClasses.cs b/DBClasses.cs index e9ca855..0a97ed1 100644 --- a/DBClasses.cs +++ b/DBClasses.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Text.RegularExpressions; namespace CryptoCalc @@ -71,10 +72,10 @@ namespace CryptoCalc public long WalletID { get; set; } public string Currency { get; set; } - public ulong Amount { get; set; } + public string Amount { get; set; } public string TransactionType { get; set; } public string FeeCurrency { get; set; } - public ulong FeeAmount { get; set; } + public string FeeAmount { get; set; } public string Platform { get; set; } public string Note { get; set; } @@ -84,12 +85,12 @@ namespace CryptoCalc public Transaction() { SetDBStrings(); } - public Transaction(long walletID, string currency, decimal amount, string type) + public Transaction(long walletID, string currency, string amount, string type) { SaveUnixTimeNow(); WalletID = walletID; Currency = currency; - Amount = Util.ConvToLong(amount); + Amount = amount; TransactionType = type; Platform = ""; @@ -98,14 +99,14 @@ namespace CryptoCalc SetDBStrings(); } - public Transaction(string currency, decimal amount, string type, string feeCurrency, decimal feeAmount) + public Transaction(string currency, string amount, string type, string feeCurrency, string feeAmount) { SaveUnixTimeNow(); Currency = currency; - Amount = Util.ConvToLong(amount); + Amount = amount.ToString(CultureInfo.InvariantCulture); TransactionType = type; FeeCurrency = feeCurrency; - FeeAmount = Util.ConvToLong(feeAmount); + FeeAmount = feeAmount.ToString(CultureInfo.InvariantCulture); Platform = ""; Note = ""; @@ -130,7 +131,7 @@ namespace CryptoCalc + $"@{nameof(Note)}"; } - public string FullInfo => $"{ Index } {WalletID} { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Amount } { TransactionType }"; + public string FullInfo => $"{ Index } {WalletID} { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { decimal.Parse(Amount, CultureInfo.InvariantCulture) } { TransactionType }"; public string CreateTable(string walletTableName) { @@ -140,10 +141,10 @@ namespace CryptoCalc + $"\"{nameof(WalletID)}\" INTEGER NOT NULL," + $"\"{nameof(UnixTime)}\" INTEGER NOT NULL," + $"\"{nameof(Currency)}\" TEXT NOT NULL," - + $"\"{nameof(Amount)}\" INTEGER NOT NULL," + + $"\"{nameof(Amount)}\" TEXT NOT NULL," + $"\"{nameof(TransactionType)}\" TEXT NOT NULL," + $"\"{nameof(FeeCurrency)}\" TEXT," - + $"\"{nameof(FeeAmount)}\" INTEGER," + + $"\"{nameof(FeeAmount)}\" TEXT," + $"\"{nameof(Platform)}\" TEXT," + $"\"{nameof(Note)}\" TEXT," + $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT)," @@ -218,7 +219,7 @@ namespace CryptoCalc + $"\"{nameof(Platform)}\" TEXT," + $"\"{nameof(Name)}\" TEXT," + $"\"{nameof(Currency)}\" TEXT NOT NULL," - + $"\"{nameof(Balance)}\" INTEGER NOT NULL," + + $"\"{nameof(Balance)}\" TEXT NOT NULL," + $"\"{nameof(DefaultWallet)}\" INTEGER," + $"\"{nameof(Note)}\" TEXT," + $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT)" diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 666cd42..9eb8c89 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -49,7 +49,7 @@ namespace CryptoCalc new Transaction( selectedWallet.Index, inputCurrency.Text, - Convert.ToDecimal(inputAmount.Text), + inputAmount.Text, inputType.Text ) ); @@ -110,7 +110,7 @@ namespace CryptoCalc t.WalletID = selectedWallet.Index; t.SaveUnixTimeNow(); t.Currency = "SOL"; - t.Amount = Util.ConvToLong(30m * (decimal)rand.NextDouble()); + t.Amount = (30m * (decimal)rand.NextDouble()).ToString(); t.TransactionType = "BUY"; t.Platform = "Firi"; t.Note = "Test"; @@ -135,6 +135,7 @@ namespace CryptoCalc private void inputAmount_LostFocus(object sender, RoutedEventArgs e) { inputAmount.Text = inputAmount.Text.Replace(".", ","); + //inputAmount.Text = inputAmount.Text.Replace(",", "."); } private void currencyText_LostFocus(object sender, RoutedEventArgs e) diff --git a/Util.cs b/Util.cs index b27e6eb..601e300 100644 --- a/Util.cs +++ b/Util.cs @@ -19,5 +19,6 @@ namespace CryptoCalc { return value * 1e-18M; } + } }