search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to add Week view in Daypilot lite (Solution)

Asked by Martin Sørensen
12 years ago.

If you want to add weekView for your daypilot lite calendar do the following:

first you add a class.cs in App_code. Call this Week.cs. (Or whatever you like)

inside Week.cs write follownig code:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace DayPilot
{
/// <summary>
/// Summary description for Daypilot_FirstDayOfWeek
/// </summary>
public class Week
{
/// <summary>
/// Gets the first day of this week. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek()
{
return FirstDayOfWeek(DateTime.Today);
}

/// <summary>
/// Gets the first day of a week where day (parameter) belongs. Based on current culture.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
}
/// <summary>
/// Gets the first day of a week where day (parameter) belongs. weekStart (parameter) specifies the starting day of week.
/// </summary>
/// <returns></returns>
public static DateTime FirstDayOfWeek(DateTime day, DayOfWeek weekStarts)
{
DateTime d = day;
while (d.DayOfWeek != weekStarts)
{
d = d.AddDays(-1);
}
return d;
}

/// <summary>
/// Returns Monday of the week where day (parameter) belongs.
/// </summary>
/// <param name="day"></param>
/// <returns></returns>
public static DateTime FirstWorkingDayOfWeek(DateTime day)
{
return FirstDayOfWeek(day, DayOfWeek.Monday);
}
}
}

Then in your page file codebehind you import the file as following:

if you have a file in app_code named Week.cs that has this code:

namespace DayPilot
{
public class Week
{

}
}


To use this class in a page you must add:

using DayPilot;

public partial class _default : System.Web.UI.Page
{
Week weekObj;
protected void Page_Load(object sender, EventArgs e)
{
weekObj = new Week();
}

}
}

(change the names in bold as needed)

You can now call thesemethods/signatures

- Week.FirstDayOfWeek() - first day of this week, using the current culture settings
- Week.FirstDayOfWeek(DateTime day) - first day of a week that contains the specified day, using the current culture settings
- Week.FirstDayOfWeek(DateTime day, DayOfWeek weekStarts) - first day of a week that contains a specified day, using weekStarts as the first day of week
- Week.FirstWorkingDayOfWeek(DateTime day) - first Monday of the specified week

Happy Programming.

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.