Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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