Compare commits

...

8 Commits

Author SHA1 Message Date
Stedd 5b80b0c177 Solution file update 2022-02-19 12:47:58 +01:00
Stedd 0e218f3da5 Fixed naming violation 2022-02-19 12:44:06 +01:00
Stedd eb7ef0821f Selectable date for manual transactions 2022-02-19 12:43:39 +01:00
Stedd 64a1334f1e DBVariables are now read only 2022-02-19 12:42:34 +01:00
Stedd 457aeb4eca Merge branch 'Dev/Decimals' 2022-02-13 16:39:25 +01:00
Stedd 9ef6358089 Saving high precision decimal numbers to SQlite 2022-02-13 16:39:18 +01:00
Stedd 6d8bf44077 Save as string test
This did not work well
2022-02-13 16:39:17 +01:00
Stedd 6469960b9c ulong test 2022-02-13 16:39:17 +01:00
5 changed files with 125 additions and 59 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptoCalc", "CryptoCalc.csproj", "{E83CB079-DF59-452D-9FA3-F5736553DC07}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoCalc", "CryptoCalc.csproj", "{E83CB079-DF59-452D-9FA3-F5736553DC07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,10 +11,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Release|Any CPU.Build.0 = Release|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Debug|Any CPU.Build.0 = Release|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{E83CB079-DF59-452D-9FA3-F5736553DC07}.Release|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,28 +1,45 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;
namespace CryptoCalc
{
public enum TransactionTypes
{
Buy,
Sell,
Transfer,
Mining
}
public interface IDBClasses
{
static string DBName { get; }
string DBTableName { get; }
string DBVariables { get; set; }
string DBVariables { get; }
string DBSaveDataString { get; }
}
public class DBClasses : IDBClasses
{
#region Protected
protected string dbVariables;
#endregion
#region Publics
public static string DBName => "CryptoCalc";
public virtual string DBTableName { get; }
public virtual string DBVariables { get; set; }
public string DBSaveDataString => $"({Regex.Replace(DBVariables, "@", "")}) values ({DBVariables})";
public string DBVariables => dbVariables;
public string DBSaveDataString => $"({Regex.Replace(dbVariables, "@", "")}) values ({dbVariables})";
public int Index { get; set; }
public long UnixTime { get; set; }
public long Index { get; set; }
public ulong UnixTime { get; set; }
#endregion
@ -31,20 +48,20 @@ namespace CryptoCalc
public void SaveUnixTimeNow()
{
UnixTime = (long)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalSeconds;
UnixTime = (ulong)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalSeconds;
}
public static long GetUnixTime(DateTime dateTime)
public static ulong GetUnixTime(DateTime dateTime)
{
return (long)dateTime.Subtract(DateTime.UnixEpoch).TotalSeconds;
return (ulong)dateTime.Subtract(DateTime.UnixEpoch).TotalSeconds;
}
public static DateTime GetUTCTimeFromUnixTime(long unix)
public static DateTime GetUTCTimeFromUnixTime(ulong unix)
{
return DateTime.UnixEpoch.AddSeconds(unix).ToUniversalTime();
}
public static DateTime GetLocalTimeFromUnixTime(long unix)
public static DateTime GetLocalTimeFromUnixTime(ulong unix)
{
return DateTime.UnixEpoch.AddSeconds(unix).ToLocalTime();
}
@ -57,15 +74,16 @@ namespace CryptoCalc
{
#region Publics
public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; }
public override string DBTableName => "Transactions";
public int WalletID { get; set; }
public long WalletID { get; set; }
public string Currency { get; set; }
public decimal Amount { get; set; }
public long Amount { get; set; }
public ulong AmountDecimal { get; set; }
public string TransactionType { get; set; }
public string FeeCurrency { get; set; }
public decimal FeeAmount { get; set; }
public long FeeAmount { get; set; }
public ulong FeeAmountDecimal { get; set; }
public string Platform { get; set; }
public string Note { get; set; }
@ -75,12 +93,26 @@ namespace CryptoCalc
public Transaction() { SetDBStrings(); }
public Transaction(int walletID, string currency, decimal amount, string type)
public Transaction(long walletID, string currency, decimal amount, string type)
{
SaveUnixTimeNow();
WalletID = walletID;
Currency = currency;
Amount = amount;
(Amount, AmountDecimal) = Util.SplitDecimal(amount);
TransactionType = type;
Platform = "";
Note = "";
SetDBStrings();
}
public Transaction(DateTime dateTime, long walletID, string currency, decimal amount, string type)
{
UnixTime = GetUnixTime(dateTime);
WalletID = walletID;
Currency = currency;
(Amount, AmountDecimal) = Util.SplitDecimal(amount);
TransactionType = type;
Platform = "";
@ -93,10 +125,10 @@ namespace CryptoCalc
{
SaveUnixTimeNow();
Currency = currency;
Amount = amount;
(Amount, AmountDecimal) = Util.SplitDecimal(amount);
TransactionType = type;
FeeCurrency = feeCurrency;
FeeAmount = feeAmount;
(FeeAmount, FeeAmountDecimal) = Util.SplitDecimal(feeAmount);
Platform = "";
Note = "";
@ -109,19 +141,21 @@ namespace CryptoCalc
private void SetDBStrings()
{
DBVariables =
dbVariables =
$"@{nameof(WalletID)},"
+ $"@{nameof(UnixTime)},"
+ $"@{nameof(Currency)},"
+ $"@{nameof(Amount)},"
+ $"@{nameof(AmountDecimal)},"
+ $"@{nameof(TransactionType)},"
+ $"@{nameof(FeeCurrency)},"
+ $"@{nameof(FeeAmount)},"
+ $"@{nameof(FeeAmountDecimal)},"
+ $"@{nameof(Platform)},"
+ $"@{nameof(Note)}";
}
public string FullInfo => $"{ Index } {WalletID} { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Amount } { TransactionType }";
public string FullInfo => $"{ Index } {WalletID} { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Util.CombineDecimal(Amount, AmountDecimal) } { TransactionType }";
public string CreateTable(string walletTableName)
{
@ -131,10 +165,12 @@ namespace CryptoCalc
+ $"\"{nameof(WalletID)}\" INTEGER NOT NULL,"
+ $"\"{nameof(UnixTime)}\" INTEGER NOT NULL,"
+ $"\"{nameof(Currency)}\" TEXT NOT NULL,"
+ $"\"{nameof(Amount)}\" REAL NOT NULL,"
+ $"\"{nameof(Amount)}\" INTEGER NOT NULL,"
+ $"\"{nameof(AmountDecimal)}\" INTEGER NOT NULL,"
+ $"\"{nameof(TransactionType)}\" TEXT NOT NULL,"
+ $"\"{nameof(FeeCurrency)}\" TEXT,"
+ $"\"{nameof(FeeAmount)}\" REAL,"
+ $"\"{nameof(FeeAmount)}\" INTEGER,"
+ $"\"{nameof(FeeAmountDecimal)}\" INTEGER,"
+ $"\"{nameof(Platform)}\" TEXT,"
+ $"\"{nameof(Note)}\" TEXT,"
+ $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT),"
@ -149,14 +185,14 @@ namespace CryptoCalc
public class Wallet : DBClasses
{
#region Publics
public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; }
public override string DBTableName => "Wallets";
public long UnixTimeCreated { get; set; }
public ulong UnixTimeCreated { get; set; }
public string Platform { get; set; }
public string Name { get; set; }
public string Currency { get; set; }
public decimal Balance { get; set; }
public long Balance { get; set; }
public ulong BalanceDecimal { get; set; }
public int DefaultWallet { get; set; }
public string Note { get; set; }
@ -173,7 +209,7 @@ namespace CryptoCalc
Platform = platform;
Name = name;
Currency = currency;
Balance = 0M;
(Balance, BalanceDecimal) = Util.SplitDecimal(0);
DefaultWallet = 0;
Note = note;
@ -186,13 +222,14 @@ namespace CryptoCalc
private void SetDBStrings()
{
DBVariables =
dbVariables =
$"@{nameof(UnixTime)},"
+ $"@{nameof(UnixTimeCreated)},"
+ $"@{nameof(Platform)},"
+ $"@{nameof(Name)},"
+ $"@{nameof(Currency)},"
+ $"@{nameof(Balance)},"
+ $"@{nameof(BalanceDecimal)},"
+ $"@{nameof(DefaultWallet)},"
+ $"@{nameof(Note)}";
}
@ -209,7 +246,8 @@ namespace CryptoCalc
+ $"\"{nameof(Platform)}\" TEXT,"
+ $"\"{nameof(Name)}\" TEXT,"
+ $"\"{nameof(Currency)}\" TEXT NOT NULL,"
+ $"\"{nameof(Balance)}\" REAL NOT NULL,"
+ $"\"{nameof(Balance)}\" INTEGER NOT NULL,"
+ $"\"{nameof(BalanceDecimal)}\" INTEGER NOT NULL,"
+ $"\"{nameof(DefaultWallet)}\" INTEGER,"
+ $"\"{nameof(Note)}\" TEXT,"
+ $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT)"

View File

@ -10,19 +10,20 @@
<TabControl x:Name="tabControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TabItem Header="Debug">
<Grid Background="#FFE5E5E5" Width="Auto" Height="Auto">
<Button x:Name="saveButton" Content="Save Random" Margin="0,10,37,0" Click="saveButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239" Height="38" VerticalAlignment="Top"/>
<Button x:Name="readButton" Content="PrintToConsole" Margin="0,53,37,0" Click="readButton_click" FontSize="20" Height="36" VerticalAlignment="Top" HorizontalAlignment="Right" Width="239"/>
<Button x:Name="saveButton_fromInput" Content="Save Data" Margin="0,0,37,10" VerticalAlignment="Bottom" Height="39" Click="saveButtonFromInput_Click" FontSize="20" HorizontalAlignment="Right" Width="239"/>
<TextBox x:Name="inputCurrency" Margin="0,0,60,125" TextWrapping="Wrap" Text="BTC" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120" LostFocus="inputCurrency_LostFocus"/>
<Button x:Name="saveButton" Content="Save Random" Margin="0,10,37,0" Click="SaveRandomTransactionButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239" Height="38" VerticalAlignment="Top"/>
<Button x:Name="readButton" Content="PrintToConsole" Margin="0,53,37,0" Click="PrintToConsoleButton_click" FontSize="20" Height="36" VerticalAlignment="Top" HorizontalAlignment="Right" Width="239"/>
<Button x:Name="saveButton_fromInput" Content="Save Data" Margin="0,0,37,10" VerticalAlignment="Bottom" Height="39" Click="SaveTransactionButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239"/>
<TextBox x:Name="inputCurrency" Margin="0,0,60,125" TextWrapping="Wrap" Text="BTC" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120" LostFocus="InputCurrency_LostFocus"/>
<Label x:Name="label" Content="Currency" HorizontalAlignment="Right" Margin="0,0,185,125" Width="69" Height="27" VerticalAlignment="Bottom"/>
<TextBox x:Name="inputAmount" Margin="0,0,60,94" TextWrapping="Wrap" Text="1,3141592" LostFocus="inputAmount_LostFocus" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120"/>
<TextBox x:Name="inputAmount" Margin="0,0,60,94" TextWrapping="Wrap" Text="1,3141592" LostFocus="InputAmount_LostFocus" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120"/>
<Label x:Name="label_Copy" Content="Amount" HorizontalAlignment="Right" Margin="0,0,185,94" Width="69" Height="27" VerticalAlignment="Bottom"/>
<TextBox x:Name="inputType" Margin="0,0,60,62" TextWrapping="Wrap" Text="BUY" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120"/>
<Label x:Name="label_Copy1" Content="Type" HorizontalAlignment="Right" Margin="0,0,185,62" Width="69" Height="27" VerticalAlignment="Bottom"/>
<Label x:Name="currencyLablel" Content="Currency" HorizontalAlignment="Left" Margin="27,16,0,0" VerticalAlignment="Top" Height="32"/>
<ListBox x:Name="transactionsFoundListBox" Margin="27,66,331,10"/>
<TextBox x:Name="currencyText" HorizontalAlignment="Left" Margin="89,21,0,0" Text="SOL" TextWrapping="Wrap" VerticalAlignment="Top" Width="75" Height="22" LostFocus="currencyText_LostFocus"/>
<Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="169,20,0,0" VerticalAlignment="Top" Click="searchButton_Click" Height="25" Width="55"/>
<TextBox x:Name="currencyText" HorizontalAlignment="Left" Margin="89,21,0,0" Text="SOL" TextWrapping="Wrap" VerticalAlignment="Top" Width="75" Height="22" LostFocus="CurrencyText_LostFocus"/>
<Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="169,20,0,0" VerticalAlignment="Top" Click="ShowTransactionsOfCurrencyButton_Click" Height="25" Width="55"/>
<DatePicker x:Name="insertTransactionDatePicker" HorizontalAlignment="Right" Margin="0,0,60,157" VerticalAlignment="Bottom" Width="120" FirstDayOfWeek="Monday" SelectedDateFormat="Short"/>
</Grid>
</TabItem>
<TabItem Header="Overview">
@ -30,10 +31,10 @@
</TabItem>
<TabItem Header="Wallets">
<Grid Background="#FFE5E5E5">
<ListBox x:Name="listBox_Wallets" Margin="0,278,37,258" SelectionChanged="listBox_Wallets_SelectionChanged" HorizontalAlignment="Right" Width="239"/>
<Button x:Name="show_Wallets" Content="Show Wallets" HorizontalAlignment="Right" Margin="0,240,37,0" VerticalAlignment="Top" Click="show_Wallets_Click" Width="239" Height="28"/>
<Button x:Name="saveRandomWalletButton" Content="Save Random Wallet" Margin="0,38,37,0" Click="saveRandomWalletButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239" Height="38" VerticalAlignment="Top"/>
<Button x:Name="saveWalletButton" Content="Save Wallet" Margin="45,125,0,0" Click="saveWalletButton_Click" FontSize="20" Height="38" VerticalAlignment="Top" HorizontalAlignment="Left" Width="239"/>
<ListBox x:Name="listBox_Wallets" Margin="0,278,37,258" SelectionChanged="ListBox_Wallets_SelectionChanged" HorizontalAlignment="Right" Width="239"/>
<Button x:Name="show_Wallets" Content="Show Wallets" HorizontalAlignment="Right" Margin="0,240,37,0" VerticalAlignment="Top" Click="Show_Wallets_Click" Width="239" Height="28"/>
<Button x:Name="saveRandomWalletButton" Content="Save Random Wallet" Margin="0,38,37,0" Click="SaveRandomWalletButton_Click" FontSize="20" HorizontalAlignment="Right" Width="239" Height="38" VerticalAlignment="Top"/>
<Button x:Name="saveWalletButton" Content="Save Wallet" Margin="45,125,0,0" Click="SaveWalletButton_Click" FontSize="20" Height="38" VerticalAlignment="Top" HorizontalAlignment="Left" Width="239"/>
<TextBox x:Name="inputWalletName" HorizontalAlignment="Left" Margin="135,269,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="149" Height="31"/>
<Label x:Name="label1" Content="Name" HorizontalAlignment="Left" Height="31" Margin="34,269,0,0" VerticalAlignment="Top" Width="96"/>
<TextBox x:Name="inputWalletPlatform" HorizontalAlignment="Left" Margin="135,235,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="149" Height="31" RenderTransformOrigin="0.354,-0.643"/>

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
@ -32,30 +33,31 @@ namespace CryptoCalc
walletDB.ExecuteQuery(genericW, genericW.CreateTable());
}
private void saveButton_Click(object sender, RoutedEventArgs e)
private void SaveRandomTransactionButton_Click(object sender, RoutedEventArgs e)
{
transactionDB.SaveData(DummyTransaction());
}
private void saveRandomWalletButton_Click(object sender, RoutedEventArgs e)
private void SaveRandomWalletButton_Click(object sender, RoutedEventArgs e)
{
walletDB.SaveData(DummyWallet());
}
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
private void SaveTransactionButton_Click(object sender, RoutedEventArgs e)
{
transactionDB.SaveData
(
new Transaction(
(DateTime)insertTransactionDatePicker.SelectedDate,
selectedWallet.Index,
inputCurrency.Text,
Convert.ToDecimal(inputAmount.Text),
Convert.ToDecimal(inputAmount.Text, CultureInfo.InvariantCulture),
inputType.Text
)
);
}
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
private void SaveWalletButton_Click(object sender, RoutedEventArgs e)
{
walletDB.SaveData(
new Wallet(
@ -68,16 +70,16 @@ namespace CryptoCalc
);
}
private void readButton_click(object sender, RoutedEventArgs e)
private void PrintToConsoleButton_click(object sender, RoutedEventArgs e)
{
string query = $"select * from {genericT.DBTableName}";
IEnumerable<Transaction> transactions = transactionDB.ReturnQuery(genericT, query);
foreach (Transaction t in transactions)
{
Debug.WriteLine($"{DBClasses.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
Debug.WriteLine($"{DBClasses.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {Util.CombineDecimal(t.Amount, t.AmountDecimal)}");
}
}
private void searchButton_Click(object sender, RoutedEventArgs e)
private void ShowTransactionsOfCurrencyButton_Click(object sender, RoutedEventArgs e)
{
string query = $"SELECT * from {genericT.DBTableName} WHERE {nameof(genericT.Currency)}=\'{currencyText.Text}\'";
IEnumerable<Transaction> transactions = transactionDB.ReturnQuery(genericT, query);
@ -88,7 +90,7 @@ namespace CryptoCalc
}
}
private void show_Wallets_Click(object sender, RoutedEventArgs e)
private void Show_Wallets_Click(object sender, RoutedEventArgs e)
{
selectedWallet = null;
walletList.Clear();
@ -110,7 +112,7 @@ namespace CryptoCalc
t.WalletID = selectedWallet.Index;
t.SaveUnixTimeNow();
t.Currency = "SOL";
t.Amount = Convert.ToDecimal(30 * rand.NextDouble());
(t.Amount, t.AmountDecimal) = Util.SplitDecimal(Convert.ToDecimal(30m * (decimal)rand.NextDouble()));
t.TransactionType = "BUY";
t.Platform = "Firi";
t.Note = "Test";
@ -132,23 +134,24 @@ namespace CryptoCalc
}
private void inputAmount_LostFocus(object sender, RoutedEventArgs e)
private void InputAmount_LostFocus(object sender, RoutedEventArgs e)
{
inputAmount.Text = inputAmount.Text.Replace(".", ",");
//inputAmount.Text = inputAmount.Text.Replace(".", ",");
inputAmount.Text = inputAmount.Text.Replace(",", ".");
}
private void currencyText_LostFocus(object sender, RoutedEventArgs e)
private void CurrencyText_LostFocus(object sender, RoutedEventArgs e)
{
currencyText.Text = currencyText.Text.ToUpper();
}
private void inputCurrency_LostFocus(object sender, RoutedEventArgs e)
private void InputCurrency_LostFocus(object sender, RoutedEventArgs e)
{
inputCurrency.Text = inputCurrency.Text.ToUpper();
}
private void listBox_Wallets_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
private void ListBox_Wallets_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (listBox_Wallets.Items.Count > 0)
{

24
Util.cs
View File

@ -4,9 +4,33 @@ namespace CryptoCalc
{
public class Util
{
private static readonly decimal lowestUnit = 1e18m;
public static string GetConnectionString(string name = "Default")
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
public static ulong ConvToULong(decimal value)
{
return decimal.ToUInt64(value * lowestUnit);
}
public static decimal ConvToDecimal(ulong value)
{
return value / lowestUnit;
}
public static (long wholeNumber, ulong fractionNumber) SplitDecimal(decimal value)
{
long w = (long)value;
ulong f = ConvToULong((value % 1));
return (w, f);
}
public static decimal CombineDecimal(long amount, ulong amountDecimal)
{
return amount + ConvToDecimal(amountDecimal);
}
}
}