新闻发布管理系统 - 毕业论文

更新时间:2024-03-10 09:47:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

河北大学2016届本科生毕业论文(设计)

新闻发布管理系统

摘 要

随着互联网的普及和迅速发展,人们对获取外界信息的实时性要求也有所提高。而媒体作为新闻消息的提供者,其报道模式对人类生活质量有着重要影响。针对新闻发布管理这一环节,传统的报纸杂志电视已经不能跟上生活节奏越来越快的步伐,开发高效实用的新闻发布管理系统是有必要的。该毕业设计采用ASP.NET的三层架构模型,基于Browser/Server结构,在Visual Studio开发工具下,把C#作为开发语言,SQL Server作为数据库,按照软件工程的方法开发新闻发布管理系统。系统主要分为前台功能模块和后台管理模块,其中前台功能模块主要包括用户注册模块、用户登录模块、新闻浏览模块、新闻评论模块、个人信息管理模块;后台管理模块包括类别管理模块、新闻管理模块、评论管理模块、用户管理模块。该系统与传统纸质新闻媒体相比,将广大浏览者、新闻消息、新闻记者和新闻发行者紧密联系在一起,有效缩短了新闻的发布时间,大大提高了工作效率。经过系统测试,达到了预期目标。

关键字:新闻发布系统;ASP.NET;三层架构;数据库;

河北大学2016届本科生毕业论文(设计)

News Issuing And Management System

ABSTRACT

With the popularity and rapid development of the Internet, people need to obtain the real-time information of the outside world. And the media as a news provider , its report way has a significant impact on the quality of human life. For the aspect of News issuing , the traditional newspapers ,magazines and television has been unable to keep up with the pace of life,it is necessary to develop an efficient and practical management system.This graduation project based on Browser/Server structure adopts 3-Tier Architecture of ASP.NET,uses Visual Studio as the development tools, the development language is made by using C#, the data base is built by SQL Server,and the development of system is completely according to the method of the software engineering.This system is divided into the background management module and front function module.function module of the front desk includes user registration module, the user login module, news browsing module, news commentary module, personal information management module;Background management module includes category management module, news management module, comment management module, user management module.Compared with the traditional paper media,the system binds readers,news, journalists and chief editor together,effectively shortens the release time,greatly improves the work efficiency.After the system test, the anticipated goal is achieved.

Key words: News issuing system;ASP.NET;3-Tier architecture;Database

河北大学2016届本科生毕业论文(设计)

目 录

1 引言 ................................................... 1 1.1 课题的背景 ................................................ 1 1.2 国内外研究现状及发展趋势 .................................. 1 1.2.1 国内外研究现状 .......................................... 1 1.2.2 发展趋势 ................................................ 1 1.3 系统设计目标 .............................................. 2 1.4 论文构成及研究内容 ........................................ 2

2 系统分析 ............................................... 3

2.1 可行性研究 ................................................ 3 2.1.1 技术可行性 .............................................. 3 2.1.2 经济可行性 .............................................. 3 2.1.3 操作可行性 .............................................. 3 2.1.4 法律可行性 .............................................. 3 2.2 需求分析 .................................................. 3 2.2.1 系统用户需求 ............................................ 4 2.2.2 系统业务流程分析 ........................................ 4 2.2.3 系统功能需求 ............................................ 5 2.2.4 数据流分析 .............................................. 6

3 系统总体设计 ........................................... 9

3.1 总体设计的原理 ............................................ 9

河北大学2016届本科生毕业论文(设计)

3.2 系统的功能层次结构图 ...................................... 9 3.3 数据库设计 ............................................... 10 3.3.1 实体E-R图 ............................................. 10 3.3.2 数据库的逻辑结构 ....................................... 13

4 详细设计 .............................................. 14

4.1 数据库的实现 ............................................. 14 4.1.1 数据库的建立 ........................................... 14 4.1.2 数据库的连接 ........................................... 17 4.2 系统设计流程 ............................................. 18

5 开发工具及相关技术介绍 ................................ 22

5.1 开发工具介绍 ............................................. 22 5.1.1 Visual Studio介绍 ..................................... 22 5.1.2 SQL Server介绍 ........................................ 23 5.1.3 IIS介绍 ............................................... 23 5.2 开发模式B/S介绍 ......................................... 23 5.3 开发技术介绍 ............................................. 24 5.3.1 ASP.NET介绍 ........................................... 24 5.3.2 ADO.NET介绍 ........................................... 24

6 系统实现 .............................................. 25

6.1 前台功能模块的实现 ....................................... 25 6.1.1 新闻主页模块 ........................................... 25 6.1.2 用户注册模块 ........................................... 26

河北大学2016届本科生毕业论文(设计)

6.1.3 用户登录模块 ........................................... 26 6.1.4 个人信息管理模块 ....................................... 26 6.1.5 新闻搜索模块 ........................................... 27 6.1.6 新闻阅读模块 ........................................... 28 6.1.7 分类阅读模块 ........................................... 29 6.1.8 新闻评论模块 ........................................... 30 6.2 后台管理模块的实现 ....................................... 31 6.2.1 后台登录模块 ........................................... 31 6.2.2 类别管理模块 ........................................... 33 6.2.3 新闻管理模块 ........................................... 34 6.2.4 用户管理模块 ........................................... 36 6.2.5 评论管理模块 ........................................... 37 6.3 系统出错界面 ............................................. 38

