Wrong appointment deleted if not selected

5 posts, 1 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 25 Aug 2011 Link to this post

    Hi,

    I have created my own factory class based on ISchedulerDialogHostFactory

    I use my own dialogs for edit appointment and delete confirmation dialog.
    In my delete confirmation dialog i display information about the appointment to be deleted.
    I get hold of the appointment by using CurrentAppointment on the ScheduleView control, but that doesn't seem to be all good.

    If I select one appointment by clicking on it, then click the delete button on another appointment, CurrentAppointment is still the first appointment I seletced. So just clicking the delete button will not set it as current.
    How can I tell which appointment I clicked the delete button on?

    Regards,
    Håkan



     


  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 25 Aug 2011 Link to this post

    Hello Håkan,

    I guess that you're using ShowDialog event, you can easily get the appointment that is about to be deleted in its handler like this:

    private void ScheduleView_ShowDialog(object sender, ShowDialogEventArgs e)
    {
        var confirmDialog = e.DialogViewModel as ConfirmDialogViewModel;
        if(confirmDialog != null)
        {
            var apps = confirmDialog.Appointments as IOccurrence[];
        }
    }

    Hope this helps.

    All the best,
    Yana
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft banner
  4. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 01 Sep 2011 Link to this post

    Hi,

    Actually I'm using my own delete dialog so I have a custom SchedulerDialogHostFactory.

    The code looks like this:
    public class TimeScheduleWindowFactory : ISchedulerDialogHostFactory
       {
           public event EventHandler<WindowClosedEventArgs> EditShiftDialog_Closed;
           public event EventHandler<WindowClosedEventArgs> DeleteShiftDialog_Closed;
     
           private int actorCompanyId;
           private TermUtility termUtil;
     
           public TimeScheduleWindowFactory(int actorCompanyId, TermUtility termUtil)
           {
               this.actorCompanyId = actorCompanyId;
               this.termUtil = termUtil;
           }
     
           public ISchedulerDialogHost CreateNew(ScheduleViewBase scheduleView, DialogType dialogType)
           {
               TimeScheduleShift shift = scheduleView.CurrentAppointment as TimeScheduleShift;
     
               switch (dialogType)
               {
                   case DialogType.AppointmentDialog:
                       // Create new AppointmentDialogHost
                       if (shift != null && shift.ActualStart == new DateTime())
                       {
                           shift.ActualStart = shift.Start;
                           shift.ActualEnd = shift.End;
                       }
                       EditShiftDialog editShiftDialog = new EditShiftDialog(termUtil, shift, actorCompanyId);
                       editShiftDialog.ScheduleView = scheduleView;
                       editShiftDialog.Closed += new EventHandler<WindowClosedEventArgs>(AppointmentDialog_Closed);
                       editShiftDialog.Initialize();
                       return editShiftDialog;
                   case DialogType.ConfirmationDialog:
                       // Create new ConfirmationDialogHost
                       if (shift != null)
                       {
                           DeleteShiftDialog deleteShiftDialog = new DeleteShiftDialog(termUtil, shift, actorCompanyId);
                           deleteShiftDialog.ScheduleView = scheduleView;
                           deleteShiftDialog.Closed += new EventHandler<WindowClosedEventArgs>(ConfirmationDialog_Closed);
                           return deleteShiftDialog;
                       }
                       break;
                   case DialogType.RecurrenceChoiceDialog:
                       // Create new RecurrenceChoiceDialogHost
                       //throw new NotImplementedException();
                       break;
                   case DialogType.RecurrenceDialog:
                       // Create new RecurrenceDialogHost
                       //throw new NotImplementedException();
                       break;
                   default:
                       //throw new NotImplementedException();
                       break;
               }
     
               return null;
           }
     
           private void AppointmentDialog_Closed(object sender, WindowClosedEventArgs e)
           {
               if (EditShiftDialog_Closed != null)
                   EditShiftDialog_Closed(sender, e);
           }
     
           private void ConfirmationDialog_Closed(object sender, WindowClosedEventArgs e)
           {
               if (DeleteShiftDialog_Closed != null)
                   DeleteShiftDialog_Closed(sender, e);
           }
       }
  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 02 Sep 2011 Link to this post

    Hello Håkan,

    I'm sorry I missed that.

    The CreateNew method in the SchedulerDialogHostFactory is called too early, that's why you cannot get the appointment which is about to be deleted at this stage.  We're setting the DataContext of the dialog ( which contains all the needed information ) later, still before the dialog is opened.
    I would suggest to subscribe to Loaded event of the dialog and cast its DataContext to ConfirmDialogViewModel, the needed appointment can be reached through its Appointments property.

    Please try it and let us know whether it helps.

    Best wishes,
    Yana
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  6. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 20 Sep 2011 Link to this post

    Thanks Yana, that did the trick!

    Regards,
    Håkan
Back to Top
DevCraft banner