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

SharePoint CAML Query Builder Dialog for your Web Parts

Rate me:
Please Sign up or sign in to vote.
4.65/5 (9 votes)
24 Mar 2009CPOL7 min read 167.6K   847   34  
A SharePoint CAML query builder dialog for your Web Parts
using System;
using System.Collections.Generic;
using System.Text;

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

        public int StartHour
        {
            get;
            set;
        }

        public DayOfWeek DayOfWeek
        {
            get;
            set;
        }

        public override bool CanRun(DateTime lastRun)
        {
            DateTime dtNow = DateTime.Now;

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

            //If there is a week between the two then it needs to run
            if (dtNow.Subtract(lastRun).Days > 7)
                return true;

            //Create nextOccurence with this day and start hour
            DateTime nextOccurence = new DateTime(lastRun.Year, lastRun.Month, lastRun.Day, this.StartHour, 0, 0);

            //Add a day if the lastRun is already greater than equal to the StartHour
            if(nextOccurence.DayOfWeek == this.DayOfWeek &&
                lastRun.Hour >= this.StartHour)
                nextOccurence = nextOccurence.Add(new TimeSpan(1, 0, 0, 0));

            //add a day until we get the correct day of week
            while (nextOccurence.DayOfWeek != this.DayOfWeek)
                nextOccurence = nextOccurence.Add(new TimeSpan(1, 0, 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