7 结论 .................................................. 39 参考文献 ................................................. 40 致谢 ..................................................... 41 附录 ..................................................... 41

河北大学2016届本科生毕业论文(设计)

(5)用户搜索:提供用户通过新闻标题和内容关键字搜索新闻的功能,搜索到的所有新闻会以列表形式展现,用户可以点击查看。

(6)新闻阅读:新闻阅读模块主要负责新闻的格式,包括新闻类别,新闻标题,新闻作者,新闻发布日期,新闻内容,新闻评论等,这些都会按照一定的模板呈现给用户。 (7)新闻分类:用户可以查看自己感兴趣的领域的新闻,例如国际新闻、财经新闻、房产新闻等。各类新闻分页显示,用户可以通过翻页浏览更多新闻。

(8)用户评论:用户可以发表新闻评论,也可以重置评论,用户的评论也可以被其他用户看到。 ? 后台管理模块

(1)类别管理:管理新闻类别,可以对新闻类别进行添加、修改和删除操作。 (2)新闻管理:对新闻的基本信息进行管理,包括新闻的标题、新闻内容、新闻评论、等信息,可以对新闻进行删除、添加和修改操作。主编要对新闻进行审核,未经审核和审核不通过的新闻不可以显示在前台界面。

(3)用户管理:后台管理员拥有系统的最高权限,可以对系统用户进行管理。 (4)评论管理:管理新闻评论,可以对新闻评论进行删除操作。

2.2.4 数据流分析

根据系统用户需求和功能需求,得知新闻发布管理系统的总体数据流图如下

图2-4 新闻发布管理系统数据流图

用户登录数据流图如下

6

河北大学2016届本科生毕业论文(设计)

用户注册用户信息用户表用户信息后台管理员主编后台管理员主编用户登录信息身份验证编辑编辑普通用户普通用户

图2-5 用户登录数据流图

主编登录成功后数据流图如下

新闻信息新闻表审核新闻审核信息主编退出系统审核表 图2-6 主编数据流图

编辑登录成功后的数据流图如下

类别信息类别表发表新闻新闻信息编辑退出系统新闻表 图2-7 编辑数据流图

普通用户登录成功后的数据流图如下

7

河北大学2016届本科生毕业论文(设计)

用户信息退出系统修改信息用户表用户信息普通用户浏览新闻新闻信息新闻表评论新闻评论评论表 图2-8 普通用户数据流图

后台管理员登录成功后的数据流图如下

用户信息用户表添加新类别类别信息用户信息用户管理类别管理用户ID更新前信息更新后信息类别表搜索条件查询结果后台管理员新闻管理更新前信息更新后信息搜索条件查询结果新闻表评论管理退出系统更新前信息更新后信息评论表 图2-9 后台管理员数据流图

8

河北大学2016届本科生毕业论文(设计)

3 系统总体设计

3.1 总体设计的原理

总体设计原理包括:

(1)模块化。模块化就是把整个程序划分为多个模块,每个模块有自己的名字并可以被独立访问。所有模块的功能集合起来就可以满足用户需求。

(2)抽象。抽象是暂时忽略软件的细节,集中精力将软件的本质特征提取出来。 (3)逐步求精。总体设计需要先解决主要问题,再将问题一步步细化。

(4)信息隐藏和局部化。设计和确定模块时,使得一个模块内包含的信息对于不需要这些信息的模块来说,是不能访问的;并且应该在相近的物理地址上放置关系较密切的软件元素。

(5)模块独立。模块之间应该遵循高内聚,低耦合的原则。

3.2 系统的功能层次结构图

新闻发布管理系统用户登录前台功能模块后台管理模块用户注册模块用户登录模块个人信息管理模块新闻主页模块新闻搜索模块新闻阅读模块分类阅读模块新闻评论模块类别管理模块用户管理模块新闻管理模块评论管理模块添加类别修改类别删除类别删除用户添加新闻修改新闻删除新闻审核新闻删除评论 图3-1 新闻发布管理系统的功能结构层次图

前台功能模块:可以在前台Web浏览器中查看这些功能。 用户注册模块:将用户信息记录到用户表

用户登录模块:用来区分三种用户,普通用户、编辑和主编。 个人信息管理:用户登录后可以修改用户表中的个人信息

9

河北大学2016届本科生毕业论文(设计)

新闻主页模块:在类别表和新闻表中读取新闻信息并按照一定模板显示在首页。 新闻搜索模块:将新闻表中所有新闻的标题或内容关键字与搜索框中输入的字段进行

比对,找到所有包含输入字段的新闻纪录;再根据该新闻记录中的新闻类别ID,在类别表中找到类别名称;从而将新闻的所属类别,新闻标题和发布时间展示给普通用户。

新闻阅读模块:系统根据新闻ID从新闻表中取出新闻的主体内容。 分类阅读模块:系统根据类别ID在新闻表中取出该类别下的所有新闻。

新闻评论模块:将想要评论的新闻的ID号和评论的内容以及评论人的信息和评论时

间记录到评论表中。也可以根据想要查看的新闻的ID号,在评论表中调出所有他人评论。

后台管理模块:针对编辑、主编和后台管理员

添加类别:将类别信息添加到类别表,此类别可被选择。 修改类别:根据类别ID,将类别表中相应的类别信息进行更新。

删除类别:根据该类别ID找到新闻表中该类别下的所有新闻,并通过新闻ID从评论

表中找到所有相关评论,先删除所有评论再删除新闻,最后删除类别本身。 审核通过后,此新闻可以被浏览者查看。

