Manual AppointmentCollection

11 posts, 1 answers
  1. Mike
    Mike avatar
    26 posts
    Member since:
    Jul 2008

    Posted 06 Aug 2009 Link to this post

    Is there any way to create an AppointmentCollection and manually fill with Appointment objects, along the lines of:

    Create new AppointmentCollection
    Grab Appointments from database
    Loop through, add new Appointment objects to AppointmentCollection
    Call AppointmentCollection.GetAppointmentsInRange

    Currently I am doing this, but there must be an easier way to do without having to use a RadScheduler.

                    // Check for a conflict                  
                    var appointments = dc.Appointments.Select(b => b.IsCancelled == false);  
                    RadScheduler scheduler = new RadScheduler();  
                    scheduler.DataKeyField = "AppointmentID";  
                    scheduler.DataSubjectField = "Subject";  
                    scheduler.DataStartField = "Start";  
                    scheduler.DataEndField = "End";  
                    scheduler.DataRecurrenceField = "RecurrenceRule";  
                    scheduler.DataRecurrenceParentKeyField = "RecurrenceParentID";  
                    scheduler.DataSource = appointments;  
                    scheduler.DataBind();  
     
                    return scheduler.Appointments.GetAppointmentsInRange(startTime, endTime).Count == 0; 


    Cheers,
    Mike

  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 07 Aug 2009 Link to this post

    Hi Mike,


    Please, refer to the Binding to generic list demo:
    http://demos.telerik.com/aspnet-ajax/scheduler/examples/bindtolist/defaultcs.aspx

    Appointments are initialized like this:
     private void InitializeAppointments()  
            {  
                DateTime start = DateTime.UtcNow.Date;  
                start = start.AddHours(6);  
                Appointments.Add(new AppointmentInfo("Take the car to the service", start, start.AddHours(1), string.Empty, null, 1));  
                Appointments.Add(new AppointmentInfo("Meeting with Alex", start.AddHours(2), start.AddHours(3), string.Empty, null, 2));  
     
                start = start.AddDays(-1);  
                DateTime dayStart = RadScheduler1.UtcDayStart(start);  
                Appointments.Add(new AppointmentInfo("Bob's Birthday", dayStart, dayStart.AddDays(1), string.Empty, null, 1));  
                Appointments.Add(new AppointmentInfo("Call Charlie about the Project", start.AddHours(2), start.AddHours(3), string.Empty, null, 2));  
     
                start = start.AddDays(2);  
                Appointments.Add(new AppointmentInfo("Get the car from the service", start.AddHours(2), start.AddHours(3), string.Empty, null, 1));  
            }  
     

    Please, feel free to contact us if you need further assistance.


    Best wishes,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Mike
    Mike avatar
    26 posts
    Member since:
    Jul 2008

    Posted 07 Aug 2009 Link to this post

    Yes, that would work if I just wanted a generic list of appointments.

    However, I need to use the AppointmentCollection object, I would like to be able to call AppointmentCollection.GetAppointmentsInRange

    I can't call this method on a generic list.
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 11 Aug 2009 Link to this post

    Hi Mike,

    The Add method is not exposed for the AppointmentCollection, but you can add appointments anyway like this:
    * * *   
    AppointmentCollection apts = new AppointmentCollection();  
            ((IList<Appointment>) apts).Add(new Appointment(1, DateTime.Now, DateTime.Now.AddHours(1), "Test"));  
    * * * 


    Best wishes,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Mike
    Mike avatar
    26 posts
    Member since:
    Jul 2008

    Posted 11 Aug 2009 Link to this post

    This code does compile and builds successfully,
     
    AppointmentCollection apts = new AppointmentCollection();  
    ((IList<Appointment>)apts).Add(new Appointment(1, DateTime.Now, DateTime.Now.AddHours(1), "Test"));   

    Unfortunately it throws the following error at runtime: Unable to cast object of type 'Telerik.Web.UI.AppointmentCollection' to type 'System.Collections.Generic.IList`1[Telerik.Web.UI.Appointment]'.  

     I am running version 2009.1.311.35 of the Telerik DLL. I really appreciate all your help!
  6. Answer
    Peter
    Admin
    Peter avatar
    6637 posts

    Posted 11 Aug 2009 Link to this post



    Sorry, I have mislead you. The code should be like this:
    using System.Collections;  
     
    /* * *   
     
    AppointmentCollection apts = new AppointmentCollection();     
    ((IList)apts).Add(new Appointment(1, DateTime.Now, DateTime.Now.AddHours(1), "Test"));      
     

    Greetings,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Mike
    Mike avatar
    26 posts
    Member since:
    Jul 2008

    Posted 11 Aug 2009 Link to this post

    Success!  I appreciate your help Peter.

    Thanks.
  8. Steven
    Steven avatar
    27 posts
    Member since:
    May 2012

    Posted 02 Aug 2012 Link to this post

    I am binding to a generic list like the demo shows.  The demo uses its own appointment object, AppointmentInfo.  I'm using my own object which I call ProductionRun.  I have everything running smoothly.  The only issue is I'd like to be able to use the GetAppointmentsInRange to search my list of ProcuctionRun objects.  How can I do this?  AppointmentCollection only takes Appointment objects, correct?
  9. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 06 Aug 2012 Link to this post

    Hello Steven,

    Indeed, the GetAppointmentsInRange method returns  a list of appointment objects only. I am not sure what you are trying to achieve, but basically, you can convert your custom class objects from code to appointment objects, using one of the Appointment constructors. For example:
    IList<Appointment> appList = new IList<Appointment>();
    appList.Add(new Appointment(1, DateTime.Now, DateTime.Now.AddDays(1), "test"));


    Regards,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  10. Arul
    Arul avatar
    2 posts
    Member since:
    Sep 2010

    Posted 30 Oct 2012 Link to this post

      The following piece of code puts both the appointment in the same date and time . How do i insert two appointments to the RadScheduler

               meetingAppointment.Subject = "Test";
                meetingAppointment.Start = DateTime.Now;
                meetingAppointment.End = DateTime.Now;
                          RadScheduler1.InsertAppointment(meetingAppointment);
                 
               
                TimeSpan ts = new TimeSpan(0, 12, 0, 0);
      meetingAppointment.Subject = "Test2";
                meetingAppointment.Start = DateTime.Now + ts;
                meetingAppointment.End = DateTime.Now + ts;
                
                RadScheduler1.InsertAppointment(meetingAppointment);   
  11. Plamen
    Admin
    Plamen avatar
    2958 posts

    Posted 01 Nov 2012 Link to this post

    Hello Arul,

     
    If you want to add more than one appointment to RadScheduler you should add them to the DataSource and rebind because InsertAppointment is working properly with only one appointment at a time.

    Hope this will explain the issue.

    All the best,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top