Ejemplo n.º 1
0
        protected override void InitializationComplete()
        {
            // init
            _service   = ServiceManager.ConfigureService <GeneralSettingService>();
            _viewModel = new SettingsPageViewModel();
            comboLanguages.ItemsSource    = MultiLangEnumHelper.ToCollection(typeof(Language));
            comboAccentColors.ItemsSource = MCThemeManager.Instance.AccentColors;
            comboThemeColors.ItemsSource  = MCThemeManager.Instance.ThemeColors;

            this.DataContext = _viewModel;
        }
Ejemplo n.º 2
0
        public LoginWindow()
        {
            InitializeComponent();

            // apply theme
            MCThemeManager.Instance.SetTheme(AppSettings.Instance.LastAccentColor, AppSettings.Instance.LastThemeColor);

            // init service
            _settingsService           = ServiceManager.ConfigureService <GeneralSettingService>();
            _userService               = ServiceManager.ConfigureService <UserService>();
            comboLanguages.ItemsSource = MultiLangEnumHelper.ToCollection(typeof(Language));
            InitializeViewModel();
        }
        public ScheduleControl()
        {
            InitializeComponent();

            // load data
            daysOfWeek = MultiLangEnumHelper.ToSelectableCollection <DayOfWeek>();
            months     = MultiLangEnumHelper.ToSelectableCollection <Month>();

            // fill schedule selectors
            comboScheduleTypes.ItemsSource = MultiLangEnumHelper.ToCollection(typeof(ScheduleType));
            comboDaysOfMonth.ItemsSource   = ScheduleHelper.GetMonthes();
            DaysOfWeekControl.ItemsSource  = daysOfWeek;
            MonthesControl.ItemsSource     = months;
        }
Ejemplo n.º 4
0
        protected override void InitializationComplete()
        {
            // init
            _service                     = ServiceManager.ConfigureService <TransactionService>();
            _currencyService             = ServiceManager.ConfigureService <CurrencyService>();
            _storageService              = ServiceManager.ConfigureService <StorageService>();
            _currencyExchangeRateService = ServiceManager.ConfigureService <CurrencyExchangeRateService>();
            _categoryService             = ServiceManager.ConfigureService <CategoryService>();
            _settingsService             = ServiceManager.ConfigureService <ReportSettingService>();
            _builder                     = new ReportDataBuilder(GlobalVariables.UserId, _service, _currencyService, _currencyExchangeRateService, _categoryService);
            _chartDataBuilder            = new ChartDataBuilder();

            // init comboboxes
            comboChartType.ItemsSource       = MultiLangEnumHelper.ToCollection(typeof(ChartType));
            comboDataType.ItemsSource        = MultiLangEnumHelper.ToCollection(typeof(RecordType));
            comboBarChartView.ItemsSource    = MultiLangEnumHelper.ToCollection(typeof(BarChartView));
            comboSorting.ItemsSource         = MultiLangEnumHelper.ToCollection(typeof(Sorting));
            comboBarChartSection.ItemsSource = MultiLangEnumHelper.ToCollection(typeof(BarChartSection));

            // fill PeriodTypes. exclude custom period
            var values = new List <object>();

            foreach (PeriodType enumItem in Enum.GetValues(typeof(PeriodType)))
            {
                if (enumItem != PeriodType.Custom)
                {
                    values.Add(enumItem);
                }
            }
            comboBarChartPeriod.ItemsSource = MultiLangEnumHelper.ToCollection(typeof(PeriodType), values);

            // fill category levels source
            lowestCategoryLevel = _categoryService.GetLowestCategoryLevel(GlobalVariables.UserId);
            var categoryLevelDictionary = new Dictionary <int, string>();

            // add variant "All"
            categoryLevelDictionary.Add(-1, MultiLangResourceManager.Instance[MultiLangResourceName.All]);
            for (int i = 0; i <= lowestCategoryLevel; i++)
            {
                categoryLevelDictionary.Add(i, (i + 1).ToString());
            }
            comboCategoryLevel.ItemsSource = categoryLevelDictionary;

            InitializeViewModel();
        }
