100 lines
3.3 KiB
C#
100 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Windows;
|
|
|
|
namespace CryptoCalc
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
private readonly Random rand = new();
|
|
|
|
private readonly DBInteraction<Transaction> transactionDB = new();
|
|
private readonly DBInteraction<Wallet> walletDB = new();
|
|
|
|
private readonly Transaction genericT = new();
|
|
private readonly Wallet genericW = new();
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void saveButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
transactionDB.SaveData(DummyTransaction());
|
|
}
|
|
private void saveWalletButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
walletDB.SaveData(DummyWallet());
|
|
}
|
|
|
|
private void saveButtonFromInput_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
transactionDB.SaveData(new Transaction(inputCurrency.Text, Convert.ToSingle(inputAmount.Text), inputType.Text));
|
|
}
|
|
|
|
private void readButton_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($"{t.GetLocalTimeFromUnixTime(t.UnixTime)} *** {t.Currency} - {t.Amount}");
|
|
}
|
|
}
|
|
private void searchButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string query = $"SELECT * from {genericT.DBTableName} WHERE {nameof(genericT.Currency)}=\'{currencyText.Text}\'";
|
|
IEnumerable<Transaction> transactions = transactionDB.ReturnQuery(genericT, query);
|
|
transactionsFoundListBox.Items.Clear();
|
|
foreach (Transaction x in transactions)
|
|
{
|
|
transactionsFoundListBox.Items.Add(x.FullInfo);
|
|
}
|
|
}
|
|
|
|
private Transaction DummyTransaction()
|
|
{
|
|
Transaction t = new();
|
|
t.SaveUnixTimeNow();
|
|
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.SaveUnixTimeNow();
|
|
w.UnixTimeCreated = w.GetUnixTime(new DateTime(rand.Next(2011, DateTime.Now.Year), rand.Next(1,12), rand.Next(1, 28)));
|
|
w.Platform = "Ledger";
|
|
w.Name = "DefaultBTCWallet";
|
|
w.Currency = "BTC";
|
|
w.Balance = Convert.ToSingle(30 * rand.NextDouble());
|
|
w.DefaultWallet = 1;
|
|
w.Note = "Main BTC Wallet";
|
|
return w;
|
|
}
|
|
|
|
|
|
private void inputAmount_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
inputAmount.Text = inputAmount.Text.Replace(".", ",");
|
|
}
|
|
|
|
private void currencyText_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
currencyText.Text = currencyText.Text.ToUpper();
|
|
}
|
|
|
|
private void inputCurrency_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
inputCurrency.Text = inputCurrency.Text.ToUpper();
|
|
}
|
|
}
|
|
}
|