I am sure many of you have faced similar situation. Any help is appreciated. Thanks.
6 Answers, 1 is accepted
You are right - this is a common scenario. We have an online demo which will help you get started:
http://demos.telerik.com/aspnet-ajax/scheduler/examples/optimizedqueries/defaultcs.aspx
Greetings,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Cheers
Jonathan
I've implemented a DBSChedulerProvider class (below) that will be part of a class library (it's not compiled yet so thaere may be a couple of typos). I got all the way thourgh before I got the part that what I actully need to load are apointment filtered by the resource called "ServiceProvider" when viewing the scheduler. I have no idea how to pass this parameter into the GetAppointments function.
Can I use a custom template to insert appointments when using a DBSChedulerProvider?
IS there a way to do this with generic lists and allowing for mutiple resources for clients? most of my class library works with generic lists already so an exampple that uses generic lists, custom templates and muti-valued resources would be helpful as well as the answer to the above question.
Cheers
Jonathan
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Specialized; |
| using System.Configuration.Provider; |
| using System.IO; |
| using System.Xml; |
| using Telerik.Web.UI; |
| namespace FaCTSServer |
| { |
| /// <summary> |
| /// A Class implementing the DBSchedulerProviderBase for use with Telerik Scheduler. |
| /// Author: Jonathan Shaw |
| /// Date Created: 2/2/2010 |
| /// </summary> |
| public class ServiceEventDBSchedulerProvider : DbSchedulerProviderBase |
| { |
| public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner) |
| { |
| ResourceType[] resourceTypes = new ResourceType[6]; |
| resourceTypes[0] = new ResourceType("Program", false); |
| resourceTypes[1] = new ResourceType("Funding Source", false); |
| resourceTypes[2] = new ResourceType("Activity Type", false); |
| resourceTypes[3] = new ResourceType("Location Type", false); |
| resourceTypes[4] = new ResourceType("Service Provider", false); |
| resourceTypes[5] = new ResourceType("Client", true); |
| return resourceTypes; |
| } |
| public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType) |
| { |
| switch (resourceType) |
| { |
| case "Program": |
| return Programs.Values; |
| case "Funding Source": |
| return FundingSources.Values; |
| case "Activity Type": |
| return ActivityTypes.Values; |
| case "Location Type": |
| return LocationTypes.Values; |
| case "Service Provider": |
| return ServiceProviders.Values; |
| case "Client": |
| return Clients.Values; |
| default: |
| throw new InvalidOperationException("Unknown resource type: " + resourceType); |
| } |
| } |
| #region load resources |
| private IDictionary<int, Resource> Programs |
| { |
| get |
| { |
| if (_programs == null) |
| { |
| _programs = new Dictionary<int, Resource>(); |
| foreach (Resource program in LoadPrograms()) |
| { |
| _programs.Add((int)program.Key, program); |
| } |
| } |
| return _programs; |
| } |
| } |
| private IEnumerable<Resource> LoadPrograms() |
| { |
| List<Resource> resources = new List<Resource>(); |
| foreach (Lookup _program in LookupService.GetActive("Program")) |
| { |
| Resource res = new Resource(); |
| res.Type = "Program"; |
| res.Key = _program.ID; |
| res.Text = _program.Name; |
| resources.Add(res); |
| } |
| return resources; |
| } |
| private IDictionary<int, Resource> FundingSources |
| { |
| get |
| { |
| if (_fundingsources == null) |
| { |
| _fundingsources = new Dictionary<int, Resource>(); |
| foreach (Resource fundingsource in LoadfundingSources()) |
| { |
| _fundingsources.Add((int)fundingsource.Key, fundingsource); |
| } |
| } |
| return _fundingsources; |
| } |
| } |
| private IEnumerable<Resource> LoadFundingSources() |
| { |
| List<Resource> resources = new List<Resource>(); |
| foreach (Lookup _fundingSource in LookupService.GetActive("FundingSource")) |
| { |
| Resource res = new Resource(); |
| res.Type = "Funding Source"; |
| res.Key = _fundingSource.ID; |
| res.Text = _fundingSource.Name; |
| resources.Add(res); |
| } |
| return resources; |
| } |
| private IDictionary<int, Resource> ActivityTypes |
| { |
| get |
| { |
| if (_activityTypes == null) |
| { |
| _activityTypes = new Dictionary<int, Resource>(); |
| foreach (Resource activitytype in LoadActivityTypes()) |
| { |
| _activityTypes.Add((int)activitytype.Key, activitytype); |
| } |
| } |
| return _activityTypes; |
| } |
| } |
| private IEnumerable<Resource> LoadActivityTypes() |
| { |
| List<Resource> resources = new List<Resource>(); |
| foreach (Lookup _activityType in LookupService.GetActive("ActivityType")) |
| { |
| Resource res = new Resource(); |
| res.Type = "Activity Type"; |
| res.Key = _activityType.ID; |
| res.Text = _activityType.Name; |
| resources.Add(res); |
| } |
| return resources; |
| } |
| private IDictionary<int, Resource> LocationTypes |
| { |
| get |
| { |
| if (_locationTypes == null) |
| { |
| _locationTypes = new Dictionary<int, Resource>(); |
| foreach (Resource locationType in LoadLocationTypes()) |
| { |
| _locationTypes.Add((int)locationType.Key, locationType); |
| } |
| } |
| return _locationTypes; |
| } |
| } |
| private IEnumerable<Resource> LoadLocationTypes() |
| { |
| List<Resource> resources = new List<Resource>(); |
| foreach (Lookup _locationType in LookupService.GetActive("LocationType")) |
| { |
| Resource res = new Resource(); |
| res.Type = "Location Type"; |
| res.Key = _locationType.ID; |
| res.Text = _locationType.Name; |
| resources.Add(res); |
| } |
| return resources; |
| } |
| private IDictionary<int, Resource> ServiceProviders |
| { |
| get |
| { |
| if (_serviceProviders == null) |
| { |
| _serviceProviders = new Dictionary<int, Resource>(); |
| foreach (Resource serviceProvider in LoadLocationTypes()) |
| { |
| _serviceProviders.Add((int)serviceProvider.Key, serviceProvider); |
| } |
| } |
| return _serviceProviders; |
| } |
| } |
| private IEnumerable<Resource> LoadServicePorviders() |
| { |
| List<Resource> resources = new List<Resource>(); |
| foreach (UserProfile _serviceProvider in UserProfileService.GetServiceProviders()) |
| { |
| Resource res = new Resource(); |
| res.Type = "Service Provider"; |
| res.Key = _serviceProvider.ID; |
| res.Text = _serviceProvider.UserFullName; |
| resources.Add(res); |
| } |
| return resources; |
| } |
| private IDictionary<int, Resource> Clients |
| { |
| get |
| { |
| if (_clients == null) |
| { |
| _clients = new Dictionary<int, Resource>(); |
| foreach (Resource _client in LoadClients()) |
| { |
| _clients.Add((int)client.Key, _client); |
| } |
| } |
| return _clients; |
| } |
| } |
| private IEnumerable<Resource> LoadClients() |
| { |
| //load all clients that are either assigned or open. |
| foreach (Person _client in PersonService.GetFilteredSummary(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, 0, "5,6")) |
| { |
| Resource res = new Resource(); |
| res.Type = "Client"; |
| res.Key = _client.ID; |
| res.Text = _client.NameLast2First; |
| resources.Add(res); |
| } |
| return resources; |
| } |
| #endregion |
| private void LoadResources(Appointment apt) |
| { |
| //get the service event for this apt |
| ServiceEvent _serviceEvent = ServiceEventService.GetByID(new Guid(e.Appointment.ID.ToString())); |
| Resource _program = Programs[Convert.ToInt32(_serviceEvent.ProgramID)]; |
| apt.Resources.Add(_program); |
| Resource _fundingSource = FundingSources[Convert.ToInt32(_serviceEvent.FundingSourceID)]; |
| apt.Resources.Add(_fundingSource); |
| Resource _locationType = LocationTypes[Convert.ToInt32(_serviceEvent.LocationTypeID)]; |
| apt.Resources.Add(_locationType); |
| Resource _activityType = ActivityTypes[Convert.ToInt32(_serviceEvent.ActivityTypeID)]; |
| apt.Resources.Add(_activityType); |
| Resource _serviceProvider = ServiceProviders[Convert.ToInt32(_serviceEvent.ServiceProviderUserProfileID)]; |
| apt.Resources.Add(_serviceProvider); |
| foreach (Person _person in _serviceEvent.getClients(true)) |
| { |
| Resource client = Clients[_person.ID]; |
| apt.Resources.Add(client); |
| } |
| } |
| public override IEnumerable<Appointment> GetAppointments(RadScheduler owner) |
| { |
| List<Appointment> appointments = new List<Appointment>(); |
| //get the service events between the start and end dates of the scheduler - ignore recurring events as we need to report on the events and the billable minutes so each one needs to be unique |
| List<ServiceEvent> _serviceEvents = ServiceEventService.GetSearchResults(" Where (EventDate >= '" + owner.VisibleRangeStart.ToShortDateString() + "' and EventDate <= '" + owner.VisibleRangeEnd.ToShortDateString() + "'"); |
| foreach (ServiceEvent _serviceEvent in _serviceEvents) |
| { |
| Appointment apt = new Appointment(); |
| apt.Owner = owner; |
| apt.ID = _serviceEvent.ID.ToString(); |
| apt.Subject = _serviceEvent.Subject(); |
| apt.Start = _serviceEvent.Start; |
| apt.End = _serviceEvent.End; |
| apt.RecurrenceRule = _serviceEvent.RecurrenceRule; |
| apt.RecurrenceParentID = _serviceEvent.RecurrenceParentID; |
| if (apt.RecurrenceParentID != null) |
| { |
| apt.RecurrenceState = RecurrenceState.Exception; |
| } |
| else if (apt.RecurrenceRule != string.Empty) |
| { |
| apt.RecurrenceState = RecurrenceState.Master; |
| } |
| LoadResources(apt); |
| appointments.Add(apt); |
| } |
| return appointments; |
| } |
| public override void Insert(RadScheduler owner, Appointment appointmentToInsert) |
| { |
| if (!PersistChanges) |
| { |
| return; |
| } |
| ServiceEventService.InsertAppointment(appointmentToInsert); |
| } |
| public override void Update(RadScheduler owner, Appointment appointmenToUpdate) |
| { |
| if (!PersistChanges) |
| { |
| return; |
| } |
| ServiceEventService.UpdateAppointment(appointmenToUpdate); |
| } |
| public override void Delete(RadScheduler owner, Appointment appointmentToDelete) |
| { |
| ServiceEventService.DeleteAppointment(appointmentToDelete); |
| } |
| } |
| } |
On the client side programming I did notice that on get_id() function returns an integer. I just built my datamodel to use a Guid for this ID is it possible to get a string representation of the ID as a guid from the Appointment on the client side. ?
If you use GUID for your appointments' ID, then the get_id() method would return the GUID string. Let us know if you experience different behavior.
Greetings,
Peter
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.