how to forbid two appointments at the same time

Hi,


Is it possible to forbid 2 appointments at the same time for the same resource?


Many thanks


Jimmy


3 Replies

VM Vidyalakshmi Mani Syncfusion Team December 14, 2024 01:00 PM UTC

Hi Carpenter,


Thank you for contacting us. To help us assist you more effectively, could you please provide additional details about your requirements and the specific outcome you're hoping to achieve? This will enable us to better understand your needs and offer the most suitable solution.


Regards,

Vidyalakshmi M.




TC the carpenter December 16, 2024 05:41 AM UTC

Hi, 

Here is an example I would like to forbid


Thanks

  scheduler.jpg 




VM Vidyalakshmi Mani Syncfusion Team December 16, 2024 02:19 PM UTC

Hi Carpenter,


To display only non-overlapping appointments in the SfScheduler, you can filter your appointment collection to include only those appointments that do not overlap. Once filtered, you can set this collection as the `ItemsSource` for the scheduler. Here’s an example of how to implement this:  


 

public partial class MainWindow : Window

{

    public MainWindow()

    {

        InitializeComponent();

 

        var appointments = new List<ScheduleAppointment>

        {

            new ScheduleAppointment{StartTime = new DateTime(2024, 12, 16, 9, 0, 0), EndTime = new DateTime(2024, 12, 16, 10, 0, 0), Subject = "Meeting 1"},

            new ScheduleAppointment { StartTime = new DateTime(2024, 12, 16, 9, 30, 0), EndTime = new DateTime(2024, 12, 16, 11, 0, 0), Subject = "Meeting 2" },

            new ScheduleAppointment { StartTime = new DateTime(2024, 12, 16, 11, 0, 0), EndTime = new DateTime(2024, 12, 16, 12, 0, 0), Subject = "Meeting 3" }

 

        };

 

        var filteredAppointments = RemoveOverlappingAppointments(appointments);

 

        this.schedule.ItemsSource = filteredAppointments;

    }

 

 

    private List<ScheduleAppointment> RemoveOverlappingAppointments(List<ScheduleAppointment> appointments)

    {

        var sortedAppointments = appointments.OrderBy(a => a.StartTime).ToList();

           

        var filteredAppointments = new List<ScheduleAppointment>();

           

 

        ScheduleAppointment previous = null;

 

        foreach (var current in sortedAppointments)

        {

            if (previous == null || current.StartTime >= previous.EndTime)

            {

                filteredAppointments.Add(current);

                previous = current;

            }

        }

 

        return filteredAppointments;

    }

 

}

 


We have included a sample that demonstrates this approach for your reference. Please review it and let us know if you have any questions or need further assistance.


Regards,

Vidyalakshmi M.



Attachment: WpfScheduler_a3adcde9.zip

Loader.
Up arrow icon