1、网站公共模块设计淮海工学院计算机工程学院实验报告书课 程 名: 软件开发工具 题 目: 公共模块设计 (基于vs2010) 班 级: 软件081 学 号: 110831123 姓 名: XX 一、目的与要求 根据自己的网站需求设计所需的公共类。二、实验内容或题目 在编码阶段,首先要做的事就是要进行基础类和公共模块的设计。一般情况下,我们把一些数据库操作的代码封装到公共类中,同时把共同的操作放到公共类中。根据自己的网站的需求设计自己所需的公共类。三、实验步骤与源程序DAL中存放跟数据有关的操作:AdsDAO类(广告操作):/ / 更新广告(有更新存储路径) / public bool Updat
2、e_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.ExecuteNonQuer
3、y(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= +
4、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(s
5、ql, CommandType.Text); return dt; / / 取出广告的存储路径 / 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 = fal
6、se; 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.artcat
7、e_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
8、_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 + +
9、 , + + aticle.Arc_publishtime + + , + + aticle.Arc_publisher + + , + + aticle.Arc_content + + ); int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res 0) flag = true; return flag; / / 更新资讯 / public bool Update(arcticle aticle, int id) bool flag = false; string sql = update arcticle set
10、 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
11、 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 =
12、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.Execute
13、Query(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; / / 增加资讯类别 / public bool Ins
14、ert(artcate acate) bool flag = false; string sql = insert into artcate(artcate_name)values( + + acate.Artcate_name + + ); int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res 0) flag = true; return flag; / / 更新资讯类别 / public bool Update(artcate acate, int id) bool flag = false; string
15、sql = update artcate set artcate_name= + acate.Artcate_name + where artcate_id= + id + ; int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res 0) flag = true; return flag; / / 删除资讯类别 / public bool Delete(string artcate_name) bool flag = false; string sql = delete from artcate where art
16、cate_name= + artcate_name + ;int res = sqlhelper.ExecuteNonQuery(sql, CommandType.Text); if (res 0) flag = true; return flag; / / 判断类别名称是否已存在 / public bool IsExists(string artcate_name) bool flag = false; string sql = select * from artcate where artcate_name= + artcate_name + ; DataTable dt = sqlhel
17、per.ExecuteQuery(sql, CommandType.Text); if (dt.Rows.Count 0) flag = true; return flag; ArtInfoDAO类(有关资讯美食内容操作): / / 取出最新五条美食 / public DataTable SelectNewNews() return sqlhelper.ExecuteQuery(dbo.arcNewsSelectNewcook, CommandType.StoredProcedure); / / 取出五条热点美食 / public DataTable SelectHotNews() DataT
18、able dt = new DataTable(); dt = sqlhelper.ExecuteQuery(dbo.arcSelectHotcook, CommandType.StoredProcedure); return dt; / 找出最新的一篇文章 public string SelectNewArc() DataTable dt = new DataTable(); dt=sqlhelper.ExecuteQuery(dbo.arcNewcontent, CommandType.StoredProcedure); string s = dt.Rows0arc_content.ToS
19、tring(); return s; / 显示资讯中伊人美食中2条 public DataTable SelectArc_1() return sqlhelper.ExecuteQuery(dbo.arc_content1, CommandType.StoredProcedure); / 显示资讯中美容保健中2条 public DataTable SelectArc_2() return sqlhelper.ExecuteQuery(dbo.arc_content2, CommandType.StoredProcedure); / 显示资讯中饮食养性中2条 public DataTable S
20、electArc_3() return sqlhelper.ExecuteQuery(dbo.arc_content3, CommandType.StoredProcedure); / 显示资讯中食色男女中2条 public DataTable SelectArc_4() return sqlhelper.ExecuteQuery(dbo.arc_content4, CommandType.StoredProcedure); / 显示资讯中伊人美食 public DataTable Selectyiren() return sqlhelper.ExecuteQuery(dbo.arc_yire
21、n, CommandType.StoredProcedure); / 显示资讯中美容保健 public DataTable Selectmeirong() return sqlhelper.ExecuteQuery(dbo.arc_meirong, CommandType.StoredProcedure); / 显示资讯中饮食养性 public DataTable Selectyinshi() return sqlhelper.ExecuteQuery(dbo.arc_yinshi, CommandType.StoredProcedure); / 显示资讯中食色男女 public DataTa
22、ble Selectshise() return sqlhelper.ExecuteQuery(dbo.arc_shise, CommandType.StoredProcedure); /根据类别ID取出该类别下的所有美食 public DataTable SelectByCaId(string caid) DataTable dt = new DataTable(); string cmdText = dbo.arcSelectByCaId; SqlParameter paras = new SqlParameter new SqlParameter(caid,caid) ; dt = sq
23、lhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure); return dt; / / 根据类别ID取出该条美食主题内容 / public arcticle SelectById(string id) arcticle c = new arcticle(); DataTable dt = new DataTable(); string cmdText = dbo.arcSelectById; SqlParameter paras = new SqlParameter new SqlParameter(id,id) ;
24、dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure); c.Arc_caid= Convert.ToInt32(id); c.Arc_title= dt.Rows0arc_title.ToString(); c.Arc_content= dt.Rows0arc_content.ToString(); c.Arc_caid= (Int32)dt.Rows0arc_caId; return c; / 增加美食 public bool Insert(arcticle c) bool flag = false;
25、 DataTable dt = new DataTable(); string cmdText = dbo.arcInsert; SqlParameter paras = new SqlParameter new SqlParameter(title,c.Arc_title), new SqlParameter(content,c.Arc_content), new SqlParameter(caid,c.Arc_caid) ; int res = sqlhelper.ExecuteNonQuery(cmdText, paras, CommandType.StoredProcedure); i
26、f (res 0) flag = true; return flag; / 修改美食 public bool Update(arcticle c) bool flag = false; DataTable dt = new DataTable(); string cmdText = dbo.arcUpdate; SqlParameter paras = new SqlParameter new SqlParameter(id,c.Arc_id), new SqlParameter(title,c.Arc_title), new SqlParameter(content,c.Arc_conten
27、t), new SqlParameter(caid,c.Arc_caid) ; int res = sqlhelper.ExecuteNonQuery(cmdText, paras, CommandType.StoredProcedure); if (res 0) flag = true; return flag; / 删除美食 public bool Delete(string id) bool flag = false; DataTable dt = new DataTable(); string cmdText = dbo.arcDelete; SqlParameter paras = new SqlParameter new SqlParameter(id,id) ; int res = sqlhelper.ExecuteNonQuery(cmdText, paras, CommandType.StoredProcedure); if (res 0) flag = true; return flag; CommentDAO类(评论操作): / 根据新闻ID取出该新闻的所有评论 public DataTable SelectByNewsId(string m_newsid) DataTable dt = new DataTable();
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1