Can anyone please give me some help in trying to find a series of "Next Available Appointments"
I want to be able to re-iterate through all the available timeslots for a particular owner in a given date/time range and return an array of available of time slots.
There was an old post in the old forums HERE but I was wondering if there are any other better methods? I am VERY suprised this isn't a built in function (maybe it is but I haven't found it)
It would be great if I could specify the Time required (eg: 30mins or 45mins) and then the function would return an available timeslot(s) that can fit this appointment in.CheersAaron
There is no publicly exposed method that does exactly what you describe here. One of the overloads of the GetAppointmentsInRange method (used in the code sample that you referenced in this post) takes an Owner; you can use that overload to filter out the appointments that are associated with that Owner.
Brian Fallon"]GetAppointmentsInRange method (used in the code sample that you referenced in this post) takes an Owner; you can use that overload to filter out the appointments that are associated with that Owner.
I am having REAL trouble understanding how to do this. I will explain in further detail what I am trying to achieve.
Lets say I have a DayView that has 3 Visible Owners (Adam, Bob, Charlie). I want to find the FIRST Available free TimeSlot for ANY of the owners. It does not matter which owner I just want to ensure that I have the EARLIEST available appointment.
ADAM BOB CHARLIE10AM appt appt appt11AM appt appt appt12AM appt appt appt1PM appt appt2PM appt appt3PM appt appt appt
How can I code an Function which selects the TimeSlot @ 1PM for BOB???
The Code example I referenced in my opening post would find the appointment @ 2PM for ADAM wouldn't it? Because it would search the timeslots from Top to Bottom then Left to Right.(meaning it would parse through all of ADAMs timeslots, then all of BOBs timeslot then finally all of CHARLIES appointments from top to bottom)
Thanks in Advance! :)
In the first post of this thread you stated that you wanted to iterate "...through all the available timeslots for a particular owner". Since you specifically mentioned a "particular" owner, I directed you to the overload that takes an Owner object. From what I understood of your most recent post, it sounds like you want to do just the opposite, and get the appointments in a given date range without regard to which owner is associated with the appointment. If that is the case, simply use the overload that takes only a start and end date.
If i need to re-iterate through the timeslots for each Visible OWNER. I don't know how to do this.
A Timeslot does not have an "Owner" Property
Only thing I can do is.
For each ts as TimeSlot in DayView1.TimeSlots If ts meets criteria then return tsNext
Problem is I don't know who is the owner of the returned TimeSlot.
There is no one-to-one relationship between a TimeSlot and an Owner; there is, however, a one-to-one between a TimeSlotUIElement and an Owner; you can use the GetContext method off TimeSlotUIElement to get a reference to the associated Owner.
I didn't have the time to write code that does exactly what you requested in you previous posts, but hopefully this code sample contains enough information to get you started (see below). It iterates the entire TimeSlots collection and lists the status of each one, returning the ActiveOwner when it has no activity, then searching through the other owners to see if that slot is empty for them.
private void ListEmptyTimeSlots( UltraDayView dayView ){ if ( dayView == null ) throw new ArgumentNullException();
UltraCalendarInfo calendarInfo = dayView.CalendarInfo; if ( calendarInfo == null ) throw new ArgumentNullException();
// First get a list of the visible owners, making sure the specified // owner is the first one in the list. VisibleOwnersCollection visibleOwners = calendarInfo.VisibleOwners; List<Owner> owners = new List<Owner>(visibleOwners.Count); Owner owner = dayView.ActiveOwner; if ( owner != null ) owners.Add( owner );
for ( int i = 0; i < visibleOwners.Count; i ++ ) { if ( visibleOwners == owner ) continue;
owners.Add( visibleOwners ); }
TimeSlotsCollection timeSlots = dayView.TimeSlots; int timeSlotCount = timeSlots.Count; for ( int i = 0; i < timeSlotCount; i ++ ) { TimeSlot ts = this.GetEmptyTimeSlot( DateTime.Today, i, owners, ref owner ); string empty = ts == null ? "full" : "empty"; System.Diagnostics.Debug.WriteLine( string.Format("TimeSlot[{0}] for Owner[{1}] is {2}", i, owner.Key, empty) ); }}
private TimeSlot GetEmptyTimeSlot( DateTime date, int timeSlotIndex, List<Owner> visibleOwners, ref Owner owner ){ UltraCalendarInfo calendarInfo = this.dayView.CalendarInfo;
// Get the time slot duration TimeSpan timeSlotDuration = TimeSpan.FromMinutes( (int)(this.dayView.TimeSlotInterval) );
TimeSlot timeSlot = this.dayView.TimeSlots[timeSlotIndex];
// Get the range of time that reflects the time spanned by the TimeSlot in question DateTime rangeStart = date.Date.Add( timeSlot.StartTime.TimeOfDay ); DateTime rangeEnd = rangeStart.Add( timeSlotDuration.Subtract( TimeSpan.FromSeconds(1) ) );
for ( int currentOwner = 0; currentOwner < visibleOwners.Count; currentOwner ++ ) { Owner thisOwner = visibleOwners[currentOwner];
AppointmentsSubsetCollection appointments = calendarInfo.GetAppointmentsInRange( rangeStart, rangeEnd, thisOwner ); bool hasAppointments = appointments.Count > 0;
if ( hasAppointments ) continue; else { owner = thisOwner; return timeSlot; } }
return null;
}
Thank you thank you thank you... it finally makes sense.
I was thinking that there was a one to one relationship between a timeslot and an owner.
One way of re-iterating through would be to do as you said very early on.
For each owner as Owner in dayview.visibleowners For each timeslot as TimeSlot in dayview.timeslots AppointmentsCollection = dayview.calendarinfo.getAppointmentsinRange(<Range of timeslot> If AppointmentsCollection.count = 0 then Timeslot must be available THEN Store this timeslot away in a collection Move on to Next Owner
Once finished getting earliest available appt for each owner then sort by StartDateTime and return the "earliest' timeslot.
All I need now Brian, is the direct phone number of your office phone
Thanks Again!!