Added functionality for adding wallets
This commit is contained in:
parent
3d201103ae
commit
b425986885
51
DBClasses.cs
51
DBClasses.cs
|
@ -75,9 +75,10 @@ namespace CryptoCalc
|
||||||
|
|
||||||
public Transaction() { SetDBStrings(); }
|
public Transaction() { SetDBStrings(); }
|
||||||
|
|
||||||
public Transaction(string currency, float amount, string type)
|
public Transaction(int walletID, string currency, float amount, string type)
|
||||||
{
|
{
|
||||||
SaveUnixTimeNow();
|
SaveUnixTimeNow();
|
||||||
|
WalletID = walletID;
|
||||||
Currency = currency;
|
Currency = currency;
|
||||||
Amount = amount;
|
Amount = amount;
|
||||||
TransactionType = type;
|
TransactionType = type;
|
||||||
|
@ -120,23 +121,23 @@ namespace CryptoCalc
|
||||||
+ $"@{nameof(Note)}";
|
+ $"@{nameof(Note)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string FullInfo => $"{ Index } { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Amount } { TransactionType }";
|
public string FullInfo => $"{ Index } {WalletID} { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Amount } { TransactionType }";
|
||||||
|
|
||||||
public string CreateTable(string walletTableName)
|
public string CreateTable(string walletTableName)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
$"CREATE TABLE IF NOT EXISTS \"{DBTableName}\" ("
|
$"CREATE TABLE IF NOT EXISTS \"{DBTableName}\" ("
|
||||||
+ $"\"{nameof(Index)}\" INTEGER NOT NULL UNIQUE,"
|
+ $"\"{nameof(Index)}\" INTEGER NOT NULL UNIQUE,"
|
||||||
+ $"\"{nameof(WalletID)}\" INTEGER NOT NULL,"
|
+ $"\"{nameof(WalletID)}\" INTEGER NOT NULL,"
|
||||||
+ $"\"{nameof(UnixTime)}\" INTEGER NOT NULL,"
|
+ $"\"{nameof(UnixTime)}\" INTEGER NOT NULL,"
|
||||||
+ $"\"{nameof(Currency)}\" TEXT NOT NULL,"
|
+ $"\"{nameof(Currency)}\" TEXT NOT NULL,"
|
||||||
+ $"\"{nameof(Amount)}\" REAL NOT NULL,"
|
+ $"\"{nameof(Amount)}\" REAL NOT NULL,"
|
||||||
+ $"\"{nameof(TransactionType)}\" TEXT NOT NULL,"
|
+ $"\"{nameof(TransactionType)}\" TEXT NOT NULL,"
|
||||||
+ $"\"{nameof(FeeCurrency)}\" TEXT,"
|
+ $"\"{nameof(FeeCurrency)}\" TEXT,"
|
||||||
+ $"\"{nameof(FeeAmount)}\" REAL,"
|
+ $"\"{nameof(FeeAmount)}\" REAL,"
|
||||||
+ $"\"{nameof(Platform)}\" TEXT,"
|
+ $"\"{nameof(Platform)}\" TEXT,"
|
||||||
+ $"\"{nameof(Note)}\" TEXT,"
|
+ $"\"{nameof(Note)}\" TEXT,"
|
||||||
+ $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT),"
|
+ $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT),"
|
||||||
+ $"FOREIGN KEY(\"{nameof(WalletID)}\") REFERENCES \"{walletTableName}\"(\"{nameof(Index)}\")"
|
+ $"FOREIGN KEY(\"{nameof(WalletID)}\") REFERENCES \"{walletTableName}\"(\"{nameof(Index)}\")"
|
||||||
+ $"); ";
|
+ $"); ";
|
||||||
}
|
}
|
||||||
|
@ -165,15 +166,15 @@ namespace CryptoCalc
|
||||||
|
|
||||||
public Wallet() { SetDBStrings(); }
|
public Wallet() { SetDBStrings(); }
|
||||||
|
|
||||||
public Wallet(DateTime dateTime, string platform, string name, string currency, float balance, int defaultWallet, string note)
|
public Wallet(DateTime dateTime, string platform, string name, string currency, string note)
|
||||||
{
|
{
|
||||||
SaveUnixTimeNow();
|
SaveUnixTimeNow();
|
||||||
UnixTimeCreated = GetUnixTime(dateTime);
|
UnixTimeCreated = GetUnixTime(dateTime);
|
||||||
Platform = platform;
|
Platform = platform;
|
||||||
Name = name;
|
Name = name;
|
||||||
Currency = currency;
|
Currency = currency;
|
||||||
Balance = balance;
|
Balance = 0;
|
||||||
DefaultWallet = defaultWallet;
|
DefaultWallet = 0;
|
||||||
Note = note;
|
Note = note;
|
||||||
|
|
||||||
SetDBStrings();
|
SetDBStrings();
|
||||||
|
@ -202,15 +203,15 @@ namespace CryptoCalc
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
$"CREATE TABLE IF NOT EXISTS \"{DBTableName}\" ("
|
$"CREATE TABLE IF NOT EXISTS \"{DBTableName}\" ("
|
||||||
+ $"\"{nameof(Index)}\" INTEGER NOT NULL UNIQUE,"
|
+ $"\"{nameof(Index)}\" INTEGER NOT NULL UNIQUE,"
|
||||||
+ $"\"{nameof(UnixTime)}\" INTEGER NOT NULL,"
|
+ $"\"{nameof(UnixTime)}\" INTEGER NOT NULL,"
|
||||||
+ $"\"{nameof(UnixTimeCreated)}\" INTEGER NOT NULL,"
|
+ $"\"{nameof(UnixTimeCreated)}\" INTEGER NOT NULL,"
|
||||||
+ $"\"{nameof(Platform)}\" TEXT,"
|
+ $"\"{nameof(Platform)}\" TEXT,"
|
||||||
+ $"\"{nameof(Name)}\" TEXT,"
|
+ $"\"{nameof(Name)}\" TEXT,"
|
||||||
+ $"\"{nameof(Currency)}\" TEXT NOT NULL,"
|
+ $"\"{nameof(Currency)}\" TEXT NOT NULL,"
|
||||||
+ $"\"{nameof(Balance)}\" REAL NOT NULL,"
|
+ $"\"{nameof(Balance)}\" REAL NOT NULL,"
|
||||||
+ $"\"{nameof(DefaultWallet)}\" INTEGER,"
|
+ $"\"{nameof(DefaultWallet)}\" INTEGER,"
|
||||||
+ $"\"{nameof(Note)}\" TEXT,"
|
+ $"\"{nameof(Note)}\" TEXT,"
|
||||||
+ $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT)"
|
+ $"PRIMARY KEY(\"{nameof(Index)}\" AUTOINCREMENT)"
|
||||||
+ $"); ";
|
+ $"); ";
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
<TabItem Header="Debug">
|
<TabItem Header="Debug">
|
||||||
<Grid Background="#FFE5E5E5" Width="Auto" Height="Auto">
|
<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="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="saveWalletButton" Content="Save Random Wallet" Margin="0,120,37,0" Click="saveWalletButton_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="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"/>
|
<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"/>
|
<TextBox x:Name="inputCurrency" Margin="0,0,60,125" TextWrapping="Wrap" Text="BTC" Height="27" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120" LostFocus="inputCurrency_LostFocus"/>
|
||||||
|
@ -24,14 +23,28 @@
|
||||||
<ListBox x:Name="transactionsFoundListBox" Margin="27,66,331,10"/>
|
<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"/>
|
<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"/>
|
<Button x:Name="searchButton" Content="Search" HorizontalAlignment="Left" Margin="169,20,0,0" VerticalAlignment="Top" Click="searchButton_Click" Height="25" Width="55"/>
|
||||||
<ListBox x:Name="listBox" Margin="518,234,37,450"/>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Overview">
|
<TabItem Header="Overview">
|
||||||
<Grid Background="#FFE5E5E5"/>
|
<Grid Background="#FFE5E5E5"/>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Wallets">
|
<TabItem Header="Wallets">
|
||||||
<Grid Background="#FFE5E5E5"/>
|
<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"/>
|
||||||
|
<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"/>
|
||||||
|
<Label x:Name="label1_Copy" Content="Platform" HorizontalAlignment="Left" Height="31" Margin="34,235,0,0" VerticalAlignment="Top" Width="96"/>
|
||||||
|
<TextBox x:Name="inputWalletCurrency" HorizontalAlignment="Left" Margin="135,304,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="149" Height="31"/>
|
||||||
|
<Label x:Name="label1_Copy1" Content="Currency" HorizontalAlignment="Left" Height="31" Margin="34,304,0,0" VerticalAlignment="Top" Width="96"/>
|
||||||
|
<DatePicker x:Name="inputWalletCreationDate" Margin="135,199,0,0" FirstDayOfWeek="Monday" Height="31" VerticalAlignment="Top" HorizontalAlignment="Left" Width="149"/>
|
||||||
|
<Label x:Name="label1_Copy3" Content="CreationDate" HorizontalAlignment="Left" Height="31" Margin="34,199,0,0" VerticalAlignment="Top" Width="96"/>
|
||||||
|
<TextBox x:Name="inputWalletNote" HorizontalAlignment="Left" Margin="135,340,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="149" Height="31"/>
|
||||||
|
<Label x:Name="label1_Copy4" Content="Note" HorizontalAlignment="Left" Height="31" Margin="34,340,0,0" VerticalAlignment="Top" Width="96"/>
|
||||||
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Transactions">
|
<TabItem Header="Transactions">
|
||||||
<Grid Background="#FFE5E5E5">
|
<Grid Background="#FFE5E5E5">
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
namespace CryptoCalc
|
namespace CryptoCalc
|
||||||
{
|
{
|
||||||
|
@ -16,6 +17,9 @@ namespace CryptoCalc
|
||||||
private readonly Transaction genericT = new();
|
private readonly Transaction genericT = new();
|
||||||
private readonly Wallet genericW = new();
|
private readonly Wallet genericW = new();
|
||||||
|
|
||||||
|
private List<Wallet> walletList = new();
|
||||||
|
private Wallet selectedWallet = new();
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -32,20 +36,42 @@ namespace CryptoCalc
|
||||||
{
|
{
|
||||||
transactionDB.SaveData(DummyTransaction());
|
transactionDB.SaveData(DummyTransaction());
|
||||||
}
|
}
|
||||||
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
|
|
||||||
|
private void saveRandomWalletButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
walletDB.SaveData(DummyWallet());
|
walletDB.SaveData(DummyWallet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
transactionDB.SaveData(new Transaction(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text));
|
transactionDB.SaveData
|
||||||
|
(
|
||||||
|
new Transaction(
|
||||||
|
selectedWallet.Index,
|
||||||
|
inputCurrency.Text,
|
||||||
|
Convert.ToSingle(inputAmount.Text),
|
||||||
|
inputType.Text
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
walletDB.SaveData(
|
||||||
|
new Wallet(
|
||||||
|
(DateTime)inputWalletCreationDate.SelectedDate,
|
||||||
|
inputWalletPlatform.Text,
|
||||||
|
inputWalletName.Text,
|
||||||
|
inputWalletCurrency.Text,
|
||||||
|
inputWalletNote.Text
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readButton_click(object sender, RoutedEventArgs e)
|
private void readButton_click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
string query = $"select * from {genericT.DBTableName}";
|
string query = $"select * from {genericT.DBTableName}";
|
||||||
IEnumerable <Transaction> transactions = transactionDB.ReturnQuery(genericT, query);
|
IEnumerable<Transaction> transactions = transactionDB.ReturnQuery(genericT, query);
|
||||||
foreach (Transaction t in transactions)
|
foreach (Transaction t in transactions)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{DBClasses.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
|
Debug.WriteLine($"{DBClasses.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
|
||||||
|
@ -62,10 +88,26 @@ namespace CryptoCalc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void show_Wallets_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
selectedWallet = null;
|
||||||
|
walletList.Clear();
|
||||||
|
|
||||||
|
string query = $"SELECT * from {genericW.DBTableName}";
|
||||||
|
IEnumerable<Wallet> wallets = walletDB.ReturnQuery(genericW, query);
|
||||||
|
listBox_Wallets.Items.Clear();
|
||||||
|
|
||||||
|
foreach (Wallet wallet in wallets)
|
||||||
|
{
|
||||||
|
walletList.Add(wallet);
|
||||||
|
listBox_Wallets.Items.Add($"{wallet.Name}-{wallet.Currency}-{wallet.Balance}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Transaction DummyTransaction()
|
private Transaction DummyTransaction()
|
||||||
{
|
{
|
||||||
Transaction t = new();
|
Transaction t = new();
|
||||||
t.WalletID = 1;
|
t.WalletID = selectedWallet.Index;
|
||||||
t.SaveUnixTimeNow();
|
t.SaveUnixTimeNow();
|
||||||
t.Currency = "SOL";
|
t.Currency = "SOL";
|
||||||
t.Amount = Convert.ToSingle(30 * rand.NextDouble());
|
t.Amount = Convert.ToSingle(30 * rand.NextDouble());
|
||||||
|
@ -79,11 +121,11 @@ namespace CryptoCalc
|
||||||
{
|
{
|
||||||
Wallet w = new();
|
Wallet w = new();
|
||||||
w.SaveUnixTimeNow();
|
w.SaveUnixTimeNow();
|
||||||
w.UnixTimeCreated = DBClasses.GetUnixTime(new DateTime(rand.Next(2011, DateTime.Now.Year), rand.Next(1,12), rand.Next(1, 28)));
|
w.UnixTimeCreated = DBClasses.GetUnixTime(new DateTime(rand.Next(2011, DateTime.Now.Year), rand.Next(1, 12), rand.Next(1, 28)));
|
||||||
w.Platform = "Ledger";
|
w.Platform = "Ledger";
|
||||||
w.Name = "DefaultBTCWallet";
|
w.Name = "DefaultBTCWallet";
|
||||||
w.Currency = "BTC";
|
w.Currency = "BTC";
|
||||||
w.Balance = Convert.ToSingle(30 * rand.NextDouble());
|
w.Balance = 0;//Convert.ToSingle(30 * rand.NextDouble());
|
||||||
w.DefaultWallet = 1;
|
w.DefaultWallet = 1;
|
||||||
w.Note = "Main BTC Wallet";
|
w.Note = "Main BTC Wallet";
|
||||||
return w;
|
return w;
|
||||||
|
@ -104,5 +146,27 @@ namespace CryptoCalc
|
||||||
{
|
{
|
||||||
inputCurrency.Text = inputCurrency.Text.ToUpper();
|
inputCurrency.Text = inputCurrency.Text.ToUpper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void listBox_Wallets_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (listBox_Wallets.Items.Count > 0)
|
||||||
|
{
|
||||||
|
if (listBox_Wallets.SelectedIndex < walletList.Count)
|
||||||
|
{
|
||||||
|
selectedWallet = walletList[listBox_Wallets.SelectedIndex];
|
||||||
|
|
||||||
|
if (selectedWallet != null)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"{selectedWallet.Name} {selectedWallet.Balance}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.WriteLine("No wallet selected yet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue