private void InitializeGrid(Account account)
        {
            if (_account != null && Rows != null)
            {
                Rows.Dispose();
            }
            _account = account;
            _account.Transactions.EnsureCollectionLoaded();
            Rows = new TransformingObservableCollection <Transaction, TransactionGridRowViewModel>(
                _account.Transactions,
                (transaction) =>
            {
                var row              = new TransactionGridRowViewModel(this.Columns, this.SubTransactionColumns, transaction, _model);
                row.PropertyChanged += Row_PropertyChanged;
                return(row);
            },
                (transformed) =>
            {
                transformed.Dispose();
                transformed.PropertyChanged -= Row_PropertyChanged;
            });

            Rows.ReturnEmptyOnEmuerate = true;

            SortRows();
        }
        public CategoryRowViewModel(MasterCategoryRowViewModel masterCategory, Category category, BudgetEditorViewModel budgetEditor)
        {
            InitializeRelayCommands();

            MasterCategory      = masterCategory;
            _category           = category;
            _budgetEditor       = budgetEditor;
            _categoryMonthViews = new TransformingObservableCollection <BudgetMonthViewModel, CategoryMonthViewModel>(
                _budgetEditor.VisibleMonthViews, v =>
            {
                //BudgetMonthView holds it's own copy of the Budget and Categories so you have to match them up based on entityId
                //instead of ReferenceEquals on the instance
                BudgetMonthView view = v.BudgetMonthView;
                MasterCategoryMonthView masterView = view.MasterCategories.Where(mcv => mcv.MasterCategory.EntityID == category.Parent.EntityID).Single();
                var categoryMonthView = masterView.Categories.Where(c => c.Category.EntityID == _category.EntityID).SingleOrDefault();
                if (categoryMonthView != null)
                {
                    return(new CategoryMonthViewModel(v, this, categoryMonthView));
                }
                else
                {
                    return(new CategoryMonthViewModel(v, this, masterView, _category.EntityID));
                }
            },
                cmv =>
            {
                cmv.Dispose();
            });
        }
Esempio n. 3
0
        private void InitializeCategories(MasterCategory masterCategory)
        {
            _categories = new TransformingObservableCollection <Category, CategoryRowViewModel>(
                masterCategory.Categories,
                c => { return(new CategoryRowViewModel(this, c, _budgetEditor)); },
                cvm => { cvm.Dispose(); });

            _categories.Sort(c => c.Category.SortOrder);
            _categories.CollectionChanged += Categories_CollectionChanged;
        }
 private void InitializeSubTransactions()
 {
     _subTransactions = new TransformingObservableCollection <SubTransaction, SubTransactionRowViewModel>(_transaction.SubTransactions,
                                                                                                          (subTransaction) =>
     {
         return(new SubTransactionRowViewModel(SubTransactionColumns, this.Transaction, this, subTransaction));
     },
                                                                                                          (subTransaction) =>
     {
         subTransaction.Dispose();
     });
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is IEnumerable <IViewValueProvider> && value is INotifyCollectionChanged))
            {
                throw new ArgumentUniformException(ArgumentError.DOWNCAST_NOT_POSSIBLE);
            }

            var source        = (IEnumerable <IViewValueProvider>)value;
            var sourceChanged = (INotifyCollectionChanged)value;
            var casted        = new TransformingObservableCollection <IViewValueProvider, object>
                                    (source, sourceChanged, ivvp => ivvp.Value);

            return(casted);
        }
