/// <summary> /// 插入一条评论 /// </summary> /// <param name="c"></param> /// <returns></returns> public bool Insert(Comments c) { string sql = "insert into Comments( CPhotoId, CText,CName,CEmail) values(@CPhotoId, @CText,@CName,@CEmail)"; SqlParameter[] param = { new SqlParameter("@CPhotoId",c.CPhotoId), new SqlParameter("@CText",c.CText), new SqlParameter("@CName",c.CName), new SqlParameter("@CEmail",c.CEmail)}; return SQLHelper.ExecuteNonQuery(sql, param) > 0; }
/// <summary> /// 给照片添加评论 /// </summary> /// <param name="comment"></param> /// <returns></returns> public int AddComment(Comments comment) { string sql = "insert into Comments (CPhotoId,CUserName, CText, CTime, CUp, CDown) values (@CPhotoId, @CUserName, @CText, @CTime, @CUp, @CDown)"; SqlParameter[] param = { new SqlParameter("@CPhotoId",SqlDbType.Int) { Value=comment.CPhotoId }, new SqlParameter("@CUserName",SqlDbType.NVarChar) { Value=comment.CUserName }, new SqlParameter ("@CText",SqlDbType.NVarChar) {Value=comment.CText }, new SqlParameter("@CTime",DateTime.Now), new SqlParameter("@CUp",SqlDbType.Int) { Value=0 }, new SqlParameter("@CDown",SqlDbType.Int) { Value=0 } }; return SQLHelper.ExecuteNonQuery(sql, CommandType.Text, param); }
protected void tijiao_Click(object sender, EventArgs e) { Comments c = new Comments(); c.CPhotoId = Convert.ToInt32(Request.Form["pid"]); c.CText = Request.Form["txtComment"]; if (new CommentsBLL().Insert(c)) { Response.Write("<script>alert('提交成功!');location.href='PhotoDetail.aspx?pid=" + c.CPhotoId + "'</script>"); } else { Response.Write("<script>alert('提交失败!');location.href='PhotoDetail.aspx?pid=" + c.CPhotoId + "'</script>"); } }
private List<Comments> DTToList(DataTable dt) { List<Comments> list = new List<Comments>(); foreach (DataRow item in dt.Rows) { Comments comment = new Comments(); comment.CDown = Convert.ToInt32(item["CDown"]); comment.CId = Convert.ToInt32(item["CId"]); comment.CPhotoId =Convert.ToInt32(item["CPhotoId"]); comment.CUp = Convert.ToInt32(item["CUp"]); comment.CText = item["CText"].ToString(); comment.CUserName = item["CUserName"].ToString(); comment.CTime = Convert.ToDateTime(item["CTime"]); list.Add(comment); } return list; }
/// <summary> /// 获得最近的评论 /// </summary> /// <returns></returns> public List<Comments> GetRecentComments(int count) { string sql = "select top " + count + " *,DATEDIFF(hh,ctime,getdate()) as chour from Comments order by CTime desc"; DataTable dt = SQLHelper.GetDataTable(sql); List<Comments> list = new List<Comments>(); for (int i = 0; i < dt.Rows.Count; i++) { Comments c = new Comments(); c.CId = Convert.ToInt32(dt.Rows[i]["CId"]); c.CPhotoId = Convert.ToInt32(dt.Rows[i]["CPhotoId"]); c.CText = dt.Rows[i]["CText"].ToString(); c.CTime = Convert.ToDateTime(dt.Rows[i]["CTime"]); c.CName = dt.Rows[i]["CName"].ToString(); c.CEmail = dt.Rows[i]["CEmail"].ToString(); c.CHour = Convert.ToInt32(dt.Rows[i]["CHour"]); list.Add(c); } return list; }
/// <summary> /// 给照片添加评论 /// </summary> /// <param name="comment"></param> /// <returns></returns> public int AddComment(Comments comment) { return comDAL.AddComment(comment); }
/// <summary> /// 插入一条评论 /// </summary> /// <param name="c"></param> /// <returns></returns> public bool Insert(Comments c) { return cd.Insert(c); }
/// <summary> /// 将datatable转换成Comments对象集合 /// </summary> /// <param name="dt"></param> /// <returns></returns> private List<Comments> DTToComments(DataTable dt) { List<Comments> list = new List<Comments>(); for (int i = 0; i < dt.Rows.Count; i++) { Comments c = new Comments(); c.CId = Convert.ToInt32(dt.Rows[i]["CId"]); c.CPhotoId = Convert.ToInt32(dt.Rows[i]["CPhotoId"]); c.CText = dt.Rows[i]["CText"].ToString(); c.CTime = Convert.ToDateTime(dt.Rows[i]["CTime"]); c.CName = dt.Rows[i]["CName"].ToString(); c.CEmail = dt.Rows[i]["CEmail"].ToString(); list.Add(c); } return list; }