Drag Drop Appointment - move an other appoitment too

16 posts, 1 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 07 Dec 2013 Link to this post

    Hi,

    we use the SchduleView to plan our staff. Works great and we are very happy with this control. Now we have this situation:

    Two employees are planed for the same service oder. Now I we change the time for this work by moving the appointment from
    one employee and we want, that the second appointment of the second employee will move too! Is this possible and how do
    we solve this?

    Thanks a lot
    best regards
    Rene
  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 10 Dec 2013 Link to this post

    Hello Rene,

    I assume you are using ScheduleView Resources in order to display the employees. What you can do is to set multiple Resource on a single Appointment by setting the AllowMultipleSelection property of the ResourceType to true. This way the same Appointment will be shown for the both Resources and when you drag one of them, the other will be also dragged.

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 11 Dec 2013 Link to this post

    Hi,

    i tried to set my ResourceType to "AllowMultipleSelection" on true, but without any effects. I have to appointments with the same ResourceType Value "XX". I can see the ResourceType in the apooitnment, but i a drag one the other will not move.

    Is there any simple Exmaple somewhere?

    Thanks
    Rene
  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 11 Dec 2013 Link to this post

    Hello Rene,

    The AllowMultipleSelection property allows multiple Resources to be selected from the drop down in the EditAppointmentDialog. If you are adding the Appointments in the code behind you would just need to add the desired resources to the Appointment. Please check the attached sample project which demonstrates the approach.

    Hope this works for you.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 11 Dec 2013 Link to this post

    Hi,

    i think this is a misunderstanding. In your example you have one appointment which is shown in two groups! I have many different appointments and some of them have the same group like "Room 1". Now i want to drag & drop one appointment from "Room 1" and
    all the other appointments from "Room 1" should be dragged too!

    I have one employee, a car and a mower. My Car and the machine are resources which need to be planned like an employee.
    And if i change the appointment for the employee the appointment for the car and the mower must change too!

    Thanks
    Rene
  7. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 12 Dec 2013 Link to this post

    Hello Rene,

    I'm sorry for the misunderstanding. What you need to do is to override the CoerceDraggedItems in order to select all the Appointments with same resource when start dragging. The method should look like showed below:

    public override IEnumerable<IOccurrence> CoerceDraggedItems(DragDropState state)
    {
        var resource = (state.Appointment as Appointment).Resources.First();
        var allAppointments = state.SourceAppointmentsSource.Cast<IOccurrence>();
        var desiredAppointments = allAppointments.Where(a => (a as Appointment).Resources.Any(r => r == resource));
     
        return desiredAppointments;
    }

    Please try it and let me know if this works for you.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 16 Dec 2013 Link to this post

    Hi,



    I created a public class called "ScheduleViewDragDropBehavior" and I created this:



    <telerik:RadScheduleView.DragDropBehavior>
           <local:ScheduleViewDragDropBehavior />
    </telerik:RadScheduleView.DragDropBehavior>



    Ok works fine, but how do I get the appointmens in desiredAppointments with the same source called "Ursache"?



    And a second question in this case. How do I get ALL dragged appointments in the void

    "void DragDropCompleted(object sender, DragDropCompletedEventArgs e)"



    Thanks a lot

    Best Regards

    Rene


  9. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 17 Dec 2013 Link to this post

    Hi Rene,

    I'm not sure if I'm understanding your first question correctly. The code snippet from my previous post achieves exactly the required functionality - when you move a single Appointment all other Appointments with the same Resource are moving. As for the second question you can easily find the dragged appointments in the DragDropCompleted method in the DragDropState the following way - state.DraggedAppointments.

    I'm attaching a sample project which demonstrates the explained above, please check it and let me know if it helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  10. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 18 Dec 2013 Link to this post

    Hi Kalin,

    this is it!

    But one more question! I use more than one resourceType. In your example the resource is a room and the resourceType
    is location. I use four resourcetyps. How can i select one of them is this case?

    var desiredAppointments = allAppointments.Where(a => (a as Appointment).Resources.Any(r => r == resource));

    Thanks a lot
    Best Regards
    Rene
  11. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 18 Dec 2013 Link to this post

    Hi Kalin,

    just one more question....

    you handle the DragDropCompleted Event in the CustomDragDropBehavior Class. Is it possible to call a void in the MainWindow.cs out of your CustomDragDropBehavior.cs?

    The Problem ist, that i open a EDP-Session to a business-Software (EDP GlobalEDP = new EDP(); GlobalEDP.BeginSession... ). I need the GlobalEDP to write back into the Database.

    Thanks
    Best Regards
    Rene
  12. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 18 Dec 2013 Link to this post

    Hi,

    nearly solved! I use your example to explain the problem:

    XAML
    <Window x:Class="ScheduleViewCustomDragDropBehaviorWPF.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    xmlns:local="clr-namespace:ScheduleViewCustomDragDropBehaviorWPF"
                    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
        <Grid>
            <telerik:RadScheduleView x:Name="ScheduleView" FirstVisibleTime="6:0:0" FirstDayOfWeek="Monday" >          
                <telerik:RadScheduleView.ResourceTypesSource>
                    <telerik:ResourceTypeCollection>
                        <telerik:ResourceType Name="Location">
                            <telerik:Resource ResourceName="Room 1" />
                            <telerik:Resource ResourceName="Room 2" />
                            <telerik:Resource ResourceName="Room 3" />
                        </telerik:ResourceType>
                        <telerik:ResourceType Name="Ursache">
                            <telerik:Resource ResourceName="U 1" />
                            <telerik:Resource ResourceName="U 2" />
                            <telerik:Resource ResourceName="U 3" />
                        </telerik:ResourceType>
                    </telerik:ResourceTypeCollection>
                </telerik:RadScheduleView.ResourceTypesSource>
                 
                <telerik:RadScheduleView.DragDropBehavior>
                    <local:CustomDragDropBehavior />
                </telerik:RadScheduleView.DragDropBehavior>
     
                <telerik:RadScheduleView.ViewDefinitions>
                    <telerik:DayViewDefinition Orientation="Vertical" TimerulerMajorTickStringFormat="{}{00:HH}:{00:mm}" DayStartTime="06:00" DayEndTime="18:00" MinorTickLength="15min"  />
                    <telerik:WeekViewDefinition  Orientation="Horizontal" TimerulerMajorTickStringFormat="{}{00:HH}:{00:mm}" DayStartTime="06:00" DayEndTime="18:00" MinorTickLength="15min" />
                    <telerik:MonthViewDefinition  />
                    <telerik:TimelineViewDefinition TimerulerMajorTickStringFormat="{}{00:HH}:{00:mm}" MinorTickLength="15min" DayStartTime="06:00" DayEndTime="18:00" />
                </telerik:RadScheduleView.ViewDefinitions>
            </telerik:RadScheduleView>
        </Grid>
    </Window>

    MainWindow.xaml.cs:
    private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                ObservableCollection<Appointment> appointments = new ObservableCollection<Appointment>();
     
                Appointment yyy = new Appointment();           
                yyy.Start = Convert.ToDateTime("18.12.2013 14:00:00");
                yyy.End = Convert.ToDateTime("18.12.2013 16:00:00");
                yyy.Subject = "Test";
                yyy.Body = "Body";
                yyy.Resources.Add(new Resource("Room 1", "Location"));
                appointments.Add(yyy);
     
                Appointment zzz = new Appointment();
                zzz.Start = Convert.ToDateTime("18.12.2013 17:00:00");
                zzz.End = Convert.ToDateTime("18.12.2013 18:00:00");
                zzz.Subject = "Test";
                zzz.Body = "Body";
                zzz.Resources.Add(new Resource("Room 1", "Location"));
                appointments.Add(zzz);
     
                this.ScheduleView.AppointmentsSource = appointments;             
            }

    As you can see i create an ObservableColletion of Appointments and i set the ResourceType "Location" to "Room 1". Double Click the Appointment will show me "Room 1". Now i drag one of this Items and the second is "NOT" dragged too!!!!!
    Now i change the Location in Appointment Dialog to "Room 2" in both Appointments and i drag one of them, second "IS" dragged to as expected!

    Where is the problem? I can't attach the zip again sorry?

    Best Rergards
    Rene
  13. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 20 Dec 2013 Link to this post

    Hi,

    no idea? is it a bug?

    thanks
    best regards
    Rene
  14. Answer
    Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 20 Dec 2013 Link to this post

    Hello,

    The reason for this is that you are adding different Resource instances for each of the Appointments. So you could either pass the same instance or can check if the Appointments match by comparing their DisplayName instead of the Resource itself:
    var desiredAppointments = allAppointments.Where(a => (a as Appointment).Resources.Any(r => r.DisplayName == resource.DisplayName));

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  15. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 20 Dec 2013 Link to this post

    Hi,

    i love you guys. Thanks a lot that's it!

    Wish you merry X-Mas and a happy new Year !!!!!!!!

    best regards
    Rene
  16. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 28 Jan 2014 in reply to Kalin Link to this post

    Hi,

    sorry one more question in this case. This works fine:

    var desiredAppointments = allAppointments.Where(a => (a as Appointment).Resources.Any(r => r.DisplayName == resource.DisplayName));

    I must also consider whether the r.DisplayName is not "-"?

    Thanks a lot
    Best Regards
    R
  17. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 31 Jan 2014 Link to this post

    Hi Rene,

    As far I understand your requirement you might need to modify the code the following way:

    var desiredAppointments = Appointments.Where(a => (a as Appointment).Resources.Any(r => !r.DisplayName.Equals("-") && r.DisplayName == resource.DisplayName));

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready