private async Task PopulatePeriodDates()
        {
            GetResult <IEnumerable <PeriodDto> > getPeriodsResult = await _accountingManager.GetAllPeriods();

            if (!getPeriodsResult.IsSuccess)
            {
                this.ShowErrorMessage("Failed to retrieve periods.", getPeriodsResult.FailureMessage);
                Close();
                return;
            }

            PeriodDto lastPeriod = getPeriodsResult.Result.LastOrDefault();

            if (lastPeriod == null)
            {
                this.ShowErrorMessage("No periods found.");
                Close();
                return;
            }

            _synchronizationContext.Post(
                p =>
            {
                var period = (PeriodDto)p;

                _startDateValueLabel.Text = $"{period.Start:yyyy-MM-dd}";
                _endDatePicker.Value      = period.End;
            },
                lastPeriod);
        }
Пример #2
0
        private async Task PopulatePeriodDates()
        {
            GetResult <IEnumerable <PeriodDto> > getPeriodsResult = await _accountingManager.GetAllPeriods();

            if (!getPeriodsResult.IsSuccess)
            {
                this.ShowErrorMessage("Failed to retrieve periods.", getPeriodsResult.FailureMessage);
                Close();
                return;
            }

            PeriodDto lastPeriod = getPeriodsResult.Result.LastOrDefault();

            DateTime?periodStart = lastPeriod?.End.AddDays(1);

            if (!periodStart.HasValue)
            {
                DateTime now = DateTime.Now;

                periodStart = new DateTime(
                    now.Year,
                    now.Month,
                    1);
            }

            DateTime?periodEnd = lastPeriod?.End.AddMonths(1);

            if (periodEnd.HasValue)
            {
                bool doesPreviousPeriodEndOnLastDayOfMonth =
                    lastPeriod.End.Day == DateTime.DaysInMonth(lastPeriod.End.Year, lastPeriod.End.Month);

                if (doesPreviousPeriodEndOnLastDayOfMonth)
                {
                    periodEnd = new DateTime(
                        periodEnd.Value.Year,
                        periodEnd.Value.Month,
                        DateTime.DaysInMonth(periodEnd.Value.Year, periodEnd.Value.Month));
                }
            }
            else
            {
                DateTime now = DateTime.Now;

                periodEnd = new DateTime(
                    now.Year,
                    now.Month,
                    DateTime.DaysInMonth(now.Year, now.Month));
            }

            _newPeriod = new PeriodDto(periodStart.Value, periodEnd.Value);

            _synchronizationContext.Post(
                p =>
            {
                var period = (PeriodDto)p;

                _startDateValueLabel.Text = $"{period.Start:yyyy-MM-dd}";
                _endDatePicker.Value      = period.End;
            },
                _newPeriod);
        }