Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
How do you implement custom classes inheriting from the Appointment class?
posted

I'm trying to find a simple approach to implementing custom fields on the Appointment class.
My custom fields can not, easily, be serialized to the Appointment's Tag field because they are used as look ups as well as modified by other application modules.

Within my scheduling module users can modify both infragistics native properties--Subject, Description, barColor, etc, etc.-- and my custom properties--EmployeeId, CustomerId, MeetingTypeId, etc, etc.

I would like to have the Infragistics controls use my custom class which inherits from the Infragistics Appointment class. This should allow me to use the following pattern; (I'm using Net 4.0, C#, VS 2010, Entity Framework and Infragistics 10.2)

private void AddNewAppointment(DateTime start, DateTime end)
{
    MyAppointment newAppt = new MyAppointment(start,end);
    newAppt.EmployeeId = Guid.NewGuid();//Example data-- dummy data used for this example.
    newAppt.MeetingTypeId = Guid.NewGuid(); //Example data--...
    newAppt.Subject = "My subject text";
    ultraCalendarInfo1.Appointments.Add((Appointment)newAppt);
}

//Inherited class.
public class MyAppointment:Infragistics.Win.UltraWinSchedule.Appointment
{
    MyAppointment(DateTime start, DateTime end):base(start,end)
    {
    }
    public Guid EmployeeId{get;set;}
}

I currently need to know three things In order to accomplish the above:

1) How do I get infragistics to use my custom class object internally?
2) How do I initialize my custom object fields when the object get loaded?
3) How do I persist my custom object fields when the object gets saved?

Example of my current DAL

--->Sample Code Start
=================================================
//Class members of my simple form example prototype
private BindingList<MyDAL.Appointment> mBindingList = null;
private MyDAL.SchedulingEntities mDAL = null; //Entity Framework object
//Following UltraCalendarInfo already setup by the VS Designer. This is a form class.
//private UltraCalendarInfo ultraCalendarInfo1 = null;

protected override void OnLoad(EventArgs e)
{
    //Initialize entity framework DAL
    mDAL = new MyDAL.SchedulingEntities();
    LoadData(); 
    mBindingList.AddingNew += new AddingNewEventHandler(mBindingList_AddingNew);
    ultraCalendarInfo1.beforeAppointmentRemoved += new CancelableAppointmentEventHander(ultraCalendarInfo1_BeforeAppointmentRemoved);
}

//Load appointments binding list and initialize the infragistics DataBindingsForAppointments
private void LoadData()
{
    mBindingList = new BindingList<MyDAL.SchedulingEntities>();
    foreach(MyDAL.SchAppointment appt in mDAL.TodaysAppointments())
    {
        mBindingList.Add(appt); //Is there an easier way? Not liking this loop...
    }
    //Setup member fields
    ultraCalendarInfo1.DataBindingsForAppointments.AllPropertiesMember = "AllProperties"; //Field    
    ultraCalendarInfo1.DataBindingsForAppointments.StartDateTimeMember = "StartDateTime"; // Field
    ultraCalendarInfo1.DataBindingsForAppointments.EndDateTimeMember = "EndDateTime"; //Field
    ultraCalendarInfo1.DataBindingsForAppointments.SubjectMember = "Subject"; //Field
    ultraCalendarInfo1.DataBindingsForAppointments.AllDayEventMember = "AllDayEvent"; //Field
    ultraCalendarInfo1.DataBindingsForAppointments.OwnerKeyMember = "OwnerKey"; //Field
    //Assign datasource.
    ultraCalendarInfo1.DataBindingsForAppointments.DataSource = mBindingList;
}

//mBindingList AddingNew event, create and initialize the new row object.
private void mBindingList_AddingNew(object sender, AddingNewEventArgs e)
{
    MyDAL.SchAppointment newAppt = new MyDAL.Appointment();

    newAppointment.EmployeeId = Guid.NewGuid();
    mDAL.Add(newAppointment);
 
   e.NewObject = (object)newAppt;
}

private void ultraCalendarInfo1_BeforeAppointmentRemoved(object sender, CancelableAppoiuntmentEvenArgs e)
{
    //Before deleting we could access our custom object like so
    MyAppointment appt = (MyAppointment)e.Appointment;
    //Do some validation on the appt ????

    //Delete the appointment from our DAL
    mDAL.DeleteObject(e.Appointment.BindingListObject);
}

private void SaveData()
{
    mDAL.SaveChanges();
}
=================================================
--->Sample Code End

This approach should also work in the Appointment Dialog Enditor too.

How do I load and save the custom classes inheriting from the Appointment?

Russ

Parents
No Data
Reply
  • 69832
    Offline posted

    You can use a class which derives from Appointment, but the data binding layer will not recognize it. When you bind to a data source, Appointment instances are created by the data binding layer, and there is no extensibility mechanism by which you can replace those instances. If you add an Appointment-derived instance to the Appointments collection using the Add method (for example), instance identity is maintained and the derived instance will live in that collection as any other Appointment instance does, but the data binding layer will not recognize it.

Children
No Data