public void RemoveValue(int[] available, int selected, int deleted, int expectedNewSelected)
        {
            var property = new EnumeratedSingleValuedProperty<int>();
            foreach (var i in available)
            {
                property.AddValue(i);
            }
            property.Value = selected;
            property.RemoveValue(deleted);

            Assert.That(property.Value, Is.EqualTo(expectedNewSelected));
            Assert.That(property.SelectableValues.Count, Is.EqualTo(available.Length-1));
        }
Example #2
0
        public void RemoveValue(int[] available, int selected, int deleted, int expectedNewSelected)
        {
            var property = new EnumeratedSingleValuedProperty <int>();

            foreach (var i in available)
            {
                property.AddValue(i);
            }
            property.Value = selected;
            property.RemoveValue(deleted);

            Assert.That(property.Value, Is.EqualTo(expectedNewSelected));
            Assert.That(property.SelectableValues.Count, Is.EqualTo(available.Length - 1));
        }
        public CategoryManagementDialogViewModel(ApplicationViewModel application, Action<CategoryManagementDialogViewModel> ok)
        {
            CategoriesToDelete = new List<CategoryEditViewModel>();
            Categories = new EnumeratedSingleValuedProperty<CategoryEditViewModel>();
            Categories.PropertyChanged += CategoriesOnPropertyChanged;

            foreach (var categoryViewModel in application.Repository.QueryAllCategories().Select(c => new CategoryEditViewModel(c.PersistentId, c.Name, OnDeleteCategory)))
            {
                Categories.AddValue(categoryViewModel);
            }

            OkCommand = new CommandViewModel(() => ok(this));
            NewCategoryCommand = new CommandViewModel(OnNewCategoryCommand);

            UpdateCommandStates();
        }
