This question is locked. New answers and comments are not allowed.
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.
MainPage.xaml.cs
Method where i am fetching all resources dynamically, let me tell you, below methods fires before above methods.
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 OMMethod 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