Creating Objects Using the Controller Class


Defining the Properties for the Info Class

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

image from book
 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 
image from book

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

image from book
 #Region "Constructors"     Public Sub New()     End Sub #End Region 
image from book

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

image from book
 #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 
image from book

Notice that each property you expose for your object corresponds to a field name in the Events table in DotNetNuke.




Professional DotNetNuke 4.0 (c) Open Source Web Application Framework for ASP. NET 4.0
Professional DotNetNuke 4: Open Source Web Application Framework for ASP.NET 2.0 (Programmer to Programmer)
ISBN: 0471788163
EAN: 2147483647
Year: 2006
Pages: 182

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net