Completed
Last Updated: 17 Jun 2014 10:07 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 29 Nov 2013 02:28
Category: Scheduler/Reminder
Type: Bug Report
1
FIX. RadScheduler AppointmentDropped event is not always fired
Description:
When the appointment is moved (dragged and dropped) from one resource to another resource in Timeline view only, the AppointmentDropped event is not fired. This results in NullReferenceException in Windows 8.

To reproduce:
- add RadScheduler in Timeline view and use the following code:

List<Appointment> appointmentlist = new List<Appointment>();

public Form1()
{
InitializeComponent();

this.radScheduler1.Resources.Add(new Resource { Id = new EventId("1"), Name = "Jack", Visible = true });
this.radScheduler1.Resources.Add(new Resource { Id = new EventId("2"), Name = "John", Visible = true });
this.radScheduler1.Resources.Add(new Resource { Id = new EventId("3"), Name = "John", Visible = true });

this.radScheduler1.GroupType = GroupType.Resource;
this.radScheduler1.GetDayView().DayCount = 1;

Random rand = new Random();
for (int i = 0; i < 20; i++)
{
Appointment appointment = new Appointment(DateTime.Now, TimeSpan.FromMinutes(30), "Summary", "Description");
appointment.StatusId = rand.Next(1, radScheduler1.Statuses.Count);
appointment.BackgroundId = rand.Next(1, radScheduler1.Backgrounds.Count);
appointment.ResourceId = radScheduler1.Resources[rand.Next(0, radScheduler1.Resources.Count)].Id;
appointmentlist.Add(appointment);
}

this.radScheduler1.Appointments.BeginUpdate();
this.radScheduler1.Appointments.AddRange(this.appointmentlist.ToArray());
this.radScheduler1.Appointments.EndUpdate();
this.radScheduler1.AppointmentDropped += radScheduler1_AppointmentDropped;
}

private void radScheduler1_AppointmentDropped(object sender, AppointmentMovedEventArgs e)
{
MessageBox.Show("Dropped");
}

Workaround: use custom DragDropBehavior as follows:
this.radScheduler1.SchedulerElement.DragDropBehavior = new CustomDragDrop(this.radScheduler1.SchedulerElement);


public class CustomDragDrop : AppointmentDraggingBehavior
{
public CustomDragDrop(SchedulerVisualElement activeOwner) : base(activeOwner)
{
}

public override void Drop()
{
DateTime start = this.ActiveFeedback.Scheduler.SystemTimeZone.OffsetTime(this.ActiveFeedback.Appointment.Start, this.ActiveFeedback.View.DefaultTimeZone);
DateTime end = this.ActiveFeedback.Scheduler.SystemTimeZone.OffsetTime(this.ActiveFeedback.Appointment.End, this.ActiveFeedback.View.DefaultTimeZone);

IEvent ev = this.ActiveFeedback.AssociatedAppointment;
bool changeResourceId = (this.Scheduler.GroupType == GroupType.Resource) &&
(this.ActiveFeedback.Appointment.ResourceId != this.ActiveFeedback.AssociatedAppointment.ResourceId ||
this.ActiveFeedback.Appointment.ResourceIds.Count != this.ActiveFeedback.AssociatedAppointment.ResourceIds.Count);

AppointmentMovingEventArgs cancelArgs = (this.Scheduler.GroupType != GroupType.Resource) ? new AppointmentMovingEventArgs(start, ev) :
new AppointmentMovingEventArgs(start, ev, this.ActiveFeedback.Appointment.ResourceId);

this.OnAppointmentDropping(cancelArgs);

this.ActiveOwner.Scheduler.GetType().GetMethod("OnAppointmentDropping", BindingFlags.NonPublic |
BindingFlags.Instance).Invoke(this.ActiveOwner.Scheduler, new object[] { cancelArgs });

if (cancelArgs.Cancel)
{
this.Stop(false);
return;
}

this.ActiveFeedback.Scheduler.Appointments.BeginUpdate();

if (this.ActiveOwner as DayViewAllDayHeader != null && this.ActiveFeedback.Appointment.Duration < new TimeSpan(1, 0, 0, 0))
{
start = this.ActiveFeedback.Appointment.Start.Date;
end = DateHelper.GetEndOfDay(this.ActiveFeedback.Appointment.End);

start = this.ActiveFeedback.Scheduler.SystemTimeZone.OffsetTime(start, this.ActiveFeedback.View.DefaultTimeZone);
end = this.ActiveFeedback.Scheduler.SystemTimeZone.OffsetTime(end, this.ActiveFeedback.View.DefaultTimeZone);
}

this.ActiveFeedback.AssociatedAppointment.Start = start;
this.ActiveFeedback.AssociatedAppointment.End = end;

if (changeResourceId)
{
this.ActiveFeedback.AssociatedAppointment.ResourceId = this.ActiveFeedback.Appointment.ResourceId;
}

RadScheduler scheduler = this.ActiveOwner.Scheduler;
if (scheduler.DataSource != null)
{
scheduler.DataSource.GetEventProvider().Update(this.ActiveFeedback.AssociatedAppointment, "Start");
scheduler.DataSource.GetEventProvider().Update(this.ActiveFeedback.AssociatedAppointment, "End");
scheduler.DataSource.GetEventProvider().Update(this.ActiveFeedback.AssociatedAppointment, "Duration");
if (changeResourceId)
{
scheduler.DataSource.GetEventProvider().Update(this.ActiveFeedback.AssociatedAppointment, "ResourceId");
scheduler.DataSource.GetEventProvider().Update(this.ActiveFeedback.AssociatedAppointment, "ResourceIds");
}
}

while (!this.ActiveFeedback.Scheduler.Appointments.IsUpdated)
this.ActiveFeedback.Scheduler.Appointments.EndUpdate(true);

AppointmentMovedEventArgs args = (this.Scheduler.GroupType != GroupType.Resource) ? new AppointmentMovedEventArgs(start, ev) :
new AppointmentMovedEventArgs(start, ev, this.ActiveFeedback.Appointment.ResourceId);

this.HideFeedbacks();
SchedulerUIHelper.SelectAppointment(this.Scheduler, ev, true, false);

this.OnAppointmentDropped(args);
this.ActiveOwner.Scheduler.GetType().GetMethod("OnAppointmentDropped", BindingFlags.NonPublic |
BindingFlags.Instance).Invoke(this.ActiveOwner.Scheduler, new object[] { args });
}
}
0 comments