Brian Lehmann
Top achievements
Rank 2
Brian Lehmann
asked on 23 Feb 2008, 05:57 PM
Is there a straightforward way to return custom attibute fields when using a custom Scheduler Provider? We've written a provider that leverages an existing data architecture but we also need to take advantage of custom attributes. The provider architecture seems to use only Appointment objects and there doesn't seem to be any way to add arbitrary information to that object.
These two approaches may not be intended to be used together, but I thought I would check before abandoning this approach for another . . .
Thanks in advance!
brian
These two approaches may not be intended to be used together, but I thought I would check before abandoning this approach for another . . .
Thanks in advance!
brian
11 Answers, 1 is accepted
0
Hello Brian,
RadScheduler supports using custom attributes with custom providers. For example, I modified the MyDbSchedulerProvider.cs file and the online example and found that everything works as expected. Here are the changes I did to test the case:
All changes in the custom provider contain the word "CustomAttribute" so it should be easy for your to track them.
I hope you find this helpful.
Regards,
Peter
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
RadScheduler supports using custom attributes with custom providers. For example, I modified the MyDbSchedulerProvider.cs file and the online example and found that everything works as expected. Here are the changes I did to test the case:
<telerik:RadScheduler ID="RadScheduler1" CustomAttributeNames="CustomAttribute" |
All changes in the custom provider contain the word "CustomAttribute" so it should be easy for your to track them.
public class MyDbSchedulerProvider : DbSchedulerProviderBase |
{ |
public override IEnumerable<Appointment> GetAppointments(RadScheduler owner) |
{ |
List<Appointment> appointments = new List<Appointment>(); |
using (DbConnection conn = OpenConnection()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId], [CustomAttribute] FROM [DbProvider_Classes]"; |
using (DbDataReader reader = cmd.ExecuteReader()) |
{ |
while (reader.Read()) |
{ |
Appointment apt = new Appointment(); |
apt.Owner = owner; |
apt.ID = reader["ClassID"]; |
apt.Subject = Convert.ToString(reader["Subject"]); |
apt.Attributes["CustomAttribute"] = Convert.ToString( reader["CustomAttribute"]); |
apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader["Start"]), DateTimeKind.Utc); |
apt.End = DateTime.SpecifyKind(Convert.ToDateTime(reader["End"]), DateTimeKind.Utc); |
apt.RecurrenceRule = Convert.ToString(reader["RecurrenceRule"]); |
apt.RecurrenceParentID = reader["RecurrenceParentId"] == DBNull.Value ? null : reader["RecurrenceParentId"]; |
if (apt.RecurrenceParentID != null) |
{ |
apt.RecurrenceState = RecurrenceState.Exception; |
} |
else |
if (apt.RecurrenceRule != string.Empty) |
{ |
apt.RecurrenceState = RecurrenceState.Master; |
} |
LoadResources(apt); |
appointments.Add(apt); |
} |
} |
} |
return appointments; |
} |
public override void Insert(RadScheduler owner, Appointment appointmentToInsert) |
{ |
if (!PersistChanges) |
{ |
return; |
} |
using (DbConnection conn = OpenConnection()) |
{ |
using (DbTransaction tran = conn.BeginTransaction()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
cmd.Transaction = tran; |
PopulateAppointmentParameters(cmd, appointmentToInsert); |
cmd.CommandText = |
@" INSERT INTO [DbProvider_Classes] |
([Subject], [Start], [End], [CustomAttribute], [TeacherID], |
[RecurrenceRule], [RecurrenceParentID]) |
VALUES (@Subject, @Start, @End, @CustomAttribute, @TeacherID, |
@RecurrenceRule, @RecurrenceParentID)"; |
if (DbFactory is SqlClientFactory) |
{ |
cmd.CommandText += Environment.NewLine + "SELECT SCOPE_IDENTITY()"; |
} |
else |
{ |
cmd.ExecuteNonQuery(); |
cmd.CommandText = "SELECT @@IDENTITY"; |
} |
int identity = Convert.ToInt32(cmd.ExecuteScalar()); |
FillClassStudents(appointmentToInsert, cmd, identity); |
tran.Commit(); |
} |
} |
} |
public override void Update(RadScheduler owner, Appointment appointmentToUpdate) |
{ |
string oldSubject = appointmentToUpdate.Attributes["Old_Subject"]; |
if (!PersistChanges) |
{ |
return; |
} |
using (DbConnection conn = OpenConnection()) |
{ |
using (DbTransaction tran = conn.BeginTransaction()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
cmd.Transaction = tran; |
PopulateAppointmentParameters(cmd, appointmentToUpdate); |
cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToUpdate.ID)); |
cmd.CommandText = "UPDATE [DbProvider_Classes] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [CustomAttribute] = @CustomAttribute, [TeacherID] = @TeacherID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID WHERE [ClassID] = @ClassID"; |
cmd.ExecuteNonQuery(); |
ClearClassStudents(appointmentToUpdate.ID, cmd); |
FillClassStudents(appointmentToUpdate, cmd, appointmentToUpdate.ID); |
tran.Commit(); |
} |
} |
} |
public override void Delete(RadScheduler owner, Appointment appointmentToDelete) |
{ |
if (!PersistChanges) |
{ |
return; |
} |
using (DbConnection conn = OpenConnection()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
using (DbTransaction tran = conn.BeginTransaction()) |
{ |
cmd.Transaction = tran; |
ClearClassStudents(appointmentToDelete.ID, cmd); |
cmd.Parameters.Clear(); |
cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToDelete.ID)); |
cmd.CommandText = "DELETE FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID"; |
cmd.ExecuteNonQuery(); |
tran.Commit(); |
} |
} |
} |
public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner) |
{ |
ResourceType[] resourceTypes = new ResourceType[2]; |
resourceTypes[0] = new ResourceType("Teacher", false); |
resourceTypes[1] = new ResourceType("Student", true); |
return resourceTypes; |
} |
public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType) |
{ |
switch (resourceType) |
{ |
case "Teacher": |
return GetTeachers(); |
case "Student": |
return GetStudents(); |
default: |
throw new InvalidOperationException("Unknown resource type: " + resourceType); |
} |
} |
private void LoadResources(Appointment apt) |
{ |
using (DbConnection conn = OpenConnection()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID)); |
cmd.CommandText = "SELECT [TeacherID] FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID AND [TeacherID] IS NOT NULL"; |
using (DbDataReader reader = cmd.ExecuteReader()) |
{ |
if (reader.Read()) |
{ |
Resource teacher = apt.Owner.Resources.GetResource("Teacher", reader["TeacherID"]); |
apt.Resources.Add(teacher); |
} |
} |
cmd.Parameters.Clear(); |
cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID)); |
cmd.CommandText = "SELECT [StudentID] FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID"; |
using (DbDataReader reader = cmd.ExecuteReader()) |
{ |
while (reader.Read()) |
{ |
Resource student = apt.Owner.Resources.GetResource("Student", reader["StudentID"]); |
apt.Resources.Add(student); |
} |
} |
} |
} |
private IEnumerable<Resource> GetTeachers() |
{ |
List<Resource> resources = new List<Resource>(); |
using (DbConnection conn = OpenConnection()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
cmd.CommandText = "SELECT [TeacherID], [Name], [Phone] FROM [DbProvider_Teachers]"; |
using (DbDataReader reader = cmd.ExecuteReader()) |
{ |
while (reader.Read()) |
{ |
Resource res = new Resource(); |
res.Type = "Teacher"; |
res.Key = reader["TeacherID"]; |
res.Text = Convert.ToString(reader["Name"]); |
res.Attributes["Phone"] = Convert.ToString(reader["Phone"]); |
resources.Add(res); |
} |
} |
} |
return resources; |
} |
private IEnumerable<Resource> GetStudents() |
{ |
List<Resource> resources = new List<Resource>(); |
using (DbConnection conn = OpenConnection()) |
{ |
DbCommand cmd = DbFactory.CreateCommand(); |
cmd.Connection = conn; |
cmd.CommandText = "SELECT [StudentID], [Name] FROM [DbProvider_Students]"; |
using (DbDataReader reader = cmd.ExecuteReader()) |
{ |
while (reader.Read()) |
{ |
Resource res = new Resource(); |
res.Type = "Student"; |
res.Key = reader["StudentID"]; |
res.Text = Convert.ToString(reader["Name"]); |
resources.Add(res); |
} |
} |
} |
return resources; |
} |
private void FillClassStudents(Appointment appointment, DbCommand cmd, object classId) |
{ |
foreach (Resource student in appointment.Resources.GetResourcesByType("Student")) |
{ |
cmd.Parameters.Clear(); |
cmd.Parameters.Add(CreateParameter("@ClassID", classId)); |
cmd.Parameters.Add(CreateParameter("@StudentID", student.Key)); |
cmd.CommandText = "INSERT INTO [DbProvider_ClassStudents] ([ClassID], [StudentID]) VALUES (@ClassID, @StudentID)"; |
cmd.ExecuteNonQuery(); |
} |
} |
private void ClearClassStudents(object classId, DbCommand cmd) |
{ |
cmd.Parameters.Clear(); |
cmd.Parameters.Add(CreateParameter("@ClassID", classId)); |
cmd.CommandText = "DELETE FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID"; |
cmd.ExecuteNonQuery(); |
} |
private void PopulateAppointmentParameters(DbCommand cmd, Appointment apt) |
{ |
cmd.Parameters.Add(CreateParameter("@Subject", apt.Subject)); |
cmd.Parameters.Add(CreateParameter("@Start", apt.Start)); |
cmd.Parameters.Add(CreateParameter("@End", apt.End)); |
cmd.Parameters.Add(CreateParameter("@CustomAttribute", apt.Attributes["CustomAttribute"])); |
Resource teacher = apt.Resources.GetResourceByType("Teacher"); |
object teacherId = null; |
if (teacher != null) |
{ |
teacherId = teacher.Key; |
} |
cmd.Parameters.Add(CreateParameter("@TeacherID", teacherId)); |
string rrule = null; |
if (apt.RecurrenceRule != string.Empty) |
{ |
rrule = apt.RecurrenceRule; |
} |
cmd.Parameters.Add(CreateParameter("@RecurrenceRule", rrule)); |
object parentId = null; |
if (apt.RecurrenceParentID != null) |
{ |
parentId = apt.RecurrenceParentID; |
} |
cmd.Parameters.Add(CreateParameter("@RecurrenceParentId", parentId)); |
} |
} |
I hope you find this helpful.
Regards,
Peter
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Brian Lehmann
Top achievements
Rank 2
answered on 27 Feb 2008, 02:00 AM
Thanks Peter!
For some reason I was looking right past the AttributeCollection. We had come up with a somewhat ugly hack to work around this oversight on our part, but I was thankfully able to strip all that out code and use the approach you provided which is much, much cleaner!
Thanks again for your help and the excellent Telerik support!
brian
sdgInteractive, LLC
For some reason I was looking right past the AttributeCollection. We had come up with a somewhat ugly hack to work around this oversight on our part, but I was thankfully able to strip all that out code and use the approach you provided which is much, much cleaner!
Thanks again for your help and the excellent Telerik support!
brian
sdgInteractive, LLC
0
towpse
Top achievements
Rank 2
answered on 02 Dec 2009, 07:53 PM
What if the value of the Custom Attribute is a Guid that represents a combo box item?
Are custom attributes expected to only be text box based?
Are custom attributes expected to only be text box based?
0
Hello,
The attributes are strictly string-only, but since you're using a provider you're free to process them further before storing them.
I hope this helps.
All the best,
Tsvetomir Tsonev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The attributes are strictly string-only, but since you're using a provider you're free to process them further before storing them.
I hope this helps.
All the best,
Tsvetomir Tsonev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Divya
Top achievements
Rank 1
answered on 11 Aug 2010, 07:47 AM
Ho wto validate the custom attributes in the Rad SCheduler.. ??
0
Hi Divya,
You can use the Advanced Templates and create your own custom validation.
All the best,
Peter
the Telerik team
You can use the Advanced Templates and create your own custom validation.
All the best,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Divya
Top achievements
Rank 1
answered on 12 Aug 2010, 11:58 AM
Hai Peter..
I have defined 3 custom attributes in the Rad Scheduler namely PhoneNo,Email ID and Name..
So I need a validator that should give an error if i won't give the name..i.e., the name should n't be blank..
and i need validations for Phone no and Email Id too..
If i'm using the Advanced forms also i'm not knowing the ID's of the text boxes of Name and all to give the validations.
Plz consider this pblm give me the solution...
I have defined 3 custom attributes in the Rad Scheduler namely PhoneNo,Email ID and Name..
So I need a validator that should give an error if i won't give the name..i.e., the name should n't be blank..
and i need validations for Phone no and Email Id too..
If i'm using the Advanced forms also i'm not knowing the ID's of the text boxes of Name and all to give the validations.
Plz consider this pblm give me the solution...
0
Hi Divya,
To be able to validate the Custom Attributes you'll need to customize the Advanced Form to add RequiredFieldValidator-s and the according logic.
I am working on a sample project to solve your scenario.
Please accept my apologies if it takes more time than expected.
Greetings,
Veronica Milcheva
the Telerik team
To be able to validate the Custom Attributes you'll need to customize the Advanced Form to add RequiredFieldValidator-s and the according logic.
I am working on a sample project to solve your scenario.
Please accept my apologies if it takes more time than expected.
Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Divya
Top achievements
Rank 1
answered on 18 Aug 2010, 12:01 PM
HI
Thanks for ur reply.
Please solve the problem as soon as possible.
Regards,
Divya
Thanks for ur reply.
Please solve the problem as soon as possible.
Regards,
Divya
0
Hi Divya,
Thank you for your patience.
Find the example project in the attached .zip file.
Please let me know if you have some questions.
Greetings,
Veronica Milcheva
the Telerik team
Thank you for your patience.
Find the example project in the attached .zip file.
Please let me know if you have some questions.
Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Divya
Top achievements
Rank 1
answered on 19 Aug 2010, 12:02 PM
Hi
Thank u so much for ur code..
I got the solution to my application..
Thanks again..
Regards,
Divya
Thank u so much for ur code..
I got the solution to my application..
Thanks again..
Regards,
Divya