一、前言
本系统开发语言为C#,数据库为SQL Server,开发环境为VS2010。主要功能是为用户提供了一个发布信息和讨论问题的平台,用户分为三个级别,对应不同的操作权限。基础操作为浏览、发表、删除帖子和对帖子的评论回复。管理员可以对论坛板块进行管理,也可以删除普通用户发表的帖子。
二、系统设计
数据库设计
论坛系统中主要的数据表有tbUser(用户信息表)、tbPost(帖子信息表)、tbRevert(回帖信息表)和tbModule(版块信息表)。数据库名:BBSDB。
实体层(Model)设计
在论坛网站系统中,包含4个实体类,它们分别是User类(用户信息类)、Module类(版块类)、Post类(帖子类)和Revert类(回复信息类),以Post类为例,其源码如下:
namespace Model
{
public class Post
{
private int postID;//帖子ID
public int PostID
{
get { return postID; }
set { postID = value; }
}
private string postTitle;//帖子标题
public string PostTitle
{
get { return postTitle; }
set { postTitle = value; }
}
private string postContent;//帖子内容
public string PostContent
{
get { return postContent; }
set { postContent = value; }
}
private int userID;//帖子的发布者
public int UserID
{
get { return userID; }
set { userID = value; }
}
private DateTime postDate;//发布时间
public DateTime PostDate
{
get { return postDate; }
set { postDate = value; }
}
private int moduleID;//模块ID,与Module类保持一致
public int ModuleID
{
get { return moduleID; }
set { moduleID = value; }
}
}
}
数据访问层(DAL)设计
数据访问层主要用来执行一些数据库的操作,如连接数据库,对数据实行增加、删除、修改、查询等操作,DAL层将这些操作封装起来,并将所取得的结果返回给表现层。在论坛网站系统中,共包含5个类,它们分别是SQLHelper类、PostDAL类、UserDAL类、ModuleDAL类和RevertDAL类。其中SQLHelper类用来封装一些常用的数据库操作,其他4个类分别用来表示对数据库表的一些基本操作。现以postDAL为例,其源码如下:
using Model;
namespace DAL
{
public class PostDAL
{
#region 新建一个帖子
public bool CreatePost(Post post)
{
bool flag = false;
string sqlStr = "insert into tbPost(PostTitle,PostContent,PostDate,UserID,ModuleId) values" +
"(@postTitle,@postContent,@postDate,@userID,@moduleID)";
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@postTitle",post.PostTitle),
new SqlParameter("@postContent",post.PostContent),
new SqlParameter("@postDate",post.PostDate),
new SqlParameter("@userID",post.UserID),
new SqlParameter("@moduleID",post.ModuleID)
};
try
{
SQLHelper helper = new SQLHelper();
flag = helper.ExecuteCommand(sqlStr, param);
}
catch
{
flag = false;
}
return flag;
}
#endregion
#region 删除