计算机网络企业网站的设计与实现毕业设计论文(编辑修改稿)内容摘要:

(News) 字段名 说明 类型 长度 可否为空 是否为主键 Id 自动编号 int 4 否 是 Title 标题 nvarchar 200 否 Author 作者 nvarchar 50 是 PubDate 发布时间 datetime 50 是 Contents 内容 ntext 10000 是 Clicks 点击次数 int 10 是 NewsCategoryId 新闻类别 int 4 否 表 留言信息 表 (LY_Info) 字段名 说明 类型 长度 可否为空 是否为主键 LyId 自动编号 int 4 否 是 UserName 用户名 nvarchar 50 否 LyTime 留言时间 datetime 50 否 温州科技职业学院毕业设计(论文) 15 LyContent 留言内容 ntext 1000 否 HF 回复名 nvarchar 50 否 HFtime 回复时间 datetime 50 否 表 管理员信息 表 (Admin_info) 字段名 说明 类型 长度 可否为空 是否为主键 AdminId 自动编号 int 4 否 是 AdminName 管理员名 nvarchar 50 否 AdminPwd 密码 nvarchar 50 否 AdminBZ 级别 nvarchar 50 否 第五章 三层架构代码实现及页面展示 本网站的后台实现应用了三层架构:数据层、业务层( BLL 和 DAL)以及表现 层。 下面我们分别介绍。 模型 层 该网站使用的数据库是 sql server2020[7],在 模型 层将每个数据表封装起来。 下面以 新闻 数据表为例,进行代码分析。 在 Visual Studio2020 中可以看到 模型层的展示,如图。 : //命名空间 using System。 using。 using。 using。 温州科技职业学院毕业设计(论文) 16 图 namespace coffeeModel { [Serializable()] public class News {//对应数据库定义私有变量 private int id。 public int Id {//对变量进行封装 get { return id。 } set { id = value。 } } private string title =。 public string Title { get { return title。 } set { title = value。 } } private string author =。 public string Author { get { return author。 } set { author = value。 } } 模型 层 模型 层 温州科技职业学院毕业设计(论文) 17 private DateTime pubDate。 public DateTime PubDate { get { return pubDate。 } set { pubDate = value。 } } private string contents =。 public string Contents { get { return contents。 } set { contents = value。 } } private int clicks。 public int Clicks { get { return clicks。 } set { clicks = value。 } } private int newsCategoryId。 public int NewsCategoryId { get { return newsCategoryId。 } set { newsCategoryId = value。 } } private NewsCategory newsCategory。 public NewsCategory NewsCategory { get { return newsCategory。 } set { newsCategory = value。 } } public News() { }//定义构造方法 } } 数据访问层 温州科技职业学院毕业设计(论文) 18 数据访问层用于链接数据库和各种方法的书写。 在 Visual 中可以看到数据访问层和业务逻辑层的展示,如图。 图 下面以 新闻 数据表为 例,进行代码分析。 页面的源代码: //命名空间 using System。 using。 using。 using。 using coffeeModel。 using。 using。 namespace coffeeModel { public class NewsService { private static string connectionString = Data Source=.\\SQLEXPRESS。 AttachDbFilename=|DataDirectory|\\。 Integrated Security=True。 User Instance=True。 /// summary /// 删除新闻 /// /summary /// param name=news新闻对象 /param 数据访问层( DAL) 温州科技职业学院毕业设计(论文) 19 public static void DeleteNews(News news) { using (SqlConnection = new SqlConnection(connectionString)) { ()。 SqlCommand cm = new SqlCommand()。 =。 string sql = delete from News where Id=@Id。 = sql。 (@Id, )。 ()。 // } } /// summary /// 根据 SQL 语句返回部分字段的新闻列表 /// /summary /// param name=sqlSQL 语句 /param /// returns新闻对象集合 /returns private static IListNews GetNewsBySql(string sql) { using (SqlConnection = new SqlConnection(connectionString)) { ()。 SqlCommand cm = new SqlCommand()。 //建立 sql 命令对象实例 =。 = sql。 SqlDataReader dr = ()。 ListNews list = new ListNews()。 while (()) { News news = new News()。 for (int i = 0。 i。 i++) 温州科技职业学院毕业设计(论文) 20 { string fildName = (i)。 if (fildName == Id) = (int)dr[Id]。 else if (fildName == Title) = (string)dr[Title]。 else if (fildName == Author) = (string)dr[Author]。 else if (fildName == PubDate) = (DateTime)dr[PubDate]。 else if (fildName == Contents) = (string)dr[Contents]。 else if (fildName == Clicks) = (int)dr[Clicks]。 else if (fildName == NewsCategoryId) { = (int)dr[NewsCategoryId]。 = ((int)dr[NewsCategoryId])。 } } (news)。 } ()。 return list。 } } /// summary /// 查询最近的 10 条新闻 /// /summary /// returns/returns public static IListNews GetNewsTop10() { 温州科技职业学院毕业设计(论文) 21 string sql = select top 10 Id,Title from News order by Id DESC。 return GetNewsBySql(sql)。 } /// summary /// 根据查询条件,排 序字段,排序方向返回包含部分字段( Id,Title,Author,PubDate,Clicks,NewsCate。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。