Ejemplo n.º 1
0
        private bool OnTimerTick()
        {
            if (DateTime.Today > WorkDate)
            {
                if (_isTimerStarted)
                {
                    CloseEndedDayAsync();
                }
                return(_isTimerStarted = false);
            }

            if (!_currentAccounting.IsStarted)
            {
                return(_isTimerStarted);
            }
            var currentWorkTime = Breaks == null
                ? (DateTime.Now.TimeOfDay - StartWorkTime).TotalMinutes + _workedTime
                : (DateTime.Now.TimeOfDay - StartWorkTime).TotalMinutes
                                  - Breaks.Sum(d => d.EndBreakTime - d.StartBreakTime) + _workedTime;

            CurrentOverWork = _currentAccounting.IsWorking
                ? TimeSpan.FromMinutes(currentWorkTime - DateService.WorkingTime(DateTime.Now.DayOfWeek))
                : TimeSpan.FromMinutes(currentWorkTime);
            var halfTime = TimeSpan.FromMinutes(currentWorkTime
                                                - DateService.WorkingTime(DateTime.Now.DayOfWeek) / 2);

            if (CurrentOverWork > default(TimeSpan) &&
                CurrentOverWork <= TimeSpan.FromSeconds(1) &&
                _currentAccounting.IsWorking &&
                _isTimerStarted)
            {
                ShowWorkingEndAsync();
            }


            if (halfTime > default(TimeSpan) &&
                halfTime <= TimeSpan.FromSeconds(1) &&
                _currentAccounting.IsWorking &&
                _isTimerStarted)
            {
                ShowWorkingHalfAsync();
            }

            TotalOverWork = CurrentOverWork + _totalDbOverWork;
            return(_isTimerStarted);
        }
Ejemplo n.º 2
0
        private async void CloseEndedDayAsync()
        {
            if (WorkDate == DateTime.Today)
            {
                return;
            }
            IsEnable = false;
            await Task.Delay(100);

            if (!_currentAccounting.IsStarted)
            {
                _timeAccountingContext.TimeAccounts.Remove(_currentAccounting);
            }
            else
            {
                _currentAccounting.IsClosed    = true;
                _currentAccounting.EndWorkTime = new TimeSpan(23, 59, 59);

                if (_currentAccounting.StartWorkTime > _currentAccounting.EndWorkTime)
                {
                    _currentAccounting.StartWorkTime = _currentAccounting.EndWorkTime;
                }

                var workTime = Breaks == null
                                    ? (_currentAccounting.EndWorkTime - _currentAccounting.StartWorkTime).TotalMinutes
                                    : (_currentAccounting.EndWorkTime - _currentAccounting.StartWorkTime).TotalMinutes
                               - Breaks.Sum(d => d.EndBreakTime - d.StartBreakTime);
                _currentAccounting.OverWork = _currentAccounting.IsWorking
                        ? workTime - DateService.WorkingTime(_currentAccounting.WorkDate.DayOfWeek)
                        : workTime;
                _timeAccountingContext.Entry(_currentAccounting).State = EntityState.Modified;
                DependencyService.Get <IShowNotify>()
                .CancelAll();
            }
            await _timeAccountingContext.SaveChangesAsync()
            .ConfigureAwait(false);

            var isWorkDay         = DateService.IsWorking(DateTime.Today.DayOfWeek);
            var currentAccounting = new TimeAccount
            {
                WorkDate      = DateTime.Today,
                IsWorking     = isWorkDay,
                IsStarted     = IsStarted,
                StartWorkTime = default,