Hi. I'm new to this control and VB.NET so please bear with me. Anyway I'd like ask for some ideas on how to do the tasks below. Snippets are welcome.
1. Prevent multi-selection of appointments
- right now the user can multi-select appointments by simultaneously clicking the mouse and holding down the shift key. I'd like to limit it such that there's only one selected appointment at any given time.
2. Detect conflicting appointments
- Before adding a new appointment via the customized dialog box, I'd like to be able to determine if there's already an existing appointment for the given user in the specified StartDateTime/EndDateTime
TIA and more power.
You can use the CalendarInfo_BeforeSelectedAppointmentsChange or CalendarInfo_AfterSelectedAppointmentsChange events to evaluate the number of Appointments in the SelectedAppointments collection.
If you capture this in the "before" event then you can call e.cancel = true to cancel the selection of the newly clicked on appointment, but I suspect it will be better to do this in the "After" event as you can do the following.
Dim apptToAdd As Appointment = Me.CalInfo.SelectedAppointments(Me.CalInfo.SelectedAppointments.Count - 1) Me.CalInfo.SelectedAppointments.Clear() Me.CalInfo.SelectedAppointments.Add(apptToAdd)
You can call CalendarInfo.GetAppointmentsInRange(NewAppointment.StartDateTime, NewAppointment.EndDateTime).Count and retrieve how many appointments are within that time frame.
To check for just a single particular owner, then you can use the overloaded method which accepts an owner
CalendarInfo.GetAppointmentsInRange(NewAppointment.StartDateTime, NewAppointment.EndDateTime, OwnerToCheck).Count
If you call CalInfo.GetAppointmentsInRange(Now, Now).count BEFORE you create a new appointment then obviously if there is 1 already there then you will cause an overlap. If you call it AFTER you add the new appointment then obviously a count = 2 means there is an overlap.
Cheers
Aaron
Note that you can also prevent multi-selection of Appointments by setting the UltraCalendarInfo.SelectTypeActivity property to 'Single'.
I did set the SelectTypeActivity to Single and still let me select more than one appointment at a time.
I could not reproduce the behavior you describe here with any of the controls that display appointments. One possibility is that the UltraCalendarInfo instance on which you set the property is not the same one returned from the control's CalendarInfo property. If this is not the case you should report this as a bug.
I set it at design time so I'm positive I'm doing it on the correct instance so I guess this must be bug.
Also, the GetAppointmentsInRange().Count has some weird issues. Let's say I have Appointment A that goes from 8AM to 9AM and then Appointment B that goes from 10AM to 11AM. If I extend Appointment A up to 10AM such that the bottom of its box is touching the top of the lower box (Appointment B), an overlap is being detected. However if it's the top of the lower box I extend such that it will touch the bottom of the upper box, no overlap is being detected. Kindly try to reproduce this and verify if it's a bug.
You didn't mention what the parameter values were for the GetAppointmentsInRange method, so it is impossible to speculate about what it should be returning. You stated that, "If I extend Appointment A up to 10AM such that the bottom of its box is touching the top of the lower box (Appointment B), an overlap is being detected", but I did not observe any "overlapping" - Appointment A, in this scenario, would have an EndDateTime of exactly 10AM, and Appointment B, unaffected, would still have a StartDateTime of 10AM. If you call GetAppointmentsInRange with a value of 10AM for both the startDateTime and endDateTime parameters, only Appointment B would be included in the returned subset, since Appointment A ends at exactly 10AM and as such has an effective end time of 9:59:59, so does not intersect with 10AM. I saw no difference in behavior when resizing Appointment B either, since the same rules apply. If there is more to this you can repost with additional details and we can try to help.
y2kdis said: Also, the GetAppointmentsInRange().Count has some weird issues. Let's say I have Appointment A that goes from 8AM to 9AM and then Appointment B that goes from 10AM to 11AM. If I extend Appointment A up to 10AM such that the bottom of its box is touching the top of the lower box (Appointment B), an overlap is being detected. However if it's the top of the lower box I extend such that it will touch the bottom of the upper box, no overlap is being detected. Kindly try to reproduce this and verify if it's a bug.
If appointments share a common point in time such as ApptA = 9 -> 10 and ApptB = 10 -> 11 then if you check for appointments in range between 9 & 10 then you should expect and will get 2 appts returned.
You need to check for Appointments with a smaller timespan. For instance you want to do something similar to:
GetAppointmentsInRange(ApptA.StartDateTime, DateAdd(s, -1, ApptA.EndDateTime)
CheersAaron