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

Server-side mehod AppointmentUpdate not always firing

5 Answers 80 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Olof
Top achievements
Rank 1
Olof asked on 29 Dec 2014, 04:33 PM
Hello.
I'm using timelinewiew with resources (people) to develop a planning application. Purpose is to have "events" not assigned to a resource and by moving the event and dropping it on a resource's timeline assign it to that resource. The setup works fine, display of both events and resources works. The events are actually two classes of business objects that both derive from one class that exposes the Appointment attributes (start, end, subject etc.). Both types of events are supplied from database in generic lists. Resources too.

I have implemented the server-side method myScheduler_AppointmentUpdated with logic to update an event if it is dragged from one resource's timeline to another (and then setting the schedulers DataSource to an updated list of events). This seems to work, as at least sometimes when I move an event from one resource to another, the AppointmentUpdate event is fired. But, the event does not fire every time. I have tried to find a pattern for when the event fires and when not, but it seems random.

Not using any client-side stuff at all.

It seems I'm missing something basic here, which is probably correct as I'm a Telerik/scheduler noob :)

Anyone have any ideas?

Attached a screenshot of the timeline layout.
This is my scheduler:
<telerik:RadScheduler ID="schAbsences"
        runat="server"
        HoursPanelTimeFormat="HH:mm"
        SelectedView="TimelineView"
        ShowViewTabs="false"
        ShowResourceHeaders="true"
        TimelineView-EnableExactTimeRendering="true" 
        TimelineView-ShowDateHeaders="true"   
        OnAppointmentDataBound ="schAbsences_AppointmentDataBound"
        OnAppointmentDelete="schAbsences_AppointmentDelete"
        OnAppointmentUpdate="schAbsences_AppointmentUpdate"
        ColumnHeaderDateFormat="h:mm"
        FirstDayOfWeek="Monday"
        LastDayOfWeek="Sunday"
        ShowAllDayRow="true"
        ShowFooter="true"
        OverflowBehavior="Expand"
        OnNavigationComplete="schAbsences_NavigationComplete">
        <TimelineView NumberOfSlots="24" SlotDuration="01:00:00" TimeLabelSpan="1" ColumnHeaderDateFormat="HH:mm tt" />
    </telerik:RadScheduler>
And this is my code-behind:
Resource-types:
ResourceType rt = new ResourceType();
                rt.Name = "Resources";
                rt.ForeignKeyField = "ResourceId";
                rt.KeyField = "Id";
                rt.TextField = "FullName";
                List<Entities.Resource> blapp = new List<Entities.Resource>();
                blapp.AddRange(DBManager.GetExistingResources());
                Entities.Resource r = new Entities.Resource();
                r.firstName = "Inte";
                r.lastName = "tillsatt";
                r.Id = 0;
                blapp.Insert(0, r);
                rt.DataSource = blapp;
                schAbsences.ResourceTypes.Add(rt);
                DateTime startTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                schAbsences.SelectedDate = startTime;
                
                schAbsences.TimelineView.GroupBy = "Resources";
                schAbsences.TimelineView.GroupingDirection = GroupingDirection.Vertical;
AppointmentUpdate-method:
protected void schAbsences_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
        {
            String type = e.Appointment.Attributes["appointmentType"];
            if (type.Equals("Absence"))
            {
                //Do update (use Attributes)
                int origRsId = int.Parse(e.Appointment.Resources[0].Key.ToString());
            }
            else
            {
                int origResId = int.Parse(e.Appointment.Resources[0].Key.ToString());
                int newResId = int.Parse(e.ModifiedAppointment.Resources[0].Key.ToString());
                int appointmentId=int.Parse(e.Appointment.ID.ToString());
                DBManager.UpdateMovedPlacementCompetence(appointmentId, newResId);
                e.Cancel = true;
            }
            List<BDEvent> list = DBManager.GetAllAbsencesAsEvents();
            list.AddRange(DBManager.GetAllPlacementCompetences());
            schAbsences.DataSource = list;
             
        }

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 01 Jan 2015, 12:23 PM
Hello Olof,

