示例#1
0
        void ExecuteDeleteIncomeCommand(object item)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            Income itemAsIncome = (Income)item;

            try
            {
                var income = Incomes.FirstOrDefault(x => x.Id == itemAsIncome.Id);
                DataStore.Delete(income);
                Incomes.Remove(income);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
示例#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
        protected override void When(object @event)
        {
            Income      income;
            Outgo       outgo;
            Snapshot    snapshot;
            Expenditure expenditure;

            switch (@event)
            {
            case Events.DailyBudgetCreated e:
                Id       = new DailyBudgetId(e.Id);
                Name     = new BudgetName(e.Name);
                snapshot = new Snapshot(Apply);
                ApplyToEntity(snapshot, e);
                Snapshot = snapshot;
                break;

            case Events.IncomeAddedToDailyBudget e:
                income = new Income(Apply);
                ApplyToEntity(income, e);
                Incomes.Add(income);
                e.TotalIncome = TotalIncome();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.IncomeAmountChanged e:
                income = Incomes.FirstOrDefault(i => i.Id == e.IncomeId);
                if (income == null)
                {
                    throw new InvalidOperationException($"Income with id {e.IncomeId} not found");
                }
                ApplyToEntity(income, e);
                e.TotalIncome = TotalIncome();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.IncomeDescriptionChanged e:
                income = Incomes.FirstOrDefault(i => i.Id == e.IncomeId);
                if (income == null)
                {
                    throw new InvalidOperationException($"Income with id {e.IncomeId} not found");
                }
                ApplyToEntity(income, e);
                break;

            case Events.IncomeRemoved e:
                income = Incomes.FirstOrDefault(i => i.Id == e.IncomeId);
                if (income == null)
                {
                    throw new InvalidOperationException($"Income with id {e.IncomeId} not found");
                }
                Incomes.Remove(income);
                e.TotalIncome = TotalIncome();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.OutgoAddedToDailyBudget e:
                outgo = new Outgo(Apply);
                ApplyToEntity(outgo, e);
                Outgos.Add(outgo);
                e.TotalOutgo = TotalOutgo();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.OutgoAmountChanged e:
                outgo = Outgos.FirstOrDefault(i => i.Id == e.OutgoId);
                if (outgo == null)
                {
                    throw new InvalidOperationException($"Outgo with id {e.OutgoId} not found");
                }
                ApplyToEntity(outgo, e);
                e.TotalOutgo = TotalOutgo();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.OutgoDescriptionChanged e:
                outgo = Outgos.FirstOrDefault(i => i.Id == e.OutgoId);
                if (outgo == null)
                {
                    throw new InvalidOperationException($"Outgo with id {e.OutgoId} not found");
                }
                ApplyToEntity(outgo, e);
                break;

            case Events.OutgoRemoved e:
                outgo = Outgos.FirstOrDefault(o => o.Id == e.OutgoId);
                if (outgo == null)
                {
                    throw new InvalidOperationException($"Outgo with id {e.OutgoId} not found");
                }
                Outgos.Remove(outgo);
                e.TotalOutgo = TotalOutgo();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.ExpenditureAdded e:
                expenditure = new Expenditure(Apply);
                ApplyToEntity(expenditure, e);
                Expenditures.Add(expenditure);
                e.TotalExpenditure = TotalExpenditure();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.ExpenditureAmountChanged e:
                expenditure = Expenditures.FirstOrDefault(exp => exp.Id == e.ExpenditureId);
                if (expenditure == null)
                {
                    throw new InvalidOperationException($"Expenditure with id {e.ExpenditureId} not found");
                }
                ApplyToEntity(expenditure, e);
                e.TotalExpenditure = TotalExpenditure();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.PeriodAddedToDailyBudget e:
                if (Period != null)
                {
                    throw new InvalidOperationException($"Period has already been set. Update start or end");
                }
                Period = Period.Create(e.Start, e.End);
                ApplyToEntity(Snapshot, e);
                break;

            case Events.PeriodStartChanged e:
                Period = Period.Create(e.Start, Period.ToB);
                ApplyToEntity(Snapshot, e);
                break;

            case Events.PeriodEndChanged e:
                Period = Period.Create(Period.FromA, e.End);
                ApplyToEntity(Snapshot, e);
                break;
            }
        }