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.

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