This is a migrated thread and some comments may be shown as answers.

how can i assign appointment to particular resource dynamically

2 Answers 109 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
palak
Top achievements
Rank 1
palak asked on 10 Jun 2011, 03:30 PM
Dear telerik,

i am stuck with scenario i want to achieve, i hope, u will help me out.

I am loading all appointments dynamically when my scheduleView loading. Then after i create appointments, and update it. Delete it all that. But I am also creating resourcetypes and resources dynamically. So here i am stuck with the scenario , how can i assign dynamic appointments to particular resources which is also dynamically created.

Here is a snipette, pls reply after checking.

ResourceAppointment.cs

 

 

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.ScheduleView;
  
namespace HaiderSchedulerView
{
    public class ResourceAppointment : Appointment
    {
        #region Members & properties
  
        private int _AppointmentId;
          
        public int AppointmentId
        {
            get
            {
                return this.Storage<ResourceAppointment>()._AppointmentId;
            }
            set
            {
                var storage = this.Storage<ResourceAppointment>();
                if (storage._AppointmentId != value)
                {
                    this._AppointmentId = value;
                    this.OnPropertyChanged(() => this.AppointmentId);
                }
            }
        }
  
        #endregion
  
        public override IAppointment Copy()
        {
            var appointment = new ResourceAppointment();
            appointment.CopyFrom(this);
            return appointment;
        }
        public override void CopyFrom(IAppointment other)
        {
             
            var appointment = other as ResourceAppointment;
            if (appointment != null)
            {
                this.AppointmentId = appointment.AppointmentId;
                this.Subject = appointment.Subject;
                this.Start = appointment.Start;
                this.End = appointment.End;
                this.Body = appointment.Body;
            }
             base.CopyFrom(other);
        }
    }
}

