/*
* 作者:张良伟
* 创建时间:2013-12-10 10:00
* 类说明:新闻评论实体类
*/
namespace Model
{
/// <summary>
/// 新闻评论实体类
/// </summary>
public class Comment
{
private string id;
/// <summary>
/// 主键,自增
/// </summary>
public string Id
{
get { return id; }
set { id = value; }
}
private string content;
/// <summary>
/// 评论内容
/// </summary>
public string Content
{
get { return content; }
set { content = value; }
}
private string userIp;
/// <summary>
/// 评论人IP
/// </summary>
public string UserIp
{
get { return userIp; }
set { userIp = value; }
}
private string createTime;
/// <summary>
/// 评论发表时间
/// </summary>
public string CreateTime
{
get { return createTime; }
set { createTime = value; }
}
private string newsId;
/// <summary>
/// 所属新闻ID
/// </summary>
public string NewsId
{
get { return newsId; }
set { newsId = value; }
}
public Comment()
{ }
public Comment(string content, string userIp, string newsId)
{
this.content = content;
this.userIp = userIp;
this.newsId = newsId;
}
}
}
/*
* 创建人:张良伟
* 创建时间:2013-12-10 10:00
* 说明:评论表操作类
* 版权所有:张良伟&www.tg029.com(众志网)
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
namespace DAL
{
public class CommentDAO
{
private SQLHelper sqlhelper;
public CommentDAO()
{
sqlhelper = new SQLHelper();
}
/// <summary>
/// 根据新闻ID取出该新闻的所有评论
/// </summary>
/// <param name="newsId">新闻ID</param>
/// <returns></returns>
public DataTable SelectByNewsId(string newsId)
{
DataTable dt = new DataTable();
string sql = "select * from comment where newsId=@newsId order by createTime desc";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@newsId", newsId)
};
dt = sqlhelper.ExecuteQuery(sql, paras, CommandType.Text);
return dt;
}
/// <summary>
/// 添加评论
/// </summary>
/// <param name="c">评论实体类</param>
/// <returns></returns>
public bool Insert(Comment c)
{
bool flag = false;
string sql = "insert into comment([content],userIp, newsId) values(@content,@userIp,@newsId)";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@content", c.Content),
new SqlParameter("@userIp", c.UserIp),
new SqlParameter("@newsId", c.NewsId)
};
int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 删除评论
/// </summary>
/// <param name="id">评论ID</param>
/// <returns></returns>
public bool Delete(string id)
{
bool flag = false;
string sql = "delete comment where id=@id";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@id",id)
};
int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text);
if (res > 0)
{
flag = true;
}
return flag;
}
}
}