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

[Solved] SOS: Cannot make custom data source work

2 Answers 239 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
antonio
Top achievements
Rank 1
antonio asked on 30 May 2008, 05:03 PM
Hello,
I am evaluating the  RadScheduler  feature, and have followed the samples, and cannot make a custom datasource work.  Here's what I did:
1) Created a new AJAX enabled website
2) Added RadManager, added RadScheduler and setup.
3) Created a provider as an instance of DbSchedulerProviderBase
4) Deliberately left the Insert and Update events as they come (throw an exception)
5) Hardcoded 2 appointments
6) The scheduler displays fine.  The dra-and-drop feature raises an exception, which is what I expected.
7) When I open the dialog to insert or edit, it displays correctly; however, it does not raise an exception, which is what was expected.

I am getting ready to throw the towel on this.  Below, I have copied the code for this mini project; I wonder if anybody can help me. Thanks.

---- C#

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

using System.Collections;
using System.Collections.Generic;
using Telerik.Web.UI;
using Telerik.Web.UI.Scheduler.Views;

 

public partial class ctrlAppointmentWithSchedulerTelerik : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadScheduler1.SelectedView = SchedulerViewType.MonthView;
        }
        // fetch data on every postback - the question here is to determine the exact range so that we
        // fetch ONLY what we need
        MyDbSchedulerProvider schedulerProvider = new MyDbSchedulerProvider();
        RadScheduler1.Provider = schedulerProvider;
        RadScheduler1.Rebind();
        RadScheduler1.AppointmentCreated += new AppointmentCreatedEventHandler(RadScheduler1_AppointmentCreated);
        RadScheduler1.AppointmentInsert += new AppointmentInsertEventHandler(RadScheduler1_AppointmentInsert);
        RadScheduler1.AppointmentCommand += new AppointmentCommandEventHandler(RadScheduler1_AppointmentCommand);
    }
    public void RadScheduler1_AppointmentCommand(object sender, AppointmentCommandEventArgs e)
    {
        string sCommand = "";
        if (e.CommandName == "Insert")
        {
            sCommand = e.CommandName;
        }
    }
    public void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
    {
        if (e.Appointment.Subject == String.Empty)
        {
            e.Cancel = true;
        }
    }
    // constructor
    public ctrlAppointmentWithSchedulerTelerik()
    {
    }
    void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
    {
        Image templateImage = (Image)e.Container.FindControl("harmonyIcon");
        templateImage.ImageUrl = "~/images/delete.bmp";
        templateImage.AlternateText = "Status Icon";
    }
}

public class MyDbSchedulerProvider : DbSchedulerProviderBase
{
    public override void Delete(RadScheduler owner, Appointment appointmentToDelete)
    {
        throw new System.Exception("The method or operation is not implemented.");
    }
    // loading appointments
    public override IEnumerable<Appointment> GetAppointments(RadScheduler owner)
    {
        List<Appointment> appointments = new List<Appointment>();
        // hardcode some appointments
        // FIRST
        Appointment apt = new Appointment();
        apt.Owner = owner;
        apt.ID = 1;
        apt.Subject = "Subject 1";
        apt.Start = DateTime.Today.AddDays(-2);
        apt.End = DateTime.Today.AddDays(-2).AddHours(1);
        apt.RecurrenceRule = "";
        apt.RecurrenceParentID = null;
        if (apt.RecurrenceParentID != null)
        {
            apt.RecurrenceState = RecurrenceState.Exception;
        }
        else if (apt.RecurrenceRule != string.Empty)
        {
            apt.RecurrenceState = RecurrenceState.Master;
        }
        LoadResources(apt);
        appointments.Add(apt);
        // SECOND
        Appointment apt2 = new Appointment();
        apt2.Owner = owner;
        apt2.ID = 2;
        apt2.Subject = "Subject 2";
        apt2.Start = DateTime.Today;
        apt2.End = DateTime.Today.AddHours(1);
        apt2.RecurrenceRule = "";
        apt2.RecurrenceParentID = null;
        if (apt2.RecurrenceParentID != null)
        {
            apt2.RecurrenceState = RecurrenceState.Exception;
        }
        else if (apt2.RecurrenceRule != string.Empty)
        {
            apt2.RecurrenceState = RecurrenceState.Master;
        }
        LoadResources(apt2);
        appointments.Add(apt2);
        return appointments;
    }
    public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner)
    {
        ResourceType[] resourceTypes = new ResourceType[1];
        resourceTypes[0] = new ResourceType("Consumer", false);
        return resourceTypes;
    }
    public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType)
    {
        switch (resourceType)
        {
            case "Worker":
                return GetWorkers();
            case "Consumer":
                return GetConsumers();
            default:
                throw new InvalidOperationException("Unknown resource type: " + resourceType);
        }
    }
    public override void Insert(RadScheduler owner, Appointment appointmentToInsert)
    {
        //appointmentToInsert.Subject
        throw new System.Exception("I N S E R T   operation is not implemented.");
    }
    public override void Update(RadScheduler owner, Appointment appointmentToUpdate)
    {
        throw new System.Exception("The method or operation is not implemented.");
    }
    private IEnumerable<Resource> GetWorkers()
    {
        // fetch existing participants
        // assumption: we are calling this from
        List<Resource> resources = new List<Resource>();
        // Fetch all available participants (by passing 0 in ParentAppointmentID)

        return resources;
    }
    private IEnumerable<Resource> GetConsumers()
    {
        List<Resource> resources = new List<Resource>();
        // for the moment we are going to fetch the current caseNo
        Resource res = new Resource();
        res.Type = "Consumer";
        res.Key = 0;
        res.Text = "<CONSUMER_NAME_GOES_HERE>";
        resources.Add(res);
        return resources;
    }
    // loading resources for an appointment
    private void LoadResources(Appointment apt)
    {
        // add resource 'Consumer'
        Resource consumer = apt.Owner.Resources.GetResource("Consumer", 0);
        apt.Resources.Add(consumer);
    }
}

--- ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ctrlAppointmentWithSchedulerTelerik" %>

<%@ Register Assembly="Telerik.Web.UI, Version=2008.1.515.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
    Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>RadScheduler</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadScheduler1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadScheduler1"  />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>       
        <div>
<telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">
            <script type="text/javascript">
               
               
                function Client_AppointmentInserting(sender, eventArgs)
                {alert("BEFORE INSERTING");}
            </script>
 </telerik:RadScriptBlock>
<telerik:RadScheduler ID="RadScheduler1" runat="server" skin="Outlook" OverflowBehavior="Expand"
 OnAppointmentInsert="RadScheduler1_AppointmentInsert"
OnAppointmentCommand="RadScheduler1_AppointmentCommand" OnClientAppointmentInserting="Client_AppointmentInserting"
DataKeyField="ID" DataEndField = "End"
DataRecurrenceField = "RecurrenceRule" DataRecurrenceParentKeyField = "RecurrenceParentID"
DataStartField = "Start" DataSubjectField = "Subject" StartInsertingInAdvancedForm="true"
StartEditingInAdvancedForm="true">
<AppointmentTemplate><div style="background-color:Aqua"><%# Eval("Subject") %><asp:Image ID="harmonyIcon" runat="server" /></div>
</AppointmentTemplate>
</telerik:RadScheduler>
        </div>
    </form>
</body>
</html>


---- WEBCONFIG
<?xml version="1.0"?>
<configuration>
 <configSections>
  <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
   <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
     <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
     <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
     <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
    </sectionGroup>
   </sectionGroup>
  </sectionGroup>
 </configSections>
 <system.web>
  <pages>
   <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   </controls>
  </pages>
  <!--
          Set compilation debug="true" to insert debugging
          symbols into the compiled page. Because this
          affects performance, set this value to true only
          during development.
    -->
  <compilation debug="true">
   <assemblies>
    <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add assembly="Telerik.Web.UI, Version=2008.1.515.20, Culture=neutral, PublicKeyToken=121FAE78165BA3D4"/>
    <add assembly="Telerik.Charting, Version=2.0.1.0, Culture=neutral, PublicKeyToken=D14F3DCC8E3E8763"/>
    <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
  </compilation>
  <httpHandlers>
   <remove verb="*" path="*.asmx"/>
   <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
  </httpHandlers>
  <httpModules>
   <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </httpModules>
 </system.web>
 <system.web.extensions>
  <scripting>
   <webServices>
    <!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
    <!--
      <jsonSerialization maxJsonLength="500">
        <converters>
          <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
        </converters>
      </jsonSerialization>
      -->
    <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
    <!--
        <authenticationService enabled="true" requireSSL = "true|false"/>
      -->
    <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
           and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
           writeAccessProperties attributes. -->
    <!--
      <profileService enabled="true"
                      readAccessProperties="propertyname1,propertyname2"
                      writeAccessProperties="propertyname1,propertyname2" />
      -->
   </webServices>
   <!--
      <scriptResourceHandler enableCompression="true" enableCaching="true" />
      -->
  </scripting>
 </system.web.extensions>
 <system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <modules>
   <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </modules>
  <handlers>
   <remove name="WebServiceHandlerFactory-Integrated"/>
   <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </handlers>
 </system.webServer>
</configuration>

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 02 Jun 2008, 01:05 PM
Hi Antonio,

Everything looks alright with your provider. The problem seems to be the call to Rebind() in Page_Load. Removing it should resolve the issue.


Greetings,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
antonio
Top achievements
Rank 1
answered on 04 Jun 2008, 10:33 PM
It worked.

Thanks.
Tags
Scheduler
Asked by
antonio
Top achievements
Rank 1
Answers by
Peter
Telerik team
antonio
Top achievements
Rank 1
Share this question
or