我今天刚开发了一个DNN插件,也是我第一次开发DNN插件,我把开发的过程描述下来,对于精通DNN的希望多多指点,对于希望涉足DNN的起到抛砖引玉的作用.
本示例以一张基本的表Department的CRUD来说明用C#制作DNN4.3插件的全过程
1:首先创建Department表
(ModuleID,DepartmentID,DepartmentName,CreatedByUser,CreatedDate),
DepartmentID是主键
通过ModuleID建立Department表和Modules表的关系(ModuleID字段是实现模块插件的关键)
创建对应的CRUD存储过程
2:创建部门模块的内核部分
2.1: 创建VS2005的类库项目
2.2 添加DotNetNuke.dll 引用
2.3 添加DepartmentInfo实体类
using System;
using System.Configuration;
using System.Data;
![](/Images/OutliningIndicators/None.gif)
namespace ISS.DNN.Modules.Department
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
///<summary>
/// The Info class for the Department
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public class DepartmentInfo
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Private MembersPrivate Members#region Private Members
![](/Images/OutliningIndicators/InBlock.gif)
private int _ModuleId;
private int _DepartmentID;
private string _DepartmentName;
private int _CreatedByUser;
private DateTime _CreatedDate;
private string _CreatedByUserName;
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
ConstructorsConstructors#region Constructors
![](/Images/OutliningIndicators/InBlock.gif)
// initialization
public DepartmentInfo()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Public MethodsPublic Methods#region Public Methods
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// Gets and sets the Module Id
/// </summary>
public int ModuleId
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _ModuleId;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_ModuleId = value;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// Gets and sets the Item Id
/// </summary>
public int DepartmentId
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _DepartmentID;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_DepartmentID = value;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// gets and sets the DepartmentName
/// </summary>
public string DepartmentName
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _DepartmentName;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_DepartmentName = value;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// Gets and sets the User Id who Created/Updated the DepartmentName
/// </summary>
public int CreatedByUser
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _CreatedByUser;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_CreatedByUser = value;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// Gets and sets the User Id who Created/Updated the DepartmentName
/// </summary>
public string CreatedByUserName
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _CreatedByUserName;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_CreatedByUserName = value;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// Gets and sets the Date when Created/Updated
/// </summary>
public DateTime CreatedDate
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _CreatedDate;
}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_CreatedDate = value;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
}
}
![](/Images/OutliningIndicators/None.gif)
2.4 创建DataProvider抽象类并添加一下代码
using System;
using DotNetNuke;
using System.Data;
![](/Images/OutliningIndicators/None.gif)
using DotNetNuke.Framework;
![](/Images/OutliningIndicators/None.gif)
namespace ISS.DNN.Modules.Department
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// An abstract class that provides the DAL contract
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public abstract class DataProvider
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Shared/Static MethodsShared/Static Methods#region Shared/Static Methods
![](/Images/OutliningIndicators/InBlock.gif)
// singleton reference to the instantiated object
static DataProvider objProvider = null;
![](/Images/OutliningIndicators/InBlock.gif)
// constructor
static DataProvider()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CreateProvider();
}
![](/Images/OutliningIndicators/InBlock.gif)
// dynamically create provider
//一定要注意DataProvider的配置节department
private static void CreateProvider()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
objProvider = (DataProvider)Reflection.CreateObject("department");
}
![](/Images/OutliningIndicators/InBlock.gif)
// return the provider
public static DataProvider Instance()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return objProvider;
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Abstract methodsAbstract methods#region Abstract methods
![](/Images/OutliningIndicators/InBlock.gif)
public abstract void AddDepartment(int ModuleId, string DepartmentName, int UserId);
public abstract IDataReader GetDepartment(int ModuleId, int DepartmentID);
public abstract IDataReader GetDepartments(int ModuleId);
public abstract void UpdateDepartment(int ModuleId, int DepartmentID, string DepartmentName, int UserId);
public abstract void DeleteDepartment(int ModuleId, int DepartmentID);
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
}
}
![](/Images/OutliningIndicators/None.gif)
2.5 创建业务控制类DepartmentController
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;
![](/Images/OutliningIndicators/None.gif)
namespace ISS.DNN.Modules.Department
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
///<summary>
/// The Controller class for the Department
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public class DepartmentController : ISearchable, IPortable
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
ConstructorsConstructors#region Constructors
![](/Images/OutliningIndicators/InBlock.gif)
public DepartmentController()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Public MethodsPublic Methods#region Public Methods
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// adds an object to the database
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="objDepartment">The DepartmentInfo object</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public void AddDepartment(DepartmentInfo objDepartment)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (objDepartment.DepartmentName.Trim() != "")
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataProvider.Instance().AddDepartment(objDepartment.ModuleId, objDepartment.DepartmentName, objDepartment.CreatedByUser);
}
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// deletes an object from the database
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="ModuleId">The Id of the module</param>
/// <param name="DepartmentId">The Id of the item</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public void DeleteDepartment(int ModuleId, int DepartmentID)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataProvider.Instance().DeleteDepartment(ModuleId,DepartmentID);
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// gets an object from the database
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="moduleId">The Id of the module</param>
/// <param name="DepartmentId">The Id of the item</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public DepartmentInfo GetDepartment(int ModuleId, int DepartmentID)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return CBO.FillObject (DataProvider.Instance().GetDepartment(ModuleId, DepartmentID),typeof(DepartmentInfo)) as DepartmentInfo;
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// gets an object from the database
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="moduleId">The Id of the module</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public IList GetDepartments(int ModuleId)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return CBO.FillCollection(DataProvider.Instance().GetDepartments(ModuleId),typeof(DepartmentInfo));
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// saves an object to the database
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="objDepartment">The DepartmentInfo object</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public void UpdateDepartment(DepartmentInfo objDepartment)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (objDepartment.DepartmentName.Trim() != "")
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DataProvider.Instance().UpdateDepartment(objDepartment.ModuleId, objDepartment.DepartmentId, objDepartment.DepartmentName, objDepartment.CreatedByUser);
}
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Optional InterfacesOptional Interfaces#region Optional Interfaces
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// GetSearchItems implements the ISearchable Interface
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="ModInfo">The ModuleInfo for the module to be Indexed</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
IList colDepartments = GetDepartments(ModInfo.ModuleID);
![](/Images/OutliningIndicators/InBlock.gif)
foreach (DepartmentInfo objDepartment in colDepartments)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(objDepartment != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SearchItemInfo SearchItem = new SearchItemInfo(ModInfo.ModuleTitle, objDepartment.DepartmentName, objDepartment.CreatedByUser, objDepartment.CreatedDate, ModInfo.ModuleID, objDepartment.DepartmentId.ToString(), objDepartment.DepartmentName, "DepartmentId=" + objDepartment.DepartmentId.ToString());
SearchItemCollection.Add(SearchItem);
}
}
![](/Images/OutliningIndicators/InBlock.gif)
return SearchItemCollection;
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// ExportModule implements the IPortable ExportModule Interface
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="ModuleID">The Id of the module to be exported</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public string ExportModule(int ModuleID)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string strXML = "";
IList colDepartments = GetDepartments(ModuleID);
![](/Images/OutliningIndicators/InBlock.gif)
if (colDepartments.Count != 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strXML += "<Departments>";
foreach (DepartmentInfo objDepartment in colDepartments)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strXML += "<Department>";
strXML += "<DepartmentName>" + XmlUtils.XMLEncode(objDepartment.DepartmentName) + "</DepartmentName>";
strXML += "</Department>";
}
strXML += "</Departments>";
}
![](/Images/OutliningIndicators/InBlock.gif)
return strXML;
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// ImportModule implements the IPortable ImportModule Interface
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="ModuleID">The Id of the module to be imported</param>
/// <param name="DepartmentName">The DepartmentName to be imported</param>
/// <param name="Version">The version of the module to be imported</param>
/// <param name="UserId">The Id of the user performing the import</param>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public void ImportModule(int ModuleID, string DepartmentName, string Version, int UserId)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
XmlNode xmlDepartments = Globals.GetContent(DepartmentName, "Departments");
![](/Images/OutliningIndicators/InBlock.gif)
foreach (XmlNode xmlDepartment in xmlDepartments.SelectNodes("Department"))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DepartmentInfo objDepartment = new DepartmentInfo();
![](/Images/OutliningIndicators/InBlock.gif)
objDepartment.ModuleId = ModuleID;
objDepartment.DepartmentName = xmlDepartment.SelectSingleNode("DepartmentName").InnerText;
objDepartment.CreatedByUser = UserId;
AddDepartment(objDepartment);
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/None.gif)
2.6 创建UI 部门浏览控件ViewDepartment,这个类一定要继承PortalModuleBase,该类是DNN模块的基类也是模块插件机制的关键,提供了很多默认的实现,该类又实现了一个接口IActionable,这个接口指明该控件又哪些操作行为,本类指明了可以对Department进行添加操作
Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl(), false, SecurityAccessLevel.Edit, true, false);
namespace ISS.DNN.Modules.Department
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
using System;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Reflection;
using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// ViewDepartment 的摘要说明。
/// </summary>
public class ViewDepartment : PortalModuleBase, IActionable
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
protected System.Web.UI.WebControls.DataList lstDepartment;
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Web 窗体设计器生成的代码Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.Load += new System.EventHandler(this.Page_Load);
![](/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Public MethodsPublic Methods#region Public Methods
![](/Images/OutliningIndicators/InBlock.gif)
public bool DisplayAudit()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
bool retValue = false;
![](/Images/OutliningIndicators/InBlock.gif)
if ((string)Settings["auditinfo"] == "Y")
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
retValue = true;
}
![](/Images/OutliningIndicators/InBlock.gif)
return retValue;
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Event HandlersEvent Handlers#region Event Handlers
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
protected void Page_Load(System.Object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DepartmentController objDepartments = new DepartmentController();
IList colDepartments;
![](/Images/OutliningIndicators/InBlock.gif)
//get the content from the Department table
colDepartments = objDepartments.GetDepartments(ModuleId);
![](/Images/OutliningIndicators/InBlock.gif)
if (colDepartments.Count == 0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//add the content to the Department table
DepartmentInfo objDepartment = new DepartmentInfo();
objDepartment.ModuleId = ModuleId;
objDepartment.DepartmentName = Localization.GetString("DefaultContent", LocalResourceFile);
objDepartment.CreatedByUser = this.UserId;
objDepartments.AddDepartment(objDepartment);
![](/Images/OutliningIndicators/InBlock.gif)
//get the content from the Department table
colDepartments = objDepartments.GetDepartments(ModuleId);
}
![](/Images/OutliningIndicators/InBlock.gif)
//bind the content to the repeater
lstDepartment.DataSource = colDepartments;
lstDepartment.DataBind();
}
catch (Exception exc) //Module failed to load
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Optional InterfacesOptional Interfaces#region Optional Interfaces
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
/// <summary>
/// Registers the module actions required for interfacing with the portal framework
/// </summary>
/// <value></value>
/// <returns></returns>
/// <remarks></remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public ModuleActionCollection ModuleActions
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ModuleActionCollection Actions = new ModuleActionCollection();
Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl(), false, SecurityAccessLevel.Edit, true, false);
return Actions;
}
}
![](/Images/OutliningIndicators/InBlock.gif)
#endregion
}
}
![](/Images/OutliningIndicators/None.gif)
2.7 创建UI 部门编辑控件EditDepartment(实现CUD),该类也要继承PortalModuleBase
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
1
namespace ISS.DNN.Modules.Department
2![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
3
using System;
4
using System.Data;
5
using System.Drawing;
6
using System.Web;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.HtmlControls;
9
using DotNetNuke;
10
using DotNetNuke.Common;
11
using DotNetNuke.Common.Utilities;
12
using DotNetNuke.Entities.Modules;
13
using DotNetNuke.Services.Exceptions;
14
using DotNetNuke.Services.Localization;
15![](/Images/OutliningIndicators/InBlock.gif)
16![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
17
/// EditDepartment 的摘要说明。
18
/// </summary>
19
public class EditDepartment : PortalModuleBase
20![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
21
protected System.Web.UI.WebControls.RequiredFieldValidator valDepartmentName;
22
protected System.Web.UI.WebControls.LinkButton cmdUpdate;
23
protected System.Web.UI.WebControls.LinkButton cmdCancel;
24
protected System.Web.UI.WebControls.LinkButton cmdDelete;
25
protected DotNetNuke.UI.UserControls.ModuleAuditControl ctlAudit;
26
protected DotNetNuke.UI.UserControls.TextEditor txtDepartmentName;
27![](/Images/OutliningIndicators/InBlock.gif)
28![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Web 窗体设计器生成的代码Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
29
override protected void OnInit(EventArgs e)
30![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
31
//
32
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
33
//
34
InitializeComponent();
35
base.OnInit(e);
36
}
37
38![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
39
/// 设计器支持所需的方法 - 不要使用代码编辑器
40
/// 修改此方法的内容。
41
/// </summary>
42
private void InitializeComponent()
43![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
44
this.cmdUpdate.Click += new System.EventHandler(this.cmdUpdate_Click);
45
this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
46
this.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
47
this.Load += new System.EventHandler(this.Page_Load);
48![](/Images/OutliningIndicators/InBlock.gif)
49
}
50
#endregion
51![](/Images/OutliningIndicators/InBlock.gif)
52![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Private MembersPrivate Members#region Private Members
53![](/Images/OutliningIndicators/InBlock.gif)
54
private int DepartmentID = Null.NullInteger;
55![](/Images/OutliningIndicators/InBlock.gif)
56
#endregion
57![](/Images/OutliningIndicators/InBlock.gif)
58![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Event HandlersEvent Handlers#region Event Handlers
59![](/Images/OutliningIndicators/InBlock.gif)
60![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
61
/// <summary>
62
/// Page_Load runs when the control is loaded
63
/// </summary>
64
/// <remarks>
65
/// </remarks>
66
/// <history>
67
/// </history>
68
/// -----------------------------------------------------------------------------
69
protected void Page_Load(System.Object sender, System.EventArgs e)
70![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
71
try
72![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
73
//Determine DepartmentId of Department to Update
74
if(this.Request.QueryString["DepartmentId"] !=null)
75![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
76
DepartmentID = Int32.Parse(this.Request.QueryString["DepartmentId"]);
77
}
78![](/Images/OutliningIndicators/InBlock.gif)
79
//If this is the first visit to the page, bind the role data to the datalist
80
if (Page.IsPostBack == false)
81![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
82
cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
83![](/Images/OutliningIndicators/InBlock.gif)
84
if(DepartmentID != -1)
85![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
86
//get DepartmentName
87
DepartmentController objDepartments = new DepartmentController();
88
DepartmentInfo objDepartment = objDepartments.GetDepartment(ModuleId,DepartmentID);
89
if (objDepartment != null)
90![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
91
txtDepartmentName.Text = objDepartment.DepartmentName;
92
ctlAudit.CreatedByUser = objDepartment.CreatedByUserName;
93
ctlAudit.CreatedDate = objDepartment.CreatedDate.ToString();
94
}
95
else
96![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
97
Response.Redirect(Globals.NavigateURL(), true);
98
}
99
}
100
else
101![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
102
cmdDelete.Visible = false;
103
ctlAudit.Visible = false;
104
}
105
}
106
}
107
catch (Exception exc) //Module failed to load
108![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
109
Exceptions.ProcessModuleLoadException(this, exc);
110
}
111
}
112![](/Images/OutliningIndicators/InBlock.gif)
113![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
114
/// <summary>
115
/// cmdCancel_Click runs when the cancel button is clicked
116
/// </summary>
117
/// <remarks>
118
/// </remarks>
119
/// <history>
120
/// </history>
121
/// -----------------------------------------------------------------------------
122
protected void cmdCancel_Click(System.Object sender, System.EventArgs e)
123![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
124
try
125![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
126
this.Response.Redirect(Globals.NavigateURL(this.TabId), true);
127
}
128
catch (Exception exc) //Module failed to load
129![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
130
Exceptions.ProcessModuleLoadException(this, exc);
131
}
132
}
133![](/Images/OutliningIndicators/InBlock.gif)
134![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
135
/// <summary>
136
/// cmdDelete_Click runs when the delete button is clicked
137
/// </summary>
138
/// <remarks>
139
/// </remarks>
140
/// <history>
141
/// </history>
142
/// -----------------------------------------------------------------------------
143
protected void cmdDelete_Click(System.Object sender, System.EventArgs e)
144![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
145
try
146![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
147
//Only attempt to delete the item if it exists already
148
if (!Null.IsNull(DepartmentID))
149![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
150
DepartmentController objDepartments = new DepartmentController();
151
objDepartments.DeleteDepartment(ModuleId,DepartmentID);
152
}
153![](/Images/OutliningIndicators/InBlock.gif)
154
this.Response.Redirect(Globals.NavigateURL(this.TabId), true);
155
}
156
catch (Exception exc) //Module failed to load
157![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
158
Exceptions.ProcessModuleLoadException(this, exc);
159
}
160
}
161![](/Images/OutliningIndicators/InBlock.gif)
162![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// -----------------------------------------------------------------------------
163
/// <summary>
164
/// cmdUpdate_Click runs when the update button is clicked
165
/// </summary>
166
/// <remarks>
167
/// </remarks>
168
/// <history>
169
/// </history>
170
/// -----------------------------------------------------------------------------
171
protected void cmdUpdate_Click(System.Object sender, System.EventArgs e)
172![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
173
try
174![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
175
DepartmentController objDepartments = new DepartmentController();
176
DepartmentInfo objDepartment = new DepartmentInfo();
177![](/Images/OutliningIndicators/InBlock.gif)
178
objDepartment.ModuleId = ModuleId;
179
objDepartment.DepartmentId = DepartmentID;
180
objDepartment.DepartmentName = txtDepartmentName.Text;
181
objDepartment.CreatedByUser = this.UserId;
182![](/Images/OutliningIndicators/InBlock.gif)
183
//Update the DepartmentName within the Department table
184
if(Null.IsNull(DepartmentID))
185![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
186
objDepartments.AddDepartment(objDepartment);
187
}
188
else
189![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
190
objDepartments.UpdateDepartment(objDepartment);
191
}
192![](/Images/OutliningIndicators/InBlock.gif)
193
//Redirect back to the portal home page
194
this.Response.Redirect(Globals.NavigateURL(this.TabId), true);
195
}
196
catch (Exception exc) //Module failed to load
197![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
198
Exceptions.ProcessModuleLoadException(this, exc);
199
}
200
}
201![](/Images/OutliningIndicators/InBlock.gif)
202
#endregion
203![](/Images/OutliningIndicators/InBlock.gif)
204
}
205
}
206![](/Images/OutliningIndicators/None.gif)
2.8 创建模块设置控件Settings,该类一定要继承ModuleSettingsBase
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Exceptions;
![](/Images/OutliningIndicators/None.gif)
namespace ISS.DNN.Modules.Department
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
public abstract class Settings : DotNetNuke.Entities.Modules.ModuleSettingsBase
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Web Form Designer generated codeWeb Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**//**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
public override void LoadSettings()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (!Page.IsPostBack)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string setting1 = ((string)TabModuleSettings["settingname1"]);
string setting2 = ((string)Settings["settingname2"]);
}
}
catch (Exception exc)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
![](/Images/OutliningIndicators/InBlock.gif)
public override void UpdateSettings()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DotNetNuke.Entities.Modules.ModuleController objModules = new DotNetNuke.Entities.Modules.ModuleController();
objModules.UpdateTabModuleSetting(TabModuleId, "settingname1", "value");
objModules.UpdateModuleSetting(ModuleId, "settingname2", "value");
Response.Redirect(Globals.NavigateURL(), true);
}
catch (Exception exc)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
}
}
![](/Images/OutliningIndicators/None.gif)
OK,现在已经完成了系统的关键开发了,编译项目生成ISS.DNN.Modules.Department.dll,下一篇介绍SqlDataProvider的开发,UI界面的开发,以及安装包的制作!