You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
9.5 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 couponuser
  11. {
  12. #region �˴����ɹ�������
  13. /// <summary>
  14. /// ����һ������
  15. /// </summary>
  16. public int Add(Basic.Model.couponuser model)
  17. {
  18. StringBuilder strSql = new StringBuilder();
  19. strSql.Append("insert into tb_couponuser(");
  20. strSql.Append("paixu,couponid,name,couponstatus,add_time)");
  21. strSql.Append(" values (");
  22. strSql.Append("@paixu,@couponid,@name,@couponstatus,@add_time)");
  23. strSql.Append(";select @@IDENTITY");
  24. SqlParameter[] parameters = {
  25. new SqlParameter("@paixu", SqlDbType.Int,10),
  26. new SqlParameter("@couponid", SqlDbType.Int,10),
  27. new SqlParameter("@name", SqlDbType.NVarChar,255),
  28. new SqlParameter("@couponstatus", SqlDbType.Int,10),
  29. new SqlParameter("@add_time", SqlDbType.DateTime,23)};
  30. parameters[0].Value = model.paixu;
  31. parameters[1].Value = model.couponid;
  32. parameters[2].Value = model.name;
  33. parameters[3].Value = model.couponstatus;
  34. parameters[4].Value = model.add_time;
  35. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  36. if (obj == null)
  37. {
  38. return 0;
  39. }
  40. else
  41. {
  42. return Convert.ToInt32(obj);
  43. }
  44. }
  45. /// <summary>
  46. /// ����һ������
  47. /// </summary>
  48. public bool Update(Basic.Model.couponuser model)
  49. {
  50. StringBuilder strSql = new StringBuilder();
  51. strSql.Append("update tb_couponuser set ");
  52. strSql.Append("paixu=@paixu,");
  53. strSql.Append("couponid=@couponid,");
  54. strSql.Append("name=@name,");
  55. strSql.Append("couponstatus=@couponstatus,");
  56. strSql.Append("add_time=@add_time");
  57. strSql.Append(" where id=@id");
  58. SqlParameter[] parameters = {
  59. new SqlParameter("@paixu", SqlDbType.Int,10),
  60. new SqlParameter("@couponid", SqlDbType.Int,10),
  61. new SqlParameter("@name", SqlDbType.NVarChar,255),
  62. new SqlParameter("@couponstatus", SqlDbType.Int,10),
  63. new SqlParameter("@add_time", SqlDbType.DateTime,23),
  64. new SqlParameter("@id", SqlDbType.Int,4)};
  65. parameters[0].Value = model.paixu;
  66. parameters[1].Value = model.couponid;
  67. parameters[2].Value = model.name;
  68. parameters[3].Value = model.couponstatus;
  69. parameters[4].Value = model.add_time;
  70. parameters[5].Value = model.id;
  71. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  72. if (rows > 0)
  73. {
  74. return true;
  75. }
  76. else
  77. {
  78. return false;
  79. }
  80. }
  81. /// <summary>
  82. /// ɾ��һ������
  83. /// </summary>
  84. public bool Delete(int id)
  85. {
  86. StringBuilder strSql = new StringBuilder();
  87. strSql.Append("delete from tb_couponuser");
  88. strSql.Append(" where id=@id");
  89. SqlParameter[] parameters = {
  90. new SqlParameter("@id", SqlDbType.Int,4)};
  91. parameters[0].Value = id;
  92. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  93. if (rows > 0)
  94. {
  95. return true;
  96. }
  97. else
  98. {
  99. return false;
  100. }
  101. }
  102. /// <summary>
  103. /// �õ�һ������ʵ��
  104. /// </summary>
  105. public Basic.Model.couponuser GetModel(int id)
  106. {
  107. StringBuilder strSql=new StringBuilder();
  108. strSql.Append("select top 1 id,paixu,couponid,name,couponstatus,add_time from tb_couponuser");
  109. strSql.Append(" where id=@id");
  110. SqlParameter[] parameters = {
  111. new SqlParameter("@id", SqlDbType.Int,4)};
  112. parameters[0].Value = id;
  113. Basic.Model.couponuser model = new Basic.Model.couponuser();
  114. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  115. if (ds.Tables[0].Rows.Count > 0)
  116. {
  117. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  118. {
  119. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  120. }
  121. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
  122. {
  123. model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
  124. }
  125. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["couponid"].ToString()))
  126. {
  127. model.couponid = int.Parse(ds.Tables[0].Rows[0]["couponid"].ToString());
  128. }
  129. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
  130. {
  131. model.name = ds.Tables[0].Rows[0]["name"].ToString();
  132. }
  133. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["couponstatus"].ToString()))
  134. {
  135. model.couponstatus = int.Parse(ds.Tables[0].Rows[0]["couponstatus"].ToString());
  136. }
  137. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
  138. {
  139. model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
  140. }
  141. return model;
  142. }
  143. else
  144. {
  145. return null;
  146. }
  147. }
  148. /// <summary>
  149. /// ����ǰ��������
  150. /// </summary>
  151. public DataSet GetList(int Top, string strWhere, string filedOrder)
  152. {
  153. StringBuilder strSql = new StringBuilder();
  154. strSql.Append("select ");
  155. if (Top > 0)
  156. {
  157. strSql.Append(" top " + Top.ToString());
  158. }
  159. strSql.Append("id,paixu,couponid,name,couponstatus,add_time");
  160. strSql.Append(" from tb_couponuser");
  161. if (strWhere.Trim() != "")
  162. {
  163. strSql.Append(" where " + strWhere);
  164. }
  165. strSql.Append(" order by " + filedOrder);
  166. return DbHelperSQL.Query(strSql.ToString());
  167. }
  168. /// <summary>
  169. /// ���ò�ѯ��ҳ����
  170. /// </summary>
  171. public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
  172. {
  173. BasicPage bp = new BasicPage();
  174. StringBuilder str_Sql = new StringBuilder();
  175. str_Sql.Append("select top " + _pageSize + " id,paixu,couponid,name,couponstatus,add_time from tb_couponuser");
  176. str_Sql.Append(" where ");
  177. str_Sql.Append(_strWhere);
  178. str_Sql.Append(" and id not in ");
  179. str_Sql.Append(" ( ");
  180. str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_couponuser ");
  181. str_Sql.Append(" where ");
  182. str_Sql.Append(_strWhere);
  183. str_Sql.Append(" order by ");
  184. str_Sql.Append(_orderby);
  185. str_Sql.Append(" ) ");
  186. str_Sql.Append(" order by ");
  187. str_Sql.Append(_orderby);
  188. DataSet dst = bp.SelectDataBase("tb_couponuser", str_Sql.ToString());
  189. //
  190. recordCount = totlePage(showTotal(_strWhere), _pageSize);
  191. return dst;
  192. }
  193. //��ҳ��
  194. public int totlePage(int Total, int PageSize)
  195. {
  196. if (Total % PageSize == 0)
  197. {
  198. return Total / PageSize;
  199. }
  200. else
  201. {
  202. return Total / PageSize + 1;
  203. }
  204. }
  205. //������
  206. protected int showTotal(string strSql)
  207. {
  208. BasicPage bp = new BasicPage();
  209. int intTotal = 0;
  210. SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_couponuser where " + strSql);
  211. if (myread.Read())
  212. {
  213. intTotal = Convert.ToInt32(myread["CountId"].ToString());
  214. }
  215. myread.Close();
  216. return intTotal;
  217. }
  218. /// <summary>
  219. /// �Ƿ����ڸü�¼
  220. /// </summary>
  221. public bool Exists(int id)
  222. {
  223. StringBuilder strSql = new StringBuilder();
  224. strSql.Append("select count(1) from tb_couponuser");
  225. strSql.Append(" where id=@id");
  226. SqlParameter[] parameters = {
  227. new SqlParameter("@id", SqlDbType.Int,4)};
  228. parameters[0].Value = id;
  229. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  230. }
  231. /// <summary>
  232. /// �޸�һ������
  233. /// </summary>
  234. public void UpdateField(int id, string strValue)
  235. {
  236. StringBuilder strSql = new StringBuilder();
  237. strSql.Append("update tb_couponuser set " + strValue);
  238. strSql.Append(" where id=" + id);
  239. DbHelperSQL.ExecuteSql(strSql.ToString());
  240. }
  241. #endregion
  242. }
  243. }