| using System; |
| using System.Collections.Generic; |
| using System.ComponentModel; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Telerik.Cms.Engine; |
| using Telerik.Events; |
| using Telerik.Events.WebControls; |
| using Telerik.Samples.Events.DataSources; |
| using Telerik.Web.UI; |
| |
| namespace Telerik.Samples.Events.WebControls |
| { |
| |
| /// <summary> |
| /// Summary description for CustomScheduleView |
| /// </summary> |
| public class CustomScheduleView : EventsScheduleView |
| { |
| //our custom datasource for event items |
| private System.Collections.Generic.List<AppointmentInfo> appointments; |
| private EventsManager eventsManager; |
| |
| [Browsable(true)] |
| [Category("Appearance")] |
| [Description("Gets or sets the path to a custom layout template for the control.")] |
| public override string LayoutTemplatePath |
| { |
| get |
| { |
| return "~/Sitefinity/ControlTemplates/Events/EventsScheduleView.ascx"; |
| } |
| set |
| { |
| base.LayoutTemplatePath = value; |
| } |
| } |
| |
| protected override void InitializeControls(Control controlContainer) |
| { |
| if (Page == null || DesignMode) |
| { |
| Label noDesignModeLabel = new Label(); |
| noDesignModeLabel.Text = "The Events Schedule View control cannot be rendered in Design Mode"; |
| this.EventsSchedule.Visible = false; |
| this.Controls.Add(noDesignModeLabel); |
| } |
| else |
| { |
| if (base.CssFileLink1 != null) |
| { |
| base.CssFileLink1.AssemblyInfo = base.AssemblyInfo; |
| } |
| //we have to bind the RadScheduler control to a custom data source that holds all necessary information |
| appointments = new List<AppointmentInfo>(); |
| this.eventsManager = new EventsManager("Events"); |
| foreach (IEvent _event in eventsManager.GetEvents()) |
| { |
| if (_event.ContentItem.Status == Telerik.Cms.Engine.ContentStatus.Published) |
| appointments.Add(new AppointmentInfo(_event)); |
| } |
| this.EventsSchedule.DataSource = appointments; |
| this.EventsSchedule.DataKeyField = "ID"; |
| this.EventsSchedule.DataSubjectField = "Subject"; |
| this.EventsSchedule.DataStartField = "Start"; |
| this.EventsSchedule.DataEndField = "End"; |
| this.EventsSchedule.AllowDelete = false; |
| this.EventsSchedule.AllowInsert = false; |
| this.EventsSchedule.AllowEdit = false; |
| this.EventsSchedule.AppointmentCreated += new Telerik.Web.UI.AppointmentCreatedEventHandler(EventsSchedule_AppointmentCreated); |
| |
| //create an object data source that will extract categories from the Events module |
| ObjectDataSource categoriesDataSource = new ObjectDataSource(); |
| categoriesDataSource.ID = "categoriesDataSource"; |
| categoriesDataSource.TypeName = "Telerik.Cms.Engine.ContentManager"; |
| categoriesDataSource.SelectMethod = "GetCategories"; |
| categoriesDataSource.ObjectCreating += new ObjectDataSourceObjectEventHandler(categoriesDataSource_ObjectCreating); |
| Controls.Add(categoriesDataSource); |
| ResourceType rt = new ResourceType("Category"); |
| rt.DataSource = categoriesDataSource; |
| rt.KeyField = "ID"; |
| rt.TextField = "CategoryName"; |
| rt.ForeignKeyField = "CategoryID"; |
| this.EventsSchedule.ResourceTypes.Add(rt); |
| } |
| } |
| |
| void categoriesDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e) |
| { |
| e.ObjectInstance = new ContentManager("Events"); |
| } |
| void EventsSchedule_AppointmentCreated(object sender, Telerik.Web.UI.AppointmentCreatedEventArgs e) |
| { |
| IEvent event2 = this.eventsManager.GetEvent(new Guid(e.Appointment.ID.ToString())); |
| HyperLink link = (HyperLink)e.Container.FindControl("eventDetailsLink"); |
| if (link != null) |
| { |
| link.Text = e.Appointment.Subject; |
| link.NavigateUrl = this.GetItemUrl(event2.ContentItem, this.SingleEventUrl); |
| } |
| string category = event2.ContentItem.GetMetaData("Category").ToString(); |
| //here you can style the appearance of each appoinment |
| //for simplicity we use builtin RadScheduler CSS classes |
| if(category!=null) |
| e.Appointment.CssClass= "rsCategory"+category; |
| } |
| } |
| } |