|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Day view screenshotWeek view screenshotFeaturesDayPilot is an Outlook-like open-source event calendar/scheduling control:
Getting startedThe only required step to make DayPilot working is to bind it to a data source. It supports DataTable (and DataSet) as a data source so you can easily supply the data from your database. Let's have a following table:
In order to show the events in DayPilot calendar you have to do the following steps:
Setting the DataSource propertyAfter loading a DataTable from a database (or other source) you should assign it to the DayPilotCalendar.DataSource property: DayPilotCalendar1.DataSource = MyDataTable;
In our example we are building the DataTable by hand: DataTable dt;
dt= new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
DataRow dr;
dr = dt.NewRow();
dr["id"] = 0;
dr["start"] = Convert.ToDateTime("15:30").AddDays(1);
dr["end"] = Convert.ToDateTime("16:30").AddDays(1);
dr["name"] = "Partner conf. call";
dt.Rows.Add(dr);
// ...
return dt;
When loading the events from a database I recommend limiting the SELECT so only the necessary events are loaded (not all events from the table). DayPilot will work properly in both cases (it only select the relevant events) but all the events will have to be loaded and they will be stored in the ViewState. Setting column name propertiesYou need to indicate which columns contain the necessary data: DayPilotCalendar1.DataStartField = "Start";
DayPilotCalendar1.DataEndField = "End";
DayPilotCalendar1.DataTextField = "Name";
DayPilotCalendar1.DataValueField = "ID";
Setting the visible datesLet's say we want to show just a single day: DayPilotCalendar1.StartDate = Convert.ToDateTime("1 June 2006");
DayPilotCalendar1.Days = 1; // default (not necessary)
But we can show multiple days as well. This is a new feature of DayPilot 2.0. DayPilotCalendar1.StartDate = Convert.ToDateTime("1 June 2006");
DayPilotCalendar1.Days = 5;
Example: Data bindingBind the data in the Page_Load() method: if (!IsPostBack)
DataBind();
Data-related properties overviewHere are the data-related properties of DayPilotCalendar:
Integration with System.Web.UI.WebControls.CalendarFor switching the date you can use the standard .NET Framework control System.Web.UI.WebControls.Calendar. You can use the PostBack event to change the DayPilot StartDate and EndDate.
In our sample we will use the DayRender event to improve the calendar:
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
string fontWeight = "normal";
if (isThereEvent(e.Day.Date))
fontWeight = "bold";
string color = "black";
if (e.Day.IsOtherMonth)
color = this.Calendar1.OtherMonthDayStyle.ForeColor.Name;
e.Cell.Text = String.Format("<a href='Default.aspx?day={0:d}' style='color: "
+ color + ";text-decoration:none; font-weight:"
+ fontWeight + "'>{1}</a>", e.Day.Date, e.Day.Date.Day);
}
The method isThereEvent() returns true if a specific day contains any event. This method will be specific to your application. You can go through the data returned from the database (and supplied to DayPilotCalendar.DataSource) to avoid another database request. We are not using the database in our sample so it is hard-coded: private bool isThereEvent(DateTime date)
{
DateTime today = DateTime.Now;
DateTime tomorrow = today.AddDays(1);
DateTime anotherDay = today.AddDays(3);
// there are events today
if ((date.DayOfYear == today.DayOfYear) && (date.Year == today.Year))
return true;
// there are events tomorrow
if ((date.DayOfYear == tomorrow.DayOfYear) && (date.Year == tomorrow.Year))
return true;
// there are events on another day
if ((date.DayOfYear == anotherDay.DayOfYear) && (date.Year == anotherDay.Year))
return true;
return false;
}
Integration using UpdatePanelSince version 2.3 DayPilot can be used inside UpdatePanel (ASP.NET AJAX Extensions/.NET Framework 3.5). If you place both the Calendar (System.Web.UI.WebControls.Calendar) and DayPilotCalendar inside the same UpdatePanel you can switch the date using Calendar.SelectionChanged event handler. It can be used like a regular PostBack event: protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DayPilotCalendar1.StartDate = Calendar1.SelectedDate;
DayPilotCalendar1.DataBind();
}
Changing the appearanceThere are many options to change the default appearance:
Appearance examplesDefault appearance24 hours2 days, 12-hours time formatWorking weekHandling user actionsThere are two types of user actions:
The actions can be handled on the client (by custom JavaScript code) or on the server (by handling the server event).
Server-side event handling
Your server-side event handling methods will get the important data: EventClick knows the primary key (PK column)private void DayPilotCalendar1_EventClick(object sender, EventClickEventArgs e)
{
Label1.Text = "Selected event: " + e.Value;
}
FreeTimeClick knows the time clickedprivate void DayPilotCalendar1_FreeTimeClick(object sender, FreeClickEventArgs e)
{
Label1.Text = "Selected time: " + e.Start;
}
ResourcesHistory
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||