ResourceType and dynamical resources

4 posts, 0 answers
  1. Mario
    Mario avatar
    8 posts
    Member since:
    Sep 2011

    Posted 10 Oct 2011 Link to this post

    hello, I need your help

    I am working in lightswicht and I want to use the control ScheduleView.
    I created the table ScheduleViewAppts and one screen where I used the control.
    I want to add relationships to the table and edit this new fiels in the AppointmentEdit window: the fields are Serviçe and Local.
    In my RadScheduleViewControl.xaml I have:


     

    <UserControl x:Class="LightSwitchApplication.RadScheduleViewControl"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400"
        xmlns:schedule="clr-namespace:Telerik.Windows.Controls.ScheduleView;assembly=Telerik.Windows.Controls.ScheduleView"
        xmlns:scheduleView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.ScheduleView">
          
         
        <Grid x:Name="LayoutRoot" Background="White" >
            <telerik:RadScheduleView x:Name="xScheduleView" 
                                     AppointmentCreated="xScheduleView_AppointmentCreated"
                                     AppointmentDeleted="xScheduleView_AppointmentDeleted" 
                                     AppointmentEdited="xScheduleView_AppointmentEdited"  
                                     >
                <telerik:RadScheduleView.ViewDefinitions>
                    <telerik:DayViewDefinition Title="Dia"  
                                               FirstDayOfWeek="Sunday" 
                                               DayStartTime="07:00" 
                                               DayEndTime="20:00" 
                                               CalendarWeekRule="FirstFourDayWeek" />
                    <telerik:WeekViewDefinition Title="Semana"   
                                               FirstDayOfWeek="Sunday" 
                                               DayStartTime="07:00" 
                                               DayEndTime="20:00" 
                                               CalendarWeekRule="FirstFourDayWeek" />
                    <telerik:MonthViewDefinition Title="Mês" 
                                                 FirstDayOfWeek="Sunday" 
                                                 DayStartTime="07:00" 
                                               DayEndTime="20:00" 
                                               CalendarWeekRule="FirstFourDayWeek"/>
                    <telerik:TimelineViewDefinition Title="TimeLine" FirstDayOfWeek="Sunday" 
                                                 DayStartTime="07:00" 
                                               DayEndTime="20:00" 
                                               CalendarWeekRule="FirstFourDayWeek" Orientation="Vertical" />
                      
                </telerik:RadScheduleView.ViewDefinitions>
      
                  
            </telerik:RadScheduleView>
      
        </Grid>
    </UserControl>

     

     

     

     



    In my RadScheduleViewControl.xaml.cs I have:


     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls.ScheduleView;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.ScheduleView.ICalendar;
    using Microsoft.LightSwitch.Presentation;
    using System.Collections.ObjectModel;
      
      
      
    namespace LightSwitchApplication
    {
        public partial class RadScheduleViewControl : UserControl
        {
            public List<Appointment> _CoreAppointments;
            public List<ICategory> categories;
            public List<ITimeMarker> timemarkers;
      
              
            public RadScheduleViewControl()
            {
                InitializeComponent();
                xScheduleView.Loaded += new RoutedEventHandler(xScheduleView_Loaded);
            }
            void xScheduleView_Loaded(object sender, RoutedEventArgs e)
            {
                _CoreAppointments = new List<Appointment>();
      
                categories = new List<ICategory>();
                foreach (ICategory icat in xScheduleView.CategoriesSource)
                {
                    categories.Add(icat);
                }
      
                timemarkers = new List<ITimeMarker>();
                foreach (ITimeMarker marker in xScheduleView.TimeMarkersSource)
                {
                    timemarkers.Add(marker);
                }
      
                var resourceType_Service = new ResourceType("Serviçe");
                for (int i = 0; i < 4; i++)
                {
                    Resource res = new Resource("Serviçe " + i);
                    resourceType_Service.Resources.Add(res);
                }
      
                  
                  
                var resourceType_Local = new ResourceType("Local");
                resourceType_Local.AllowMultipleSelection = false;
      
                for (int i = 0; i < 4; i++)
                {
                    Resource res = new Resource("Local " + i);
                    resourceType_Local.Resources.Add(res);
                }
      
                var resourceTypes = new List<ResourceType>();
                resourceTypes.Add(resourceType_Service);
                resourceTypes.Add(resourceType_Local);
                xScheduleView.ResourceTypesSource = resourceTypes;
                  
                var GroupDescriptions = new GroupDescriptionCollection();
                  
                ResourceGroupDescription serviceGrp = new ResourceGroupDescription();
                serviceGrp.ResourceType = "Serviçe";
                serviceGrp.ShowNullGroup = false;
                GroupDescriptions.Add(serviceGrp);
      
                ResourceGroupDescription locationGrp = new ResourceGroupDescription();
                locationGrp.ResourceType = "Local";
                locationGrp.ShowNullGroup = false;
                GroupDescriptions.Add(locationGrp);
      
                xScheduleView.GroupDescriptionsSource = GroupDescriptions;
      
                  
      
            }

     

    As you can see I added two resourcetype: service and local to the AppointmentEdit window that works fine.
    What I want now is load from the tables Service and Local for the possible resource values.
    I want to change the values Serviçe0, ..., Service 4 and Local0, ..., Local4 for the values that I have in the Servicce and Local Tables.

    How can I do that?
    Any link with something like....
    Thanks.



  2. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 13 Oct 2011 Link to this post

    Hello Mario,

    Firstly you have to add query for the Resources tables into your EditableScheduleViewApptsGrid. After that you can call this query into the xScheduleView_Loaded event and load the desired resources:
    void xScheduleView_Loaded(object sender, RoutedEventArgs e)
      {
          ....
          ....
          var objDataContext = (IContentItem)this.DataContext;
          var Screen = (Microsoft.LightSwitch.Client.IScreenObject)objDataContext.Screen;
     
          Screen.Details.Dispatcher.BeginInvoke(() =>
          {
              var resourceType_Service = new ResourceType("Serviçe");
              var resourceType_Local = new ResourceType("Local");
     
              var serviceResources = (Screen as EditableScheduleViewApptsGrid).ServiceResources.ToList();
          var localResources = (Screen as        EditableScheduleViewApptsGrid).LocalResources.ToList();

              ...
              ...
          }
      }

    Hope this helps.

    Greetings,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Mario
    Mario avatar
    8 posts
    Member since:
    Sep 2011

    Posted 19 Oct 2011 Link to this post

    Hi Ivo,
    Thanks for your help. I already have the resources in my EditAppointment window. My problem now is How to save the appointments and the Local in the tables and how to import the data saved to the Radsheduleview control.
    I have in my code:

    public void GetLSAppointments(List<ScheduleViewAppt> svAppts)
            {
                foreach (ScheduleViewAppt sva in svAppts)
                {
                    Appointment appt = MakeAppointment(sva);
                     _CoreAppointments.Add(appt);
                }
      
                Dispatcher.BeginInvoke(() =>
                {
                    xScheduleView.AppointmentsSource = _CoreAppointments;
                });
      
            }
      
            private Appointment MakeAppointment(ScheduleViewAppt sva)
            {
                Appointment appt = new Appointment();
                appt.Subject = sva.Subject;
                appt.UniqueId = sva.ApptGuid;
                appt.Start = sva.StarDate;
                appt.End = sva.EndDate;
                appt.Body = sva.Description;
                appt.IsAllDayEvent = Convert.ToBoolean(sva.IsAllDay);
                appt.Location = sva.Location;
                appt.Url = sva.URL;
                  
      
                if (sva.Category != null)
                {
                    appt.Category = categories.Where(x => x.CategoryName == sva.Category).SingleOrDefault();
                }
                if (sva.Importance != null)
                {
                    appt.Importance = (Importance)Enum.Parse(typeof(Importance), sva.Importance, true);
                }
                if (sva.TimeMarker != null)
                {
                    appt.TimeMarker = timemarkers.Where(x => x.TimeMarkerName == sva.TimeMarker).SingleOrDefault();
                }
                if (sva.RecurrenceRule != null)
                {
                    RecurrencePattern pattern = new RecurrencePattern();
                    RecurrencePatternHelper.TryParseRecurrencePattern(sva.RecurrenceRule, out pattern);
                    appt.RecurrenceRule = new RecurrenceRule(pattern);
                }
      
      
                if (sva.LOCAL != null)
                {
                    ??????????????????????????????????????????????????????
                }
      
      
                return appt;
            }
             
      
            private void xScheduleView_AppointmentCreated(object sender, Telerik.Windows.Controls.AppointmentCreatedEventArgs e)
            {
                var objDataContext = (IContentItem)this.DataContext;
      
                var Screen = (Microsoft.LightSwitch.Client.IScreenObject)objDataContext.Screen;
      
                Screen.Details.Dispatcher.BeginInvoke(() =>
                {
                    ScheduleViewAppt sva = (Screen as EditableScheduleViewApptsGrid).ScheduleViewAppts.AddNew();
      
                    Appointment appt = e.CreatedAppointment as Appointment;
      
                    UpdateAppointment(sva, appt);
                });
            }
      
            private void xScheduleView_AppointmentDeleted(object sender, Telerik.Windows.Controls.AppointmentDeletedEventArgs e)
            {
                var objDataContext = (IContentItem)this.DataContext;
      
                var Screen = (Microsoft.LightSwitch.Client.IScreenObject)objDataContext.Screen;
      
                Screen.Details.Dispatcher.BeginInvoke(() =>
                {
                    Appointment appt = e.Appointment as Appointment;
      
                    ScheduleViewAppt sva = (Screen as EditableScheduleViewApptsGrid).ScheduleViewAppts.Where(x => x.ApptGuid == appt.UniqueId).SingleOrDefault();
      
                    if (sva != null)
                    {
                        sva.Delete();
                    }
                });
            }
      
            private void xScheduleView_AppointmentEdited(object sender, Telerik.Windows.Controls.AppointmentEditedEventArgs e)
            {
                var objDataContext = (IContentItem)this.DataContext;
      
                var Screen = (Microsoft.LightSwitch.Client.IScreenObject)objDataContext.Screen;
      
                Screen.Details.Dispatcher.BeginInvoke(() =>
                {
                    Appointment appt = e.Appointment as Appointment;
      
                    ScheduleViewAppt sva = (Screen as EditableScheduleViewApptsGrid).ScheduleViewAppts.Where(x => x.ApptGuid == appt.UniqueId).SingleOrDefault();
      
                    if (sva != null)
                    {
                        UpdateAppointment(sva, appt);
                    }
                });
            }
      
            private void UpdateAppointment(ScheduleViewAppt sva, Appointment appt)
            {
                //MessageBox.Show(appt.Resources.Select.ToString());
                sva.Subject = appt.Subject;
                sva.ApptGuid = appt.UniqueId;
                sva.StarDate = appt.Start;
                sva.EndDate = appt.End;
                sva.Description = appt.Body;
                sva.IsAllDay = appt.IsAllDayEvent;
                sva.Location = appt.Location;
                sva.URL = appt.Url;
      
      
                if (appt.Category != null)
                {
                    sva.Category = appt.Category.CategoryName;
                }
      
                if (appt.Importance != null)
                {
                    sva.Importance = appt.Importance.ToString();
                }
      
                if (appt.TimeMarker != null)
                {
                    sva.TimeMarker = appt.TimeMarker.TimeMarkerName;
                }
      
                if (appt.RecurrenceRule != null)
                {
                    sva.RecurrenceRule = RecurrencePatternHelper.RecurrencePatternToString(appt.RecurrenceRule.Pattern);
                }
      
                  
            }

    Where and how can do the save and load the resource information.

    Thanks
  5. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 21 Oct 2011 Link to this post

    Hello Mario,

    You will have to add many to many relationship between Appointment and Resources tables. After that you will have to add some code in UpdateAppointment and CreateAppointment methods. You can find attached a sample example.

    All the best,
    Ivo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package.
    Get it now >>
Back to Top