public void AttachEvaluator(BudgetCalculatorItem calculatorItem)
 {
     CashFlow cashFlow = null;
     CashFlowGroup cashFlowGroup = null;
     switch (calculatorItem.ValueType)
     {
         case CalculatorValueType.BudgetTotalRevenuesValue:
             calculatorItem.Evaluator = () => Budget.TotalSumOfRevenues;
             break;
         case CalculatorValueType.BudgetIncomesValue:
         case CalculatorValueType.BudgetIncomesValueOfType:
             var income = CachedService.GetAllIncomes().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
             calculatorItem.Evaluator = () => GetSumOfBudgetIncomes(income);
             break;
         case CalculatorValueType.BudgetSavingsValue:
         case CalculatorValueType.BudgetSavingsValueOfType:
             var saving = CachedService.GetAllSavings().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
             calculatorItem.Evaluator = () => GetSumOfBudgetSavings(saving);
             break;
         case CalculatorValueType.BudgetExpensesValueOfType:
             cashFlow = CachedService.GetAllCashFlows().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
             if (cashFlow == null)
             {
                 throw new NullReferenceException(string.Format("Błąd obliczania równania {0}. Brak kategorii.", calculatorItem.Equation.Name));
             }
             calculatorItem.Evaluator = () => GetSumOfBudgetExpenses(cashFlow);
             break;
         case CalculatorValueType.BudgetExpensesWithDescription:
             calculatorItem.Evaluator = () => GetSumOfBudgetExpensesWithDescription(calculatorItem.Text);
             break;
         case CalculatorValueType.CalculatorEquationValue:
             var calculatorEquation = Equations.FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
             if (calculatorEquation == null)
             {
                 throw new NullReferenceException(string.Format("Nie udało się odnaleźć równania powiązanego z równaniem: {0}", calculatorItem.Name));
             }
             calculatorItem.Evaluator = () => Calculate(calculatorEquation);
             break;
         case CalculatorValueType.BudgetPlanValue:
             calculatorItem.Evaluator = () => Budget.TotalBudgetPlanValue;
             break;
         case CalculatorValueType.BudgetPlanValueOfCategory:
             cashFlow = CachedService.GetAllCashFlows().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
             if (cashFlow == null)
             {
                 throw new NullReferenceException(string.Format("Błąd obliczania równania {0}. Brak kategorii.", calculatorItem.Equation.Name));
             }
             calculatorItem.Evaluator = () => GetSumOfBudgetPlansOfCategory(cashFlow);
             break;
         case CalculatorValueType.BudgetPlanValueOfGroup:
             cashFlowGroup = CachedService.GetAllCashFlowGroups().FirstOrDefault(x => x.Id == calculatorItem.ForeignId);
             if (cashFlowGroup == null)
             {
                 throw new NullReferenceException(string.Format("Błąd obliczania równania {0}. Brak grupy.", calculatorItem.Equation.Name));
             }
             calculatorItem.Evaluator = () => GetSumOfBudgetPlansOfGroup(cashFlowGroup);
             break;
     }
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public BudgetCalculatorItem CreateCopy()
        {
            var copy = new BudgetCalculatorItem
            {
                Id           = this.Id,
                Name         = this.Name,
                Position     = this.Position,
                ValueType    = this.ValueType,
                OperatorType = this.OperatorType,
                ForeignId    = this.ForeignId,
                Value        = this.Value,
                Equation     = this.Equation,
            };

            return(copy);
        }
 public void CreateDefaultCurrentItem()
 {
     CurrentItem = new BudgetCalculatorItem
     {
         Equation = this.Equation
     };
     InnerEquationList.Add(CurrentItem);
 }
 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 CreateCopy()
 {
     var copy = new BudgetCalculatorItem
     {
         Id = this.Id,
         Name = this.Name,
         Position = this.Position,
         ValueType = this.ValueType,
         OperatorType = this.OperatorType,
         ForeignId = this.ForeignId,
         Value = this.Value,
         Equation = this.Equation,
     };
     return copy;
 }