Esempio n. 1
0
        /// <summary>
        /// Initializes data that is needed fot this class.
        /// </summary>
        internal void Initialize()
        {
            // Initialize other stuff.
            this.database = FileSystem.FindDatabaseFile();

            this.AllDaysInMonth = new ObservableCollection <WorkdayViewModel>();
            this.GetAllDays(DateTime.Now.Year, DateTime.Now.Month);

            var todayDate = DateTime.Now.Date;

            this.Today = this.AllDaysInMonth.Single(day => day.StartTime.Date == todayDate);

            if (this.Today.StartTime.TimeOfDay.Equals(DateTime.MinValue.TimeOfDay))
            {
                var logon = UserInfo.GetLastLogOnToMachine(this.Today.StartTime.Date);
                this.Today.StartTime = logon;
            }

            this.Today = this.AllDaysInMonth.Single(day => DateTime.Now.Date.Equals(day.StartTime.Date));

            this.AppVersion = GetPublishedVersion();

            this.UpdateCommand = new RelayCommand(
                () =>
            {
                this.Today.RemainingTime = DateCalculator.GetDeltaTime(this.Today, DateTime.Now);
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Assign the available work day objects to the collection that is bound to the UI.
        /// </summary>
        /// <param name="workdayInfos">The available work day objects.</param>
        private void AssignToUi(IWorkdayInfo[] workdayInfos)
        {
            // I prefer clearing the collection because every now and then something goes wrong
            // if the observalble collection is newly instanciated and then bound again to the UI.
            this.AllDaysInMonth.Clear();

            foreach (var info in workdayInfos)
            {
                var viewModel = new WorkdayViewModel
                {
                    DefaultWorkLength = info.DefaultWorkLength,
                    EndTime           = info.EndTime,
                    StartTime         = info.StartTime,
                    TotalBreakLength  = info.TotalBreakLength,
                    WorkdayId         = info.WorkdayId
                };

                this.AllDaysInMonth.Add(viewModel);
            }
        }