The back color of appointments loses after cancelling edit the appointments

2 posts, 0 answers
  1. Meng
    Meng avatar
    9 posts
    Member since:
    Jul 2016

    Posted 14 Nov 2016 Link to this post

    Hi There,

    I am working on the timeline view of the Scheduler. I set the back color for appointments in RadScheduler1_AppointmentDataBound function. But the back color of the appointments loses after clicking the cancel button on the advanced pop-up form. Please see the following for my test code. Any help is much appreciated.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadSchedulerTest.aspx.cs" Inherits="RadSchedulerTest" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <style type="text/css">
            .rsAptDelete {
                display: none;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadScheduler1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadScheduler1" LoadingPanelID="RadAjaxLoadingPanel1">
                        </telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <div>
            <telerik:RadScheduler runat="server" ID="RadScheduler1" Width="920"
                OnAppointmentInsert="RadScheduler1_AppointmentInsert" Reminders-Enabled="false"
                OnAppointmentUpdate="RadScheduler1_AppointmentUpdate"
                DataKeyField="ID" DataSubjectField="Subject" DataStartField="Start" DataEndField="End"
                DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentId"
                DataReminderField="Reminder" SelectedView="TimelineView" ShowViewTabs="false" AppointmentStyleMode="Default"
                OnTimeSlotCreated="RadScheduler1_TimeSlotCreated" OnNavigationComplete="RadScheduler1_NavigationComplete" ColumnWidth="28"
                OnAppointmentDataBound="RadScheduler1_AppointmentDataBound" StartInsertingInAdvancedForm="true">
                <TimelineView ShowInsertArea="false" SlotDuration="1" GroupBy="User, Month" GroupingDirection="Vertical" ColumnHeaderDateFormat="MMM dd ddd" HeaderDateFormat="MMMM, yyyy"/> 
            </telerik:RadScheduler>
        </div>
        </form>
    </body>
    </html>

     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections.Generic;
    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 Telerik.Web.UI;
    using Telerik.Web.UI.Calendar;
    using Telerik.Web.UI.Calendar.View;
     
    public partial class RadSchedulerTest : System.Web.UI.Page
    {
        private const string AppointmentsKey = "Telerik.Web.Examples.Scheduler.BindToList.CS.Apts";
     
        private List<AppointmentInfo> Appointments
        {
            get
            {
                List<AppointmentInfo> sessApts = Session[AppointmentsKey] as List<AppointmentInfo>;
                if (sessApts == null)
                {
                    sessApts = new List<AppointmentInfo>();
                    Session[AppointmentsKey] = sessApts;
                }
     
                return sessApts;
            }
        }
     
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
     
            if (!IsPostBack)
            {
                Session.Remove(AppointmentsKey);
     
                InitializeResources();
                InitializeAppointments();
            }
     
            RadScheduler1.DataSource = Appointments;
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            RadScheduler1.EnableAjaxSkinRendering = true;
            if (!IsPostBack & RadScheduler1.SelectedView == SchedulerViewType.TimelineView)
            {
                int year = RadScheduler1.SelectedDate.Year;
                int month = RadScheduler1.SelectedDate.Month;
                int numberOfDaysInCurrentMonth = DateTime.DaysInMonth(year, month);
                RadScheduler1.SelectedDate = new DateTime(year, month, 1);
                RadScheduler1.TimelineView.NumberOfSlots = numberOfDaysInCurrentMonth;
            }
        }
     
        protected void RadScheduler1_NavigationComplete(object sender, SchedulerNavigationCompleteEventArgs e)
        {
            if (RadScheduler1.SelectedView == SchedulerViewType.TimelineView)
            {
                int year = RadScheduler1.SelectedDate.Year;
                int month = RadScheduler1.SelectedDate.Month;
                int numberOfDaysInCurrentMonth = DateTime.DaysInMonth(year, month);
                RadScheduler1.SelectedDate = new DateTime(year, month, 1);
                RadScheduler1.TimelineView.NumberOfSlots = numberOfDaysInCurrentMonth;
            }
        }
     
        protected void RadScheduler1_TimeSlotCreated(object sender, Telerik.Web.UI.TimeSlotCreatedEventArgs e)
        {
        }
     
        protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
        {
            e.Appointment.BackColor = System.Drawing.Color.FromName("#3d2f2b");
            e.Appointment.ForeColor = System.Drawing.Color.White;
        }
     
        protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
        {
            Appointments.Add(new AppointmentInfo(e.Appointment));
        }
     
        protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
        {
            AppointmentInfo ai = FindById(e.ModifiedAppointment.ID);
            RecurrenceRule rrule;
     
            if (RecurrenceRule.TryParse(e.ModifiedAppointment.RecurrenceRule, out rrule))
            {
                rrule.Range.Start = e.ModifiedAppointment.Start;
                rrule.Range.EventDuration = e.ModifiedAppointment.End - e.ModifiedAppointment.Start;
                TimeSpan startTimeChange = e.ModifiedAppointment.Start - e.Appointment.Start;
                for (int i = 0; i < rrule.Exceptions.Count; i++)
                {
                    rrule.Exceptions[i] = rrule.Exceptions[i].Add(startTimeChange);
                }
                e.ModifiedAppointment.RecurrenceRule = rrule.ToString();
            }
     
            ai.CopyInfo(e.ModifiedAppointment);
        }
     
        private void InitializeResources()
        {
            ResourceType resType = new ResourceType("User");
            resType.ForeignKeyField = "UserID";
     
            RadScheduler1.ResourceTypes.Add(resType);
            RadScheduler1.Resources.Add(new Resource("User", 1, "Test1"));
            RadScheduler1.Resources.Add(new Resource("User", 2, "Test2"));
            RadScheduler1.Resources.Add(new Resource("User", 3, "Test3"));
            RadScheduler1.Resources.Add(new Resource("User", 4, "Test4"));
            RadScheduler1.Resources.Add(new Resource("User", 5, "Test5"));
            RadScheduler1.Resources.Add(new Resource("User", 6, "Test6"));
            RadScheduler1.Resources.Add(new Resource("User", 7, "Test7"));
            RadScheduler1.Resources.Add(new Resource("User", 8, "Test8"));
            RadScheduler1.Resources.Add(new Resource("User", 9, "Test9"));
            RadScheduler1.Resources.Add(new Resource("User", 10, "Test10"));
        }
     
        private void InitializeAppointments()
        {
            DateTime start = DateTime.UtcNow.Date;
            start = start.AddDays(6);
            Appointments.Add(new AppointmentInfo("6", start, start.AddDays(1), string.Empty, null, string.Empty, 1));
            Appointments.Add(new AppointmentInfo("5", start.AddDays(2), start.AddDays(3), string.Empty, null, string.Empty, 2));
     
            start = start.AddDays(-1);
            DateTime dayStart = RadScheduler1.UtcDayStart(start);
            Appointments.Add(new AppointmentInfo("3", dayStart, dayStart.AddDays(1), string.Empty, null, string.Empty, 1));
            Appointments.Add(new AppointmentInfo("2", start.AddDays(2), start.AddDays(3), string.Empty, null, string.Empty, 2));
     
            start = start.AddDays(2);
            Appointments.Add(new AppointmentInfo("8", start.AddDays(2), start.AddDays(4), string.Empty, null, string.Empty, 1));
        }
     
        private AppointmentInfo FindById(object ID)
        {
            foreach (AppointmentInfo ai in Appointments)
            {
                if (ai.ID.Equals(ID))
                {
                    return ai;
                }
            }
     
            return null;
        }
    }
     
    class AppointmentInfo
    {
        private readonly string _id;
        private string _subject;
        private DateTime _start;
        private DateTime _end;
        private string _recurrenceRule;
        private string _recurrenceParentId;
        private string _reminder;
        private int? _userID;
     
        public string ID
        {
            get
            {
                return _id;
            }
        }
     
        public string Subject
        {
            get
            {
                return _subject;
            }
            set
            {
                _subject = value;
            }
        }
     
        public DateTime Start
        {
            get
            {
                return _start;
            }
            set
            {
                _start = value;
            }
        }
     
        public DateTime End
        {
            get
            {
                return _end;
            }
            set
            {
                _end = value;
            }
        }
     
        public string RecurrenceRule
        {
            get
            {
                return _recurrenceRule;
            }
            set
            {
                _recurrenceRule = value;
            }
        }
     
        public string RecurrenceParentID
        {
            get
            {
                return _recurrenceParentId;
            }
            set
            {
                _recurrenceParentId = value;
            }
        }
     
        public int? UserID
        {
            get
            {
                return _userID;
            }
            set
            {
                _userID = value;
            }
        }
     
        public string Reminder
        {
            get
            {
                return _reminder;
            }
            set
            {
                _reminder = value;
            }
        }
     
        private AppointmentInfo()
        {
            _id = Guid.NewGuid().ToString();
        }
     
        public AppointmentInfo(string subject, DateTime start, DateTime end,
            string recurrenceRule, string recurrenceParentID, string reminder, int? userID)
            : this()
        {
            _subject = subject;
            _start = start;
            _end = end;
            _recurrenceRule = recurrenceRule;
            _recurrenceParentId = recurrenceParentID;
            _reminder = reminder;
            _userID = userID;
        }
     
        public AppointmentInfo(Appointment source)
            : this()
        {
            CopyInfo(source);
        }
     
        public void CopyInfo(Appointment source)
        {
            Subject = source.Subject;
            Start = source.Start;
            End = source.End;
            RecurrenceRule = source.RecurrenceRule;
            if (source.RecurrenceParentID != null)
            {
                RecurrenceParentID = source.RecurrenceParentID.ToString();
            }
     
            if (!String.IsNullOrEmpty(Reminder))
            {
                Reminder = source.Reminders[0].ToString();
            }
     
            Resource user = source.Resources.GetResourceByType("User");
            if (user != null)
            {
                UserID = (int?)user.Key;
            }
            else
            {
                UserID = null;
            }
        }
    }
  2. Patrick
    Admin
    Patrick avatar
    209 posts

    Posted 15 Nov 2016 Link to this post

    Hello Meng,

    One approach you can do is to use the AppointmentCancelingEdit Event.  When it fires, use DataBind().
    protected void RadScheduler1_AppointmentCancelingEdit(object sender, AppointmentCancelingEditEventArgs e)
    {
        DataBind();
    }

    This will make sure when you click on the cancel button, AppointmentDataBound() will fire, and your styles will be set.

    For more information, please check out our helpful documentation pertaining to styling your appointments.

    Hope this helps!

    Regards,
    Patrick
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top