using System;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace Basic.DAL
|
|
{
|
|
/// <summary>
|
|
/// 数据访问层comment
|
|
/// </summary>
|
|
public partial class comment
|
|
{
|
|
#region 原始的
|
|
/// <summary>
|
|
/// 增加一条数据
|
|
/// </summary>
|
|
public int Add(Basic.Model.comment model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("insert into tb_comment(");
|
|
strSql.Append("name,user_id,product_id,attribute_id,product_name,product_path,content,review,status,add_time)");
|
|
strSql.Append(" values (");
|
|
strSql.Append("@name,@user_id,@product_id,@attribute_id,@product_name,@product_path,@content,@review,@status,@add_time)");
|
|
strSql.Append(";select @@IDENTITY");
|
|
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@name", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@user_id", SqlDbType.Int,10),
|
|
new SqlParameter("@product_id", SqlDbType.Int,10),
|
|
new SqlParameter("@attribute_id", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@product_name", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@product_path", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@content", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@review", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@status", SqlDbType.Int,10),
|
|
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
|
|
parameters[0].Value = model.name;
|
|
parameters[1].Value = model.user_id;
|
|
parameters[2].Value = model.product_id;
|
|
parameters[3].Value = model.attribute_id;
|
|
parameters[4].Value = model.product_name;
|
|
parameters[5].Value = model.product_path;
|
|
parameters[6].Value = model.content;
|
|
parameters[7].Value = model.review;
|
|
parameters[8].Value = model.status;
|
|
parameters[9].Value = model.add_time;
|
|
|
|
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
|
|
if (obj == null)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return Convert.ToInt32(obj);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public bool Update(Basic.Model.comment model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("update tb_comment set ");
|
|
strSql.Append("name=@name,");
|
|
strSql.Append("user_id=@user_id,");
|
|
strSql.Append("product_id=@product_id,");
|
|
strSql.Append("attribute_id=@attribute_id,");
|
|
strSql.Append("product_name=@product_name,");
|
|
strSql.Append("product_path=@product_path,");
|
|
strSql.Append("content=@content,");
|
|
strSql.Append("review=@review,");
|
|
strSql.Append("status=@status,");
|
|
strSql.Append("add_time=@add_time");
|
|
strSql.Append(" where id=@id");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@name", SqlDbType.NVarChar,50),
|
|
new SqlParameter("@user_id", SqlDbType.Int,10),
|
|
new SqlParameter("@product_id", SqlDbType.Int,10),
|
|
new SqlParameter("@attribute_id", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@product_name", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@product_path", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@content", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@review", SqlDbType.NVarChar,255),
|
|
new SqlParameter("@status", SqlDbType.Int,10),
|
|
new SqlParameter("@add_time", SqlDbType.DateTime,23),
|
|
new SqlParameter("@id", SqlDbType.Int,4)};
|
|
parameters[0].Value = model.name;
|
|
parameters[1].Value = model.user_id;
|
|
parameters[2].Value = model.product_id;
|
|
parameters[3].Value = model.attribute_id;
|
|
parameters[4].Value = model.product_name;
|
|
parameters[5].Value = model.product_path;
|
|
parameters[6].Value = model.content;
|
|
parameters[7].Value = model.review;
|
|
parameters[8].Value = model.status;
|
|
parameters[9].Value = model.add_time;
|
|
parameters[10].Value = model.id;
|
|
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public bool Delete(int id)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from tb_comment");
|
|
strSql.Append(" where id=@id");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@id", SqlDbType.Int,4)};
|
|
parameters[0].Value = id;
|
|
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
|
|
if (rows > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到一个对象实体
|
|
/// </summary>
|
|
public Basic.Model.comment GetModel(int id)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select top 1 id,name,user_id,product_id,attribute_id,product_name,product_path,content,review,status,add_time from tb_comment");
|
|
strSql.Append(" where id=@id");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@id", SqlDbType.Int,4)};
|
|
parameters[0].Value = id;
|
|
Basic.Model.comment model = new Basic.Model.comment();
|
|
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
|
|
{
|
|
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
|
|
{
|
|
model.name = ds.Tables[0].Rows[0]["name"].ToString();
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
|
|
{
|
|
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["product_id"].ToString()))
|
|
{
|
|
model.product_id = int.Parse(ds.Tables[0].Rows[0]["product_id"].ToString());
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["attribute_id"].ToString()))
|
|
{
|
|
model.attribute_id = ds.Tables[0].Rows[0]["attribute_id"].ToString();
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["product_name"].ToString()))
|
|
{
|
|
model.product_name = ds.Tables[0].Rows[0]["product_name"].ToString();
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["product_path"].ToString()))
|
|
{
|
|
model.product_path = ds.Tables[0].Rows[0]["product_path"].ToString();
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
|
|
{
|
|
model.content = ds.Tables[0].Rows[0]["content"].ToString();
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["review"].ToString()))
|
|
{
|
|
model.review = ds.Tables[0].Rows[0]["review"].ToString();
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
|
|
{
|
|
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
|
|
}
|
|
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
|
|
{
|
|
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
|
|
}
|
|
return model;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得前几行数据
|
|
/// </summary>
|
|
public DataSet GetList(int Top, string strWhere, string filedOrder)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select ");
|
|
if (Top > 0)
|
|
{
|
|
strSql.Append(" top " + Top.ToString());
|
|
}
|
|
strSql.Append("id,name,user_id,product_id,attribute_id,product_name,product_path,content,review,status,add_time");
|
|
strSql.Append(" from tb_comment");
|
|
if (strWhere.Trim() != "")
|
|
{
|
|
strSql.Append(" where " + strWhere);
|
|
}
|
|
strSql.Append(" order by " + filedOrder);
|
|
return DbHelperSQL.Query(strSql.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否存在该记录
|
|
/// </summary>
|
|
public bool Exists(int id)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select count(1) from tb_comment");
|
|
strSql.Append(" where id=@id");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@id", SqlDbType.Int,4)};
|
|
parameters[0].Value = id;
|
|
|
|
return DbHelperSQL.Exists(strSql.ToString(), parameters);
|
|
}
|
|
|
|
#endregion
|
|
|
|
//=======================================================================================================后加的
|
|
/// <summary>
|
|
/// 获得查询分页数据
|
|
/// </summary>
|
|
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
|
|
{
|
|
BasicPage bp = new BasicPage();
|
|
StringBuilder str_Sql = new StringBuilder();
|
|
str_Sql.Append("select top " + _pageSize + " * from tb_comment");
|
|
str_Sql.Append(" where ");
|
|
str_Sql.Append(_strWhere);
|
|
str_Sql.Append(" and id not in ");
|
|
str_Sql.Append(" ( ");
|
|
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_comment ");
|
|
str_Sql.Append(" where ");
|
|
str_Sql.Append(_strWhere);
|
|
str_Sql.Append(" order by ");
|
|
str_Sql.Append(_orderby);
|
|
str_Sql.Append(" ) ");
|
|
str_Sql.Append(" order by ");
|
|
str_Sql.Append(_orderby);
|
|
DataSet dst = bp.SelectDataBase("tb_comment", str_Sql.ToString());
|
|
//
|
|
recordCount = totlePage(showTotal(_strWhere), _pageSize);
|
|
return dst;
|
|
}
|
|
|
|
//总页数
|
|
public int totlePage(int Total, int PageSize)
|
|
{
|
|
if (Total % PageSize == 0)
|
|
{
|
|
return Total / PageSize;
|
|
}
|
|
else
|
|
{
|
|
return Total / PageSize + 1;
|
|
}
|
|
}
|
|
|
|
//总条数
|
|
protected int showTotal(string strSql)
|
|
{
|
|
BasicPage bp = new BasicPage();
|
|
int intTotal = 0;
|
|
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_comment where " + strSql);
|
|
if (myread.Read())
|
|
{
|
|
intTotal = Convert.ToInt32(myread["CountId"].ToString());
|
|
}
|
|
myread.Close();
|
|
return intTotal;
|
|
}
|
|
|
|
}
|
|
}
|
|
|