//event EventHandler SummaChanged; void MainWindow_SummaChanged(object sender, EventArgs e) { if (sender is ComboBox && (sender as ComboBox).Name == "cbCurrency1" || sender is TextBox && (sender as TextBox).Name == "tbSumma1") { try { summa1 = Math.Round(Int32.Parse(tbSumma1.Text) * CurrencyExtensions.CurrencyRateInRubles((Currency)cbCurrency1.SelectedIndex), 2); } catch { summa1 = 0.00M; } label1.Content = $"{summa1} ₽"; } else // if (sender is ComboBox && (sender as ComboBox).Name == "cbCurrency2" || sender is TextBox && (sender as TextBox).Name == "tbSumma2") { try { summa2 = Math.Round(Int32.Parse(tbSumma2.Text) * CurrencyExtensions.CurrencyRateInRubles((Currency)cbCurrency2.SelectedIndex), 2); } catch { summa2 = 0.00M; } label2.Content = $"{summa2} ₽"; } labelCompare.Content = summa1 <summa2? "<" : summa1> summa2 ? ">" : "=="; }
//public override int GetHashCode() //{ // return base.GetHashCode(); //} /// <summary>Вернёт 0, если this==money; вернёт -1, если this меньше money; вернёт 1, если this больше money</summary> public int CompareTo(Money money) { if (money == null) { throw new ArgumentNullException(); } decimal summaInRub = Math.Round(Summa * CurrencyExtensions.CurrencyRateInRubles(Currency), 2); decimal othersummaInRub = Math.Round(money.Summa * CurrencyExtensions.CurrencyRateInRubles(money.Currency), 2); return(summaInRub > othersummaInRub ? 1 : summaInRub < othersummaInRub ? -1 : 0); }
/// <summary>Возвращает сумму в рублях</summary> public static Money operator +(Money a, Money b) { if (a == null || b == null) { return(null); } return(new Money { Summa = Math.Round(a.Summa * CurrencyExtensions.CurrencyRateInRubles(a.Currency), 2) + Math.Round(b.Summa * CurrencyExtensions.CurrencyRateInRubles(b.Currency), 2), Currency = Currency.RUB }); }