Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

177 Zeilen
5.7 KiB

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层
/// </summary>
public partial class followproduct
{
#region 此代码由工具生成
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.followproduct model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_followproduct(");
strSql.Append("product_id,add_time,openid)");
strSql.Append(" values (");
strSql.Append("@product_id,@add_time,@openid)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters =
{
new SqlParameter("@product_id", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@openid", SqlDbType.NVarChar,255)
};
parameters[0].Value = model.product_id;
parameters[1].Value = model.add_time;
parameters[2].Value = model.openid;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_followproduct");
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 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("product_id,add_time,openid from tb_followproduct");
strSql.Append(" from tb_followproduct");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <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 + " product_id,add_time,openid from tb_followproduct");
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_followproduct ");
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_followproduct", 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;
}
}
//总条数
public int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_shopcart where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_followproduct");
strSql.Append(" where product_id=@product_id");
SqlParameter[] parameters =
{
new SqlParameter("@product_id", SqlDbType.Int,10)
};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_followproduct set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
#endregion
}
}