Click here to Skip to main content
15,887,875 members
Articles / Web Development / ASP.NET

SharePoint Page Navigation Web Part

Rate me:
Please Sign up or sign in to vote.
4.56/5 (4 votes)
25 Mar 2009CPOL6 min read 126.9K   540   19  
Web Part for users to drop on their pages for navigation across the site collection.
using System;
using System.Collections.Generic;
using System.Text;

namespace Mullivan.SharePoint.Reminders
{
    public class RmdMonthlyRecurrence : RmdRecurrence
    {
        public override string Name
        {
            get { return "Monthly"; }
        }

        public int StartDay
        {
            get;
            set;
        }

        public int StartHour
        {
            get;
            set;
        }

        public override bool CanRun(DateTime lastRun)
        {
            DateTime dtNow = DateTime.Now;
            int totalDaysInMonth = DateTime.DaysInMonth(lastRun.Year, lastRun.Month);
            int startDay = this.StartDay;
            if(startDay > totalDaysInMonth)
                startDay = totalDaysInMonth;


            //If never run then run
            if (lastRun.Equals(DateTime.MinValue))
                return true;

            DateTime nextOccurence = new DateTime(lastRun.Year, lastRun.Month, startDay, this.StartHour, 0, 0);

            //If lastRun is already greater than the next occurence
            // then we need to increment to the next month
            if (lastRun > nextOccurence)
            {
                //Increment by one month
                int month = lastRun.Month + 1;
                int year = lastRun.Year;

                //If month is over 12 then we need to change the year and set the month
                // back to january
                if (month > 12)
                {
                    month = 1;
                    year++;
                }

                startDay = this.StartDay;
                totalDaysInMonth = DateTime.DaysInMonth(year, month);
                if (startDay > totalDaysInMonth)
                    startDay = totalDaysInMonth;
                nextOccurence = new DateTime(year, month, startDay, this.StartHour, 0, 0);
            }

            if (dtNow > nextOccurence)
                return true;

            return false;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions