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

Manual AppointmentCollection

10 Answers 126 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 2
Mike asked on 06 Aug 2009, 04:25 PM

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

10 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 07 Aug 2009, 02:42 PM
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.
0
Mike
Top achievements
Rank 2
answered on 07 Aug 2009, 03:15 PM
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.
0
Peter
Telerik team
answered on 11 Aug 2009, 01:05 PM
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.
0
Mike
Top achievements
Rank 2
answered on 11 Aug 2009, 02:17 PM
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!
0
Accepted
Peter
Telerik team
answered on 11 Aug 2009, 03:12 PM


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.
0
Mike
Top achievements
Rank 2
answered on 11 Aug 2009, 03:27 PM
Success!  I appreciate your help Peter.

Thanks.
0
Steven
Top achievements
Rank 1
answered on 02 Aug 2012, 09:49 PM
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?
0
Peter
Telerik team
answered on 06 Aug 2012, 07:56 AM
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.
0
Arul
Top achievements
Rank 1
answered on 30 Oct 2012, 10:19 PM
  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);   
0
Plamen
Telerik team
answered on 01 Nov 2012, 12:13 PM
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.
Tags
Scheduler
Asked by
Mike
Top achievements
Rank 2
Answers by
Peter
Telerik team
Mike
Top achievements
Rank 2
Steven
Top achievements
Rank 1
Arul
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or