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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 为入门者准备! (适用于 DotNetNuke Version 4.3.1 or higher) 使用 VB.NET 或 C# 这个教程向你演示如何创建一个使用DAL+“ExecuteSQL”方法的DotNetNuke模块,DAL+是DotNetNuke数据存取层(Data Access Layer, DAL)的一个扩展。

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

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

步骤

1. 安装Visual Studio Express (点击下载) clip_image002

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

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

l Setting-up the Development Environment (using IIS)

l Setting-up the Development Environment (without IIS)

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

 

 

 

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

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

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

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

 

 

创建模块

创建模块的分为两步:

  1. 创建view控件
  2. 在DotNetNuke中注册这个模块

 

 

clip_image006创建模块目录

在Visual Studio中打开你的DotNetNuke网站

 

 

 

 

 

 

 

 

 

 

 

clip_image007创建View控件

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

 

 

 

 

clip_image008新建的目录命名为"SuperSimple"

 

 

 

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

 

 

 

 

 

 

点击"Add New Item"后出现一个对话框: clip_image011

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

  • 在"Name"后面输入"SuperSimple.ascx"
  • 确保"Place code in a separate file"已经选中
  • 点击"Add"按键

 

 

 

 

 

 

 

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

 

 

 

 

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

 

 

 

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

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

 

 

 

 

输入如下的代码:

VB:

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

Inherits="DesktopModules_SuperSimple_SuperSimple" %>


Search:&nbsp;

<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>&nbsp;

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

<br />

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

 

C#:

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

Inherits="DesktopModules_SuperSimple_SuperSimple" %>


Search:&nbsp;

<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>&nbsp;

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

<br />

<asp:GridView ID="GridView1" runat="server">

</asp:GridView>
 

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

 

 

 

 

 

 

 

clip_image017双击"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();

}

}
 

clip_image019

BUILD 菜单下选择"Build Page".

 

 

 

 

clip_image021页面应该能通过编译

 

 

 

在 DotNetNuke中注册模块

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

 

 

 

 

 

 

 

 

 

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

 

 

 

Edit Module Definitions菜单里: clip_image026

  • MODULE NAME处输入"SuperSimple"
  • FOLDER TITLE处输入"SuperSimple"
  • FRIENDLY TITLE处输入"SuperSimple"
  • DESCRIPTION处输入"SuperSimple"
  • VERSION处输入"1.0"

然后点击UPDATE

 

 

 

 

 

 

clip_image028NEW DEFINITION 输入 "SuperSimple"

然后点击 "Add"

 

 

clip_image029

然后点击 "Add Control"

 

 

 

 

clip_image031

Edit Module Control 菜单里:

  • TITLE处 输入 "SuperSimple"
  • SOURCE处从下拉列表中选择 "DesktopModule/SuperSimple/SuperSimple.ascx"
  • TYPE 处从下拉列表中选择"View"

然后点击 UPDATE

 

 

 

 

clip_image032

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

 

 

 

 

 

 

 

 

clip_image034PAGE MANAGEMENT 菜单的 PAGE DETAILS里:

  • PAGE NAME 处输入"SuperSimple"
  • PAGE TITLE处输入"SuperSimple"
  • DESCRIPTION处输入"SuperSimple"
  • VIEW PAGE 下面选中 ALL USERS

点击“UPDATE”

 

 

 

 

 

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

 

 

 

 

 

 

 

 

 

 

clip_image037

然后点击 ADD.

 

 

模块将在页面上显示

clip_image039

 

 

 

 

 

 

 

 

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

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

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
2月前
|
数据库
如何通过增强(Enhancement)的方式,给 ABAP Function Module 增添新的功能试读版
如何通过增强(Enhancement)的方式,给 ABAP Function Module 增添新的功能试读版
26 0
|
前端开发
前端hook项目moblie总结笔记-ant design动态数据赋值
前端hook项目moblie总结笔记-ant design动态数据赋值
57 0
|
前端开发
前端hook项目moblie总结笔记-ant design进行动态表单添加
前端hook项目moblie总结笔记-ant design进行动态表单添加
83 0
|
前端开发
前端hook项目moblie总结笔记-ant design动态数据赋值
前端hook项目moblie总结笔记-ant design动态数据赋值
58 0
|
存储 数据库
|
编译器
Qt Creator plugin动手实践(5)分享一个简化版的插件框架,qt-creator-minimal
Qt Creator plugin动手实践(5)分享一个简化版的插件框架,qt-creator-minimal
356 0
Qt Creator plugin动手实践(5)分享一个简化版的插件框架,qt-creator-minimal

热门文章

最新文章