In such scenarios when the DataSource property of RadScheduler is used we kindly recommend using the approach described in this help topic and implemented in the Binding to Generic List demo.

I am attaching an isolated page where it is working correctly at my side.

Hope this will help you solve the issue.

Regards,
Plamen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Olof
Top achievements
Rank 1
answered on 02 Jan 2015, 03:34 PM
Thanks for the reply.
I've tried to implement your suggested changes, but I still have the same problem. Strange thing is that I still cannot see any pattern to when the event fires and when it does not. Tested with both debugging mode on local machine and deployed to separate IIS server.
So, now I have:
Property for appointments:
private List<BDEvent> BDEvents
        {
            get
            {
                List<BDEvent> apts = Session[appointmentsKey] as List<BDEvent>;
                if (apts == null)
                {
                    apts = new List<BDEvent>();
                    Session[appointmentsKey] = apts;
                }
                return apts;
            }
        }
In my OnInit:
base.OnInit(e);
            if (!IsPostBack)
            {
                schAbsences.RenderMode = RenderMode.Lightweight;
 
                DateTime startTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                schAbsences.SelectedDate = startTime;
 
                schAbsences.TimelineView.GroupBy = "Resources";
                schAbsences.TimelineView.GroupingDirection = GroupingDirection.Vertical;
 
                Session.Remove(appointmentsKey);
                schAbsences.DataKeyField = "Id";
                schAbsences.DataStartField = "Start";
                schAbsences.DataEndField = "End";
                schAbsences.DataSubjectField = "Subject";
                schAbsences.ItemType = "BDEvent";
                SetupResources();
                SetupEvents();
            }
            schAbsences.DataSource = BDEvents;
SetupEvents:
private void SetupEvents()
        {
            List<BDEvent> list = DBManager.GetAllAbsencesAsEvents();
            list.AddRange(DBManager.GetAllPlacementCompetences(schAbsences.VisibleRangeStart, schAbsences.VisibleRangeEnd));
            BDEvents.AddRange(list);
        }
My AppointmentUpdate method now uses FindById and updates the appointment list in the session, as well as updating the database. Works fine.
The resources generic list is not updated, as it is somewhat static between postbacks.
Debugging suggests that when the update event IS fired, all seems normal, i.e appointment id's are correct and so forth.

Since it seems that this is not a common problem, I cna't quite shake the feeling that I'm missing something basic.
Thanks for the help so far.
0
Plamen
Telerik team
answered on 07 Jan 2015, 06:59 AM
Hello Olof,

Be default the resources that are used in RadScheduler should be static because otherwise there may be some binding errors when adding or updating appointments with missing resource.

I have inspected the code provided and noticed that you are setting Lightweight RenderMode to the RadScheduler. This line is not needed because RadScheduler has only Classic and Mobile rendering mode in the current version. 

I have also noticed that you are grouping by resources with name "Resources"- this may be also causing some confusion somewhere in the scenario.

Hope this information will be helpful.

Regards,
Plamen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Olof
Top achievements
Rank 1
answered on 15 Jan 2015, 02:12 PM
Ok...this is getting stranger..I have now used your example BindToList.zip. I made minimal changes, such as specifying timeline view and setting up resources on the vertical axis (I changed to .net FW 4.5 as well), like I have them in my project.
Guess what? :) Same problem. Moving apppointments vertically works, sometimes (maybe most of the time), but not always (which means that the AppointmentUpdate-event will not fire, as the appointment is not actually moved, I guess).

So, as there is no AppointmentUpdate-method in your example code, the problem might be slightly different i that it is the moving of appointments vertically in timeline view that is not always functioning.

I cannot attach my slightly modified code, so it would be interesting if I could send it some other way so that you could test it.
I have run this code on different machines, same result.

0
Plamen
Telerik team
answered on 20 Jan 2015, 11:12 AM
Hello Olof,

You could submit a support ticket and described the unusual behavior there s owe could inspect it and be more helpful. Please shsre the browser where the issue is reproduced and if you can replicate it on our online demo too.

Regards,
Plamen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Scheduler
Asked by
Olof
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Olof
Top achievements
Rank 1
Share this question
or