Esempio n. 6
0
        private void InitializeAccountItems()
        {
            if (_budgetModel == null)
            {
                return;
            }

            if (OnBudgetAccounts != null)
            {
                OnBudgetAccounts.CollectionChanged   -= OnBudgetAccounts_CollectionChanged;
                OnBudgetAccounts.ItemPropertyChanged -= OnBudgetAccounts_ItemPropertyChanged;
                OnBudgetAccounts.Dispose();
            }

            if (OffBudgetAccounts != null)
            {
                OffBudgetAccounts.CollectionChanged   -= OffBudgetAccounts_CollectionChanged;
                OffBudgetAccounts.ItemPropertyChanged -= OffBudgetAccounts_ItemPropertyChanged;
                OffBudgetAccounts.Dispose();
            }

            OnBudgetAccounts = new TransformingObservableCollection <Account, AccountMenuItemViewModel>(_budget.Accounts,
                                                                                                        (account) =>
            {
                return(new AccountMenuItemViewModel(account, account.Name));
            },
                                                                                                        a =>
            {
                a.Dispose();
            }, a => a.BudgetingType == BudgetingTypes.OnBudget, null, true);

            OnBudgetAccounts.CollectionChanged   += OnBudgetAccounts_CollectionChanged;
            OnBudgetAccounts.ItemPropertyChanged += OnBudgetAccounts_ItemPropertyChanged;

            OffBudgetAccounts = new TransformingObservableCollection <Account, AccountMenuItemViewModel>(_budget.Accounts,
                                                                                                         (account) =>
            {
                return(new AccountMenuItemViewModel(account, account.Name));
            },
                                                                                                         a =>
            {
                a.Dispose();
            },
                                                                                                         a => a.BudgetingType == BudgetingTypes.OffBudget, null, true);

            OffBudgetAccounts.CollectionChanged   += OffBudgetAccounts_CollectionChanged;
            OffBudgetAccounts.ItemPropertyChanged += OffBudgetAccounts_ItemPropertyChanged;
        }
Esempio n. 7
0
        public BudgetMonthView(BudgetModel model, DateTime date)
        {
            _model          = model;
            Date            = date.FirstDayOfMonth();
            _internalBudget = _model.GetBudget();
            _internalBudget.MasterCategories.LoadCollection();
            _lastDayOfMonth = Date.LastDayOfMonth();
            _incomeCategory = _internalBudget.IncomeCategories.GetIncomeCategory(Date);

            _masterCategories = new TransformingObservableCollection <MasterCategory, MasterCategoryMonthView>(
                _internalBudget.MasterCategories,
                mc => { return(new MasterCategoryMonthView(mc, Date)); },
                mcv => { mcv.Dispose(); });

            _cache = _model.BudgetViewCache;
            _cache.CacheUpdated += Cache_CacheUpdated;
            RefreshValues();
        }
Esempio n. 8
0
        public BudgetEditorViewModel(BudgetModel budgetModel)
        {
            _budgetModel = budgetModel;

            InitializeRelayCommands();
            _addMasterCategoryEditor = new AddMasterCategoryViewModel(this);

            _budget = _budgetModel.GetBudget();
            _budget.MasterCategories.LoadCollection();
            _monthSelector = new MonthSelectorViewModel();
            _monthSelector.OnMonthSelected += MonthSelector_OnMonthSelected;

            InitializeMonthViews();
            _masterCategories = new TransformingObservableCollection <MasterCategory, MasterCategoryRowViewModel>(
                _budget.MasterCategories,
                (mc) => { return(new MasterCategoryRowViewModel(mc, this)); },
                mcvm => { mcvm.Dispose(); });
            _masterCategories.Sort(mcr => mcr.MasterCategory.SortOrder);
        }
Esempio n. 9
0
 private void InitializeMonthViews()
 {
     _masterCategoryMonthViews = new TransformingObservableCollection <BudgetMonthViewModel, MasterCategoryMonthViewModel>(
         _budgetEditor.VisibleMonthViews, v =>
     {
         //BudgetMonthView holds it's own copy of the Budget and Categories so you have to match them up based on entityId
         //instead of ReferenceEquals on the instance
         BudgetMonthView view = v.BudgetMonthView;
         MasterCategoryMonthView masterView = view.MasterCategories.Where(mcv => mcv.MasterCategory.EntityID == _masterCategory.EntityID).SingleOrDefault();
         if (masterView != null)
         {
             return(new MasterCategoryMonthViewModel(_budgetEditor, v, this, masterView));
         }
         else
         {
             return(new MasterCategoryMonthViewModel(_budgetEditor, v, this, view, _masterCategory.EntityID));
         }
     },
         cmv =>
     {
     });
 }
        public MasterCategoryMonthView(MasterCategory category, DateTime date)
        {
            MasterCategory = category;
            if (!category.Categories.IsLoaded)
            {
                category.Categories.LoadCollection();
            }
            _date = date.FirstDayOfMonth();

            _categories = new TransformingObservableCollection <Category, CategoryMonthView>(MasterCategory.Categories,
                                                                                             sc =>
            {
                return(new CategoryMonthView(sc, _date));
            },
                                                                                             scv =>
            {
                scv.Dispose();
            }, null, null, true);

            _categories.ItemPropertyChanged += Categories_ItemPropertyChanged;

            CalculateValues();
        }