Added functionality for adding wallets

This commit is contained in:
Stedd 2022-02-12 19:59:00 +01:00
parent 3d201103ae
commit b425986885
3 changed files with 112 additions and 34 deletions

View File

@ -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,7 +121,7 @@ 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)
{ {
@ -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();

View File

@ -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">

View File

@ -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,14 +36,36 @@ 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)
@ -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());
@ -83,7 +125,7 @@ namespace CryptoCalc
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");
}
}
} }
} }