添加新闻:将新闻的类别ID和新闻标题以及新闻内容等记录到到新闻表中,经主编修改新闻:根据新闻ID,在新闻表中找出相应记录并进行更新。

删除新闻:根据该新闻ID从评论表中找到所有相关评论,先删除所有评论再将新闻

本身从新闻表中进行删除。

审核新闻:将主编ID、新闻ID、审阅时间等记录到审阅表,经主编审核通过后的新

闻才可以在前台界面显示。

删除评论:将该评论记录从评论表中移除。 删除用户:将该用户从用户表中移除。

3.3 数据库设计

在系统的开发过程中,数据库的设计是非常关键的一步。良好的数据结构设计不仅可以减少数据冗余、提高查询效率,而且还可以降低应用程序的编写难度,提高工作效率。

3.3.1 实体E-R图

本系统在数据库中存放了七个表,分别是主编表(chiefEditor)、用户表(user)、类别表(category)、新闻表(news)、审阅表(review)、评论表(comment)、权限表(rights)。

新闻发布管理系统的主要实体间关系E-R图如图3-2所示:

10

河北大学2016届本科生毕业论文(设计)

对应n用户评论1新闻m新闻管理发表审阅nn1后台管理员编辑主编nn属于1新闻类别发表m普通用户 图3-2 新闻发布管理系统主要实体间关系E-R图

用户实体E-R图如下:

用户用户ID用户名电子邮箱所属权限密码图3-3 用户实体E-R图

类别实体E-R图如下:

类别类别ID图3-4 类别实体E-R图

类别名称 新闻实体E-R图如下:

11

河北大学2016届本科生毕业论文(设计)

新闻新闻标题新闻内容所属类别发布时间图片路径新闻ID新闻作者修改时间 图3-5 新闻实体E-R图

审阅的E-R图如下:

审阅ID号主编ID新闻ID审核时间 图3-6 审阅E-R图

评论实体E-R图如下:

评论评论ID评论内容评论时间评论人姓名所属新闻图3-7 评论实体E-R图

权限实体E-R图如下:

权限权限ID图3-8 权限实体E-R图

权限名称 12

河北大学2016届本科生毕业论文(设计)

3.3.2 数据库的逻辑结构

根据以上E-R图可以得到如下关系模式: ? user( id,userName,password,E-mail,rightId)

用户表(用户id号,用户名,密码,电子邮箱,所属权限) ? category( id,caName)

类别表(类别id号,类别名称)

? news( id,title,content,createTime,caId,updateTime,author,imagePath)

新闻表(新闻id号,新闻标题,新闻内容,发布时间,所属类别,修改时间,新闻作者,图片路径)

? review( id,cfeditorId,newsId,reviewTime)

审阅表(审阅id号,主编id号,新闻id号,审阅时间) ? comment( id,content,createTime,commentator,newsId)

评论表(评论id号,评论内容,发表时间,评论人姓名,所属新闻) ? rights ( id,rightName)

权限表(权限id号,权限名称)

综上,本系统在数据库中存放的表如表3-1所示:

表3-1 数据库中的表介绍

数据库表名 说明 存放用户信息 存放新闻类别信息 存放新闻信息 存放新闻审核信息 存放新闻评论 存放权限信息 user category news review comment rights

13

河北大学2016届本科生毕业论文(设计)

4 详细设计

4.1 数据库的实现

本节在SQL Server2012中利用SQL语句和图形界面相结合的方法建立各个表并设置其主外键联系,并在项目中对数据库的连接进行详细设计。

4.1.1 数据库的建立

首先,将用户表、类别表、新闻表、审阅表、评论表和权限表的基本元素建立起来,如图4-1、图4-2、图4-3、图4-4、图4-5、图4-6:

用户表:

图4-1 用户表

类别表:

图4-2 类别表

新闻表:

图4-3 新闻表

审阅表:

14

河北大学2016届本科生毕业论文(设计)

图4-4 审阅表

评论表:

图4-5 新闻评论表

权限表:

图4-6 权限表

接下来,将评论时间、新闻发布时间、新闻修改时间和审核时间的默认值设置为getdate(),如图4-7:

图4-7 时间的默认值设置图

最后,通过数据库关系图来设置用户表、新闻表和评论表的外键,如图4-8、图4-9、图4-10、图4-11、图4-12、图4-13、图4-14:

15

河北大学2016届本科生毕业论文(设计)

图4-8 新闻发布管理系统数据库关系图

图4-9 用户表外键设置图

图4-10 新闻表外键设置图

16

河北大学2016届本科生毕业论文(设计)

图4-11 审阅表外键设置图(1)

图4-12 审阅表外键设置图(2)

图4-13 评论表外键设置图(1)

图4-14 评论表外键设置图(2)

4.1.2 数据库的连接

如果将数据库的连接字符串写在cs文件中,当数据库的用户名或密码发生改变时,项目需要重新生成,这样会耗费大量资源。比较好的解决方法是将其写在Web.config中。

Web.config中数据库连接字符串如下:

17

河北大学2016届本科生毕业论文(设计)

另外需要建立一个数据库助手类来执行基本的数据库增删改查工作,在cs文件建立数据库连接的主要代码是:

