来源:
中国自学编程网
作者:
若水
2008-04-11/11:25
最近要开发一个项目,初定开发环境为DotNetNuke,从来没有用过这东东,一阵疯狂的研究,终于可以用C#做一个模块在环境中运行。但之后又决定弃用此工具,一阵郁闷。不过我发现网上的关于DotNetNuke环境下C#开发的文章不多,所以把我学的奉献给大家,虽然很多方面还处于搞不明白阶段,但是同舟共济,大家相互补充,也能给初学者一点启示。
不过第天工作忙,只能晚上写了,所以要分几篇来写,请大家担待。
一,配制环境
我本人用的是DotNetNuke 04.05.03,之后安装了中文包。不过我想版本对开发的影响不大,所以大家如果是4点几的版本就可以试着开发。至于DotNetNuke的下载地址,从网上很容易就能搜索出来,这里就不再废话。开发工具是VS.NET2005,然后安装dotnetnuke starterKit,没有安装的大家可以去百度搜索下载一下,这都不是难题,这里就不再详细说明。数据库用的是SqlServer2000。
二,建数据脚本
本例子旨在演示一下怎么能够建立模块,所以功能上不会很强大。流程很简单,只要建一个文章表(Article),然后实现在其中添加文章。表中有五个字段,分别是
Id(唯一标识),Title(文章标题),Content(文章正文),CreateTime(文章发布时间),Author(文章作者)。我是在企业管理器中建表与存储过程,然后在数据库文件夹上右击==>所有任务==>生成Sql脚本来建立的数据脚本。大家可以手写脚本,也可以这样去做。脚本最终结果如下:
if exists (select * from dbo.sysobjects where id = object_id(N’{databaseOwner}[{objectQualifier}article]’) and OBJECTPROPERTY(id,N’IsUserTable’) = 1)
drop table {databaseOwner}[{objectQualifier}article]
GO
CREATE TABLE {databaseOwner}[{objectQualifier}article] (
[Id] [int] IDENTITY (1, 1) NOT NULL ,
[Title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
[Content] [nvarchar] (4000) COLLATE Chinese_PRC_CI_AS NULL ,
[CreateTime] [datetime] NULL ,
[Author] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
if exists (select * from dbo.sysobjects where id = object_id(N’{databaseOwner}{objectQualifier}F_ARTICLE_CREATE’) and OBJECTPROPERTY(id,
N’IsProcedure’) = 1)
drop procedure {databaseOwner}{objectQualifier}F_ARTICLE_CREATE
GO
if exists (select * from dbo.sysobjects where id = object_id(N’{databaseOwner}{objectQualifier}F_ARTICLE_DELETE’) and OBJECTPROPERTY(id,
N’IsProcedure’) = 1)
drop procedure {databaseOwner}{objectQualifier}F_ARTICLE_DELETE
GO
if exists (select * from dbo.sysobjects where id = object_id(N’{databaseOwner}{objectQualifier}F_ARTICLE_GETALL’) and OBJECTPROPERTY(id,
N’IsProcedure’) = 1)
drop procedure {databaseOwner}{objectQualifier}F_ARTICLE_GETALL
GO
if exists (select * from dbo.sysobjects where id = object_id(N’{databaseOwner}{objectQualifier}F_ARTICLE_GETDETAILS’) and OBJECTPROPERTY(id,
N’IsProcedure’) = 1)
drop procedure {databaseOwner}{objectQualifier}F_ARTICLE_GETDETAILS
GO
if exists (select * from dbo.sysobjects where id = object_id(N’{databaseOwner}{objectQualifier}F_ARTICLE_UPDATE’) and OBJECTPROPERTY(id,
N’IsProcedure’) = 1)
drop procedure {databaseOwner}{objectQualifier}F_ARTICLE_UPDATE
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}F_ARTICLE_CREATE
@Title nvarchar(100),
@Content nvarchar(4000),
@CreateTime datetime,
@Author nvarchar(50)
AS
INSERT INTO {objectQualifier}article(title,content,createtime,author)VALUES(@Title,@content,@CreateTime,@author)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}F_ARTICLE_DELETE
@ID INT
AS
DELETE FROM {databaseOwner}[{objectQualifier}article] WHERE [ID]=@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}F_ARTICLE_GETALL
AS
SELECT * FROM {databaseOwner}[{objectQualifier}article]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON #p#分页标题#e#
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}F_ARTICLE_GETDETAILS
@ID int
AS
SELECT * FROM {databaseOwner}[{objectQualifier}article] WHERE [ID]=@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE {databaseOwner}{objectQualifier}F_ARTICLE_UPDATE
@ID int,
@Title nvarchar(100),
@Content nvarchar(4000),
@CreateTime datetime,
@Author nvarchar(50)
AS
UPDATE {databaseOwner}[{objectQualifier}article] SET Title=@Title,Content=@Content,CreateTime=@CreateTime,author=@Author
WHERE [ID]=@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
注意:如果是生成的脚本,要在存储过程名称和表名称前如上所示加上{databaseOwner}{objectQualifier}. 生成的脚本如果出现先建立存储过程后建表的现实,要把顺序更正,否则会出现错误。 脚本生成之后,要用正确的命名方式命名:01.00.00.SqlDataProvider(等下面谈到建立项目时模板会自动添加正确格式的数据脚本文件,把这些脚本复制粘贴过去即可)。
至此,数据库脚本建立完毕。