您的位置:首页 > 其它

DotNetNuke模块制作Super-Simple(DAL+)教程-翻译

2008-06-12 13:04 453 查看

为入门者准备!(适用于DotNetNukeVersion4.3.1orhigher)使用VB.NET或C#

这个教程向你演示如何创建一个使用DAL+“ExecuteSQL”方法的DotNetNuke模块,DAL+是DotNetNuke数据存取层(DataAccessLayer,DAL)的一个扩展。

步骤

1.安装VisualStudioExpress(点击下载)



2.安装SQLServerExpress(点击下载)

3.使用下面两种方法中的一种安装DotNetNuke并创建一个DotNetNuke网站

lSetting-uptheDevelopmentEnvironment(usingIIS)

lSetting-uptheDevelopmentEnvironment(withoutIIS)

4.在VisualStudio,选择“Build”下的“BuildSolution”,如果顺利通过编译,我们就可以进入下一步。



是否已经具备开发的环境了?

你必须有一个已经架好并能运行的DotNetNuke4网站才可以进行下一步,如果你没做到这一点,可以使用这个链接和这个链接寻求帮助。

DotNetNuke不断的在更新,所以DotNetNuke的论坛是寻找最新的帮助和信息最好的地方。

非常抱歉我没法为网站架设提供单独的技术支持,不过我会对跟本篇教程有关的问题提供帮助。

创建模块

创建模块的分为两步:

创建view控件

在DotNetNuke中注册这个模块



创建模块目录

在VisualStudio中打开你的DotNetNuke网站



创建View控件

在"DesktopModules"目录上右键,选择"NewFolder"



新建的目录命名为"SuperSimple"



然后在"SuperSimple"目录上右键,选择"AddNewItem..."

点击"AddNewItem"后出现一个对话框:



点击"VisualStudioInstalledTemplates"下的"WebUserControl"

在"Name"后面输入"SuperSimple.ascx"

确保"Placecodeinaseparatefile"已经选中

点击"Add"按键



一个"SuperSimple.ascx"文件会在"DesktopModules"目录下的"SuperSimple"目录内创建。



点击文件旁边的“加号”就会显示现关联的codebehind文件"SuperSimple.ascx.vb"(或者"SuperSimple.ascx.cs").



双击"SuperSimple.ascx"文件,主编辑窗口就会打开它,这个时候页面还只是一片空白。

点击页面左下角的"Source"按键,转换到源代码视图。

输入如下的代码:

VB:

<%@ControlLanguage="VB"AutoEventWireup="false"CodeFile="SuperSimple.ascx.vb"

Inherits="DesktopModules_SuperSimple_SuperSimple"%>

Search: 

<asp:TextBoxID="txtSearch"runat="server"></asp:TextBox> 

<asp:ButtonID="btnSearch"runat="server"Text="Button"/><br/>

<br/>

<asp:GridViewID="GridView1"runat="server">

</asp:GridView>


C#:

<%@ControlLanguage="C#"AutoEventWireup="true"CodeFile="SuperSimple.ascx.cs"

Inherits="DesktopModules_SuperSimple_SuperSimple"%>

Search: 

<asp:TextBoxID="txtSearch"runat="server"></asp:TextBox> 

<asp:ButtonID="btnSearch"runat="server"Text="Button"OnClick="btnSearch_Click"/><br/>

<br/>

<asp:GridViewID="GridView1"runat="server">

</asp:GridView>




点击页面左下角的"Design"按键转换到设计视图



双击"SuperSimple.ascx.vb"(或"SuperSimple.ascx.cs")

把里面的代码用下面的代码完全替换:

VB:

ImportsDotNetNuke

ImportsSystem.Web.UI

ImportsSystem.Collections.Generic

ImportsSystem.Reflection

ImportsDotNetNuke.Security.PortalSecurity

PartialClassDesktopModules_SuperSimple_SuperSimple

InheritsEntities.Modules.PortalModuleBase

