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

load appointments and resources with datatable

3 Answers 361 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Emmanuel
Top achievements
Rank 1
Emmanuel asked on 01 Nov 2019, 03:31 PM

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

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Nov 2019, 12:29 PM

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.
0
Emmanuel
Top achievements
Rank 1
answered on 04 Nov 2019, 03:33 PM
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 ...
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Nov 2019, 08:19 AM

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.
Tags
Scheduler and Reminder
Asked by
Emmanuel
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Emmanuel
Top achievements
Rank 1
Share this question
or