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

Get Resource ID from EventID Key

1 Answer 233 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 19 Jan 2015, 09:10 PM
I am creating radScheduler resources by creating a EventId where the key is an employee number.  Like this:

resource.Id = new EventId([Emp#])

I later need to add an appointment to radScheduler and assign it to the resource who's Id is that of the EventId([Emp#]).

How can I get the ResourceId from the collection where the EventId Key that the resource was created with equals [Emp#]?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 21 Jan 2015, 04:46 PM
Hello Art,

Thank you for writing.

You could iterate the RadScheduler.Resources collection and select the resource which has an Id equal to the searched employee number. 

I have prepared a small example in which I populate sample data and later in the handler of a button Click event add a new appointment to an employee according to its id. Please see my implementation below:
public partial class Form1 : Form
{
    Appointment appointment;
    Random rand;
 
    public Form1()
    {
        InitializeComponent();
 
        DateTime baseDate = DateTime.Today;
        DateTime[] start = new DateTime[] { baseDate.AddHours(14.0), baseDate.AddDays(1.0).AddHours(9.0), baseDate.AddDays(2.0).AddHours(13.0),
            baseDate.AddDays(1.0).AddHours(17.0), baseDate.AddDays(1.0).AddHours(5.0) };
        DateTime[] end = new DateTime[] { baseDate.AddHours(16.0), baseDate.AddDays(1.0).AddHours(15.0), baseDate.AddDays(2.0).AddHours(17.0),
        baseDate.AddDays(1.0).AddHours(21.0), baseDate.AddDays(1.0).AddHours(8.0)};
        string[] summaries = new string[] { "Mr. Brown", "Mr. White", "Mrs. Green", "Ms. Black", "Mrs. Grey" };
        rand = new Random();
 
        Color[] colors = new Color[]
        {
            Color.LightBlue, Color.LightGreen, Color.LightYellow,
            Color.Red, Color.Orange, Color.Pink, Color.Purple, Color.Peru, Color.PowderBlue
        };
 
        string[] names = new string[]
        {
            "Alan Smith", "Anne Dodsworth",
            "Boyan Mastoni", "Richard Duncan", "Maria Shnaider"
        };
 
        for (int i = 0; i < names.Length; i++)
        {
            Resource resource = new Resource();
            resource.Id = new EventId(rand.Next(10000, 20000));
            resource.Name = names[i];
            resource.Color = colors[i];
            this.radScheduler1.Resources.Add(resource);
 
            Console.WriteLine("Name: " + resource.Name + " No.: " + resource.Id);
        }
 
        this.radScheduler1.GetDayView().ResourcesPerView = 5;
        this.radScheduler1.GroupType = GroupType.Resource;
        SchedulerDayViewGroupedByResourceElement headerElement = this.radScheduler1.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement;
        headerElement.ResourceHeaderHeight = 80;
 
        for (int i = 0; i < summaries.Length; i++)
        {
            appointment = new Appointment(start[i], end[i], summaries[i]);
            appointment.ResourceId = this.radScheduler1.Resources[i].Id;
            this.radScheduler1.Appointments.Add(appointment);
        }
    }
 
    private void radButton1_Click(object sender, EventArgs e)
    {
        int employeeId;
        bool isInt = int.TryParse(this.radTextBox1.Text, out employeeId);
 
        if (isInt)
        {
            IResource resource = this.radScheduler1.Resources.Where(r => (int)r.Id.KeyValue == employeeId).FirstOrDefault();
            if (resource != null)
            {
                appointment = new Appointment();
                appointment.ResourceId = resource.Id;
                this.radScheduler1.Appointments.Add(appointment);
            }
        }
    }
}

I am also sending you a .gif file showing how the scheduler behaves on my end.

I hope this information helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Scheduler and Reminder
Asked by
Art
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or