This is a migrated thread and some comments may be shown as answers.

Replacing SchedulerInfo in ResourcesPopulating not working

1 Answer 104 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
David Bryant
Top achievements
Rank 1
David Bryant asked on 28 Jan 2011, 05:51 PM
I using a web service to bind the scheduler and now trying to populate the resources.  I need to pass some additional info to the web service so I've created a class that implements ISchedulerInfo and have followed the instructions for passing additional info to the web service via a custom implementation of ISchedulerInfo.  I'm successful with the call to GetAppointments with additional parameters but I set the custom parameters in javascript. 

So, the web service settings show ResourcePopulationMode="ServerSide".  On the page...

    Protected Sub RadScheduler1_ResourcesPopulating(ByVal sender As Object, ByVal e As Telerik.Web.UI.ResourcesPopulatingEventArgs)
        Dim myInfo As New CustomSchedulerInfo
        myInfo.UserID = 1234
        e.SchedulerInfo = myInfo
    End Sub

Setting breakpoints shows ResourcePopulating firing before the web method call to GetResources. 

    <WebMethod()> _
    Public Function GetResources(ByVal schedulerInfo As CustomSchedulerInfo) As IEnumerable(Of ResourceData)
        Return Controller.GetResources(schedulerInfo)
    End Function

When I set a breakpoint in GetResources and evaluate schedulerInfo, schedulerInfo.UserID = 0 (default). 

Maybe I'm just missing some setting but it appears as though replacing e.SchedulerInfo is not working -- at least not in VB.

Any suggestions?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 02 Feb 2011, 11:11 AM
Hi David,

For your convenience, I have prepared a simple working demo which shows how to bind RadScheduler to a Web Service and how to filter appointments based on a selected resource. Here is the code with highlighted relevant sections:


MySchedulerInfo.cs
Copy Code
public class MySchedulerInfo : SchedulerInfo
{
    public string TeacherID { get; set; }
    public MySchedulerInfo(ISchedulerInfo baseInfo, string teacherID)
        : base(baseInfo)
    {
        TeacherID = teacherID;
    }
    public MySchedulerInfo()
    {
  
    }
}

SchedulerWebService.cs
Copy Code
[WebMethod]
    public IEnumerable<AppointmentData> GetAppointments(MySchedulerInfo schedulerInfo)
    {        
        return Controller.GetAppointments(schedulerInfo);
    }
  
    [WebMethod]
    public IEnumerable<AppointmentData> InsertAppointment(MySchedulerInfo schedulerInfo, AppointmentData appointmentData)
    {
        return Controller.InsertAppointment(schedulerInfo, appointmentData);
    }
  
    [WebMethod]
    public IEnumerable<AppointmentData> UpdateAppointment(MySchedulerInfo schedulerInfo, AppointmentData appointmentData)
    {
        return Controller.UpdateAppointment(schedulerInfo, appointmentData);
    }
  
    [WebMethod]
    public IEnumerable<AppointmentData> CreateRecurrenceException(MySchedulerInfo schedulerInfo, AppointmentData recurrenceExceptionData)
    {
        return Controller.CreateRecurrenceException(schedulerInfo, recurrenceExceptionData);
    }
  
    [WebMethod]
    public IEnumerable<AppointmentData> RemoveRecurrenceExceptions(MySchedulerInfo schedulerInfo, AppointmentData masterAppointmentData)
    {
        return Controller.RemoveRecurrenceExceptions(schedulerInfo, masterAppointmentData);
    }
  
    [WebMethod]
    public IEnumerable<AppointmentData> DeleteAppointment(MySchedulerInfo schedulerInfo, AppointmentData appointmentData, bool deleteSeries)
    {
        return Controller.DeleteAppointment(schedulerInfo, appointmentData, deleteSeries);
    }
  
    [WebMethod]
    public IEnumerable<ResourceData> GetResources(MySchedulerInfo schedulerInfo)
    {
        return Controller.GetResources(schedulerInfo);
    }

RadSchedulerWebServiceCustomProvider.aspx

Copy Code
<script type="text/javascript">
       //Put your JavaScript code here.
       var teacherID = "all";
       function OnClientSelectedIndexChanged(sender, args) {
           teacherID = args.get_item().get_value();
           var scheduler = $find('<%=RadScheduler1.ClientID %>');
           scheduler.rebind();
       }
       function OnClientAppointmentsPopulating(sender, eventArgs) {
           eventArgs.get_schedulerInfo().TeacherID = teacherID;
       }
   </script>
   <p>
       Filter appointments by teacher (resource):
   </p>
   <p>
       <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
           <Items>
               <telerik:RadComboBoxItem Text="All" Value="all" />
               <telerik:RadComboBoxItem Text="Teacher 1" Value="1" />
               <telerik:RadComboBoxItem Text="Teacher 2" Value="2" />
           </Items>
       </telerik:RadComboBox>
   </p>
   <telerik:RadScheduler ID="RadScheduler1" runat="server" OnClientAppointmentsPopulating="OnClientAppointmentsPopulating"
       AppointmentStyleMode="Default" SelectedView="WeekView" SelectedDate="2011-01-21" Width="600px">
       <WebServiceSettings Path="SchedulerWebService.asmx" ResourcePopulationMode="ServerSide" />
       <ResourceStyles>
           <telerik:ResourceStyleMapping Type="Teacher" Key="1" BackColor="Orange" />
           <telerik:ResourceStyleMapping Type="Teacher" Key="2" BackColor="Aqua" />
       </ResourceStyles>
   </telerik:RadScheduler>


MyDbSchedulerProvider.cs
Copy Code
public override IEnumerable<Appointment> GetAppointments(ISchedulerInfo shedulerInfo)
    {
        var myInfo = shedulerInfo as MySchedulerInfo;
        string teacherID = myInfo.TeacherID;
  
        List<Appointment> appointments = new List<Appointment>();
  
        using (DbConnection conn = OpenConnection())
        {
            DbCommand cmd = DbFactory.CreateCommand();
            cmd.Connection = conn;
            cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId], [Reminder] FROM [DbProvider_Classes]";
              
            if (teacherID != "all")        
                cmd.CommandText += "WHERE TeacherID = " + teacherID;

Peruse it at leisure and don't hesitate to contact us if you need further guidance. We will be glad to help.


Greetings,
Peter
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Scheduler
Asked by
David Bryant
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or