CryptoCalc/MainWindow.xaml.cs

90 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows;
using System.Diagnostics;
using static CryptoCalc.DBClasses;
namespace CryptoCalc
{
public partial class MainWindow : Window
{
private readonly Random rand = new();
private List<Transaction> transactions = new();
public MainWindow()
{
InitializeComponent();
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
Transaction dummy = DummyTransaction();
DBInteraction.SaveData(ref dummy);
}
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
{
Wallet dummy = DummyWallet();
DBInteraction.SaveData(ref dummy);
}
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
{
Transaction rd = new(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text);
DBInteraction.SaveData(ref rd);
}
private void readButton_click(object sender, RoutedEventArgs e)
{
transactions = DBInteraction.LoadTransactions();
foreach (Transaction x in transactions)
{
Debug.WriteLine($"{x.DateTimeString} *** {x.Currency} - {x.Amount}");
}
}
private void searchButton_Click(object sender, RoutedEventArgs e)
{
transactions = DBInteraction.LoadTransactionsOfCurrency(currencyText.Text);
transactionsFoundListBox.Items.Clear();
foreach (Transaction x in transactions)
{
transactionsFoundListBox.Items.Add(x.FullInfo);
}
}
private Transaction DummyTransaction()
{
Transaction t = new();
t.SaveDateTime();
t.Currency = "SOL";
t.Amount = Convert.ToSingle(30 * rand.NextDouble());
t.TransactionType = "BUY";
t.Platform = "Firi";
t.Note = "Test";
return t;
}
private Wallet DummyWallet()
{
Wallet w = new();
w.SaveDateTime();
w.CreationYear = 2017;
w.CreationMonth = 08;
w.CreationDay = 20;
w.Platform = "Ledger";
w.Name = "TestWalled";
w.Currency = "SOL";
w.Balance = Convert.ToSingle(30 * rand.NextDouble());
w.DefaultWallet = 0;
w.Note = "Test";
return w;
}
private void inputAmount_LostFocus(object sender, RoutedEventArgs e)
{
inputAmount.Text = inputAmount.Text.Replace(".", ",");
}
}
}