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

为入门者准备! (适用于 DotNetNuke Version 4.3.1 or higher) 使用 VB.NET 或 C#

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

步骤

1. 安装Visual Studio Express (点击下载) 3fd425c700d10b2d248e99b4a19b09f6.png

2. 安装SQL Server Express (点击下载)

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

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

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

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

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

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

创建模块

创建模块的分为两步:

创建view控件

在DotNetNuke中注册这个模块

29ec99c68db97afae0e8ee2406cfd384.png创建模块目录

在Visual Studio中打开你的DotNetNuke网站

08b0c3ec3ec7c0b9da8dd78c948d4179.png创建View控件

在"DesktopModules" 目录上右键,选择"New Folder"

13c3253587f0cdc40edbe1d6f26ac28d.png新建的目录命名为"SuperSimple"

333e9f579653ef7c7c7d9036d6c8ad4e.png然后在"SuperSimple"目录上右键,选择 "Add New Item..."

点击"Add New Item"后出现一个对话框: b40590b9f01bb0ca90a3faa7cedd5f8e.png

点击"Visual Studio Installed Templates"下的"Web User Control"

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

确保"Place code in a separate file"已经选中

点击"Add"按键

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

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

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

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

输入如下的代码:

VB:

Inherits="DesktopModules_SuperSimple_SuperSimple" %>

Search: 

C#:

Inherits="DesktopModules_SuperSimple_SuperSimple" %>

Search: 

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

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

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

VB:

Imports DotNetNuke

Imports System.Web.UI

Imports System.Collections.Generic

Imports System.Reflection

Imports DotNetNuke.Security.PortalSecurity

Partial Class DesktopModules_SuperSimple_SuperSimple

Inherits Entities.Modules.PortalModuleBase

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

ShowData("")

End If

End Sub

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

ShowData(txtSearch.Text)

End Sub

Private Sub ShowData(ByVal SearchString As String)

Dim mySqlString As New StringBuilder()

mySqlString.Append("SELECT FriendlyName, Description")

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

mySqlString.Append("WHERE Description like '%' + @SearchString + '%'")

mySqlString.Append("ORDER BY FriendlyName")

Dim myParam As SqlParameter = New SqlParameter("@SearchString", SqlDbType.VarChar, 150)

myParam.Value = SearchString

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

Me.GridView1.DataBind()

End Sub

End Class

C#:

using DotNetNuke;

using System.Web.UI;

using System.Text;

using System.Collections.Generic;

using System.Reflection;

using DotNetNuke.Security;

using System.Data.SqlClient;

using System.Data;

using DotNetNuke.Data;

partial class DesktopModules_SuperSimple_SuperSimple : DotNetNuke.Entities.Modules.PortalModuleBase

{

protected void Page_Load(object sender, System.EventArgs e) {

if (!Page.IsPostBack)

{

ShowData("");

}

}

protected void btnSearch_Click(object sender, System.EventArgs e) {

ShowData(txtSearch.Text);

}

private void ShowData(string SearchString) {

StringBuilder mySqlString = new StringBuilder();

mySqlString.Append("SELECT FriendlyName, Description");

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

mySqlString.Append("WHERE Description like \'%\' + @SearchString + \'%\'");

mySqlString.Append("ORDER BY FriendlyName");

SqlParameter myParam = new SqlParameter("@SearchString", SqlDbType.VarChar, 150);

myParam.Value = SearchString;

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

this.GridView1.DataBind();

}

}

6bd07300e1a18c82eb59a72776c33198.png

从BUILD 菜单下选择"Build Page".

3e6476d12dc0dc6e87ab3c28b71f0472.png页面应该能通过编译

在 DotNetNuke中注册模块

16c6ec5d446b35f3772d460dca6b6443.png使用"host"登录到你的DotNetNuke站点,在菜单中选择"Host"然后选择 "Module Definitions"。

3f6f04eb937e3f8fa712be5589fe1be4.png点击左上角向下的小黑箭头,在出现的菜单中选择"Create New Module"。

在 Edit Module Definitions菜单里: 93bb4c5418d0599cecde1f70def7549f.png

在MODULE NAME处输入"SuperSimple"

在FOLDER TITLE处输入"SuperSimple"

在FRIENDLY TITLE处输入"SuperSimple"

在DESCRIPTION处输入"SuperSimple"

在VERSION处输入"1.0"

然后点击UPDATE

d25f465b5a2eac1572855a0cf24a8576.png在 NEW DEFINITION 输入 "SuperSimple"

然后点击 "Add"

bd4b236c891158c870b5de872792e174.png

然后点击 "Add Control"

0fc2cf1199e97d70e8a30369ab4c2783.png

在 Edit Module Control 菜单里:

在TITLE处 输入 "SuperSimple"

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

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

然后点击 UPDATE

17e94ca285699e5b9fcff625541e6b77.png

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

91e6bef1509265d31dfdd861bcf7cf63.png在PAGE MANAGEMENT菜单的PAGE DETAILS里:

在PAGE NAME 处输入"SuperSimple"

在 PAGE TITLE处输入"SuperSimple"

在DESCRIPTION处输入"SuperSimple"

在 VIEW PAGE 下面选中 ALL USERS

点击“UPDATE”

在 MODULE 的下拉列表中选择 "SuperSimple". 7dbbbcd1fa144e274365d44fc7614f4c.png

6959119f15e26095b66ce7aac67d0a33.png

然后点击 ADD.

模块将在页面上显示

8cd7352560e126ffe14483bf97ceef0c.png

本文译者m2land,转载请注明出处,作者博客地址:http://m2land.cnblogs.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值