Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

177 righe
5.7 KiB

  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Data.SqlClient;
  5. namespace Basic.DAL
  6. {
  7. /// <summary>
  8. /// ���ݷ��ʲ�
  9. /// </summary>
  10. public partial class followproduct
  11. {
  12. #region �˴����ɹ�������
  13. /// <summary>
  14. /// ����һ������
  15. /// </summary>
  16. public int Add(Basic.Model.followproduct model)
  17. {
  18. StringBuilder strSql = new StringBuilder();
  19. strSql.Append("insert into tb_followproduct(");
  20. strSql.Append("product_id,add_time,openid)");
  21. strSql.Append(" values (");
  22. strSql.Append("@product_id,@add_time,@openid)");
  23. strSql.Append(";select @@IDENTITY");
  24. SqlParameter[] parameters =
  25. {
  26. new SqlParameter("@product_id", SqlDbType.Int,10),
  27. new SqlParameter("@add_time", SqlDbType.DateTime,23),
  28. new SqlParameter("@openid", SqlDbType.NVarChar,255)
  29. };
  30. parameters[0].Value = model.product_id;
  31. parameters[1].Value = model.add_time;
  32. parameters[2].Value = model.openid;
  33. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  34. if (obj == null)
  35. {
  36. return 0;
  37. }
  38. else
  39. {
  40. return Convert.ToInt32(obj);
  41. }
  42. }
  43. /// <summary>
  44. /// ɾ��һ������
  45. /// </summary>
  46. public bool Delete(int id)
  47. {
  48. StringBuilder strSql = new StringBuilder();
  49. strSql.Append("delete from tb_followproduct");
  50. strSql.Append(" where id=@id");
  51. SqlParameter[] parameters = {
  52. new SqlParameter("@id", SqlDbType.Int,4)};
  53. parameters[0].Value = id;
  54. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  55. if (rows > 0)
  56. {
  57. return true;
  58. }
  59. else
  60. {
  61. return false;
  62. }
  63. }
  64. /// <summary>
  65. /// ����ǰ��������
  66. /// </summary>
  67. public DataSet GetList(int Top, string strWhere, string filedOrder)
  68. {
  69. StringBuilder strSql = new StringBuilder();
  70. strSql.Append("select ");
  71. if (Top > 0)
  72. {
  73. strSql.Append(" top " + Top.ToString());
  74. }
  75. strSql.Append("product_id,add_time,openid from tb_followproduct");
  76. strSql.Append(" from tb_followproduct");
  77. if (strWhere.Trim() != "")
  78. {
  79. strSql.Append(" where " + strWhere);
  80. }
  81. strSql.Append(" order by " + filedOrder);
  82. return DbHelperSQL.Query(strSql.ToString());
  83. }
  84. /// <summary>
  85. /// ���ò�ѯ��ҳ����
  86. /// </summary>
  87. public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
  88. {
  89. BasicPage bp = new BasicPage();
  90. StringBuilder str_Sql = new StringBuilder();
  91. str_Sql.Append("select top " + _pageSize + " product_id,add_time,openid from tb_followproduct");
  92. str_Sql.Append(" where ");
  93. str_Sql.Append(_strWhere);
  94. str_Sql.Append(" and id not in ");
  95. str_Sql.Append(" ( ");
  96. str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_followproduct ");
  97. str_Sql.Append(" where ");
  98. str_Sql.Append(_strWhere);
  99. str_Sql.Append(" order by ");
  100. str_Sql.Append(_orderby);
  101. str_Sql.Append(" ) ");
  102. str_Sql.Append(" order by ");
  103. str_Sql.Append(_orderby);
  104. DataSet dst = bp.SelectDataBase("tb_followproduct", str_Sql.ToString());
  105. //
  106. recordCount = totlePage(showTotal(_strWhere), _pageSize);
  107. return dst;
  108. }
  109. //��ҳ��
  110. public int totlePage(int Total, int PageSize)
  111. {
  112. if (Total % PageSize == 0)
  113. {
  114. return Total / PageSize;
  115. }
  116. else
  117. {
  118. return Total / PageSize + 1;
  119. }
  120. }
  121. //������
  122. public int showTotal(string strSql)
  123. {
  124. BasicPage bp = new BasicPage();
  125. int intTotal = 0;
  126. SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_shopcart where " + strSql);
  127. if (myread.Read())
  128. {
  129. intTotal = Convert.ToInt32(myread["CountId"].ToString());
  130. }
  131. myread.Close();
  132. return intTotal;
  133. }
  134. /// <summary>
  135. /// �Ƿ����ڸü�¼
  136. /// </summary>
  137. public bool Exists(int id)
  138. {
  139. StringBuilder strSql = new StringBuilder();
  140. strSql.Append("select count(1) from tb_followproduct");
  141. strSql.Append(" where product_id=@product_id");
  142. SqlParameter[] parameters =
  143. {
  144. new SqlParameter("@product_id", SqlDbType.Int,10)
  145. };
  146. parameters[0].Value = id;
  147. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  148. }
  149. /// <summary>
  150. /// �޸�һ������
  151. /// </summary>
  152. public void UpdateField(int id, string strValue)
  153. {
  154. StringBuilder strSql = new StringBuilder();
  155. strSql.Append("update tb_followproduct set " + strValue);
  156. strSql.Append(" where id=" + id);
  157. DbHelperSQL.ExecuteSql(strSql.ToString());
  158. }
  159. #endregion
  160. }
  161. }