Scheduler for Silverlight Tutorials > Creating a Custom Application for Custom Data > Step 2 of 5: Defining Custom Data Structure |
In this step, you will define business object classes (BusinessObjects.cs or BusinessObjects.vb files).
Visual Basic |
Copy Code
|
---|---|
Imports System Imports System.ComponentModel Imports System.Collections.ObjectModel |
C# |
Copy Code
|
---|---|
using System; using System.ComponentModel; using System.Collections.ObjectModel; |
Visual Basic |
Copy Code
|
---|---|
' Business object should implement INotifyPropertyChanged interface. Public Class AppointmentBORow Implements INotifyPropertyChanged Private _subject As String = "" Private _body As String = "" Private _location As String = "" Private _properties As String = "" Private _start As DateTime = DateTime.Today Private _end As DateTime = (DateTime.Today + TimeSpan.FromDays(1)) Private _id As Guid = Guid.NewGuid Private _isDeleted As Boolean = False 'Custom Data Private _BOProperty1 As String = "" Private _BOProperty2 As String = "" Public Sub New() MyBase.New() End Sub Public Property Subject As String Get Return _subject End Get Set(value As String) If (_subject <> value) Then _subject = value OnPropertyChanged("Subject") End If End Set End Property Public Property BOProperty1 As String Get Return _BOProperty1 End Get Set(value As String) If (_BOProperty1 <> value) Then _BOProperty1 = value OnPropertyChanged("BOProperty1") End If End Set End Property Public Property BOProperty2 As String Get Return _BOProperty2 End Get Set(value As String) If (_BOProperty2 <> value) Then _BOProperty2 = value OnPropertyChanged("BOProperty2") End If End Set End Property Public Property Properties As String Get Return _properties End Get Set(value As String) If (_properties <> value) Then _properties = value OnPropertyChanged("Properties") End If End Set End Property Public Property Start As DateTime Get Return _start End Get Set(value As DateTime) If (_start <> value) Then _start = value OnPropertyChanged("Start") End If End Set End Property Public Property dt As DateTime Get Return _end End Get Set(value As DateTime) If (_end <> value) Then _end = value OnPropertyChanged("End") End If End Set End Property Public Property Body As String Get Return _body End Get Set(value As String) If (_body <> value) Then _body = value OnPropertyChanged("Body") End If End Set End Property Public Property Location As String Get Return _location End Get Set(value As String) If (_location <> value) Then _location = value OnPropertyChanged("Location") End If End Set End Property Public Property Id As Guid Get Return _id End Get Set(value As Guid) If (_id <> value) Then _id = value OnPropertyChanged("Id") End If End Set End Property Public Property IsDeleted As Boolean Get Return _isDeleted End Get Set(value As Boolean) If (_isDeleted <> value) Then _isDeleted = value OnPropertyChanged("IsDeleted") End If End Set End Property Public Event PropertyChanged As PropertyChangedEventHandler Protected Overridable Sub OnPropertyChanged(ByVal propName As String) If PropertyChangedEvent IsNot Nothing Then RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End If End Sub Public Event PropertyChanged1(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged End Class |
C# |
Copy Code
|
---|---|
// Business object should implement INotifyPropertyChanged interface. public class AppointmentBORow : INotifyPropertyChanged { private string _subject = ""; private string _body = ""; private string _location = ""; private string _properties = ""; private DateTime _start = DateTime.Today; private DateTime _end = DateTime.Today + TimeSpan.FromDays(1); private Guid _id = Guid.NewGuid(); private bool _isDeleted = false; //Custom Data private string _BOProperty1 = ""; private string _BOProperty2 = ""; public AppointmentBORow() { } public string Subject { get { return _subject; } set { if (_subject != value) { _subject = value; OnPropertyChanged("Subject"); } } } public string BOProperty1 { get { return _BOProperty1; } set { if (_BOProperty1 != value) { _BOProperty1 = value; OnPropertyChanged("BOProperty1"); } } } public string BOProperty2 { get { return _BOProperty2; } set { if (_BOProperty2 != value) { _BOProperty2 = value; OnPropertyChanged("BOProperty2"); } } } public string Properties { get { return _properties; } set { if (_properties != value) { _properties = value; OnPropertyChanged("Properties"); } } } public DateTime Start { get { return _start; } set { if (_start != value) { _start = value; OnPropertyChanged("Start"); } } } public DateTime End { get { return _end; } set { if (_end != value) { _end = value; OnPropertyChanged("End"); } } } public string Body { get { return _body; } set { if (_body != value) { _body = value; OnPropertyChanged("Body"); } } } public string Location { get { return _location; } set { if (_location != value) { _location = value; OnPropertyChanged("Location"); } } } public Guid Id { get { return _id; } set { if (_id != value) { _id = value; OnPropertyChanged("Id"); } } } public bool IsDeleted { get { return _isDeleted; } set { if (_isDeleted != value) { _isDeleted = value; OnPropertyChanged("IsDeleted"); } } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } |
Visual Basic |
Copy Code
|
---|---|
' Business objects collection should implement INotifyCollectionChanged interface. Public Class AppointmentBOList Inherits ObservableCollection(Of AppointmentBORow) Protected Overrides Sub RemoveItem(ByVal index As Integer) Dim item As AppointmentBORow = Me(index) If (Not (item) Is Nothing) Then item.IsDeleted = True End If MyBase.RemoveItem(index) End Sub End Class |
C# |
Copy Code
|
---|---|
// Business objects collection should implement INotifyCollectionChanged interface. public class AppointmentBOList : ObservableCollection<AppointmentBORow> { protected override void RemoveItem(int index) { AppointmentBORow item = this[index]; if (item != null) { item.IsDeleted = true; } base.RemoveItem(index); } } } |
Visual Basic |
Copy Code
|
---|---|
Public Class AppointmentsBO Private _list As AppointmentBOList = Nothing Public Sub New() MyBase.New() _list = New AppointmentBOList _list.Add(New AppointmentBORow) End Sub Public Property Appointments As AppointmentBOList Get Return _list End Get Set(value As AppointmentBOList) _list = value End Set End Property End Class |
C# |
Copy Code
|
---|---|
public class AppointmentsBO { AppointmentBOList _list = null; public AppointmentsBO() { _list = new AppointmentBOList(); _list.Add(new AppointmentBORow()); } public AppointmentBOList Appointments { get { return _list; } set { _list = value; } } } |
In this step you created business objects which will provide data for the C1Scheduler control in the future steps.