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

Access context menu items New/Edit appointment

5 Answers 84 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Smiljan
Top achievements
Rank 1
Smiljan asked on 20 Mar 2015, 08:37 AM
Hi!

I modified appointment edit/insert form with my own custom fields.

Now I need to "tap into" New and Edit methods of the Context menu.

I need to add some of my own code (code1) if New appointment is selected AND add my own code (code2) id Edit appointment is selected.
How can I do this? Is there any possibility inside AppointmentEditForm class to differentiate if "New" or "Edit" was selected in context menu prior to openning AppointmentEditForm?

Thank you for any kind of info.

BR, Smiljan

5 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 25 Mar 2015, 07:24 AM
Hello Smiljan,

Thank you for writing.

By design, whether creating a new appointment or editing an existing one the same EditAppointmentDialog gets initialized.

As it is explained in this article the right place to substitute the default EditAppointmentDialog is to handle the AppointmentEditDialogShowing event. Please note that in the handler you receive as an argument an appointment which may be an existing one or a new one. Checking if the appointment is part of the RadScheduler.Appointments collection will tell you if an appointment is about to be edited or created. Having this information you can plug your case specific code before instantiating the editor dialog. You can go even further and create different EditAppointmentDialog elements which may be used in different cases:
private void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
{
    if (this.radScheduler1.Appointments.Contains(e.Appointment))
    {
        //An appointment is about to be edited
    }
    else
    {
        //An appointment is about to be created
    }
}

Shortly, after a new EditAppointmentDialog is initialized, a call to the EditAppointment method is made. You could override it in your implementation of the dialog and follow a similar approach as shown above. Please see my code snippet below:
public override bool EditAppointment(IEvent appointment, ISchedulerData schedulerData)
{
    if ( ((RadScheduler)schedulerData).Appointments.Contains(appointment))
    {
        //An appointment is about to be edited
    }
    else
    {
        //An appointment is about to be created
    }
 
    return base.EditAppointment(appointment, schedulerData);
}

I hope this information helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Smiljan
Top achievements
Rank 1
answered on 25 Mar 2015, 02:15 PM
Great! THANK YOU for this helpful reply.
One more question in this case - I want to transfer a value over to custom inherited class (some public variable definied in the custom inherited class - named "mode"). Now if I define it as "public int mode;" I'm not able to set it's value (access it) inside private void radScheduler1_AppointmentEditDialogShowing(object sender, Telerik.WinControls.UI.AppointmentEditDialogShowingEventArgs e) event.
How can I transfere variable value over to the custom inherited EditForm class?

For example I did change some of the code to accomodate this (please see if my solution is OK. But I think now on SaveChanges application takes about 5-10x more time to save into DB)

// private IEditAppointmentDialog appointmentDialog = null; // original
private AppointmentWithDataEditForm appointmentDialog = null; // my idea of solving this
private void radScheduler1_AppointmentEditDialogShowing(object sender, Telerik.WinControls.UI.AppointmentEditDialogShowingEventArgs e)
{
 if (appointmentDialog == null)
   appointmentDialog = new AppointmentWithDataEditForm(); this.appointmentDialog.mode = 0; // transfer value over to inherited custom EditForm
 e.AppointmentEditDialog = this.appointmentDialog;
}
0
Accepted
Hristo
Telerik team
answered on 30 Mar 2015, 12:04 PM
Hi Smiljan,

Thank you for writing.

Changing the default EditAppointmentDialog should not affect the time for which an appointment is being saved in a database. If you are still experiencing any issue please try and isolate the problem in a separate project and upload it to some free cloud server, e.g. Dropbox. We will be happy to further investigate it.

As to your question about passing data to the CustomAppointmentEditForm you could also achieve it by passing a parameter in the constructor. In this case the initialization of the edit form should look similar to this:
public partial class CustomAppointmentEditForm : EditAppointmentDialog
{
    private int mode;
 
    public CustomAppointmentEditForm()
    {
        InitializeComponent();
    }
 
    public CustomAppointmentEditForm(int mode)
        : this()
    {
        this.mode = mode;
    }
 
   //.............................................
}

I hope this information is useful. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Smiljan
Top achievements
Rank 1
answered on 30 Mar 2015, 12:20 PM
Works like a charm! :)))
Thank you!!!

BR, Smiljan
0
Hristo
Telerik team
answered on 02 Apr 2015, 07:35 AM
Hello,

I am glad that the provided approach worked for your scenario.

Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Scheduler and Reminder
Asked by
Smiljan
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Smiljan
Top achievements
Rank 1
Share this question
or