Back to Devexpress

IAppointmentFactory Interface

corelibraries-devexpress-dot-xtrascheduler-752c7951.md

latest6.0 KB
Original Source

IAppointmentFactory Interface

Provides methods for creating appointments.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.Core.dll

NuGet Package : DevExpress.Scheduler.Core

Declaration

csharp
public interface IAppointmentFactory
vb
Public Interface IAppointmentFactory

The following members return IAppointmentFactory objects:

Remarks

Warning

Creating custom appointments is not safe and may lead to the control malfunction. It is strongly recommended that you use custom fields and mappings instead.

The IAppointmentFactory interface declares the IAppointmentFactory.CreateAppointment method, which defines a way of creating appointments. To specify a custom way of creating appointments using the SchedulerStorage you should implement this method and then assign the new appointment factory to the Scheduler Storage via the SchedulerStorageBase.SetAppointmentFactory method.

Then the Scheduler Storage will use this factory when creating an appointment via its SchedulerStorageBase.CreateAppointment method.

The following code illustrates the use of the IAppointmentFactory interface to implement a wrapper class which is intended to expose custom fields as common object properties. Using the AppointmentStorageBase.SetAppointmentFactory method, Scheduler’s Appointment objects are replaced with the Task class instances. A TaskCollection class holds Task objects, and can be used as a data source capable of providing data contained within appointment custom fields.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/winforms-scheduler-print-appointments-using-reports

csharp
public class TaskFactory : IAppointmentFactory
{
    public Appointment CreateAppointment(AppointmentType type)
    {
        Task task = new Task(type);
        return task;
    }
}
public class Task : DevExpress.XtraScheduler.Internal.Implementations.AppointmentInstance {

    public Task() { }
    public Task (AppointmentType type) : base(type){}

    // Convert custom fields into the Task properties
    public string CustomText {
        get { return (string)base.CustomFields["CustomTextField"]; }
        set { base.CustomFields["CustomTextField"] = value; }
    }
    public Color CustomColor {
        get { return (Color)base.CustomFields["CustomColorField"]; }
        set { base.CustomFields["CustomColorField"] = value; }
    }
    public int CustomColorARGB { get { return ((Color)base.CustomFields["CustomColorField"]).ToArgb(); } }
}
public class TaskCollection : List<Task> {

    public void AddAppointment(Appointment appointment) {
        Task task = (Task)appointment;
        base.Add(task);
    }

    public virtual void AddAppointmentRange(AppointmentBaseCollection collection) {
        foreach(Appointment item in collection)
            this.AddAppointment(item);
    }
}
vb
Public Class TaskFactory
    Implements IAppointmentFactory

    Public Function CreateAppointment(type As AppointmentType) As Appointment Implements IAppointmentFactory.CreateAppointment
        Dim task As New Task(type)
        Return task
    End Function

End Class
Public Class Task
    Inherits DevExpress.XtraScheduler.Internal.Implementations.AppointmentInstance

    Public Sub New()
    End Sub
    Public Sub New(ByVal type As AppointmentType)
        MyBase.New(type)
    End Sub

    ' Convert custom fields into the Task properties
    Public Property CustomText() As String
        Get
            Return CStr(MyBase.CustomFields("CustomTextField"))
        End Get
        Set(ByVal value As String)
            MyBase.CustomFields("CustomTextField") = value
        End Set
    End Property
    Public Property CustomColor() As Color
        Get
            Return CType(MyBase.CustomFields("CustomColorField"), Color)
        End Get
        Set(ByVal value As Color)
            MyBase.CustomFields("CustomColorField") = value
        End Set
    End Property
    Public ReadOnly Property CustomColorARGB() As Integer
        Get
            Return CType(MyBase.CustomFields("CustomColorField"), Color).ToArgb()
        End Get
    End Property
End Class
Public Class TaskCollection
    Inherits List(Of Task)

    Public Sub AddAppointment(ByVal appointment As Appointment)
        Dim task As Task = CType(appointment, Task)
        MyBase.Add(task)
    End Sub

    Public Overridable Sub AddAppointmentRange(ByVal collection As AppointmentBaseCollection)
        For Each item As Appointment In collection
            Me.AddAppointment(item)
        Next item
    End Sub
End Class

See Also

IAppointmentFactory Members

SetAppointmentFactory(IAppointmentFactory)

DevExpress.XtraScheduler Namespace