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

Pass parameters to GetAppointments in Provider

6 Answers 215 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 28 Jan 2008, 11:36 PM
Hi,
Is there a way to pass parameters to the GetAppointments function in a custom DB provider.  I want to select the appointments based on criteria that is chosen by the user, and then update the schedule with appointments that match the criteria.  Is there another way to do this that I'm overlooking?  Basically, I don't want to select all appointments and then filter on the scheduling page, I want to filter the appointments that are selected from the database.

Thanks

6 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 29 Jan 2008, 01:22 PM
I think I solved my own problem.  I'm using custom attributes to pass info back to GetAppointments.  If there is a better way then please inform me.

Thanks
0
CMSC_345
Top achievements
Rank 1
answered on 19 Mar 2008, 11:24 PM
I would like to ask the same question. Can anyone comment on the proper way to pass parameters into the GetAppointments so the GetAppointment's query can use the parameters for filtering?
0
Peter
Telerik team
answered on 20 Mar 2008, 08:23 AM
Hello Ryan,

Please, find attached a small demo project of how to parameters to the GetAppointments function in a custom DB provider. Here is an outline of the steps needed to implement this solution.

  • Create your own class in App_Code which inherits from the Page class. In the example, I create the MyPage.cs file.
  • Define the properties which will be passed to the provider in MyPage.cs.
  • Set your page to inherit from MyPage
  • Find and cast MyPage in the provider like this:
    using (DbConnection conn = OpenConnection())  
                {  
                    DbCommand cmd = DbFactory.CreateCommand();  
                    cmd.Connection = conn;  
                    cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId] FROM [DbProvider_Classes]";  
     
                    MyPage page1 = (MyPage) owner.Page;  
                    string param1 = page1.MyParam;  
                    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.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);  
                                if (apt.Subject.ToString() == param1)  
                                {  
                                  appointments.Add(apt);                          
                                }                         
                          }  
                     }  
                } 
Note also that the above code illustrates a simple filter functionality by comparing the appointment's subject to the passed parameter (this is just for an example).

To keep things simple, I created three appointments with Subject: "a", "b", and "c". If you want to display appointments with subject "a" for example, just set MyParam  = "a"; in the code behind of your page:
public partial class _Default : MyPage  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        MyParam = "c";  
    }  

I hope this helps you get started. Should you have any question, feel free to contact us.



Regards,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
CMSC_345
Top achievements
Rank 1
answered on 20 Mar 2008, 03:31 PM
Thank you so much. It works as expected. It's much cleaner this way.
0
Tree
Top achievements
Rank 1
answered on 04 Apr 2009, 07:58 PM
Is there another way to do this rather than relying on subclassing a Page type?  The solution offered by Telerik means that I am tying my provider to a particular web page type.  Not exactly good architecture in my opinion.

0
T. Tsonev
Telerik team
answered on 06 Apr 2009, 08:16 AM
Hi,

I totally agree with you that this is not the cleanest solution for passing custom parameters. A proper solution would be to include a custom "context" object as a parameter to each provider method. Then RadScheduler will let you populate it by firing the appropriate events before calling provider methods.

For the moment we can only provide workarounds such as inheriting the page. Another option would be to instantiate the provider on the page. You'll incur performance hit, as the provider will not be shared, but you'll gain complete control over the instance.

Regards,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Scheduler
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
CMSC_345
Top achievements
Rank 1
Peter
Telerik team
Tree
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or