Outside of the scheduler, I'm trying to loop through all events in a given date range. Due to the complexity of recurrence, I have a hidden instance of the RadScheduler on my form, and I am looping through the appointments and resources examining each appointment to see if it falls within range. The process is not smooth. I'm having lots of trouble with recurrence. For example, if I select one date, I'm getting two copies of the same event...one with, say, an ID of 105, and the other with an ID of 105_0. If I select a week, I am only seeing the 105_0 appointment.
I am finding work-arounds for each issue as I encounter one, but do not have faith that there aren't other hidden problems. Is there a better way to loop through by date range? The code below is just my latest experimentation. I probably need to scrap and start over.
I am finding work-arounds for each issue as I encounter one, but do not have faith that there aren't other hidden problems. Is there a better way to loop through by date range? The code below is just my latest experimentation. I probably need to scrap and start over.
private
void
LoopEvents()
{
RadListBox rlbResources = PanelBar.Items[0].Items[0].FindControl(
"rlbResources"
)
as
RadListBox;
DataTable dt;
string
canceled =
"Canceled"
;
string
sql =
"SELECT * FROM AppointmentResource"
;
string
errString =
""
;
DateTime currdt = Convert.ToDateTime(
"1/1/1901"
);
dt = PageData.GetData(sql,
ref
errString).Tables[0];
if
(rlbResources.Items.Count == 0)
rlbResources.DataBind();
foreach
(Telerik.Web.UI.RadDate rd
in
RadCalendar1.SelectedDates)
{
foreach
(Telerik.Web.UI.Appointment a
in
RadScheduler1.Appointments)
{
foreach
(Telerik.Web.UI.RadListBoxItem l
in
rlbResources.Items)
{
if
(l.Checked & a.Resources.GetResource(
"Resource"
, Convert.ToInt32(l.Value)) !=
null
)
{
//Occurrences of a recurrence master are not generated untill they
//are within RadScheduler's visible range. This mandates the occurrences
//information to be extracted from the Master's recurrence rule as follows:
if
((a.RecurrenceState == RecurrenceState.Master) & RadCalendar1.SelectedDates.Count > 1)
{
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(a.RecurrenceRule.ToString(),
out
parsedRule);
//If a recurring appointment does not have specified end time it will have
//endless occurrences. In this case you can explicitly put a restriction:
if
(RadCalendar1.SelectedDates.Count > 1)
parsedRule.SetEffectiveRange(RadCalendar1.SelectedDates[0].Date, RadCalendar1.SelectedDates[RadCalendar1.SelectedDates.Count - 1].Date);
else
parsedRule.SetEffectiveRange(RadCalendar1.SelectedDate.AddDays(-1), RadCalendar1.SelectedDate.AddDays(1));
foreach
(DateTime occurrence
in
parsedRule.Occurrences)
{
if
(occurrence.ToShortDateString() == rd.Date.ToShortDateString())
{
//We have a match
}
}
}
else
//Get the rest of the appointments
//If the SelectedDate of RadScheduler is set so that the visible range encompasses occurences of
//a recurring appointement, these occurences will be generated now so they will be added once again
//to the DataTable. To prevent this, we use the following check:
//if (a.RecurrenceState != RecurrenceState.Occurrence)
//{
if
(WithinDate(a.Start, a.End, rd.Date))
{
//We have a match
}
//}
}
}
}
}
}