Ejemplo n.º 5
0
        private void InitializeViewModel()
        {
            _viewModel = new ChequeViewModel();

            _viewModel.AddCommand = new Command(() =>
            {
                var record = new RecordModel()
                {
                    UserId     = GlobalVariables.UserId,
                    RecordType = _viewModel.Entities.Count > 0 ? _viewModel.Entities.Last().RecordType : RecordType.Expense
                };

                record.PropertyChanged += (sender, e) =>
                {
                    if (e.PropertyName == nameof(RecordModel.Value) || e.PropertyName == nameof(RecordModel.RecordType))
                    {
                        _viewModel.RefreshTotalAmount();
                    }
                };

                _viewModel.Entities.Add(record);
            });

            _viewModel.DuplicateCommand = new DataGridSelectedItemCommand <RecordModel>(GridRecords, (item) =>
            {
                _viewModel.Entities.Add(new RecordModel()
                {
                    Description = item.Description,
                    RecordType  = item.RecordType,
                    Value       = item.Value,
                    Remark      = item.Remark,
                    CategoryId  = item.CategoryId,
                    UserId      = item.UserId
                });
            });

            _viewModel.DeleteCommand = new DataGridSelectedItemsCommand <RecordModel>(GridRecords, (items) =>
            {
                // remove in only grid
                foreach (var item in items.ToList())
                {
                    _viewModel.Entities.Remove(item);
                }
            });

            _viewModel.SaveCommand = new Command(() =>
            {
                // check valid data
                if (!ValidateData())
                {
                    MessageBox.Show(MultiLangResourceManager.Instance[MultiLangResourceName.SaveFailedMessage],
                                    MultiLangResourceManager.Instance[MultiLangResourceName.SaveFailed], MessageBoxButton.OK,
                                    MessageBoxImage.Exclamation);

                    return;
                }

                foreach (var entity in _viewModel.Entities)
                {
                    entity.Date                 = _viewModel.Date;
                    entity.CurrencyId           = _viewModel.CurrencyId;
                    entity.StorageId            = _viewModel.StorageId;
                    entity.Storage              = _viewModel.Storage;
                    entity.CurrencyExchangeRate = _viewModel.CurrencyExchangeRate;
                    if (string.IsNullOrEmpty(entity.Description))
                    {
                        entity.Description = _viewModel.Description;
                    }
                    if (string.IsNullOrEmpty(entity.Remark))
                    {
                        entity.Remark = _viewModel.Remark;
                    }
                    _service.Add(entity);
                }

                _viewModel.Entities.Clear();
                DialogResult = true;
                this.Close();
            });

            _viewModel.CancelCommand = new Command(() =>
            {
                DialogResult = false;
                this.Close();
            });

            // init columns
            _viewModel.RecordTypeList = MultiLangEnumHelper.ToCollection(typeof(RecordType));

            // fill defaults
            _viewModel.Date       = DateTime.Now;
            _viewModel.CurrencyId = _currencies.FirstOrDefault(x => x.IsMain)?.Id ?? _currencies.FirstOrDefault()?.Id ?? 0;
            _viewModel.Currency   = _currencies.FirstOrDefault(x => x.Id == _viewModel.CurrencyId)?.ToReferenceView();
            _viewModel.StorageId  = _storages.FirstOrDefault(x => x.CurrencyId == _viewModel.CurrencyId)?.Id ?? 0;
            _viewModel.Storage    = _storages.FirstOrDefault(x => x.Id == _viewModel.StorageId)?.ToReferenceView();

            _viewModel.Entities.CollectionChanged += (sender, e) => _viewModel.RefreshTotalAmount();

            this.DataContext = _viewModel;
        }