RadScheduler with RadCalendar interaction

21 posts, 0 answers
  1. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post

    Hello Telerik Expert,
    What I need is when a user clicks on a RadCalendar's date, it will open up a RadScheduler.
    To start off with, for the RadScheduler, what I have done is to actually hard code the ID.
    But as it interacts with the RadCalendar, what it should do is when a user clicks on a date, it will open up a RadScheduler.
    When the user fills in some info for the specific time span, a new ID will be created and stored back to the Database.
    So when the user comes back to that date or any other date on a calender to see their schedule, they can see that specific ID's information. How can we do this? Will the RadScheduler automatically create a new ID, etc. on Insert and update the ID's value on update and even delete automatically.

    Please advise.

    Thank you.
  2. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post

    Hi Nate,

    What you're describing sounds like the default behavior for the RadScheduler.

    This demo should show you how to this:
    http://demos.telerik.com/aspnet-ajax/scheduler/examples/outlook2007/defaultcs.aspx

    Let me know if this helps,
    -Gimmik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 02 Jun 2011 Link to this post

    Hello Gimmik,

    Thank you very much for your reply.
    Question, for the RadScheduler to work 4 things are needed as the basic things:

    DataKeyField
    DataStartField 
    DataEndField 
    DataSubjectField 

    Is the DataKeyField the same as  ID="RadScheduler1" in the example shown?
    DataStartField  would be DayStartTime and DataEndField would be DayEndTime.
    I do not see where DataSubjectField is used though.

     

  5. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 02 Jun 2011 Link to this post

    Hi Nate,

    I'm glad you found the demo useful. I used that demo myself while testing Telerik products. Those fields represent the minimum required fields in your DataSet to bind to RadScheduler. Basically it is the basic information needed to define an appointment.

    DataKeyField - This is a unique identifier for each appointment.
    DataStartField - This the starting DateTime for the appointment.
    DataEndField - This the starting DateTime for the appointment.
    DataSubjectField - This is the title of the appointment, e.g. "Dentist Appointment."

    Here's the relevant documentation pages:
    http://www.telerik.com/help/aspnet-ajax/scheduler-data-source-configuration-wizard.html
    http://www.telerik.com/help/aspnet-ajax/scheduler-database-structure.html


    I hope that helps,
    -Gimmik
  6. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 06 Jun 2011 Link to this post

    Hello Gimmik,
    When the user does an insert an appointment, for example based on the example provided, does Telerik automatically create an ID for appointment. It appears so..

    In our application, we need to create the ability to do insert, update, delete through Stored Procedures.
    As such, how would I be able to get the ID info, etc. such that this is possible. I guess I would need to get the ID, StartTime, EndTime and also subject to then insert back into the table.

    Thanks

  7. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 06 Jun 2011 Link to this post

    Hi Nate,

    I believe the mechanism for creating the unique ID really depends on how you setup your data structure. In the case you describe, it doesn't appear that you really need to control the ID very much. I think the simplest thing to do is force the burden to the DBMS. Can you setup your ID column to auto-increment, NOT NULL, and make it a PRIMARY KEY column? Those properties should satisfy all your needs. When inserting a new appointment, let the DBMS worry about managing the unique ID for you.

    The RadScheduler will act as an interface for selecting and updating the appointments. For example, when you click an appointment in the RadScheduler, it already knows the ID, Subject, StartTime, etc. Using the RadScheduler to pass parameters to your SQL will enable you to make the correct insertions and updates.

    Hope this helps,
    -Gimmik
  8. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 06 Jun 2011 Link to this post

    Gimmik,
    Thanks for the response. What you have stated makes sense in terms of having a field in the table that auto increments when a new record is inserted.

    One of the questions though is how do I 'intercept' the StartTime, EndTime, Subject when an insert happens as with the way we are doing it, these values need to be passed to a stored procedure which then inserts these into the table.
    Also say once I do an update, how do I intercept the value of the ID that the RadScheduler will be updating as again I will need to use a stored procedure to process this.

    Thanks Gimmik
  9. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 06 Jun 2011 Link to this post

    Hi Nate,

    I think I know what you're looking for now. You'll have to implement the server-side code to Insert/Update appointments into the Database via your stored procedures, but Telerik does expose the insert/update fields via it's handy API. You can use the DataSource property of the RadScheduler to read from your database. At this point, your RadScheduler is read-only. You can then implement custom logic to handle updates by using the AppointmentUpdateAppointmentInsert, and AppointmentDelete server-side events.

    Here is the link to Telerik's documentation on the DataSource property:
    http://www.telerik.com/help/aspnet-ajax/scheduler-using-datasource-property.html

    Enjoy,
    -Gimmik
  10. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 11 Jun 2011 Link to this post

    Gimmik,
    Thank you so much for your responses. 
    In my scenerio, I need to create to used stored procedures for the insert, update, delete. I found an example online: 
     http://www.dotnetfunda.com/articles/article1101-how-to-use-telerik-scheduler-to-display-appointments-in-aspnet-part-i-.aspx

    As the example is not complete, I am not sure how to do and update, delete through the stored procedures via the radscheduler. Also say if the user does and a new insert, how do I then pass that info back to the stored procedure and then have it shown on the radscheduler as only then will I be able to delete it.
     
    Thanks again Gimmik, I really appreciate your assistance.


  11. Nayan
    Nayan avatar
    7 posts
    Member since:
    Apr 2011

    Posted 13 Jun 2011 Link to this post

     
  12. Nayan
    Nayan avatar
    7 posts
    Member since:
    Apr 2011

    Posted 13 Jun 2011 Link to this post

     
  13. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 13 Jun 2011 Link to this post

    Hi Nate,

    Yes - I have reviewed your your post. I will work up an example for you and post it as soon as possible.

    -Gimmik
  14. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 14 Jun 2011 Link to this post

    Hello Gimmik,
    I really appreciate your assistance.
    I was wondering if you had anything available yet or if you know how long as I get it up as soon as possible?

    Thanks again.
  15. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Hi Nate,

    I have good news - this is fairly easy to do based on my example.

    I setup a sample datebase with four columns (ID, Subject, Start, End). I manually inserting a few appointments into the database.

    I built a stored procedure on the database like this to delete appointments:
    ALTER PROCEDURE dbo.DeleteApp
        @ID int
        /*
        (
        @parameter1 int = 5,
        @parameter2 datatype OUTPUT
        )
        */
    AS
        DELETE FROM [sample] WHERE [ID] = @ID
        /* SET NOCOUNT ON */
        RETURN

    I setup my ASPX page like the following. Notice that the DeleteCommand for the SqlDataSource is the stored procedure we setup above. Also note the DeleteParameters which specifies which parameters should be passed into the stored procedure. The Telerik RadScheduler does all the rest for you when you bind it to the the DataSource.
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT * FROM [sample]"
        DeleteCommand="DeleteApp" DeleteCommandType="StoredProcedure">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />set
        </DeleteParameters>
        </asp:SqlDataSource>
     
    <telerik:RadScheduler ID="RadScheduler1" runat="server" DataSourceID="SqlDataSource1"
        DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End">
    </telerik:RadScheduler>

    This should provide you with a base to build upon.

    -Gimmik
  16. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Hello Gimmik,
    Thank you very much for your response.
    My scenerio is somewhat more complicated but what you have defintely helps.
    One question that I have is say if the user inserts a new appointment. That appointment will need a to do 2 things.
    First it will need to insert it into the table and get the next sequence # for that appointment and
    2) it will need to repopulate the appointment so that the user can delete that new record that was created if they choose to. I was wondering if the scheduler was able to do that automatically based on your example?
  17. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Hi Nate,

    All of the insert work is done for you by the RadScheduler control. I was able to update the sample project to handle insertion in about 30 seconds by creating a new stored procedure, then updating the SqlDataSource. Remember, the ID column is set to auto-increment, so we need not worry about the ID at all. Between the DBMS and Telerik RadControl, all the work is done for you.

    From your reference - here is my new stored procedure and updated SqlDataSource:
    ALTER PROCEDURE dbo.InsertApp
        @Subject nvarchar(255),
        @Start datetime,
        @End datetime
        /*
        (
        @parameter1 int = 5,
        @parameter2 datatype OUTPUT
        )
        */
    AS
        INSERT INTO [sample] ([Subject], [Start], [End])
        VALUES (@Subject, @Start, @End)
        /* SET NOCOUNT ON */
        RETURN

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT * FROM [sample]"
        DeleteCommand="DeleteApp" DeleteCommandType="StoredProcedure"
        InsertCommand="InsertApp" InsertCommandType="StoredProcedure">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Subject" Type="String" />
            <asp:Parameter Name="Start" Type="DateTime" />
            <asp:Parameter Name="End" Type="DateTime" />
        </InsertParameters>

    No changes were made at all to the RadScheduler.

    I hope this helps you complete you project,
    -Gimmik
  18. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Hello Gimmik,
    I appreciate your help.  I will need to use the server side events but the way you have it clearly shows how simple it is to do it with the built in features:

    For the server side events:

    AppointmentUpdateAppointmentInsert, and AppointmentDelete

    I did take a look at http://www.telerik.com/help/aspnet-ajax/scheduler-using-datasource-property.html but not sure how it will retreive the next ID from the table. I also look at http://demos.telerik.com/aspnet-ajax/scheduler/examples/bindtolist/defaultcs.aspx but again, there is no sample on how to interact with the db table to where we get the next avail sequence number.
     
  19. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Hi Nate,

    Why do you need the next available ID from the database?

    -Gimmik
  20. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 15 Jun 2011 Link to this post

    Gimmik,
    Thanks for your response. Yes, I understand how when an insert happens the table will automatically insert the next sequence ID. So yes, that is taken care of.

    With the recommended way of interacting with server side codes using the following http://www.telerik.com/help/aspnet-ajax/scheduler-using-datasource-property.html , I am not sure how to interact with the insert, update, delete stored procedures and still retreive the ID.

    For example for the and insert event they currently have:

    protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
    {
      Appointments.Add(new AppointmentInfo(e.Appointment));
    }

    I have modified the above to the following:
     
    protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
    {
      Appointments.Add(new AppointmentInfo(e.Appointment));
      
      string subjectval = e.Appointment.Subject.ToString();
      DateTime startval = e.Appointment.Start;
      DateTime endval = e.Appointment.End;
    // then make a call to the insert stored prodecure with the above values of subjectval, startval, endval 
      
    }

    Similarly for the update, I have the following modified version. Please note that I will also be calling
    the update stored procedure after this.
     
    protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
    {
      AppointmentInfo ai = FindById(e.ModifiedAppointment.ID.ToString());
      ai.CopyInfo(e.ModifiedAppointment);
      
       string idval = e.ModifiedAppointment.ID.ToString();
       string subjectval = e.ModifiedAppointment.Subject.ToString();
        DateTime   startval = e.ModifiedAppointment.Start;
         DateTime       endval = e.ModifiedAppointment.End;
      
      
    }


    For the Delete we have the following:
    protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e)
    {
       Appointments.Remove(FindById(e.Appointment.ID.ToString()));
         
       string idval = e.Appointment.ID.ToString();
       string subjectval = e.Appointment.Subject.ToString();
        DateTime startval = e.Appointment.Start;
        DateTime endval = e.Appointment.End;
          
       // make a call with the delete stored proc with these parameters
          
    }

    Gimmik, with what is there at http://www.telerik.com/help/aspnet-ajax/scheduler-using-datasource-property.html,
    I am not sure how ID the code knows what ID to use when it does and update, delete as no where in the code, are we passing it back
    for the system to know. Also I am not sure if the above approach that I am taking is correct.

    Thanks again Gimmik, you have been a tremendous help!
  21. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 16 Jun 2011 Link to this post

    Hi Nate,

    It looks like you're most of the way there already. I think this article will greatly help you. It shows fairly easily how to use stored procedures with parameters from the server-side code.
    http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx

    -Gimmik
  22. Nate
    Nate avatar
    26 posts
    Member since:
    May 2011

    Posted 20 Jun 2011 Link to this post

    Gimmik,
    Thank you for your help. I think I have it figured out now.

    Thanks again.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017