예제 #1
0
 protected override void OnModelLoaded()
 {
     base.OnModelLoaded();
     if (Model.Items.Any())
     {
         Model.CurrentItem = Model.Items.First();
     }
     else
     {
         Model.CreateDefaultCurrentItem();
     }
     SelectedOperatorType = CalculatorOperatorType.None;
     RefreshUI();
 }
예제 #2
0
        private void RefreshUI()
        {
            _suppressEvents = true;
            if (Model.CurrentItem == null)
            {
                Model.CreateDefaultCurrentItem();
                SetToDefault();
            }
            else if (!Model.Items.Contains(Model.CurrentItem))
            {
                SetToDefault();
            }
            else
            {
                var  currentItem        = Model.CurrentItem;
                bool isOperatorType     = currentItem.ValueType == CalculatorValueType.Operator;
                bool isNoneOperatorType = currentItem.OperatorType == CalculatorOperatorType.None;
                IsLastElement         = isOperatorType && isNoneOperatorType;
                SelectedOperatorType  = currentItem.OperatorType;
                SelectedValueType     = ValueTypes.FirstOrDefault(x => x.Value == currentItem.ValueType);
                SelectedCashFlow      = CashFlows.FirstOrDefault(x => x.Id == currentItem.ForeignId);
                SelectedCashFlowGroup = CashFlowGroups.FirstOrDefault(x => x.Id == currentItem.ForeignId);
                SelectedIncome        = Incomes.FirstOrDefault(x => x.Id == currentItem.ForeignId);
                SelectedSaving        = Savings.FirstOrDefault(x => x.Id == currentItem.ForeignId);
                UserValue             = currentItem.Value;
                UserText         = currentItem.Text;
                SelectedEquation = Equations.FirstOrDefault(x => x.Id == currentItem.ForeignId);
            }

            NotifyOfPropertyChange(() => IsNoneOperatorSelected);
            NotifyOfPropertyChange(() => IsOperatorElementVisible);
            NotifyOfPropertyChange(() => IsAddOperatorSelected);
            NotifyOfPropertyChange(() => IsSubstractOperatorSelected);
            NotifyOfPropertyChange(() => IsMultiplyOperatorSelected);
            NotifyOfPropertyChange(() => IsDivideOperatorSelected);

            Title           = string.Format("Składowe równania ({0}/{1})", Model.CurrentPageNumber, Model.TotalPagesNumber);
            _suppressEvents = false;
        }
예제 #3
0
        private void SetToDefault()
        {
            SelectedValueType     = ValueTypes.FirstOrDefault();
            SelectedCashFlow      = CashFlows.FirstOrDefault();
            SelectedCashFlowGroup = CashFlowGroups.FirstOrDefault();
            SelectedIncome        = null;
            SelectedSaving        = null;
            UserValue             = null;
            UserText             = string.Empty;
            SelectedEquation     = null;
            SelectedOperatorType = CalculatorOperatorType.None;

            var  lastItem = Model.Items.LastOrDefault();
            bool isLastItemNotOperator = (lastItem != null) && (lastItem.ValueType != CalculatorValueType.Operator);

            IsLastElement = (Model.Items.Count > 2) && (isLastItemNotOperator);

            if (IsOperatorElementVisible)
            {
                IsAddOperatorSelected = true;
            }
        }
예제 #4
0
        public static string ToMath(this CalculatorOperatorType operatorType)
        {
            switch (operatorType)
            {
            case CalculatorOperatorType.None:
                return(string.Empty);

            case CalculatorOperatorType.Add:
                return("+");

            case CalculatorOperatorType.Substract:
                return("-");

            case CalculatorOperatorType.Multiply:
                return("*");

            case CalculatorOperatorType.Divide:
                return("/");

            default:
                throw new ArgumentOutOfRangeException(string.Format("Undefined name for: {0}", operatorType.ToString()));
            }
        }
예제 #5
0
        public static string ToName(this CalculatorOperatorType operatorType)
        {
            switch (operatorType)
            {
            case CalculatorOperatorType.None:
                return(string.Empty);

            case CalculatorOperatorType.Add:
                return("Dodaj");

            case CalculatorOperatorType.Substract:
                return("Odejmij");

            case CalculatorOperatorType.Multiply:
                return("Pomnóż");

            case CalculatorOperatorType.Divide:
                return("Podziel");

            default:
                throw new ArgumentOutOfRangeException(string.Format("Undefined name for: {0}", operatorType.ToString()));
            }
        }
예제 #6
0
 public BudgetCalculatorItem AddItem(CalculatorValueType valueType, CalculatorOperatorType operatorType, decimal?value, int foreignId)
 {
     CurrentItem = _equation.AddItem(string.Empty, valueType, operatorType, value, foreignId);
     return(CurrentItem);
 }
 public BudgetCalculatorItem AddItem(CalculatorValueType valueType, CalculatorOperatorType operatorType, decimal? value, int foreignId)
 {
     CurrentItem = _equation.AddItem(string.Empty, valueType, operatorType, value, foreignId);
     return CurrentItem;
 }
예제 #8
0
        public BudgetCalculatorItem AddItem(string name, CalculatorValueType valueType, CalculatorOperatorType operatorType = CalculatorOperatorType.None, decimal?value = null, int foreignId = 0)
        {
            var item = new BudgetCalculatorItem
            {
                Name         = name,
                ValueType    = valueType,
                OperatorType = operatorType,
                ForeignId    = foreignId,
                Value        = value,
                Equation     = this,
            };

            Items.Add(item);
            return(item);
        }
 public BudgetCalculatorItem AddItem(string name, CalculatorValueType valueType, CalculatorOperatorType operatorType = CalculatorOperatorType.None, decimal? value = null, int foreignId = 0)
 {
     var item = new BudgetCalculatorItem
     {
         Name = name,
         ValueType = valueType,
         OperatorType = operatorType,
         ForeignId = foreignId,
         Value = value,
         Equation = this,
     };
     Items.Add(item);
     return item;
 }