string connStr = ConfigurationManager.ConnectionStrings[\SqlConnection conn = new SqlConnection(connStr);

每次执行数据库的基本操作时询问数据库的连接状态,若处于关闭状态则连接数据库:conn.Open();执行完数据库的基本增删改查工作后需要断开连接:conn.Close()。

4.2 系统设计流程

以下将分别介绍各个模块的设计流程。 (1)用户注册模块

注册开始发送注册请求信息验证用户名是否已经存在是用户名已存在,重新注册用户否信息唯一,注册成功返回注册页面

图4-15 用户注册流程

(2)用户登录模块

输入用户名和密码验证是否存在该用户名密码否用户名与密码不匹配或者该用户名不存在是显示登录成功返回新闻主界面

图4-16 用户登录流程图

18

河北大学2016届本科生毕业论文(设计)

(3)新闻主页模块

开始连接数据库显示界面参数初始化读取数据库的新闻表读取显示模板读取数据库的新闻标题读取数据库的新闻内容对读取的新闻标题按照时间顺序倒序排序按照模板设计位置显示新闻标题刷新显示界面断开数据库连接结束

图4-17 新闻主页模块流程图

(4)新闻搜索模块

查询开始输入需要查询的新闻标题或内容关键字是否有与查询条件匹配的新闻?是否无符合条件的新闻显示新闻标题列表返回查询界面用户可以根据需要进入相关新闻界面

图4-18 新闻搜索流程

19

(5)新闻阅读模块

(6)分类阅读模块

(7)新闻评论模块

河北大学2016届本科生毕业论文(设计)

开始连接数据库显示界面参数初始化读取数据库中新闻编号读取显示模板读取数据库的新闻标题读取数据库中该新闻的存储路径读取显示网页文件按照模板设计位置显示新闻刷新显示界面断开数据库连接结束

图4-19 新闻阅读流程

开始连接数据库获取类别名称读取数据库中该类别的所有新闻标题读取显示模板按类别显示查询结果结束

图4-20 分类阅读流程

20

河北大学2016届本科生毕业论文(设计)

用户登录成功后浏览新闻页面输入评论语发表该评论返回相关评论界面请求重置评论修改评论

图4-21 新闻评论流程

(8)类别管理模块

进入类别管理添加类别修改现有类别删除现有类别录入类别信息编辑类别信息删除类别提交类别已启用NY保存抛出业务逻辑异常退出

图4-22 类别管理流程

(9)新闻管理模块

进入新闻管理模块添加新闻修改新闻删除新闻审核新闻添加新闻信息(类别、标题、新闻内容等)N是否已通过审核Y查看新闻并决定其是否通过审核对新闻进行修改或删除等待审核查看新闻发布详情审核通过的新闻在前台显示返回新闻管理界面

图4-23 新闻管理流程

21

河北大学2016届本科生毕业论文(设计)

5 开发工具及相关技术介绍

5.1 开发工具介绍

开发工具介绍主要介绍使用到的软件,包括Visual Studio、SQL Server和IIS服务器。

5.1.1 Visual Studio介绍

Visio Studio是一个可视化编译环境,它为开发者提供了很大的便利,从编写源代码到编译链接,从调试到最终发布,可以通过预设的菜单及选项很方便的完成。

Visual Studio .NET是为建立.NET Framework应用而设置的集成开发环境(IDE),它在.NET Framework和公共语言规范CLS(Common Language SPecification)基础上可运行VB、C++、C#、Jscript、J#等多种语言。它的体系结构如下:

VBC++C#JscriptJ#Common Language SpecificationVisio Studio .NET公共语言规范基于XML和SOAPWeb FormsWindows FormsXML & SOAPWeb ServiceData&XMLBase Class LibraryCommon Language Runtime基于XML的数据存取基础类库公共语言运行库

.Net Framework图5-1 Visio Studio .NET的结构

其中CLR公共语言运行时的结构如下:

通用类型系统(CTS)基础类库(Base Class Library)支持线程支持COM Marshaler类型检查器安全引擎MSIL编译器异常管理器调试引擎代码管理器垃圾回收器

类加载器(Class Loader)图5-2 CLR的结构

22

河北大学2016届本科生毕业论文(设计)

5.1.2 SQL Server介绍

现代计算机中存储的数据呈现暴涨的趋势,这样就需要一款高效的数据库管理工具来定义数据和操纵数据,使得数据在计算机中的存储更加有秩序,降低数据的冗余度,提高数据的独立性,也让数据的操纵更加方便。SQL Server采用图形界面,使用方法一目了然。

(1)SQL Server是一款Relational Database Management System (2)SQL Server与Windows系统完美结合 (3)SQL Server对计算机的硬件条件要求不高 (4)SQL Server具有良好的可伸缩性

(5)SQL Server具有良好的灵活性,它可以适应快速变化的环境

5.1.3 IIS介绍

IIS(Internet Information Server)是微软公司推出的Web服务器,具有安全、高效、易于管理的特点,是目前主流的Web服务器之一,可支持HTML、ASP、ASP.NET等。IIS在管理与配置上继承了Windows的特点,全部是图形界面的方式,操作起来十分简单。

5.2 开发模式B/S介绍

B/S模式也就是浏览器/服务器模式,它的界面部分是在浏览器端展示,而主要工作是由服务器端进行实现的,用户的请求由浏览器端提交给服务器端进行处理,而服务器将处理结果反馈给浏览器端,在浏览器端界面描画给用户查看。采用B/S模式不仅可以避免用户必须安装专业软件才能开发系统或者访问系统的局限性,而且更加便利。另外,软件系统的更新换代速度越来越快,采用B/S模式开发的系统的升级工作主要在服务器端进行,这样不管系统的用户群是多么的庞大,都不会影响系统维护工作的工作量,降低了系统的维护成本,这也是B/S模式的一大优点。

B/S模式的结构模型如下:

Web浏览器Web服务器事务处理过程功能层数据库服务器数据处理过程数据层

输出结果表示层发送请求发送请求数据库返回结果返回结果图5-3 B/S模式及其工作过程

23

河北大学2016届本科生毕业论文(设计)

5.3 开发技术介绍

开发技术介绍主要介绍系统中使用到的关键技术,包括ASP.NET和ADO.NET。

5.3.1 ASP.NET介绍

ASP.NET是一种动态网页技术,它开发的是Web应用程序,可以和数据库以及其他程序进行交互,是一种快捷的动态服务器页面开发工具。另外,ASP.NET的代码和页面分离,大大提高了代码的可读性,这样使得功能的扩展更加容易。

本课题将采用ASP.NET的三层架构,三层架构模型如下:

表示层业务逻辑层XML WebSOAP服务组件服务数据访问层客户端浏览器Web表单ADO.NET二进制DBMS 图5-4 三层架构

表示层用来和用户交互,接受用户的请求,并且将服务器的处理结果展示给用户。 业务逻辑层位于表示层和数据访问层之间,它在两者之间传递数据,按功能需求调用数据访问层中的方法,并向客户展示数据和信息。

数据访问层使用了一个强类型的DataSet,通过ADO.NET操纵数据,不涉及具体业务,它为业务逻辑层提供数据服务,如存储数据操作结果、返回数据检索结果等。

5.3.2 ADO.NET介绍

数据库是ASP.NET动态网站的基石,离开了数据库,ASP.NET的魅力将大大减少,所以ASP.NET支持ADO.NET以实现对数据库的访问。通过ADO.NET能够建立起用户与数据库之间的桥梁。用户只需在网页中执行SQL指令,即可对Web服务器上的数据库进行添加、修改和删除操作。

ADO.NET的结构模型如图5-5所示:

.NET Framework数据提供程序ConnectionDataAdapter事务SelectCommandCommand参数DataSetDataTableCollection数据表DataRowCollectionDataColumnCollectionConstraintCollectionDataRelationCollectionInsertCommandUpdateCommandDeleteCommandDataAdapter数据库XML

图5-5 ADO.NET的结构

24

河北大学2016届本科生毕业论文(设计)

6 系统实现

6.1 前台功能模块的实现

本系统是用作毕业设计,IIS在本机上开启一个服务器,系统实现的功能局限在本机使用。本章将对前台功能模块的实现界面及核心代码进行阐述。

6.1.1 新闻主页模块

在浏览器的地址栏里输入http://localhost:1675/default.aspx地址,就可以跳转到新闻发布管理系统的首页,这里也是浏览者访问系统的入口,如图6-1所示。

图6-1 新闻主页模块

其中展示最新新闻的主要代码如下: public DataTable SelectNewNews() {

return sqlhelper.ExecuteQuery(\CommandType.StoredProcedure); }

其中调用的数据库存储过程为:

CREATE PROCEDURE [dbo].[news_selectNewNews] AS BEGIN

select top 5 n.id,n.title,n.createTime,c.[name],c.id as caId from news n

25

河北大学2016届本科生毕业论文(设计)

GO

inner join category c on n.caId = c.id order by n.createTime desc

END

6.1.2 用户注册模块

点击主页上方的注册会弹出如下登录框:

图6-2 用户注册界面

6.1.3 用户登录模块

点击主页上方的登录会弹出如下登录框:

图6-3 前台用户登录界面

6.1.4 个人信息管理模块

用户登录成功后,点击右上方的管理个人信息即可进入个人信息管理模块。

26

河北大学2016届本科生毕业论文(设计)

图6-4 前台用户登录成功界面

图6-5 个人信息管理界面

6.1.5 新闻搜索模块

本系统可以根据新闻标题或者新闻内容来搜索新闻,如图6-6所示:

27

河北大学2016届本科生毕业论文(设计)

图6-6 搜索新闻界面

根据标题搜索新闻代码:

public DataTable SelectByTitle(string title)//title是新闻标题关键字 {

DataTable dt = new DataTable(); string cmdText = \

SqlParameter[] paras = new SqlParameter[] {new SqlParameter(\dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure); return dt; }

调用的数据库存储过程为:

CREATE PROCEDURE [dbo].[news_selectByTitle] @title varchar(100) AS BEGIN

select top 10 n.id,n.title,n.createTime,c.[name],n.caId from news n inner join category c on n.caId = c.id where n.title like '%'+@title+'%' order by n.createTime desc END GO

6.1.6 新闻阅读模块

在新闻首页或者分类浏览界面点击新闻标题可以查看新闻详细内容,如图6-7所示:

28

河北大学2016届本科生毕业论文(设计)

图6-7 查看新闻内容界面

查看新闻内容的主要代码:

public News SelectById(string id)//id是新闻ID {

News n = new News(); DataTable dt = new DataTable(); string cmdText = \

SqlParameter[] paras = new SqlParameter[] {new SqlParameter(\dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure); n.Id = id;

n.Title = dt.Rows[0][\n.Content = dt.Rows[0][\n.CreateTime = dt.Rows[0][\n.CaId = dt.Rows[0][\return n; }

6.1.7 分类阅读模块

浏览者点击左侧导航栏可以分类查看新闻,以浏览财经新闻为例,如图6-8所示:

29

河北大学2016届本科生毕业论文(设计)

图6-8 分类浏览新闻界面

分类浏览新闻是根据类别ID取出该类别下的所有新闻,调用的数据库存储过程为: CREATE PROCEDURE [dbo].[news_selectByCaId] @caid int AS BEGIN GO

select n.id,n.title,n.createTime,c.[name],n.caId from news n inner join category c on n.caId = c.id and n.caId=@caid order by n.createTime desc

END

6.1.8 新闻评论模块

本系统可以对新闻进行评论和查看他人对该条新闻的评论,如图6-9所示:

30

河北大学2016届本科生毕业论文(设计)

图6-9 新闻评论流程

添加评论的主要代码:

public bool Insert(Comment c)//c是评论实体类 {

bool flag = false;

string sql = \

values(@content,@userIp,@newsId)\SqlParameter[] paras = new SqlParameter[] { new SqlParameter(\ new SqlParameter(\ new SqlParameter(\

};

int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text); if (res > 0){flag = true;} return flag; }

6.2 后台管理模块的实现

后台管理模块主要包括类别管理模块、新闻管理模块、用户管理模块、评论管理模块。以下将分别介绍各个模块的实现。

6.2.1 后台登录模块

31

河北大学2016届本科生毕业论文(设计)

后台登录界面如下:

图6-10 后台登录界面

输入用户名、密码和验证码之后点击登陆按钮会进行以下判断:判断验证码是否输入正确,验证码不正确会提示重新输入;判断用户名和密码是否正确,只有当用户名和密码都正确时才会登录成功,否则就会提示登录失败。如图6-11、图6-12所示:

图6-11 登录信息不全界面

32

河北大学2016届本科生毕业论文(设计)

图6-12 登录信息错误界面

6.2.2 类别管理模块

类别管理的界面,如图6-13所示:

图6-13 类别管理界面

增加类别的核心代码:

public bool Insert(string caName)//caName是类别名称 {

bool flag = false;

private SQLHelper sqlhelper =new SQLHelper();

string sql = \SqlParameter[] paras = new SqlParameter[] {

new SqlParameter(\

};

int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text); if (res > 0){flag = true;}//插入成功 return flag; }

删除类别所使用数据库触发器:

CREATE TRIGGER [dbo].[trigCategoryDelete] ON [dbo].[category]

33

河北大学2016届本科生毕业论文(设计)

instead of DELETE AS BEGIN declare @caId int

select @caId=id from deleted

delete comment where newsId in (select ID from news where caId=@caId)- 删除评论 delete news where caId=@caId-- 删除新闻 delete category where id=@caId-- 删除类别 END

6.2.3 新闻管理模块

图6-14 新闻管理界面

删除新闻调用的数据库中的存储过程为: CREATE PROCEDURE [dbo].[news_delete] @id int AS BEGIN

delete comment where newsId=@id-- 先删除该新闻下的评论 delete news where id=@id-- 再删除新闻本身 END GO

34

河北大学2016届本科生毕业论文(设计)

修改新闻的界面,如图6-15所示:

图6-15 修改新闻界面

修改新闻调用的数据库中的存储过程为: CREATE PROCEDURE [dbo].[news_update] @id int,

@title varchar(100), @content text, @caid int AS BEGIN UPDATE news

SET title = @title, [content] = @content, caId = @caid where id=@id END GO

添加新闻的界面,如图6-16所示:

35

河北大学2016届本科生毕业论文(设计)

图6-16 添加新闻界面

添加新闻的核心代码: public bool Insert(News n) {

bool flag = false;

private SQLHelper sqlhelper =new SQLHelper(); string cmdText = \

SqlParameter[] paras = new SqlParameter[] {

new SqlParameter(\new SqlParameter(\new SqlParameter(\

};

int res = sqlhelper.ExecuteNonQuery(cmdText, paras,CommandType.StoredProcedure); if (res > 0){flag = true;} return flag; }

6.2.4 用户管理模块

用户管理的界面,如图6-17所示:

36

河北大学2016届本科生毕业论文(设计)

图6-17 用户管理界面

6.2.5 评论管理模块

删除评论的界面,如图6-18所示:

图6-18 删除评论界面

删除评论的主要代码为: public bool Delete(string id) {

37

河北大学2016届本科生毕业论文(设计)

bool flag = false;

string sql = \

SqlParameter[] paras = new SqlParameter[] { new SqlParameter(\

int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text); if (res > 0){flag = true;} return flag; }

6.3 系统出错界面

新闻发布管理系统的出错界面,如图6-19所示:

图6-19 出错界面

出错界面是一个静态页面,当浏览者发出的请求出现错误时,会弹出出错页,当出错页面出现5秒之后会返回主页,出错页面的主要代码实现为:

var i = 5;//倒数5秒后返回首页 var intervalid;

intervalid = setInterval(\每1000毫秒触发一次函数 function fun() {

if (i == 0) {

window.location.href = \是主页

clearInterval(intervalid);//当网络不好时,防止在计数器减到0时继续减少 }

document.getElementById(\提示i秒后返回主页 i=i-1; }

38

河北大学2016届本科生毕业论文(设计)

7 结论

在新闻发布管理系统的设计过程中,由于对ASP.NET并不熟悉,系统的开发也属于边学习边应用的过程,因此对ASP.NET的理解不免出现偏差和错误,程序中肯定存在许多需要改正的地方。另外,由于毕业设计的时间比较紧张,而且自己技术有限,系统不免有些简陋,这也是今后系统需要改进和完善的地方。

在开发过程中遇到了很多疑问,在查阅了大量的文献和教学视频以及老师同学的指导之后,终于解决了问题。在学习过程中学到了很多新知识,对ASP.NET、ADO.NET、HTML、CSS、Javascript等都有了更深层次的理解,对三层架构模型也更加的熟悉。这次毕业设计使我不但学习到了新技术,而且也积累了开发经验,从中也得到了许多乐趣。

39

河北大学2016届本科生毕业论文(设计)

参考文献

[1] Eric L.Brown Quilogy.SQL Server 2005中文版精粹.机械工业出版社华章公司,2007 [2] 杨晓光.Visual C#.net程序设计(修订本)[M].清华大学出版社,2011 [3] 萨师煊,王珊.数据库系统概论.北京:高等教育出版社,2000

[4] 刘志成.Windows 程序设计(C#2.0)实例教程[M].清华大学出版社,2010 [5] 张德静.深入浅出ASP程序设计与开发.中国青年出版社,2005年5月

[6] 宋昆,李严.SQL Server数据库开发实例解析[M].北京:机械工业出版社,2006 [7] 张海藩.软件工程导论.北京:清华大学出版社,2003

[8] 汪小平,吴永强.ASP.NET网络开发技术.北京:北京邮电出版社,2002 [9] 百度百科.B/S结构.http://baike.http://www.wodefanwen.com//view/268862.htm

[10] 刘晓华.SQL Server 2000数据库应用开发.北京:电子工业出版社,2001 [11] 张林.软件工程.北京:中国铁道出版社,2009

[12] 姜力,高群.SQL Server数据库设计与管理.中国林业出版社,2006

[13] 张蓓.ASP.NET通用模块及典型系统开发实例导航.北京:人民邮电出版社,2006

[14] (美)Fritz Onion著,施诺译.ASP.NET基础教程C#案例版.北京:清华大学出版社,2003 [15] Jesse Liberty,Dan Hurwitz.Programmimg ASP.NET 3rd Edition.New York:O'Reilly

40

河北大学2016届本科生毕业论文(设计)

致 谢

光阴如梭,毕业在即。本次系统的设计过程中,有许多人给了我很大的帮助,没有他们的支持,毕业设计也不会进行得这么顺利。在此,要衷心感谢给予我帮助的老师和同学们。

首先要衷心感谢我的指导老师张瑜老师,感谢张老师对我精心指导,在寒假的时候张老师就提前给了我们学习ASP.NET的电子书和论文相关的资料,从论文的选题、开题报告、系统的设计到论文的撰写,都倾注了大量的心血和提出了宝贵的意见,帮我调整思路和方向,督促毕业设计的进度,使我能够顺利完成本次毕业设计。再次向张老师表达我衷心的感谢!

同时,感谢这四年来教过我的老师和我的导员们,他们不仅教授了我知识,也在我这四年的成长中给了我许多宝贵的意见和鼓励。也非常感谢我的同学和舍友们,在学习的过程中他们不厌其烦的帮我解答编写代码中遇到的难题,鼓励我继续努力。有了他们的支持,我才顺利的完成了毕业设计!

41

河北大学2016届本科生毕业论文(设计)

附 录

外文资料:

ASP.NET Overview

Russ Basiura,Mike Batongbacal

ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Framework. You can code your applications in any language compatible with the common language runtime (CLR), including Microsoft Visual Basic, C#,JScript .NET, and J#. These languages enable you to develop ASP.NET applications that benefit from the common language runtime, type safety, inheritance,and so on.

ASP.NET includes:

? A page and controls framework ? The ASP.NET compiler ? Security infrastructure ? State-management facilities ? Application configuration

? Health monitoring and performance features ? Debugging support

? An XML Web services framework

? Extensible hosting environment and application life cycle management ? An extensible designer environment

The ASP.NET page and controls framework is a programming framework that runs on a Web server to dynamically produce and render ASP.NET Web pages. ASP.NET Web pages can be requested from any browser or client device, and ASP.NET renders mark up (such as HTML) to the requesting browser. As a rule, you can use the same page for multiple browsers, because ASP.NET renders the appropriate mark up for the browser making the request.However, you can design your ASP.NET Web page to target a specific browser,such as Microsoft Internet Explorer 6, and take advantage of the features of that browser. ASP.NET supports mobile controls for Web-enabled devices such as cellular phones, handheld computers, and personal digital assistants (PDAs).

ASP.NET Web pages are completely object-oriented. Within ASP.NET Web pages you can work with HTML elements using properties, methods, and events. The ASP.NET page framework removes the implementation details of the separation of client and server inherent in

42

河北大学2016届本科生毕业论文(设计)

Web-based applications by presenting a unified model for responding to client events in code that runs at the server. The framework also automatically maintains the state of a page and the controls on that page during the page processing life cycle.

The ASP.NET page and controls framework also enables you to encapsulate common UI functionality in easy-to-use,reusable controls. Controls are written once, can be used in many pages, and are integrated into the ASP.NET Web page that they are placed in during rendering.

The ASP.NET page and controls framework also provides features to control the overall look and feel of your Web site via themes and skins. You can define themes and skins and then apply them at a page level or at a control level.

In addition to themes, you can define master pages that you use to create a consistent layout for the pages in your application. A single master page defines the layout and standard behavior that you want for all the pages (or a group of pages) in your application. You can then create individual content pages that contain the page-specific content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.

All ASP.NET code is compiled, which enables strong typing, performance optimizations, and early binding, among other benefits. Once the code has been compiled, the common language runtime further compiles ASP.NET code to native code, providing improved performance.

ASP.NET includes a compiler that will compile all your application components including pages and controls into anassembly that the ASP.NET hosting environment can then use to service user requests.

In addition to the security features of .NET, ASP.NET provides an advanced security infrastructure for authenticating and authorizing user access as well as performing other security-related tasks.You can authenticate users using Windows authentication supplied by IIS, or you can manage authentication using your own user database using ASP.NET forms authentication and ASP.NET membership. Additionally, you can manage the authorization to the capabilities and information of your Web application using Windows groups or your own custom role database using ASP.NET roles. You can easily remove, add to, or replace these schemes depending upon the needs of your application.

ASP.NET always runs with a particular Windows identity so you can secure your application using Windows capabilities such as NTFS Access Control Lists (ACLs), database permissions, and so on. Formore information on the identity of ASP.NET,

ASP.NET provides intrinsic statemanagement functionality that enables you to store information between page requests, such as customer information or the contents of a shopping cart. You can save and manage application-specific, session-specific, page-specific,user-specific,

43

河北大学2016届本科生毕业论文(设计)

and developer-defined information. This information can be independent of any controls on the page.

ASP.NET offers distributed statefacilities, which enable you to manage state information across multipleinstances of the same application on one computer or on several computers.

ASP.NET applications use a configuration system that enables you to define configuration settings for your Web server,for a Web site, or for individual applications. You can make configuration settings at the time your ASP.NET applications are deployed and can add orrevise configuration settings at any time with minimal impact on operational Web applications and servers. ASP.NET configuration settings are stored in XML-based files. Because these XML files are ASCII text files, it is simple to make configuration changes to your Web applications. You can extend the configuration scheme to suit your requirements.

ASP.NET includes features that enable you to monitor health and performance of your ASP.NET application. ASP.NET health monitoring enables reporting of key events that provide information about the health of an application and about error conditions. These events show a combination of diagnostics and monitoring characteristics and offer a high degree of flexibility in terms of what is logged and how it is logged.

ASP.NET supports two groups of performance counters accessible to your applications: ? The ASP.NET system performance counter group ? The ASP.NET application performance counter group

ASP.NET takes advantage of the run-time debugging infrastructure to provide cross-language and cross-computer debugging support. You can debug both managed and unmanaged objects, as well as all languages supported by the common language runtime and script languages.

In addition, the ASP.NET page framework provides a trace mode that enables you to insert instrumentation messages into your ASP.NET Web pages.

ASP.NET supports XML Web services. An XML Web service is a component containing business functionality that enables applications to exchange information across firewalls using standards like HTTP and XML messaging. XML Web services are not tied to a particular component technology or object-calling convention. As a result, programs written in any language, using any component model, and running on any operating system can access XML Web services.

ASP.NET includes an extensible hosting environment that controls the life cycle of an application from when a user first accesses a resource (such as a page) in the application to the point at which the application is shut down. While ASP.NET relies on a Web server (IIS)as an application host, ASP.NET provides much of the hosting functionality itself. The architecture of

44

河北大学2016届本科生毕业论文(设计)

ASP.NET enables you to respond to applicationevents and create custom HTTP handlers and HTTP modules.

ASP.NET includes enhanced support for creating designers for Web server controls for use with a visual design tool such as Visual Studio. Designers enable you to build a design-time user interface for acontrol, so that developers can configure your control's properties and content in the visual design tool.

Introduction to the C# Language and the .NETFramework C# is an elegant and type-safe object-oriented language that enables developers to build a wide range of secure and robust applications that run on the .NET Framework. You can use C# to create traditional Windows client applications, XML Web services, distributed components, client-server applications, database applications, and much, much more. Microsoft Visual C# 2005 provides an advanced code editor, convenient user interface designers, integrated debugger, and many other tools to facilitate rapid application development based on version 2.0 of the C# language and the .NET Framework.

C# syntax is highly expressive, yet with less than 90 keywords, it is also simple and easy to learn. The curly-brace syntax of C# will be instantly recognizable to anyone familiar with C, C++ or Java. Developers who know any of these languages are typically able to begin working productively in C# within a very short time. C# syntax simplifies many of the complexities of C++ while providing powerful features such as nullable value types, enumerations, delegates, anonymous methods and direct memory access, which are not found in Java. C# also supports generic methods and types, which provide increased type safety and performance, and iterators,which enable implementers of collection classes to define custom iteration behaviors that are simple to use by client code.

As an object-oriented language, C# supports the concepts of encapsulation, inheritance and polymorphism. Allvariables and methods, including the Main method, the application's entry point, are encapsulated within class definitions. A class may inherit directly from one parent class, but it may implement any number of interfaces. Methods that override virtual methods in a parent class require theoverride keyword as a way to avoid accidental redefinition. In C#, a struct is like a lightweight class; it is a stack-allocated type that can implement interfaces but does not support inheritance.

In addition to these basic object-oriented principles, C# facilitates the development of software components through several innovative language constructs, including:

? Encapsulated method signatures called delegates, which enable type-safe event notifications. ? Properties, which serve as accessors for private member variables. ? Attributes, which provide declarative meta data about types at run time. ? Inline XML documentation comments.

45

本文来源:https://www.bwwdw.com/article/p0c8.html

Top