MainPage.xaml.cs
#region Sharepoint Client OM
  
        private void Connect()
        {
            // Runs in the UI Thread
            busyIndicator.IsBusy = true;
            lblStatus.Content = "Connecting sharepoint..";
            _Context = new SP.ClientContext
            (SP.ApplicationContext.Current.Url);
            //_Context = new SP.ClientContext("http://rxdotnet4");
            _Context.Load(_Context.Web);
            //_Context.Load(_Context.Web, website => website.Title);
            _Context.ExecuteQueryAsync(OnConnectSucceeded, OnConnectFailed);
        }
        private void OnConnectSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
        {
            // This callback isn't called on the UI thread
            Dispatcher.BeginInvoke(ConnectLists);
        }
        private void OnConnectFailed(object sender, ClientRequestFailedEventArgs args)
        {
            // This callback isn't called on the UI thread
            // Invoke a delegate and send the args instance as a parameter
            Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
        }
  
        private void ConnectLists()
        {
            // Runs in the UI Thread
            lblStatus.Content = "Web Connected. Connecting to Lists...";
            _Context.Load(_Context.Web.Lists, l => l.Include(i => i.Title, i => i.Hidden));
            _Context.ExecuteQueryAsync(OnConnectListsSucceeded, OnConnectListsFailed);
        }
        private void OnConnectListsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
        {
            // This callback isn't called on the UI thread
            Dispatcher.BeginInvoke(GetListData);
        }
        private void OnConnectListsFailed(object sender, ClientRequestFailedEventArgs args)
        {
            // This callback isn't called on the UI thread
            // Invoke a delegate and send the args instance as a parameter
            Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
        }
  
        private void GetListData()
        {
            // Runs in the UI Thread
            lblStatus.Content = "Getting Calendar List data...";
            // Events2011 is the list of events in sp2010 calendar view
            _ResourceAppointment = _Context.Web.Lists.GetByTitle("Events2011");
            _Context.Load(_ResourceAppointment);
            _Context.Load(_ResourceAppointment.RootFolder);
            _Context.ExecuteQueryAsync(OnGetListDataSucceeded, OnGetListDataFailed);
        }
        private void OnGetListDataSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
        {
            // This callback isn't called on the UI thread
            Dispatcher.BeginInvoke(LoadItems);
        }
        private void OnGetListDataFailed(object sender, ClientRequestFailedEventArgs args)
        {
            // This callback isn't called on the UI thread
            // Invoke a delegate and send the args instance as a parameter
            Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
        }
  
        private void LoadItems()
        {
            // Runs in the UI Thread
            lblStatus.Content = String.Format("Loading {0} events...",
            _ResourceAppointment.RootFolder.ItemCount);
            var camlQuery = new SP.CamlQuery();
            camlQuery.ViewXml = "<View/>";
            _ResourceAppointmentItemCol = _ResourceAppointment.GetItems(camlQuery);
            _Context.Load(_ResourceAppointmentItemCol);
            _Context.ExecuteQueryAsync(OnLoadItemsSucceeded, OnLoadItemsFailed);
        }
        private void OnLoadItemsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
        {
            // This callback isn't called on the UI thread
            Dispatcher.BeginInvoke(ShowItems);
        }
        private void OnLoadItemsFailed(object sender, ClientRequestFailedEventArgs args)
        {
            // This callback isn't called on the UI thread
            // Invoke a delegate and send the args instance as a parameter
            Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
        }
  
        private void ShowItems()
        {
            // Runs in the UI Thread
            lblStatus.Content = "Showing events...";
            _ResourceAppointmentList = new List<ResourceAppointment>();
  
            // This is the place where i am assigning listitem values to my appointment, but i am not able to assign values to resources so that it shows in scheduleview at particular resource group
  
            foreach (SP.ListItem listItem in _ResourceAppointmentItemCol)
            {                
                _ResourceAppointmentList.Add(
                new ResourceAppointment()
                {
                    AppointmentId = Convert.ToInt32(listItem["ID"]),
                    Subject = listItem["Title"].ToString(),
                    Body = listItem["Description"].ToString(),
                    Start = Convert.ToDateTime(listItem["EventDate"]).ToLocalTime(),
                    End = Convert.ToDateTime(listItem["EndDate"]).ToLocalTime()
                     
                });
            }
            //SchedulerView.AppointmentsSource = null;
            SchedulerView.AppointmentsSource = _ResourceAppointmentList;
            _Context.ExecuteQueryAsync(OnShowItemsSucceeded, OnShowItemsFailed);
        }
        private void OnShowItemsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
        {
            // This callback isn't called on the UI thread
            Dispatcher.BeginInvoke(ShowItemsDone);
        }
        private void OnShowItemsFailed(object sender, ClientRequestFailedEventArgs args)
        {
            // This callback isn't called on the UI thread
            // Invoke a delegate and send the args instance as a parameter
            Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
        }
  
        private void ShowItemsDone()
        {
            // Runs in the UI Thread
            //MessageBox.Show("WebPart Successfully synchronized with sharepoint calendar list.", "Information", MessageBoxButton.OK);
            lblStatus.Content = "Synchronization with sharepoint done.";
            busyIndicator.IsBusy = false;
            this.ResetTemplate();
        }
  
        #endregion Sharepoint Client OM

