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

Inherit from Appointment and use AdvancedEditForm

1 Answer 114 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Matthias S
Top achievements
Rank 1
Matthias S asked on 30 Jun 2009, 04:11 PM
Hello,

I try to implement a custom RadScheduler within my webapplication. The problem is I don't want to use direkt DB Binding or Objectbinding.
My own appointment objects look like this. And there is the Problem. Each of myAppointments has a List<int> AttachedFiles which I need to populate to the edit form.
public class myAppointment 
    { 
        private object m_id; 
        public object ID 
        { 
            get { return m_id; } 
            set { m_id = value; } 
        } 
        ... 
        private DateTime m_start; 
        public DateTime StartsOn 
        { 
            get { return m_start; } 
            set { m_start = value; } 
        } 
        ... 
        private myAppointmentFilter m_type = myAppointmentFilter.none; 
        public myAppointmentFilter Type 
        { 
            get { return m_type; } 
            set { m_type = value; } 
        } 
        ... 
        private List<int> m_attachedFiles = null
        public List<int> AttachedFiles 
        { 
            get { return m_attachedFiles; } 
            set { m_attachedFiles = value; } 
        } 
 
    } 

Therefore I have some "DB Wrapper Classes" which load / save / delete my appointments.
This classes return a List of my own DB Appointments. This Method only loads appointments of type p_appFilter and between start and end.
public enum myAppointmentFilter {none, globalFollowUps, personalFollowUps, freeAppointments }


public class DBWrapper
{
    public List<myAppointment> LoadAppointments(int p_userID, myAppointmentFilter p_appFilter, DateTime p_start, DateTime p_end)
        {
            List<myAppointment> appointments = new List<myAppointment>();

            switch (p_appFilter)
            {
                case myAppointmentFilter.freeAppointments:
                    appointments.AddRange(LoadFreeAppointments(p_userID, p_start,p_end));
                    break;
                case myAppointmentFilter.personalFollowUps:
                    appointments.AddRange(LoadFollowUps(p_start, p_end, true, p_userID));
                    break;
                case myAppointmentFilter.globalFollowUps:
                    appointments.AddRange(LoadFollowUps(p_start, p_end, false, -1));
                    break;
            }

            return appointments;
        }
        
        private List<myAppointment> LoadFreeAppointments(int p_userID, DateTime p_start, DateTime p_end)
        {...}
        private List<myAppointment> LoadFollowUps(DateTime p_start, DateTime p_end, bool p_personal, int p_userID)
        {...}
}
after that I create "GUI Objects" out of my DB Appointments.
These "ExtAppointment" inherit from Telerik.Web.UI.Appoinment and add some additonal Properties. e.g. a string name, but also a List<int> fileIds.

This Inherited ExtAppointmenst will be added by the following code:
public partial class scheduler : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            m_currentAppointments = new List<myAppointment>();
                //Nur Appointments der ausgewählten Filter laden
                foreach (int key in m_filterIDs.Keys)
                {
                    CheckBox cb = PanelBar.Items[0].Items[0].FindControl(m_filterIDs[key]) as CheckBox;
                    if (cb.Checked)
                    {
                        switch (m_filterIDs[key])
                        {
                            case "cbFollowUps":
                                m_currentAppointments.AddRange(m_schedulerDBDataProvider.LoadAppointments(1, myAppointmentFilter.globalFollowUps, DateTime.Today.AddDays(-3), DateTime.Today.AddDays(3)));
                                break;
                            case "cbPersonalFollowUps":
                                m_currentAppointments.AddRange(m_schedulerDBDataProvider.LoadAppointments(1, myAppointmentFilter.personalFollowUps, DateTime.Today.AddDays(-3), DateTime.Today.AddDays(3)));
                                break;
                            case "cbFreeAppointments":
                                m_currentAppointments.AddRange(m_schedulerDBDataProvider.LoadAppointments(1, myAppointmentFilter.freeAppointments, DateTime.Today.AddDays(-3), DateTime.Today.AddDays(3)));
                                break;
                        }
                    }
                }

                CreateAppointments();
            }
            ...
                
        private void CreateAppointments()
        {
            int id = 0;

            foreach (myAppointment app in m_currentAppointments)
            {
                //ExtAppointment inherits of Telerik.Web.UI.Appointment
                ExtAppointment telerikApp = new ExtAppointment();
                telerikApp.ID = id;
                telerikApp.DBID = app.DBID;
                telerikApp.Title = app.Title;
                telerikApp.Start = app.StartsOn.ToUniversalTime();
                telerikApp.End = app.EndsOn.ToUniversalTime();
                telerikApp.Description = app.Description;
                telerikApp.UserID = app.UserID;
                telerikApp.Type = app.Type;

                switch (app.Type)
                {
                    case myAppointmentFilter.globalFollowUps:
                        telerikApp.CssClass = "rsCategoryRed";
                        telerikApp.AllowDelete = false;
                        break;
                    case myAppointmentFilter.personalFollowUps:
                        telerikApp.CssClass = "rsCategoryOrange";
                        telerikApp.AllowDelete = false;
                        break;
                    case myAppointmentFilter.freeAppointments:
                        telerikApp.CssClass = "rsCategoryGreen";
                        break;
                }

                RadScheduler1.InsertAppointment(telerikApp);

                id++;
            }
        }    
    }

So far so good, that works fine. But as soon as it comes to Load the AdvancedEditForm I get into trouble receiving my ExtAppointment. There is no problem for the base class properties. These are all loaded correctly. My problem is that my added properties do not have a value asigned.
I tried to receive the appointment like you did in some examples: (but added a cast)
protected ExtAppointment Appointment  
get 
    SchedulerFormContainer container = SchedulerFormContainer)BindingContainer; 
    return container.Appointment as ExtAppointment; 

So finally my question comes donw to one point. How do I populate this List<int> to my advancedEditForm?
I was looking at Resources, but I guess this is not the correct way as each appointment has it's own different List. That's why I tried to inherit of Telerik.Web.UI.Appointment in order to extend the properties and manipulate them within the editform.

many thanks in advance!

greetz mat

I'm using RadControls_ASP.NET_AJAX_2009_1_527_dev

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 02 Jul 2009, 08:13 AM
Hello Matthias S,

The way you have implemented the properties is wrong. When you create a property for web control, you need to write that property to the view state in order to preserve its value over the postbacks. The correct way to define, say AttachedFiles property is:

 
public List<int> AttachedFiles 
    { 
        get 
        { 
            return (List<int>)ViewState["attachedFiles"] ?? null
        } 
        set 
        { 
            ViewState["attachedFiles"] = value; 
        } 
    }  

?? operators means: If there is such value in the view state - return that value. If not - return null.

Since you have your own logic to handle the appointments manipulation, the upper mentioned change should be enough to make your code work.

Greetings,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Scheduler
Asked by
Matthias S
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or