ProtectedSubPage_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load

IfNotPage.IsPostBackThen

ShowData("")

EndIf

EndSub

ProtectedSubbtnSearch_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnSearch.Click

ShowData(txtSearch.Text)

EndSub

PrivateSubShowData(ByValSearchStringAsString)

DimmySqlStringAsNewStringBuilder()

mySqlString.Append("SELECTFriendlyName,Description")

mySqlString.Append("FROM{databaseOwner}{objectQualifier}DesktopModules")

mySqlString.Append("WHEREDescriptionlike'%'+@SearchString+'%'")

mySqlString.Append("ORDERBYFriendlyName")

DimmyParamAsSqlParameter=NewSqlParameter("@SearchString",SqlDbType.VarChar,150)

myParam.Value=SearchString

Me.GridView1.DataSource=CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(),myParam),IDataReader)

Me.GridView1.DataBind()

EndSub

EndClass



C#:

usingDotNetNuke;

usingSystem.Web.UI;

usingSystem.Text;

usingSystem.Collections.Generic;

usingSystem.Reflection;

usingDotNetNuke.Security;

usingSystem.Data.SqlClient;

usingSystem.Data;

usingDotNetNuke.Data;

partialclassDesktopModules_SuperSimple_SuperSimple:DotNetNuke.Entities.Modules.PortalModuleBase

{

protectedvoidPage_Load(objectsender,System.EventArgse){

if(!Page.IsPostBack)

{

ShowData("");

}

}

protectedvoidbtnSearch_Click(objectsender,System.EventArgse){

ShowData(txtSearch.Text);

}

privatevoidShowData(stringSearchString){

StringBuildermySqlString=newStringBuilder();

mySqlString.Append("SELECTFriendlyName,Description");

mySqlString.Append("FROM{databaseOwner}{objectQualifier}DesktopModules");

mySqlString.Append("WHEREDescriptionlike\'%\'+@SearchString+\'%\'");

mySqlString.Append("ORDERBYFriendlyName");

SqlParametermyParam=newSqlParameter("@SearchString",SqlDbType.VarChar,150);

myParam.Value=SearchString;

this.GridView1.DataSource=((IDataReader)(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(),myParam)));

this.GridView1.DataBind();

}

}






BUILD菜单下选择"BuildPage".



页面应该能通过编译

在DotNetNuke中注册模块



使用"host"登录到你的DotNetNuke站点,在菜单中选择"Host"然后选择"ModuleDefinitions"。



点击左上角向下的小黑箭头,在出现的菜单中选择"CreateNewModule"。

EditModuleDefinitions菜单里:



MODULENAME处输入"SuperSimple"

FOLDERTITLE处输入"SuperSimple"

FRIENDLYTITLE处输入"SuperSimple"

DESCRIPTION处输入"SuperSimple"

VERSION处输入"1.0"

然后点击UPDATE



NEWDEFINITION输入"SuperSimple"

然后点击"Add"





然后点击"AddControl"





EditModuleControl菜单里:

TITLE处输入"SuperSimple"

SOURCE处从下拉列表中选择"DesktopModule/SuperSimple/SuperSimple.ascx"

TYPE处从下拉列表中选择"View"

然后点击UPDATE





在网站的左上角的PAGEFUNCTIONS菜单里点击ADD。



PAGEMANAGEMENT菜单的PAGEDETAILS里:

PAGENAME处输入"SuperSimple"

PAGETITLE处输入"SuperSimple"

DESCRIPTION处输入"SuperSimple"

VIEWPAGE下面选中ALLUSERS

点击“UPDATE”

MODULE的下拉列表中选择"SuperSimple".







然后点击ADD.

模块将在页面上显示





原为地址:http://www.adefwebserver.com/DotNetNukeHELP/DNN_ShowMeThePages/

本文译者m2land,转载请注明出处,作者博客地址:http://m2land.cnblogs.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: