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

[Solved] Adding a Resource Programatically

4 Answers 393 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
JK
Top achievements
Rank 1
JK asked on 04 Oct 2007, 05:28 AM
Hi,

How do you you insert a new resource to a appointment programatically?  I have teh employee in a drop down list and want to obtain that value and put it into a new appoitnment.  I can see there are two possible options (appointment.owner or appointment.resources) I have tried both to no avail.  Below is a snippet of my code which I hope will put my question into context.
Telerik.Web.UI.Appointment appointment = new Telerik.Web.UI.Appointment();  
appointment.Start = DateTime.Parse(starttime.ToString());  
appointment.End = DateTime.Parse(endtime.ToString());  
appointment.Subject = Reg.Text + strCRLF.ToString() + jobtype.SelectedItem.ToString() + strCRLF.ToString() + "Employee:" + employee.SelectedItem.ToString();  
Scheduler.InsertAppointment(appointment); 
Thanks,

JK

4 Answers, 1 is accepted

Sort by
0
Dimitar Milushev
Telerik team
answered on 04 Oct 2007, 04:09 PM
Hi,

If everything is set up properly, calling 'appointment.Resources.Add(employee.SelectedItem.ToString());', before inserting the appointment, should do the job. Did you try this:

Telerik.Web.UI.Appointment appointment = new Telerik.Web.UI.Appointment();     
appointment.Start = DateTime.Parse(starttime.ToString());     
appointment.End = DateTime.Parse(endtime.ToString());     
appointment.Subject = Reg.Text + strCRLF.ToString() + jobtype.SelectedItem.ToString() + strCRLF.ToString() + "Employee:" + employee.SelectedItem.ToString();  
appointment.Resources.Add(employee.SelectedItem.ToString());  
Scheduler.InsertAppointment(appointment); 


Sincerely yours,
Dimitar Milushev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JK
Top achievements
Rank 1
answered on 04 Oct 2007, 04:41 PM
Yep,

Did that.  I placed my code in the from creating event and it failed with the following message:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'Telerik.Web.StronglyTypedStateManagedCollection<Telerik.Web.UI.Resource>.Add(Telerik.Web.UI.Resource)' has some invalid arguments

Source Error:


Line 202:            appointment.End = DateTime.Parse(endtime.ToString());
Line 203:            appointment.Subject = Reg.Text + strCRLF.ToString() + jobtype.SelectedItem.ToString() + strCRLF.ToString() + "Employee:" + employee.SelectedItem.ToString();
Line 204:            appointment.Resources.Add(employee.SelectedItem.ToString());  
Line 205:            Scheduler.InsertAppointment(appointment);
Line 206:        }

Thanks,

Jon
0
Dimitar Milushev
Telerik team
answered on 05 Oct 2007, 03:06 PM
Hello,

Unless you have a separate table in your data source (I'm assuming SQL or similar here) for a specific Resource type, I believe it would be better to use Appointments' Custom Attributes.

For example, if you have a column 'Employee' in the table that holds your appointments you can make the Scheduler to load the data from this column by setting the CustomAttributeNames="Employee" property of the Scheduler (it's a comma separated value). The Scheduler will read the value in the 'Employee' column for each appointment and put it in the Appointment.Attributes collection of the corresponding appointment. You can  later access it or modify it by using Appointment.Attributes["Employee"].

If you want to set the 'Employee' attribute of an appointment that is being inserted, you can use an AppointmentInsert event handler similar to this:

void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)  
{  
    e.Appointment.Attributes["Employee"] = "James";  

Of course, this handler will set the same 'Employee' to all newly inserted appointments, so you will probably need to get the value from some other place (e.g. a dropdown in your case).

This is the simplest approach for this kind of problem, but it requires that you have a column for the custom attribute in the same table that appointment data resides. Let us know if that is not your case and you need 'resources' to be  loaded from a separate table / datasource.

Kind regards,
James
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JK
Top achievements
Rank 1
answered on 18 Oct 2007, 03:07 PM
James,

Sorry for the delay in replying.  Thanks for the feedback,  your suggestion of using attributes was the right thing to do. 

Thanks again!

JK
Tags
Scheduler
Asked by
JK
Top achievements
Rank 1
Answers by
Dimitar Milushev
Telerik team
JK
Top achievements
Rank 1
Share this question
or