aDEFWEBSERVER
Los Angeles, CA *  Webmaster@ADefWebserver.com

Creating a Super-Fast and Super-Easy DotNetNuke® Module
For absolute beginners! (For DotNetNuke Version 4.3) - Page 2 (Page 1)

Setting Up The Module

We will create the module using the following steps:

Create The Directories

Open your DotNetNuke website in Visual Studio.

A DotNetNuke module resides in 2 directories.

The Web User Controls and their associated code behind files reside in the "DesktopModules" directory and all other code (Data Access Layer and Business Logic Layer code) resides in the "App_Code" directory.

Create the DAL+

First we will create the Data Access Layer using the DAL+ method. This is the class that communicates with the database.
 

Create the "info class"

Right-click on the "App_Code" folder and select "New Folder"

Name the new folder "ThingsForSale"  

 

Right-click on the "ThingsForSale" folder you just created and select "Add New Item"  

 

In the "Add New Item" box that opens, click on "Class" under "Visual Studio Installed Templates", enter "ThingsForSaleInfo.vb" in the "Name" box and click the "Add" button.
The class will now open up in the designer.
Replace ALL the code with the following code:  
Namespace YourCompany.Modules.ThingsForSale

Public Class ThingsForSaleInfo

Private _ModuleId As Integer
Private
_ID As Integer
Private
_UserID As Integer
Private
_Category As String
Private
_Description As String
Private
_Price As Double
' initialization
Public Sub New()
MyBase.New()
End Sub
' <summary>
' Gets and sets the Module Id
' </summary>
Public Property ModuleId() As Integer
Get
Return
_ModuleId
End Get
Set
(ByVal value As Integer)
_ModuleId = value
End Set
End
Property
' <summary>
' Gets and sets the Item ID
' </summary>
Public Property ID() As Integer
Get
Return
_ID
End Get
Set
(ByVal value As Integer)
_ID = value
End Set
End
Property
' <summary>
' Gets and sets the UserID
' </summary>
Public Property UserID() As Integer
Get
Return
_UserID
End Get
Set
(ByVal value As Integer)
_UserID = value
End Set
End
Property
' <summary>
' Gets and sets the Category
' </summary>
Public Property Category() As String
Get
Return
_Category
End Get
Set
(ByVal value As String)
_Category = value
End Set
End
Property
' <summary>
' Gets and sets the Description
' </summary>
Public Property Description() As String
Get
Return
_Description
End Get
Set
(ByVal value As String)
_Description = value
End Set
End
Property
' <summary>
' Gets and sets the Price
' </summary>
Public Property Price() As Double
Get
Return
_Price
End Get
Set
(ByVal value As Double)
_Price = value
End Set
End
Property

End
Class

End
Namespace

 

 

 

What Did We Just Do?

 
We created a simple class file. This class when instantiated becomes an object and that object will be used to pass the data between the Data Access Layer that we are constructing and the Web User Control that we will create later.

Notice this class has one property for each field of data that we will need to transfer back and forth.

 
   

Create the "controller class"

Right-click on the "ThingsForSale" folder and select "Add New Item".

In the "Add New Item" box that opens, click on "Class" under "Visual Studio Installed Templates", enter "ThingsForSaleController.vb" in the "Name" box and click the "Add" button.
The class will now open up in the designer.
Replace ALL the code with the following code:  

Imports System
Imports
System.Collections.Generic
Imports
System.Data

Namespace YourCompany.Modules.ThingsForSale

Public Class ThingsForSaleController

<DataObjectMethod(DataObjectMethodType.Insert)> _
Public Shared Sub ThingsForSale_Insert(ByVal ThingsForSaleInfo As ThingsForSaleInfo)
    DataProvider.Instance().ExecuteNonQuery(
"ThingsForSale_Insert", ThingsForSaleInfo.ModuleId, GetNull(ThingsForSaleInfo.UserID), GetNull(ThingsForSaleInfo.Category.ToString), GetNull(ThingsForSaleInfo.Description.ToString), GetNull(ThingsForSaleInfo.Price))
End Sub

<DataObjectMethod(DataObjectMethodType.Delete)> _
Public Shared Sub ThingsForSale_Delete(ByVal ThingsForSaleInfo As ThingsForSaleInfo)
    DataProvider.Instance().ExecuteNonQuery(
"ThingsForSale_Delete", ThingsForSaleInfo.ID)
End Sub

<DataObjectMethod(DataObjectMethodType.Update)> _
Public Shared Sub ThingsForSale_Update(ByVal ThingsForSaleInfo As ThingsForSaleInfo)
    DataProvider.Instance().ExecuteNonQuery(
"ThingsForSale_Update", ThingsForSaleInfo.ID, ThingsForSaleInfo.ModuleId, GetNull    (ThingsForSaleInfo.UserID), GetNull(ThingsForSaleInfo.Category.ToString), GetNull(ThingsForSaleInfo.Description.ToString), GetNull(ThingsForSaleInfo.Price))
End Sub

<DataObjectMethod(DataObjectMethodType.Select)> _
Public Shared Function ThingsForSale_SelectAll(ByVal ModuleId As Integer) As List(Of ThingsForSaleInfo)
    Return CBO.FillCollection(Of ThingsForSaleInfo)(CType(DataProvider.Instance().ExecuteReader("ThingsForSale_SelectAll", ModuleId), IDataReader))
End Function

Private Shared Function GetNull(ByVal Field As Object) As Object
    Return
Null.GetNull(Field, DBNull.Value)
End Function

End Class

End Namespace


What Did We Just Do?
 
This time we did a lot. However, we did a lot without using a lot of code.

We have constructed a class called "ThingsForSaleController" that has 4 public methods. Each of these methods uses one of the new methods of the DAL+ to execute stored procedures.

 

We haven't created the stored procedures yet. We will do that in a later step. For now, we have simply created a method for each task we will need to perform with the database:

  • Delete - (ThingsForSale_Delete)
  • Insert - (ThingsForSale_Insert)
  • Select - (ThingsForSale_SelectAll)
  • Update - (ThingsForSale_Update)

Note: A protected method, "GetNull" is used to pass the proper null value to the database for any values that could be empty.

 

The Delete, Insert, and Update methods accept the "ThingsForSaleInfo" class that was created previously as a parameter.

 

 

The SelectAll methods takes an integer as a parameter and RETURNS a "ThingsForSaleInfo" class.

 


The DAL+ is comprised of 4 methods used to execute stored procedures. The methods are:
  • ExecuteNonQuery - Used to execute a stored procedure that will not return a value.
  • ExecuteReader - Used to execute a stored procedure that will return multiple records.
  • ExecuteScalar - Used to execute a stored procedure that will return a single value.
  • ExecuteSQL - Used to execute a sql statement.
DotNetNuke DAL+
The Delete, Insert, and Update methods use the ExecuteNonQuery method of the DAL+ and the SelectAll method uses the ExecuteReader method of the DAL+ (the ExecuteScalar and ExecuteSQL methods of the DAL+ are not used in this tutorial).
   

Below is an explanation of the format used to implement the DAL+. The ExecuteReader method that is used in the "ThingsForSale_SelectAll" method is used in this example:

 

We have completed creating the DAL+ for our module.

Now, the steps that remain are:

   

BACK
 

Next: Create the "View" control

 

   
   
 
DotNetNuke MarketPlace

(C) by Michael Washington - ADefWebserver.com - Webmaster@ADefWebserver.com

DotNetNuke® is a registered trademark of Perpetual Motion Interactive Systems Inc.