RecurrenceValues GetRecurrenceValues()
        {
            RecurrenceValues values = null;

            switch (RegenType)
            {
            case DailyRegenType.OnEveryXDays:
                values = GetEveryXDaysValues();
                break;

            case DailyRegenType.OnEveryWeekday:
                values = GetEveryWeekday();
                break;
            }
            // Values will be null if just getting next date in series. No need
            // to fill the RecurrenceValues collection if all we need is the last date.
            if (values != null)
            {
                if (values.Values.Count > 0)
                {
                    values.SetStartDate(values.Values[0]);

                    // Get the end date if not open-ended
                    if (base.TypeOfEndDate != EndDateType.NoEndDate)
                    {
                        values.SetEndDate(values.Values[values.Values.Count - 1]);
                    }
                }
                // Set the Series information that's used to get the next date
                // values for no ending dates.
                values.SetSeriesInfo(GetSeriesInfo());
            }

            return(values);
        }
        RecurrenceValues GetRecurrenceValues()
        {
            RecurrenceValues values = null;

            switch (RegenType)
            {
            case MonthlyRegenType.OnSpecificDayOfMonth:
                values = GetSpecificDayOfMonthDates();
                break;

            case MonthlyRegenType.OnCustomDateFormat:
                values = GetCustomDayOfMonthDates();
                break;

            case MonthlyRegenType.AfterOccurrenceCompleted:
                break;
            }

            if (values.Values.Count > 0)
            {
                values.SetStartDate(values.Values[0]);

                // Get the end date if not open-ended
                if (base.TypeOfEndDate != EndDateType.NoEndDate)
                {
                    values.SetEndDate(values.Values[values.Values.Count - 1]);
                }
            }

            // Set the Series information that's used to get the next date
            // values for no ending dates.
            values.SetSeriesInfo(GetSeriesInfo());

            return(values);
        }
        RecurrenceValues GetRecurrenceValues()
        {
            RecurrenceValues values = null;

            switch (RegenType)
            {
            case WeeklyRegenType.OnEveryXWeeks:
                values = GetEveryXWeeksValues();
                break;
            }
            if (values.Values.Count > 0)
            {
                values.SetStartDate(values.Values[0]);

                // Get the end date if not open-ended
                if (base.TypeOfEndDate != EndDateType.NoEndDate)
                {
                    values.SetEndDate(values.Values[values.Values.Count - 1]);
                }
            }
            // Set the Series information that's used to get the next date
            // values for no ending dates.
            values.SetSeriesInfo(GetSeriesInfo());

            return(values);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the values for just weekdays.
        /// </summary>
        /// <returns>RecurrenceValues</returns>
        RecurrenceValues GetEveryWeekday()
        {
            RecurrenceValues values;
            DateTime         dt = base.StartDate;

            // Make sure the first date is a weekday
            if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
            {
                dt = GetNextWeekday(dt);
            }

            if (getNextDateValue)
            {
                do
                {
                    finalNextDateValue = dt;
                    if (finalNextDateValue > nextDateValue)
                    {
                        break;
                    }
                    dt = GetNextWeekday(dt);
                } while (dt <= nextDateValue.AddDays(3));                  // Make sure it's past what may possibly be the next weekday.
                return(null);
            }
            else
            {
                values = new RecurrenceValues();
                switch (base.TypeOfEndDate)
                {
                case EndDateType.NoEndDate:
                    throw new Exception("The ability to create recurring dates with no End date is not currently available.");

                case EndDateType.NumberOfOccurrences:
                    for (int i = 0; i < base.NumberOfOccurrences; i++)
                    {
                        values.AddDateValue(dt);
                        dt = GetNextWeekday(dt);
                    }
                    break;

                case EndDateType.SpecificDate:
                    int occurrences = 0;
                    do
                    {
                        values.AddDateValue(dt);
                        dt = GetNextWeekday(dt);

                        occurrences++;
                    } while (dt <= base.EndDate);

                    NumberOfOccurrences = occurrences;
                    break;

                default:
                    throw new ArgumentNullException("TypeOfEndDate", "The TypeOfEndDate property has not been set.");
                }
                return(values);
            }
        }
Exemplo n.º 5
0
        RecurrenceValues GetEveryXWeeksValues()
        {
            RecurrenceValues values = new RecurrenceValues();
            DateTime         dt     = base.StartDate.AddDays(-1); // Backup a day so the first instance of GetNextDay will increment to the next day.

            if (getNextDateValue)
            {
                do
                {
                    dt = GetNextDay(dt);
                    values.AddDateValue(dt);
                    if (values.Values[values.Values.Count - 1] > nextDateValue)
                    {
                        break;
                    }
                } while (dt <= nextDateValue.AddDays((regenEveryXWeeks * 7) + 7));                 // Ensure the last date if greater than what's needed for the next date in the cycle
            }
            else
            {
                switch (base.TypeOfEndDate)
                {
                case EndDateType.NoEndDate:
                    throw new Exception("The ability to create recurring dates with no End date is not currently available.");

                case EndDateType.NumberOfOccurrences:

                    for (int i = 0; i < base.NumberOfOccurrences; i++)
                    {
                        dt = GetNextDay(dt);
                        values.AddDateValue(dt);
                    }
                    break;

                case EndDateType.SpecificDate:
                    int occurrences = 0;
                    do
                    {
                        dt = GetNextDay(dt);
                        // Handle for dates past the end date
                        if (dt > base.EndDate)
                        {
                            break;
                        }

                        values.AddDateValue(dt);
                        occurrences++;
                    } while (dt <= base.EndDate);

                    NumberOfOccurrences = occurrences;
                    break;

                default:
                    throw new ArgumentNullException("TypeOfEndDate", "The TypeOfEndDate property has not been set.");
                }
            }

            return(values);
        }
        internal override DateTime GetNextDate(DateTime currentDate)
        {
            getNextDateValue = true;
            nextDateValue    = currentDate;
            // Now get the values and return the last date found.
            RecurrenceValues values = GetValues();

            return(values.EndDate);
        }
        /// <summary>
        /// Get recurring dates from custom date such as First Sunday of July.
        /// </summary>
        /// <returns></returns>
        RecurrenceValues GetCustomDayOfMonthDates()
        {
            if (this.SpecificDatePartOne == MonthlySpecificDatePartOne.NotSet)
            {
                throw new Exception("The First part of the custom date has not been set.");
            }
            if (this.SpecificDatePartTwo == MonthlySpecificDatePartTwo.NotSet)
            {
                throw new Exception("The Second part of the custom date has not been set.");
            }

            RecurrenceValues values = new RecurrenceValues();
            DateTime         dt     = base.StartDate;

            // Get Next Date value only
            if (getNextDateValue)
            {
                do
                {
                    dt = GetCustomDate(dt);
                    // If the date returned is less than the start date
                    // then do it again to increment past the start date
                    if (dt < base.StartDate)
                    {
                        dt = dt.AddMonths(1);
                        dt = GetCustomDate(dt);
                    }
                    values.AddDateValue(dt, adjustmentValue);
                    if (values.Values[values.Values.Count - 1] > nextDateValue)
                    {
                        break;
                    }

                    dt = dt.AddMonths(RegenEveryXMonths);
                } while (dt <= nextDateValue.AddMonths(RegenEveryXMonths + 1));                 // Ensure the last date if greater than what's needed for the next date in the cycle
            }
            else
            {
                switch (base.TypeOfEndDate)
                {
                case EndDateType.NoEndDate:
                    throw new Exception("The ability to create recurring dates with no End date is not currently available.");

                case EndDateType.NumberOfOccurrences:
                    for (int i = 0; i < base.NumberOfOccurrences; i++)
                    {
                        dt = GetCustomDate(dt);
                        // If the date returned is less than the start date
                        // then do it again to increment past the start date
                        if (dt < base.StartDate)
                        {
                            dt = dt.AddMonths(1);
                            dt = GetCustomDate(dt);
                        }
                        values.AddDateValue(dt, adjustmentValue);
                        dt = dt.AddMonths(RegenEveryXMonths);
                    }
                    break;

                case EndDateType.SpecificDate:
                    do
                    {
                        dt = GetCustomDate(dt);
                        // If the date returned is less than the start date
                        // then do it again to increment past the start date
                        if (dt < base.StartDate)
                        {
                            dt = dt.AddMonths(1);
                            dt = GetCustomDate(dt);
                        }
                        values.AddDateValue(dt, adjustmentValue);
                        dt = dt.AddMonths(RegenEveryXMonths);
                    } while (dt <= base.EndDate);
                    break;

                default:
                    throw new ArgumentNullException("TypeOfEndDate", "The TypeOfEndDate property has not been set.");
                }
            }
            return(values);
        }
        /// <summary>
        /// Get recurring dates from a specific constant date such as 27 July.
        /// </summary>
        /// <returns></returns>
        RecurrenceValues GetSpecificDayOfMonthDates()
        {
            RecurrenceValues values = new RecurrenceValues();
            DateTime         dt     = base.StartDate;
            int dayValue            = regenerateOnSpecificDateDayValue;
            int daysOfMonth         = DateTime.DaysInMonth(dt.Year, dt.Month);

            // Get the max days of the month and make sure it's not
            // less than the specified day value trying to be set.
            if (daysOfMonth < regenerateOnSpecificDateDayValue)
            {
                dayValue = daysOfMonth;
            }

            // Determine if start date is greater than the Day and Month values
            // for a specific date.
            DateTime newDate = new DateTime(dt.Year, dt.Month, dayValue);

            // Is the specific date before the start date, if so
            // then make the specific date next month.
            if (newDate < dt)
            {
                dt = newDate.AddMonths(1);
            }
            else
            {
                dt = newDate;
            }


            if (getNextDateValue)
            {
                do
                {
                    values.AddDateValue(dt, adjustmentValue);
                    if (values.Values[values.Values.Count - 1] > nextDateValue)
                    {
                        break;
                    }

                    dt = dt.AddMonths(RegenEveryXMonths);
                    dt = GetCorrectedDate(dt);
                } while (dt <= nextDateValue.AddMonths(RegenEveryXMonths + 1));                 // Ensure the last date if greater than what's needed for the next date in the cycle
            }
            else
            {
                switch (base.TypeOfEndDate)
                {
                case EndDateType.NoEndDate:
                    throw new Exception("The ability to create recurring dates with no End date is not currently available.");

                case EndDateType.NumberOfOccurrences:
                    for (int i = 0; i < base.NumberOfOccurrences; i++)
                    {
                        values.AddDateValue(dt, adjustmentValue);
                        dt = dt.AddMonths(RegenEveryXMonths);
                        dt = GetCorrectedDate(dt);
                    }
                    break;

                case EndDateType.SpecificDate:
                    int occurrences = 0;
                    do
                    {
                        values.AddDateValue(dt, adjustmentValue);
                        dt = dt.AddMonths(RegenEveryXMonths);
                        dt = GetCorrectedDate(dt);

                        occurrences++;
                    } while (dt <= base.EndDate);

                    NumberOfOccurrences = occurrences;
                    break;

                default:
                    throw new ArgumentNullException("TypeOfEndDate", "The TypeOfEndDate property has not been set.");
                }
            }

            return(values);
        }