public SingleMonthViewModel(MainViewModel mainViewModel, IWebRequestObserver webRequestObserver, IWebDavConnection webDavConnection)
        {
            _mainViewModel      = mainViewModel;
            _webRequestObserver = webRequestObserver;
            _webDavConnection   = webDavConnection;

            _days = new ObservableCollection <SingleDayViewModel>();
            _days.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_days_CollectionChanged);

            this.CorrectionsRequestCommand = new RelayCommand((obj) => onCorrectionsRequest());
        }
Beispiel #2
0
        private void executeJumpToYearMonth(object param)
        {
            logger.Info("executeJumpToYearMonth()");

            App nonDesignModeApp = System.Windows.Application.Current as App;

            if (nonDesignModeApp != null)
            {
                nonDesignModeApp.EnterBusyState("Načítavanie údajov...", this.MessageBarVM);
            }

            int perfStart = System.Environment.TickCount;

            var nowTime = TimeMerge.Utils.Calculations.NowTime;

            bool needNewMonthViewModel = false;

            if (this.MonthViewModel != null)
            {
                TimeSpan wholeMonthBalance = MonthViewModel.BalanceWholeMonth;
                this.MonthViewModel.TurnOffNotifications();
                this.MonthViewModel.SaveData(wholeMonthBalance);

                if (nowTime.Month != _mostRecentJumpToYearMonthExecution.Month)
                {
                    // automatic transition to a new month when running TimeMerge for several days in a row (e.g. date changes from "Jan" to "Feb" overnight)
                    this.Year  = nowTime.Year;
                    this.Month = nowTime.Month;
                }

                if (this.Year != this.MonthViewModel.YearMonth.Year ||
                    this.Month != this.MonthViewModel.YearMonth.Month)
                {
                    needNewMonthViewModel = true;
                }
                else
                {
                    needNewMonthViewModel = false;
                    this.MonthViewModel.PopulateDataFromWebOnBackground();
                }
            }
            else
            {
                needNewMonthViewModel = true;
            }

            if (needNewMonthViewModel)
            {
                var monthData = new TimeMerge.Model.SingleMonthData()
                {
                    YearMonth = new DateTime(this.Year, this.Month, 1)
                };

                // Reuse existing Month VM if possible. When also reusing ViewModels of individual days inside the Month VM, it will improve performance
                // since the DataGrid controls won't need to be recreated. They'll be just updated instead.
                if (this.MonthViewModel == null)
                {
                    IWebRequestObserver webRequestObserver = App.Current == null ? null : (App.Current as App).Context.WebRequestObserver;
                    this.MonthViewModel = new TimeMerge.ViewModel.SingleMonthViewModel(this, webRequestObserver, (App.Current as App)?.Context.WebDavConnection);
                }

                this.MonthViewModel.SetMonthData(monthData);
            }

            this.MonthViewModel.TurnOnNotifications();

            m_HomeOfficeDetector?.DetectNow();

            if (nonDesignModeApp != null)
            {
                nonDesignModeApp.ExitBusyState();
            }

            int perfStop = System.Environment.TickCount;

//             System.Windows.MessageBox.Show(string.Format("Jump took {0} msecs", perfStop - perfStart), "TimeMerge", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);

            _mostRecentJumpToYearMonthExecution = nowTime;
        }