Exemple #1
0
        /// <summary>
        ///     Get a user-friendly class that is a easy way using Properties that define the Series Info
        /// </summary>
        /// <param name="seriesInfo" type="string">
        ///     <para>
        ///         String of Series Info that was first generated by this MonthlyRecurrenceSettings Class object.
        ///     </para>
        /// </param>
        /// <returns>
        ///     A RecurrenceGenerator.RecurrenceInfo value...
        /// </returns>
        internal static RecurrenceInfo GetFriendlyRecurrenceInfo(string seriesInfo)
        {
            RecurrenceInfo info         = new RecurrenceInfo();
            EndDateType    endType      = EndDateType.NotDefined;
            DateTime       endDateValue = DateTime.MinValue;
            int            noOccurrences;

            // Exit if not a Yearly seriesInfo type
            if (!seriesInfo.StartsWith("Y"))
            {
                return(null);
            }

            info.SetSeriesInfo(seriesInfo);
            info.SetRecurrenceType(RecurrenceType.Yearly);
            // FORMATTING DEFINITIONS
            //  Y = Yearly Designator
            //  |       0 = Start Date (8 chars)
            //  |       |        1 = End Date (8 chars)
            //  |       |        |        2 = Number of occurrences (4 chars)
            //  |       |        |        |      3 = Regeneration Type (1 char)
            //  |       |        |        |      |    4 = End date type (1 char)
            //  |       |        |        |      |    |      5 = Regenerate on specific date DAY value (2 chars)
            //  |       |        |        |      |    |      |       6 = Regenerate on specific date MONTH value (2 chars)
            //  |       |        |        |      |    |      |       |       7 = Custom Date Part One (1 char)
            //  |       |        |        |      |    |      |       |       |       8 = Custom Date Part Two (1 char)
            //  |       |        |        |      |    |      |       |       |       |       9 = Custom Date Part Three (1 char)
            //  |       |        |        |      |    |      |       |       |       |       |       10 = Adjustment Value (3 chars)
            //  |       |        |        |      |    |      |       |       |       |       |       |
            // [0]    [1-8]    [9-16]  [17-20]  [21] [22] [23-24] [25-26]  [27]    [28]    [29] [31-33]
            //  Y   20071231  20171231   0000    1     1     00      00      A      A        A      000
            string startDate = seriesInfo.Substring(1, 8);

            DateTime dtStartDate = new DateTime(int.Parse(startDate.Substring(0, 4)), int.Parse(startDate.Substring(4, 2)), int.Parse(startDate.Substring(6, 2)));
            string   endDate     = seriesInfo.Substring(9, 8);

            string occurrences                   = seriesInfo.Substring(17, 4);
            string yearlyRegenType               = seriesInfo.Substring(21, 1);
            string endDateType                   = seriesInfo.Substring(22, 1);
            string regenOnSpecificDateDayValue   = seriesInfo.Substring(23, 2);
            string regenOnSpecificDateMonthValue = seriesInfo.Substring(25, 2);
            string specDatePartOne               = seriesInfo.Substring(27, 1);
            string specDatePartTwo               = seriesInfo.Substring(28, 1);
            string specDatePartThree             = seriesInfo.Substring(29, 1);
            string adjustValue                   = seriesInfo.Substring(30, 3);

            endType       = (EndDateType)(int.Parse(endDateType));
            noOccurrences = int.Parse(occurrences);
            YearlySpecificDatePartOne   partOne   = YearlySpecificDatePartOne.NotSet;
            YearlySpecificDatePartTwo   partTwo   = YearlySpecificDatePartTwo.NotSet;
            YearlySpecificDatePartThree partThree = YearlySpecificDatePartThree.NotSet;

            if (specDatePartOne == "Z")
            {
                partOne = YearlySpecificDatePartOne.NotSet;
            }
            else
            {
                partOne = (YearlySpecificDatePartOne)(Convert.ToInt32(specDatePartOne[0]) - 65);
            }

            if (specDatePartTwo == "Z")
            {
                partTwo = YearlySpecificDatePartTwo.NotSet;
            }
            else
            {
                partTwo = (YearlySpecificDatePartTwo)(Convert.ToInt32(specDatePartTwo[0]) - 65);
            }

            if (specDatePartThree == "Z")
            {
                partThree = YearlySpecificDatePartThree.NotSet;
            }
            else
            {
                partThree = (YearlySpecificDatePartThree)(Convert.ToInt32(specDatePartThree[0]) - 64);
            }

            // Get the EndDate before any modifications on it are performed
            if (endType == EndDateType.SpecificDate)
            {
                endDateValue = new DateTime(int.Parse(endDate.Substring(0, 4)), int.Parse(endDate.Substring(4, 2)), int.Parse(endDate.Substring(6, 2)));
            }

            info.SetEndDateType(endType);
            // Determine the Constructor by the type of End Date.
            // All constructors start with a Start date at a minimum.
            switch (endType)
            {
            case EndDateType.NumberOfOccurrences:
                info.SetStartDate(dtStartDate);
                info.SetNumberOfOccurrences(noOccurrences);
                break;

            case EndDateType.SpecificDate:
                info.SetStartDate(dtStartDate);
                info.SetEndDate(endDateValue);
                break;

            case EndDateType.NoEndDate:
                info.SetStartDate(dtStartDate);
                break;
            }

            // Set the adjusted values
            info.SetAdjustmentValue(Convert.ToInt32(adjustValue));

            info.SetYearlyRegenType((YearlyRegenType)(int.Parse(yearlyRegenType)));
            // Determine the Type of dates to get, specific, custom, etc.
            switch (info.YearlyRegenType)
            {
            case YearlyRegenType.OnSpecificDayOfYear:
                info.SetSpecificDateDayValue(int.Parse(regenOnSpecificDateDayValue));
                info.SetSpecificDateMonthValue(int.Parse(regenOnSpecificDateMonthValue));
                break;

            case YearlyRegenType.OnCustomDateFormat:
                info.SetYearlySpecificDatePartOne(partOne);
                info.SetYearlySpecificDatePartTwo(partTwo);
                info.SetYearlySpecificDatePartThree(partThree);
                break;

            case YearlyRegenType.AfterOccurrenceCompleted:

                break;
            }

            return(info);
        }