123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using Avalonia.Controls;
- using avaloniaPr.Models;
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace avaloniaPr.ViewModels
- {
- public class CalculatorViewModel : ViewModelBase
- {
- string textCalculator = "Выберите арифметическую операцию:";
- string textButton = "Вычислить";
- string selectItem = "";
- double result;
- double oneNum;
- double twoNum;
- public string TextCalculator
- {
- get => textCalculator;
- set => this.RaiseAndSetIfChanged(ref textCalculator, value);
- }
- public string TextButton
- {
- get => textButton;
- set => this.RaiseAndSetIfChanged(ref textButton, value);
- }
- public List<string> ListItem
- {
- get => Models.ItemsOperation.Items;
- }
- public string SV
- {
- get => selectItem;
- set
- {
- if (value == "Сумма")
- {
- this.RaiseAndSetIfChanged(ref selectItem, "+");
- }
- else if (value == "Разность")
- {
- this.RaiseAndSetIfChanged(ref selectItem, "-");
- }
- else if (value == "Умножение")
- {
- this.RaiseAndSetIfChanged(ref selectItem, "*");
- }
- else if (value == "Деление")
- {
- this.RaiseAndSetIfChanged(ref selectItem, "/");
- }
- }
- }
- public double OneNum
- {
- get => oneNum;
- set
- {
- this.RaiseAndSetIfChanged(ref oneNum, value);
- }
- }
- public double TwoNum
- {
- get => twoNum;
- set
- {
- this.RaiseAndSetIfChanged(ref twoNum, value);
- }
- }
- public void CommandCalculator()
- {
- switch (SV)
- {
- case "+":
- {
- result = OneNum + TwoNum;
- Result++;
- Result--;
- }
- break;
- case "-":
- {
- result = OneNum - TwoNum;
- Result++;
- Result--;
- }
- break;
- case "*":
- {
- result = OneNum * TwoNum;
- Result++;
- Result--;
- }
- break;
- case "/":
- {
- result = OneNum / TwoNum;
- Result++;
- Result--;
- }
- break;
- }
- }
- public double Result
- {
- get => result;
- set
- {
- this.RaiseAndSetIfChanged(ref result, value);
- }
- }
- }
- }
|