private void LoadSavingsData() { Savings.Clear(); var savingsList = CachedService.GetAllSavings(); savingsList.ForEach(x => { Savings.Add(x); var notifyPropertyChanged = (x.Values as BindableCollectionExt <SavingValue>); if (notifyPropertyChanged != null) { notifyPropertyChanged.PropertyChanged += OnSavingPropertyChanged; } }); }
private void ShowWizard() { Shell.ShowDialog <BudgetEquationWizardShellViewModel, BudgetEquationWizardVM>( new { ValueTypes = ValueTypes.ToList(), OperatorTypes = OperatorTypes.ToList(), Incomes = CachedService.GetAllIncomes().ToList(), Savings = CachedService.GetAllSavings().ToList(), CashFlows = CachedService.GetAllCashFlows().ToList(), CashFlowGroups = CachedService.GetAllCashFlowGroups().ToList(), Equations = Equations.ToList(), Equation = EquationToEdit, BudgetCalculatorEvaluator = BudgetCalculatorEvaluator, }, null, null); }
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; } }