天天看點

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 (

點選下載下傳

)

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

2. 安裝SQL Server Express (

)

3. 使用下面兩種方法中的一種安裝DotNetNuke并建立一個DotNetNuke網站

l

Setting-up the Development Environment

(using IIS)

(without IIS)

4. 在Visual Studio,選擇“Build”下的“Build Solution”,如果順利通過編譯,我們就可以進入下一步。

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯
是否已經具備開發的環境了?

你必須有一個已經架好并能運作的DotNetNuke 4 網站才可以進行下一步,如果你沒做到這一點,可以使用

這個連結

尋求幫助。

DotNetNuke不斷的在更新,是以

DotNetNuke的論壇

是尋找最新的幫助和資訊最好的地方。

非常抱歉我沒法為網站架設提供單獨的技術支援,不過我會對跟本篇教程有關的問題提供幫助。

建立子產品

建立子產品的分為兩步:

  1. 建立view控件
  2. 在DotNetNuke中注冊這個子產品

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯
建立子產品目錄

在Visual Studio中打開你的DotNetNuke網站

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯
建立View控件

在"DesktopModules" 目錄上右鍵,選擇"New Folder"

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

建立的目錄命名為"SuperSimple"

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

然後在"SuperSimple"目錄上右鍵,選擇 "Add New Item..."    

點選"Add New Item"後出現一個對話框:

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

點選"Visual Studio Installed Templates"下的"Web User Control"

  • 在"Name"後面輸入"SuperSimple.ascx"
  • 確定"Place code in a separate file"已經選中
  • 點選"Add"按鍵
DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

一個"SuperSimple.ascx"檔案會在"DesktopModules"目錄下的"SuperSimple"目錄内建立。

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

點選檔案旁邊的“加号”就會顯示現關聯的code behind檔案"SuperSimple.ascx.vb" (或者 "SuperSimple.ascx.cs").

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

輕按兩下"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>       
DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

點選頁面左下角的"Design"按鍵轉換到設計視圖

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

輕按兩下"SuperSimple.ascx.vb" (或 "SuperSimple.ascx.cs")

把裡面的代碼用下面的代碼完全替換:

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       
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(); 


} 


}       
DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

從BUILD 菜單下選擇"Build Page".

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

頁面應該能通過編譯

在 DotNetNuke中注冊子產品

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

使用"host"登入到你的DotNetNuke站點,在菜單中選擇"Host"然後選擇 "Module Definitions"。

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

點選左上角向下的小黑箭頭,在出現的菜單中選擇"Create New Module"。

在 Edit Module Definitions菜單裡:

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯
  • 在MODULE NAME處輸入"SuperSimple"
  • 在FOLDER TITLE處輸入"SuperSimple"
  • 在FRIENDLY TITLE處輸入"SuperSimple"
  • 在DESCRIPTION處輸入"SuperSimple"
  • 在VERSION處輸入"1.0"

然後點選UPDATE

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

在 NEW DEFINITION 輸入 "SuperSimple"

然後點選 "Add"

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

然後點選 "Add Control"

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

在 Edit Module Control 菜單裡:

  • 在TITLE處 輸入 "SuperSimple"
  • 在SOURCE處從下拉清單中選擇 "DesktopModule/SuperSimple/SuperSimple.ascx"
  • 在TYPE 處從下拉清單中選擇"View"

然後點選 UPDATE

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

在網站的左上角的PAGE FUNCTIONS菜單裡點選ADD。

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

在PAGE MANAGEMENT 菜單的 PAGE DETAILS裡:

  • 在PAGE NAME 處輸入"SuperSimple"
  • 在 PAGE TITLE處輸入"SuperSimple"
  • 在 VIEW PAGE 下面選中 ALL USERS

點選“UPDATE”

在 MODULE 的下拉清單中選擇 "SuperSimple".

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯
DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

然後點選 ADD.

子產品将在頁面上顯示

DotNetNuke子產品制作Super-Simple(DAL+)教程-翻譯

原為位址:

http://www.adefwebserver.com/DotNetNukeHELP/DNN_ShowMeThePages/

本文譯者m2land,轉載請注明出處,作者部落格位址:

http://m2land.cnblogs.com