Example #4
0
        public CategoryManagementDialogViewModel(ApplicationViewModel application, Action <CategoryManagementDialogViewModel> ok)
        {
            CategoriesToDelete          = new List <CategoryEditViewModel>();
            Categories                  = new EnumeratedSingleValuedProperty <CategoryEditViewModel>();
            Categories.PropertyChanged += CategoriesOnPropertyChanged;

            foreach (var categoryViewModel in application.Repository.QueryAllCategories().Select(c => new CategoryEditViewModel(c.PersistentId, c.Name, OnDeleteCategory)))
            {
                Categories.AddValue(categoryViewModel);
            }

            OkCommand          = new CommandViewModel(() => ok(this));
            NewCategoryCommand = new CommandViewModel(OnNewCategoryCommand);

            UpdateCommandStates();
        }
        public StandingOrderDetailsViewModel(ApplicationViewModel application, Action <StandingOrderEntityData> onSave, Action <StandingOrderDetailsViewModel> onCancel)
        {
            _application     = application;
            SaveCommand      = new CommandViewModel(() => onSave(CreateStandingOrderEntityData()));
            CancelCommand    = new CommandViewModel(() => onCancel(this));
            PaymentsProperty = new SingleValuedProperty <int> {
                Value = 1
            };
            ValueProperty = new SingleValuedProperty <double>();
            IsEndingTransactionProperty = new SingleValuedProperty <bool>();
            MonthPeriods          = new EnumeratedSingleValuedProperty <MonthPeriod>();
            Categories            = new EnumeratedSingleValuedProperty <CategoryViewModel>();
            FirstBookDateProperty = new SingleValuedProperty <DateTime>();
            DescriptionProperty   = new SingleValuedProperty <string>();
            RequestKind           = new EnumeratedSingleValuedProperty <RequestKind>();

            IsEndingTransactionProperty.OnValueChanged += OnIsEndingTransactionPropertyChanged;
            MonthPeriods.OnValueChanged     += OnMonthPeriodsPropertyChanged;
            PaymentsProperty.OnValueChanged += OnPaymentsPropertyChanged;
            RequestKind.OnValueChanged      += RequestKindOnOnValueChanged;
            ValueProperty.OnIsValidChanged  += ValuePropertyOnOnIsValidChanged;
            ValueProperty.OnValueChanged    += ValuePropertyOnOnValueChanged;
            ValueProperty.Validate           = ValidateValueProperty;

            foreach (MonthPeriod value in Enum.GetValues(typeof(MonthPeriod)))
            {
                MonthPeriods.AddValue(value);
            }

            var allCategoryViewModels = application.Repository.QueryAllCategories().Select(c => new CategoryViewModel(application, c.PersistentId)).ToList();

            allCategoryViewModels.ForEach(a => a.Refresh());
            Categories.SetRange(allCategoryViewModels.OrderBy(c => c.Name));
            FirstBookDateProperty.Value = application.ApplicationContext.Now.Date;

            RequestKind.SetRange(Enum.GetValues(typeof(RequestKind)).Cast <RequestKind>());
            RequestKind.Value = RequestManagement.RequestKind.Expenditure;

            UpdateCommandStates();
            UpdateCaption();
        }
        public StandingOrderDetailsViewModel(ApplicationViewModel application, Action<StandingOrderEntityData> onSave, Action<StandingOrderDetailsViewModel> onCancel)
        {
            _application = application;
            SaveCommand = new CommandViewModel(() => onSave(CreateStandingOrderEntityData()));
            CancelCommand = new CommandViewModel(() => onCancel(this));
            PaymentsProperty = new SingleValuedProperty<int> { Value = 1 };
            ValueProperty = new SingleValuedProperty<double>();
            IsEndingTransactionProperty = new SingleValuedProperty<bool>();
            MonthPeriods = new EnumeratedSingleValuedProperty<MonthPeriod>();
            Categories = new EnumeratedSingleValuedProperty<CategoryViewModel>();
            FirstBookDateProperty = new SingleValuedProperty<DateTime>();
            DescriptionProperty = new SingleValuedProperty<string>();
            RequestKind = new EnumeratedSingleValuedProperty<RequestKind>();

            IsEndingTransactionProperty.OnValueChanged += OnIsEndingTransactionPropertyChanged;
            MonthPeriods.OnValueChanged += OnMonthPeriodsPropertyChanged;
            PaymentsProperty.OnValueChanged += OnPaymentsPropertyChanged;
            RequestKind.OnValueChanged += RequestKindOnOnValueChanged;
            ValueProperty.OnIsValidChanged += ValuePropertyOnOnIsValidChanged;
            ValueProperty.OnValueChanged += ValuePropertyOnOnValueChanged;
            ValueProperty.Validate = ValidateValueProperty;

            foreach (MonthPeriod value in Enum.GetValues(typeof(MonthPeriod)))
            {
                MonthPeriods.AddValue(value);
            }

            var allCategoryViewModels = application.Repository.QueryAllCategories().Select(c => new CategoryViewModel(application, c.PersistentId)).ToList();
            allCategoryViewModels.ForEach(a => a.Refresh());
            Categories.SetRange(allCategoryViewModels.OrderBy(c => c.Name));
            FirstBookDateProperty.Value = application.ApplicationContext.Now.Date;

            RequestKind.SetRange(Enum.GetValues(typeof(RequestKind)).Cast<RequestKind>());
            RequestKind.Value = RequestManagement.RequestKind.Expenditure;

            UpdateCommandStates();
            UpdateCaption();
        }
        public RequestManagementPageViewModel(ApplicationViewModel application, int year, int month) : base(application)
        {
            Months = new EnumeratedSingleValuedProperty <MonthNameViewModel>();
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameJanuary, 1));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameFebuary, 2));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameMarch, 3));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameApril, 4));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameMay, 5));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameJune, 6));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameJuly, 7));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameAugust, 8));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameSeptember, 9));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameOctober, 10));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameNovember, 11));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameDecember, 12));

            Requests = new EnumeratedSingleValuedProperty <RequestViewModel>();

            _year        = year;
            Months.Value = Months.SelectableValues.Single(m => m.Index == month);

            AddRequestCommand         = new CommandViewModel(OnAddRequestCommand);
            DeleteRequestCommand      = new CommandViewModel(OnDeleteRequestCommand);
            PreviousMonthCommand      = new CommandViewModel(OnPreviousMonthCommand);
            NextMonthCommand          = new CommandViewModel(OnNextMonthCommand);
            EditRequestCommand        = new CommandViewModel(OnEditRequestCommand);
            SwitchAccountCommand      = new CommandViewModel(OnSwitchAccountCommand);
            EditCategoriesCommand     = new CommandViewModel(OnEditCategoriesCommand);
            GotoCurrentMonthCommand   = new CommandViewModel(OnGotoCurrentMonthCommand);
            EditStandingOrdersCommand = new CommandViewModel(OnEditStandingOrdersCommand);

            Months.PropertyChanged   += OnMonthsPropertyChanged;
            Requests.PropertyChanged += OnSelectedRequestChanged;

            UpdateCurrentMonth();
            UpdateCommandStates();
            UpdateSaldoAsString();

            Caption = string.Format(Properties.Resources.RequestManagementPageCaptionFormat, Application.Repository.Name);
        }
        public RequestManagementPageViewModel(ApplicationViewModel application, int year, int month)
            : base(application)
        {
            Months = new EnumeratedSingleValuedProperty<MonthNameViewModel>();
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameJanuary, 1));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameFebuary, 2));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameMarch, 3));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameApril, 4));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameMay, 5));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameJune, 6));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameJuly, 7));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameAugust, 8));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameSeptember, 9));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameOctober, 10));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameNovember, 11));
            Months.AddValue(new MonthNameViewModel(Properties.Resources.MonthNameDecember, 12));

            Requests = new EnumeratedSingleValuedProperty<RequestViewModel>();

            _year = year;
            Months.Value = Months.SelectableValues.Single(m => m.Index == month);

            AddRequestCommand = new CommandViewModel(OnAddRequestCommand);
            DeleteRequestCommand = new CommandViewModel(OnDeleteRequestCommand);
            PreviousMonthCommand = new CommandViewModel(OnPreviousMonthCommand);
            NextMonthCommand = new CommandViewModel(OnNextMonthCommand);
            EditRequestCommand = new CommandViewModel(OnEditRequestCommand);
            SwitchAccountCommand = new CommandViewModel(OnSwitchAccountCommand);
            EditCategoriesCommand = new CommandViewModel(OnEditCategoriesCommand);
            GotoCurrentMonthCommand = new CommandViewModel(OnGotoCurrentMonthCommand);
            EditStandingOrdersCommand = new CommandViewModel(OnEditStandingOrdersCommand);

            Months.PropertyChanged += OnMonthsPropertyChanged;
            Requests.PropertyChanged += OnSelectedRequestChanged;

            UpdateCurrentMonth();
            UpdateCommandStates();
            UpdateSaldoAsString();
            UpdateMonthsIsEnabled();

            Caption = string.Format(Properties.Resources.RequestManagementPageCaptionFormat, Application.Repository.Name);
        }