Completed
Last Updated: 21 Oct 2015 12:44 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 13 Oct 2015 12:54
Category: Scheduler/Reminder
Type: Bug Report
0
FIX. RadScheduler - copy/paste a custom appointment does not create the Appointment from the custom class
To reproduce: 

1. Follow the steps for creating custom Appointment as it is demonstrated here: http://www.telerik.com/help/winforms/scheduler-appointments-and-dialogs-adding-a-custom-field-to-the-editappointment-dialog.html
2. Create a new Appointment and press Ctrl+C to copy the selected custom appointment.
3. Press Ctrl+V to paste. You will notice that the pasted appointment is from the default type, not the custom one.

Workaround:

this.radScheduler1.AppointmentsCopying += radScheduler1_AppointmentsCopying;
this.radScheduler1.AppointmentsPasting += radScheduler1_AppointmentsPasting;

private void radScheduler1_AppointmentsCopying(object sender, SchedulerClipboardEventArgs e)
{
    email = ((AppointmentWithEmail)this.radScheduler1.SelectionBehavior.SelectedAppointments.First()).Email;
}

private void radScheduler1_AppointmentsPasting(object sender, SchedulerClipboardEventArgs e)
{
    e.Cancel = true;
    if (e.Format == "ICal")
    {
        DataObject clipboardObject = Clipboard.GetDataObject() as DataObject;
        if (clipboardObject == null)
        {
            return;
        }
        string ical = Convert.ToString(clipboardObject.GetData(RadScheduler.ICalendarDataFormat));
        bool pasteResult = PasteFromICal(ical);
    }
}
 
private bool PasteFromICal(string ical)
{
    SchedulerICalendarImporter importer = new SchedulerICalendarImporter( this.radScheduler1.AppointmentFactory);
    
    SnapshotAppointmentsSchedulerData data = new SnapshotAppointmentsSchedulerData(this.radScheduler1, null);
    importer.Import(data, ical);

    ISchedulerStorage<IEvent> storage = data.GetEventStorage();
    if (storage == null || storage.Count == 0)
    {
        return false;
    }
    IEnumerator<IEvent> enumerator = storage.GetEnumerator();
    enumerator.MoveNext();
    TimeSpan pasteOffset = this.radScheduler1.SelectionBehavior.SelectionStartDate - enumerator.Current.Start;
    enumerator.Dispose();

    foreach (IEvent appointment in storage)
    {
        TimeSpan oldDuration = appointment.Duration;
        appointment.Start = appointment.Start.Add(pasteOffset);
        appointment.Duration = oldDuration;
        appointment.UniqueId = new EventId(Guid.NewGuid());
        ((AppointmentWithEmail)appointment).Email = email;
        if (appointment.RecurrenceRule != null && appointment.Exceptions != null)
        {
            foreach (IEvent exception in appointment.Exceptions)
            {
                oldDuration = exception.Duration;
                exception.Start = exception.Start.Add(pasteOffset);
                exception.Duration = oldDuration;
                exception.UniqueId = new EventId(Guid.NewGuid());
            }
        }

        if (this.radScheduler1.GroupType == GroupType.Resource)
        {
            appointment.ResourceId = this.radScheduler1.SelectionBehavior.SelectedResourceId;
        }
    }

    foreach (IEvent appointment in storage)
    {
        this.radScheduler1.Appointments.Add(appointment);
    }

    return true;
}
0 comments