西安航空技术高等专科学校计算机工程系
SET QUOTED_IDENTIFIER ON GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[message]') AND type in (N'U')) BEGIN
CREATE TABLE [dbo].[message](
[messageId] [bigint] IDENTITY(1,1) NOT NULL, [massageNickName] [nvarchar](50) NOT NULL, [messageTitle] [nvarchar](50) NOT NULL, [messageHomePage] [nvarchar](50) NOT NULL, [messageContent] [ntext] NOT NULL, [messageDate] [datetime] NOT NULL, [messageReply] [ntext] NULL,
CONSTRAINT [PK__message__060DEAE8] PRIMARY KEY CLUSTERED (
[messageId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] END GO
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[admin]') AND type in (N'U')) BEGIN
CREATE TABLE [dbo].[admin](
[adminId] [char](10) NOT NULL,
[adminPWD] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_admin] PRIMARY KEY CLUSTERED (
[adminId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] END GO
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[critique]') AND type in (N'U')) BEGIN
11
西安航空技术高等专科学校计算机工程系
CREATE TABLE [dbo].[critique](
[critiqueId] [bigint] IDENTITY(1,1) NOT NULL, [critiqueNickName] [nvarchar](50) NULL, [critiqueTitle] [nvarchar](50) NOT NULL, [critiqueContent] [nvarchar](250) NOT NULL, [critiqueDate] [datetime] NOT NULL, [articleId] [bigint] NOT NULL,
CONSTRAINT [PK_critique] PRIMARY KEY CLUSTERED (
[critiqueId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] END GO
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[article]') AND type in (N'U')) BEGIN
CREATE TABLE [dbo].[article](
[articleId] [bigint] IDENTITY(1,1) NOT NULL, [articleAuthor] [nvarchar](50) NOT NULL, [articleTitle] [nvarchar](200) NOT NULL, [articleBrief] [nvarchar](200) NOT NULL, [articleContent] [ntext] NOT NULL, [articleDate] [datetime] NOT NULL,
[articleRQ] [bigint] NULL CONSTRAINT [DF_article_articleRQ] DEFAULT ((0)),
[articleReply] [bigint] NULL CONSTRAINT [DF_article_articleReply] DEFAULT ((0)),
[classId] [bigint] NOT NULL,
CONSTRAINT [PK__article__09DE7BCC] PRIMARY KEY CLUSTERED (
[articleId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] END GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_critique_critique]') AND parent_object_id = OBJECT_ID(N'[dbo].[critique]'))
ALTER TABLE [dbo].[critique] WITH CHECK ADD CONSTRAINT
12
西安航空技术高等专科学校计算机工程系
[FK_critique_critique] FOREIGN KEY([articleId]) REFERENCES [dbo].[article] ([articleId]) GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_article_class]') AND parent_object_id = OBJECT_ID(N'[dbo].[article]')) ALTER TABLE [dbo].[article] WITH CHECK ADD CONSTRAINT [FK_article_class] FOREIGN KEY([classId])
REFERENCES [dbo].[class] ([classId])
5.系统实现
5.1普通用户进入的主页
从数据库中分别查询出文章类别、友情链接、人气比较高的文章作为推荐文章、所有文章的数据,具体代码如下: 生成文章类别的代码如下: public void ClassBind() {
DBOperate DBOp = new DBOperate();
string sqlString = string.Format(\); DataSet ds = DBOp.GetDataSet(sqlString); dlClass.DataSource = ds; dlClass.DataBind(); }
生成友情Blog链接的代码和以上的类似 生成推荐文章的代码如下:
public void NewArticleBind() {
DBOperate DBOp = new DBOperate();
string sqlString = string.Format(\article order by articleRQ desc\); DataSet ds = new DataSet();
ds = DBOp.GetDataSet(sqlString); dlArticle.DataSource = ds; dlArticle.DataBind(); }
生成文章列表的代码和上面的类似 生成阅读文章的代码如下:
protected void grdArticle_RowUpdating(object sender, GridViewUpdateEventArgs e)
13
西安航空技术高等专科学校计算机工程系
{
string articleId =
grdArticle.DataKeys[e.RowIndex].Value.ToString ();
string sqlString = string.Format(\articleRQ=articleRQ+1 where articleId=articleId\); DBOperate DBOp = new DBOperate(); DBOp.Query(sqlString); ArticleBind();
Response.Redirect(\+articleId); }
运行界面如下:
5.2普通用户阅读文章对文章进行评论
普通用户点击“点击阅读文章”按钮给文章阅读数量加一,进入阅读文章界面,用户可以给文章进行评论,填写完评论内容后,点击“评论”按钮可以进行评论,具体代码如下:
进行评论的代码如下:
protected void btnCritique_Click(object sender, EventArgs e) {
if (txtName.Text.Trim() == \ || txtTitle.Text.Trim() == \ || txtContent.Text.Trim() == \) {
Response.Write(\网友昵称,评论标题,评论类容不能为空!')\);
14
西安航空技术高等专科学校计算机工程系
} else {
CritiqueManage cm = new CritiqueManage(); cm.CritiqueNickName = txtName.Text.Trim(); cm.CritiqueTitle = txtTitle.Text.Trim();
cm.CritiqueContent = txtContent.Text.Trim(); cm.CritiqueDate = DateTime.Now; cm.ArticleId
=Convert.ToInt32( Request.QueryString[\]); cm.AddCritique();
string sqlString = string.Format(\articleReply=articleReply+1 where articleId='{0}'\, cm.ArticleId); DBOperate DBOp = new DBOperate(); DBOp.Query(sqlString); ArticleBind(); txtName.Text = \; txtTitle.Text = \; txtContent.Text = \; }
CritiqueBind(); }
运行界面如下:
15