Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        public void MountBudget(BudgetModel budgetModel)
        {
            //Set thread culture before updating the Budget so when bindings refresh the appropriate culture
            //is used for display.
            var budget = budgetModel.GetBudget();

            try
            {
                if (!string.IsNullOrWhiteSpace(budget.CurrencyCulture))
                {
                    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(budget.CurrencyCulture);
                }
            }
            catch (Exception) { }

            BudgetModel = budgetModel;
            this.Header = $"OpenBudget - {budget.Name}";
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private void OpenBudget()
        {
            var budgetPath = _budgetLoader.GetBudgetOpenPath();

            if (budgetPath == null)
            {
                return;
            }

            ValidBudgetCheck validBudgetCheck = _budgetLoader.IsBudgetValid(budgetPath);

            if (!validBudgetCheck.IsValid)
            {
                _dialogService.ShowError(validBudgetCheck.Error);
                return;
            }

            try
            {
                BudgetModel budgetModel = _budgetLoader.LoadBudget(budgetPath);
                Budget      budget      = budgetModel.GetBudget();
                BudgetStub  stub        = new BudgetStub()
                {
                    BudgetName = budget.Name, BudgetPath = budgetPath, LastEdited = DateTime.Now
                };

                var deviceSettings = _settingsProvider.Get <Device>();
                deviceSettings.AddRecentBudgetToTop(stub);
                deviceSettings.Save();

                _mainViewModel.MountBudget(budgetModel);
                _navigationService.NavigateTo <MainBudgetViewModel>();
            }
            catch (Exception)
            {
                _dialogService.ShowError($"There was an error opening the budget {budgetPath}. It may be corrupt.");
            }
        }
Ejemplo n.º 5
0
 public void ReloadBudget()
 {
     BudgetModel = BudgetModel.Load(DeviceID, BudgetStore);
     Budget      = BudgetModel.GetBudget();
 }