Create Dynamic Appointment with spesific Source-Type

3 posts, 1 answers
  1. Abdulaziz
    Abdulaziz avatar
    8 posts
    Member since:
    Jun 2013

    Posted 23 Jun 2014 Link to this post

    I want To Create dynamic Appointment list and  dynamic Source Type in C# for my ScheduleView ,,
    However: I already add dynamic Appointment and Resource with Resource Type ,,

    But when i try to Assign resource-type to the Appointment I cant get it.

       public ObservableCollection<Appointment> Appointments { get; set; }
        public ObservableCollection<ResourceType> ResourceTypes { get; set; }



        private void MakeResources()
            {
                ResourceTypes = new ObservableCollection<ResourceType>();
                ResourceType rt = new ResourceType("Location");
                rt.Resources.Add(new Resource("Hall A", "Location"));
                rt.Resources.Add(new Resource("Hall B", "Location"));
                rt.Resources.Add(new Resource("Hall C", "Location"));
                ResourceTypes.Add(rt);

            TestScheduleView.ResourceTypesSource=ResourceTypes 
             }


       private void MakeAppointments()
            {
                Appointments = new ObservableCollection<Appointment>();
                for ( int i = 0; i < 10; i++)
                {
                    Appointments.Add(new Appointment()
                    {
                        Subject = "Appointment " + i.ToString(),
                        Start = DateTime.Now.AddHours(i),
                        End = DateTime.Now.AddHours(i).AddMinutes(30)

                    });
                }
          AppointmentsSource.Source=Appointments 
            }




    The Appointement List is Appear in ShedulView but How I can add them under The 
    resource Type which I create?

    I try to use
  2. Answer
    Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    135 posts

    Posted 23 Jun 2014 Link to this post

    Hello Abdulaziz,

    You can add a Resource to the appointment before adding it to the Appointments collection. Using your code, here is how to add a resource to a new appointment...

    for (int i = 0; i < 10; i++)
                {
                    //new-up an Appointment object
                    var app = new Appointment()
                    {
                        Subject = "Appointment " + i.ToString(),
                        Start = DateTime.Now.AddHours(i),
                        End = DateTime.Now.AddHours(i).AddMinutes(30),
     
                    };
     
                    //add the Resource to the appointment
                    app.Resources.Add(new Resource("Hall A", "Location"));
     
                    //add the appointment to the ScheduleView
                    this.Appointments.Add(app);
                }


    Note: you don't have to add the ResourceType when initially adding them, so you can shorten your approach to this:

    var rt = new ResourceType("Location");
    rt.Resources.Add(new Resource("Hall A"));
    rt.Resources.Add(new Resource("Hall B"));
    rt.Resources.Add(new Resource("Hall C"));
    this.ResourceTypes.Add(rt);


    I have built a sample application based on your code, find it attached. Go to MainViewModel.cs to see the implementation. I create sample appointments and add them to each Resource (Hall A, Hall B and Hall C). 

    Thank you for contacting Support and thank you for choosing Telerik.

    Regards,
    Lance
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Abdulaziz
    Abdulaziz avatar
    8 posts
    Member since:
    Jun 2013

    Posted 24 Jun 2014 in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Thanks Lance for your quick answer , and It's more Clear in your Example.

Back to Top