网站公共模块设计

  • 格式:doc
  • 大小:112.00 KB
  • 文档页数:10

淮海工学院计算机工程学院 实验报告书

课 程 名: 《软件开发工具》 题 目: 公共模块设计 (基于vs2010) 班 级: 软件081 学 号: 110831123 姓 名: XX 评语:

成绩: 指导教师: 批阅时间: 年 月 日 《软件开发工具》实验报告 - 1 - 一、目的与要求 根据自己的网站需求设计所需的公共类。 二、实验内容或题目 在编码阶段,首先要做的事就是要进行基础类和公共模块的设计。一般情况下,我们把一些数据库操作的代码封装到公共类中,同时把共同的操作放到公共类中。根据自己的网站的需求设计自己所需的公共类。 三、实验步骤与源程序 DAL中存放跟数据有关的操作: AdsDAO类(广告操作): /// /// 更新广告(有更新存储路径) /// public bool Update_image(advertise ads, int id) { bool flag = false; string sql = "update advertise set Avlocation=" + ads.Avlocation + ",Avdescription='" + ads.Avdescription + "',Avadduser='" + ads.Avadduser + "',Avlinkurl='" + ads.Avlinkurl + "',Avimageurl='" + ads.Avimageurl + "' where Avid=" + id + ""; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) { flag = true; } return flag; } /// /// 更新广告(没有更新存储路径) /// public bool Update_noimage(advertise ads, int id) { bool flag = false; string sql = "update advertise set Avlocation=" + ads.Avlocation + ",Avdescription='" + ads.Avdescription + "',Avadduser='" + ads.Avadduser + "',Avlinkurl='" + ads.Avlinkurl + "' where Avid=" + id + ""; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) { flag = true; } return flag; } /// /// 取出当前所有广告 /// public DataTable SelectAll(int id) { DataTable dt = new DataTable(); string sql = "select * from advertise where Avid="+id+ ""; dt = sqlhelper.ExecuteQuery(sql, CommandType.Text); return dt; } /// /// 取出广告的存储路径 《软件开发工具》实验报告 - 2 - /// public DataTable Selectimage(int id) { DataTable dt = new DataTable(); string sql = "select Avimageurl from advertise where Avid=" + id+""; dt = sqlhelper.ExecuteQuery(sql, CommandType.Text); return dt; } /// /// 删除广告 /// public bool Delete(int id) { bool flag = false; string sql = "delete from advertise where Avid=" + id + ""; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) {flag = true; }

return flag; } ArcticleDAO类(资讯操作): /// /// 取出当前所有资讯 /// public DataTable SelectAll(){ DataTable dt = new DataTable(); string sql = " select m.arc_id,m.arc_title,n.artcate_name,m.arc_publishtime,m.arc_publisher from arcticle m , artcate n where m.arc_caId=n.artcate_id"; dt = sqlhelper.ExecuteQuery(sql, CommandType.Text); return dt; } /// /// 返回特定资讯 /// public SqlDataReader ExecuteReader(int arc_id) { SqlDataReader reader; string sql = "select * from arcticle where arc_id=" + arc_id + ""; reader = sqlhelper.ExecuteReader(sql, CommandType.Text); return reader; } /// /// 增加资讯 /// public bool Insert(arcticle aticle) { bool flag = false; string sql = "insert into arcticle(arc_title,arc_caid,arc_publishtime,arc_publisher,arc_content) values(" + "'" + aticle.Arc_title + "'" + "," + "'" + aticle.Arc_caid + "'" + " ," + "'" + aticle.Arc_publishtime + "'" + "," + "'" + aticle.Arc_publisher + "'" + "," + "'" + aticle.Arc_content + "'" + ")"; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) { flag = true; } return flag; 《软件开发工具》实验报告 - 3 - } /// /// 更新资讯 /// public bool Update(arcticle aticle, int id) { bool flag = false; string sql = "update arcticle set arc_title='" + aticle.Arc_title + "',arc_caid=" + aticle.Arc_caid + ",arc_publishtime= '" + aticle.Arc_publishtime + "',arc_publisher='" + aticle.Arc_publisher + "',arc_content='" + aticle.Arc_content + "' where arc_id=" + id + ""; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) {flag = true; } return flag; } /// /// 删除资讯 /// public bool Delete(string arc_title) { bool flag = false; string sql = "delete from arcticle where arc_title='" + arc_title + "'"; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) { flag = true; } return flag; } public bool Delete(int arc_id) { bool flag = false; string sql = "delete from arcticle where arc_id=" + arc_id + ""; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res > 0) {flag = true; }

return flag; } ArtcateDAO类(资讯类别操作): /// /// 取出当前所有资讯类别 /// public DataTable SelectAll(){ DataTable dt = new DataTable(); string sql = "select * from artcate"; dt = sqlhelper.ExecuteQuery(sql, CommandType.Text); return dt;} /// /// 返回特定资讯类别名 /// public SqlDataReader ExecuteReader(int artcate_id) { SqlDataReader reader; string sql = "select * from artcate where artcate_id=" + artcate_id + ""; reader = sqlhelper.ExecuteReader(sql, CommandType.Text); return reader; } ///