This section covers the EventsInfo.vb class contained in the project folder. This class is what describes your objects for the Events module that will be returned from the database.
At the top of the class file, do your imports as in the following code:
Imports System Imports System.Configuration Imports System.Data
Following this you have your namespace. For this example, you'll stay within the DotNetNuke namespace, but if you were creating your own modules separate from DNN, you could use a custom namespace in the form of CompanyName.ModuleName:
Namespace DotNetNuke.Modules.Events
Listing 14-1 shows the Private Members region at the top of the class. Here you define private variables and their types. These variables will be used to store the values for each property for your class.
Listing 14-1: The Private Members Region of the EventInfo Class
Public Class EventInfo #Region "Private Members" Private _ItemId As Integer Private _ModuleId As Integer Private _Description As String Private _DateTime As Date Private _Title As String Private _ExpireDate As Date Private _CreatedByUser As String Private _CreatedDate As Date Private _Every As Integer Private _Period As String Private _IconFile As String Private _AltText As String Private _MaxWidth As Integer #End Region
Below the Private Members region is the Constructors region (see Listing 14-2). In object-oriented programming, the constructor is a special method for this class that must be present for the object to be instantiated. In the Events module with VB.NET, it is New. If you needed to write special initialization code for the EventInfo class, you would do so here to ensure the code is executed.
Listing 14-2: The Constructors for the EventInfo Class
#Region "Constructors" Public Sub New() End Sub #End Region
Next are the public properties of the EventInfo class, which are used to define your object (see Listing 14-3). For example, an event has an ItemID, ModuleID, Description, and other properties. These correspond to the fields contained within the database for this module (see Chapter 13).
Listing 14-3: The Public Properties for the EventInfo Class
#Region "Properties" Public Property ItemId() As Integer Get Return _ItemId End Get Set(ByVal Value As Integer) _ItemId = Value End Set End Property Public Property ModuleId() As Integer Get Return _ModuleId End Get Set(ByVal Value As Integer) _ModuleId = Value End Set End Property Public Property Description() As String Get Return _Description End Get Set(ByVal Value As String) _Description = Value End Set End Property Public Property DateTime() As Date Get Return _DateTime End Get Set(ByVal Value As Date) _DateTime = Value End Set End Property Public Property Title() As String Get Return _Title End Get Set(ByVal Value As String) _Title = Value End Set End Property Public Property ExpireDate() As Date Get Return _ExpireDate End Get Set(ByVal Value As Date) _ExpireDate = Value End Set End Property Public Property CreatedByUser() As String Get Return _CreatedByUser End Get Set(ByVal Value As String) _CreatedByUser = Value End Set End Property Public Property CreatedDate() As Date Get Return _CreatedDate End Get Set(ByVal Value As Date) _CreatedDate = Value End Set End Property Public Property Every() As Integer Get Return _Every End Get Set(ByVal Value As Integer) _Every = Value End Set End Property Public Property Period() As String Get Return _Period End Get Set(ByVal Value As String) _Period = Value End Set End Property Public Property IconFile() As String Get Return _IconFile End Get Set(ByVal Value As String) _IconFile = Value End Set End Property Public Property AltText() As String Get Return _AltText End Get Set(ByVal Value As String) _AltText = Value End Set End Property Public Property MaxWidth() As Integer Get Return _MaxWidth End Get Set(ByVal Value As Integer) _MaxWidth = Value End Set End Property #End Region End Class End Namespace
Notice that each property you expose for your object corresponds to a field name in the Events table in DotNetNuke.