Untitled
unknown
plain_text
9 months ago
2.1 kB
2
Indexable
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
namespace CashManagerWPF
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
private decimal _usdBalance;
private decimal _kesBalance;
public ObservableCollection<Transaction> Transactions { get; set; }
public decimal USDBalance
{
get => _usdBalance;
set { _usdBalance = value; OnPropertyChanged(); }
}
public decimal KESBalance
{
get => _kesBalance;
set { _kesBalance = value; OnPropertyChanged(); }
}
public MainWindow()
{
InitializeComponent();
Transactions = new ObservableCollection<Transaction>();
DataContext = this;
}
private void AddTransaction(string type, decimal amount, string currency)
{
if (currency == "USD")
{
if (type == "IN") USDBalance += amount;
else if (type == "OUT" && USDBalance >= amount) USDBalance -= amount;
}
else if (currency == "KES")
{
if (type == "IN") KESBalance += amount;
else if (type == "OUT" && KESBalance >= amount) KESBalance -= amount;
}
Transactions.Add(new Transaction { Type = type, Amount = amount, Currency = currency, Date = DateTime.Now });
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public class Transaction
{
public string Type { get; set; } // IN or OUT
public decimal Amount { get; set; }
public string Currency { get; set; } // USD or KES
public DateTime Date { get; set; }
}
}
Editor is loading...
Leave a Comment