load appointments and resources with datatable

4 posts, 0 answers
  1. Emmanuel
    Emmanuel avatar
    9 posts
    Member since:
    Sep 2018

    Posted 01 Nov 2019 Link to this post

    Hello,
    I need to load appointment data and resources using datatable, Here I leave the code, the resources are loading, but the appointments are not loading, they help me that I am doing wrong..

          SqlDataAdapter da = new SqlDataAdapter("Select ID, Summary, Start, End, RecurrenceRule,Location,Description, BackgroundId, StatusId From Appointments", DConexion.CnConexion);
                DataTable dtAppointments = new DataTable();
                da.Fill(dtAppointments);

                SqlDataAdapter da1 = new SqlDataAdapter("SELECT IdPerson, Name,  FROM Persons", DConexion.CnConexion);
                DataTable dtResources = new DataTable();
                da1.Fill(dtResources);

                SchedulerBindingDataSource source = new SchedulerBindingDataSource();

                AppointmentMappingInfo appointmentMappingInfo1 = new AppointmentMappingInfo();
                appointmentMappingInfo1.BackgroundId = "BackgroundId";
                appointmentMappingInfo1.Description = "Description";
                appointmentMappingInfo1.End = "End";
                appointmentMappingInfo1.Location = "Location";
                appointmentMappingInfo1.RecurrenceRule = "RecurrenceRule";
                appointmentMappingInfo1.ResourceId = "ResourceID";
                appointmentMappingInfo1.Start = "Start";
                appointmentMappingInfo1.StatusId = "StatusId";
                appointmentMappingInfo1.Summary = "Summary";
                appointmentMappingInfo1.UniqueId = "ID";
                source.EventProvider.Mapping = appointmentMappingInfo1;

                ResourceMappingInfo resourceMappingInfo1 = new ResourceMappingInfo();
                resourceMappingInfo1.Id = "IdPerson";
                resourceMappingInfo1.Name = "Name";
                source.ResourceProvider.Mapping = resourceMappingInfo1;

                source.EventProvider.DataSource = dtAppointments;
                source.ResourceProvider.DataSource = dtResources;

                this.radSchedulerCitas.DataSource = source;

     

    I think I need to relate to the other AppointmentsResources table, if that's how I do it

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 04 Nov 2019 Link to this post

    Hello, Emmanuel,         

    The following help article is quite useful about binding RadScheduler and showing Appointments and Resources from your database. It also shows how to add a relation between the Appointments and AppointmentsResources tables: https://docs.telerik.com/devtools/winforms/controls/scheduler/data-binding/data-binding-walkthrough

    I have attached a sample project for your reference. It also contains a backup file of my local database. It is necessary to restore it on your end and change the connection string in the App.config file in order to point to your server. 

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Emmanuel
    Emmanuel avatar
    9 posts
    Member since:
    Sep 2018

    Posted 04 Nov 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess, the idea is to load the data into DataTable because I don't want to use TableAdapter for the connection, if you can help me do it in DataTable with or without DataSet, I just ask that ...
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 05 Nov 2019 Link to this post

    Hello, Emmanuel, 

    If you use two DataTables for the appointments and resources in RadScheduler, you can add directly a field in the Appointments table for the resource. Please refer to the below code snippet which result is illustrated in the below screenshot. I have also attached a sample project for your reference.

    Note that depending on the field type that stores the ResourceId, you may need to convert it to EventId in order RadScheduler to recognize it: https://docs.telerik.com/devtools/winforms/controls/scheduler/data-binding/scheduler-mapping 

     

            public RadForm1()
            {
                InitializeComponent();
                 
                DataTable events = new DataTable("Events");
                events.Columns.Add("Id", typeof(int));
                events.Columns.Add("Title", typeof(string));
                events.Columns.Add("Start", typeof(DateTime));
                events.Columns.Add("End", typeof(DateTime));
                events.Columns.Add("ResourceId", typeof(int));
                events.Rows.Add(1, "Business Lunch", DateTime.Now, DateTime.Now.AddHours(2), 2);
                events.Rows.Add(2, "Release Meeting", DateTime.Now, DateTime.Now.AddHours(2), 1); 
    
                DataTable resources = new DataTable("Resources");
                resources.Columns.Add("ID", typeof(int));
                resources.Columns.Add("Name", typeof(string));
                resources.Rows.Add(1, "Resource1");
                resources.Rows.Add(2, "Resource2"); 
    
                SchedulerBindingDataSource source = new SchedulerBindingDataSource();
    
                AppointmentMappingInfo appointmentMappingInfo = new AppointmentMappingInfo();
                appointmentMappingInfo.Start = "Start";
                appointmentMappingInfo.End = "End";
                appointmentMappingInfo.Summary = "Title";
                appointmentMappingInfo.ResourceId = "ResourceId";      
                source.EventProvider.Mapping = appointmentMappingInfo;
    
                appointmentMappingInfo.FindBySchedulerProperty("ResourceId").ConvertValueToScheduler += ConvertValueToScheduler;
                appointmentMappingInfo.FindBySchedulerProperty("ResourceId").ConvertValueToDataSource += ConvertValueToDataSource;
     
                ResourceMappingInfo resourceMappingInfo1 = new ResourceMappingInfo();
                resourceMappingInfo1.Id = "Id";
                resourceMappingInfo1.Name = "Name";
                source.ResourceProvider.Mapping = resourceMappingInfo1;
    
                source.EventProvider.DataSource = events;
                source.ResourceProvider.DataSource = resources;
    
                this.radScheduler1.DataSource = source;
                this.radScheduler1.GroupType = GroupType.Resource;
            }
    
            private void ConvertValueToDataSource(object sender, ConvertFromToSchedulerEventArgs e)
            {
                if (e.PropertyName == "ResourceId")
                {
                    e.Value = (int)((EventId)e.Value).KeyValue;
                }
            }
    
            private void ConvertValueToScheduler(object sender, ConvertFromToSchedulerEventArgs e)
            {
                if (e.PropertyName == "ResourceId")
                {
                    e.Value = new EventId((int)e.Value);
                }
            }

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top