Method where i am fetching all resources dynamically, let me tell you, below methods fires before above methods.
#region Rooms
      private void ConnectRooms()
      {
          // Runs in the UI Thread
          busyIndicator.IsBusy = true;
          lblStatus.Content = "Connecting sharepoint..";
          _Context = new SP.ClientContext
          (SP.ApplicationContext.Current.Url);
          //_Context = new SP.ClientContext("http://rxdotnet4");
          _Context.Load(_Context.Web);
          //_Context.Load(_Context.Web, website => website.Title);
          _Context.ExecuteQueryAsync(OnConnectRoomsSucceeded, OnConnectRoomsFailed);
      }
      private void OnConnectRoomsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(ConnectRoomLists);
      }
      private void OnConnectRoomsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void ConnectRoomLists()
      {
          // Runs in the UI Thread
          lblStatus.Content = "Web Connected. Connecting to Lists...";
          _Context.Load(_Context.Web.Lists, l => l.Include(i => i.Title, i => i.Hidden));
          _Context.ExecuteQueryAsync(OnConnectRoomListsSucceeded, OnConnectRoomListsFailed);
      }
      private void OnConnectRoomListsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(GetRoomListData);
      }
      private void OnConnectRoomListsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void GetRoomListData()
      {
          // Runs in the UI Thread
          lblStatus.Content = "Getting Rooms...";
          // Rooms is the separate list in sharepoint 2010 linked with calendar list
          _Roomlist = _Context.Web.Lists.GetByTitle("Rooms");
          _Context.Load(_Roomlist);
          _Context.Load(_Roomlist.RootFolder);
          _Context.ExecuteQueryAsync(OnGetRoomListDataSucceeded, OnGetRoomListDataFailed);
      }
      private void OnGetRoomListDataSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(LoadRoomItems);
      }
      private void OnGetRoomListDataFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void LoadRoomItems()
      {
          // Runs in the UI Thread
          lblStatus.Content = String.Format("Loading {0} rooms...",
          _Roomlist.RootFolder.ItemCount);
          var camlQuery = new SP.CamlQuery();
          camlQuery.ViewXml = "<View/>";
          _RoomItemCol = _Roomlist.GetItems(camlQuery);
          _Context.Load(_RoomItemCol);
          _Context.ExecuteQueryAsync(OnLoadRoomItemsSucceeded, OnLoadRoomItemsFailed);
      }
      private void OnLoadRoomItemsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(ShowRoomItems);
      }
      private void OnLoadRoomItemsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void ShowRoomItems()
      {
          // Runs in the UI Thread
          lblStatus.Content = "Showing Rooms...";
          //var resourceType = new ResourceType("Rooms");
          resourceType = new ResourceType("Rooms");
          resourceType.DisplayName = "Rooms";
          resourceType.Name = "Rooms";
          foreach (SP.ListItem listItem in _RoomItemCol)
          {
              //Below code to prevent adding duplicate Rooms in scheduleview
              if (resourceType.Resources.Where(r => listItem["Title"].ToString() == r.ResourceName).Count() == 0)
              {
                  resourceType.Resources.Add(new Resource(listItem["Title"].ToString()));
              }
          }
          resourceTypes = new List<ResourceType>();
          resourceTypes.Add(resourceType);
          SchedulerView.ResourceTypesSource = resourceTypes;
          _Context.ExecuteQueryAsync(OnShowRoomItemsSucceeded, OnShowRoomItemsFailed);
      }
      private void OnShowRoomItemsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(ShowRoomItemsDone);
      }
      private void OnShowRoomItemsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void ShowRoomItemsDone()
      {
          // Runs in the UI Thread
          busyIndicator.IsBusy = false;
          lblStatus.Content = "Rooms loaded successfully.";
          this.ResetTemplate();
          ConnectResources();
      }
      #endregion
      #region Resources
      private void ConnectResources()
      {
          // Runs in the UI Thread
          busyIndicator.IsBusy = true;
          lblStatus.Content = "Connecting sharepoint..";
          _Context = new SP.ClientContext
          (SP.ApplicationContext.Current.Url);
          //_Context = new SP.ClientContext("http://rxdotnet4");
          _Context.Load(_Context.Web);
          //_Context.Load(_Context.Web, website => website.Title);
          _Context.ExecuteQueryAsync(OnConnectResourcesSucceeded, OnConnectResourcesFailed);
      }
      private void OnConnectResourcesSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(ConnectResourcesLists);
      }
      private void OnConnectResourcesFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void ConnectResourcesLists()
      {
          // Runs in the UI Thread
          lblStatus.Content = "Web Connected. Connecting to Lists...";
          _Context.Load(_Context.Web.Lists, l => l.Include(i => i.Title, i => i.Hidden));
          _Context.ExecuteQueryAsync(OnConnectResourcesListsSucceeded, OnConnectResourcesListsFailed);
      }
      private void OnConnectResourcesListsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(GetResourcesListData);
      }
      private void OnConnectResourcesListsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void GetResourcesListData()
      {
          // Runs in the UI Thread
          lblStatus.Content = "Getting Resources...";
          // Resources is the separate list in sharepoint 2010 linked with calendar list
          _ResourcesList = _Context.Web.Lists.GetByTitle("Resources");
          _Context.Load(_ResourcesList);
          _Context.Load(_ResourcesList.RootFolder);
          _Context.ExecuteQueryAsync(OnGetResourcesListDataSucceeded, OnGetResourcesListDataFailed);
      }
      private void OnGetResourcesListDataSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(LoadResourcesItems);
      }
      private void OnGetResourcesListDataFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void LoadResourcesItems()
      {
          // Runs in the UI Thread
          lblStatus.Content = String.Format("Loading {0} resources...",
          _ResourcesList.RootFolder.ItemCount);
          var camlQuery = new SP.CamlQuery();
          camlQuery.ViewXml = "<View/>";
          _ResourcesItemCol = _ResourcesList.GetItems(camlQuery);
          _Context.Load(_ResourcesItemCol);
          _Context.ExecuteQueryAsync(OnLoadResourcesItemsSucceeded, OnLoadResourcesItemsFailed);
      }
      private void OnLoadResourcesItemsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(ShowResourceItems);
      }
      private void OnLoadResourcesItemsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void ShowResourceItems()
      {
          // Runs in the UI Thread
          lblStatus.Content = "Showing Resources...";
          //var resourceType = new ResourceType("Resources");
          resourceType = new ResourceType("Resources");
          resourceType.DisplayName = "Resources";
          resourceType.Name = "Resources";
          foreach (SP.ListItem listItem in _ResourcesItemCol)
          {
              //Below code to prevent adding duplicate Rooms in scheduleview
              if (resourceType.Resources.Where(r => listItem["Title"].ToString() == r.ResourceName).Count() == 0)
              {
                  resourceType.Resources.Add(new Resource(listItem["Title"].ToString()));
              }
          }
          resourceTypes.Add(resourceType);
          SchedulerView.ResourceTypesSource = resourceTypes;
          _Context.ExecuteQueryAsync(OnShowResourcesItemsSucceeded, OnShowResourcesItemsFailed);
      }
      private void OnShowResourcesItemsSucceeded(Object sender, SP.ClientRequestSucceededEventArgs args)
      {
          // This callback isn't called on the UI thread
          Dispatcher.BeginInvoke(ShowResourcesItemsDone);
      }
      private void OnShowResourcesItemsFailed(object sender, ClientRequestFailedEventArgs args)
      {
          // This callback isn't called on the UI thread
          // Invoke a delegate and send the args instance as a parameter
          Dispatcher.BeginInvoke(() => ShowErrorInformation(args));
      }
      private void ShowResourcesItemsDone()
      {
          // Runs in the UI Thread
          busyIndicator.IsBusy = false;
          lblStatus.Content = "Resources loaded successfully.";
          this.ResetTemplate();
          Connect();
      }
      #endregion

2 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 16 Jun 2011, 02:19 PM
Hello,

In general you would have a table in your database that links appointments and resources in some way. When you load that data dynamically you should create the appointments and resources and than for every appointment add the resources that this appoinment belongs to in the appointment's Resources collection. It is more like the resources belong to the appointment instead and not the other way around appointments in resources.

Greetings,
Pana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
palak
Top achievements
Rank 1
answered on 17 Jun 2011, 06:16 AM

Hey pana,

thanks for the response. actually you might have seen my code as i am working with sharepoint API, not with any database. due to that limitation, i was stuck, but now i resolved this problem by implementing some code. Also i'll look forward from telerik to release products for sharepoint 2010. latest telerik sharepoint kit ajax webparts stuck with sharepoint 2010 so i am not going to use it. silverlight webpart seems very limited in customizations.
        

foreach (Telerik.Windows.Controls.Resource resource in roomsResourceType.Resources)
{
          if (roomLookUp.LookupValue == resource.ResourceName)
          newApp.Resources.Add(resource);

}
thanks
Tags
ScheduleView
Asked by
palak
Top achievements
Rank 1
Answers by
Pana
Telerik team
palak
Top achievements
Rank 1
Share this question
or