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.

258 line
9.4 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. /// ���ݷ��ʲ�bed_class
  9. /// </summary>
  10. public partial class bed_class
  11. {
  12. #region ԭʼ��
  13. /// <summary>
  14. /// ����һ������
  15. /// </summary>
  16. public int Add(Basic.Model.bed_class model)
  17. {
  18. StringBuilder strSql = new StringBuilder();
  19. strSql.Append("insert into tb_bed_class(");
  20. strSql.Append("paixu,title,state,yongliao,gongfei)");
  21. strSql.Append(" values (");
  22. strSql.Append("@paixu,@title,@state,@yongliao,@gongfei)");
  23. strSql.Append(";select @@IDENTITY");
  24. SqlParameter[] parameters = {
  25. new SqlParameter("@paixu", SqlDbType.Int,10),
  26. new SqlParameter("@title", SqlDbType.NVarChar,255),
  27. new SqlParameter("@state", SqlDbType.Int,10),
  28. new SqlParameter("@yongliao", SqlDbType.Decimal,18),
  29. new SqlParameter("@gongfei", SqlDbType.Decimal,18)};
  30. parameters[0].Value = model.paixu;
  31. parameters[1].Value = model.title;
  32. parameters[2].Value = model.state;
  33. parameters[3].Value = model.yongliao;
  34. parameters[4].Value = model.gongfei;
  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.bed_class model)
  49. {
  50. StringBuilder strSql = new StringBuilder();
  51. strSql.Append("update tb_bed_class set ");
  52. strSql.Append("paixu=@paixu,");
  53. strSql.Append("title=@title,");
  54. strSql.Append("state=@state,");
  55. strSql.Append("yongliao=@yongliao,");
  56. strSql.Append("gongfei=@gongfei");
  57. strSql.Append(" where id=@id");
  58. SqlParameter[] parameters = {
  59. new SqlParameter("@paixu", SqlDbType.Int,10),
  60. new SqlParameter("@title", SqlDbType.NVarChar,255),
  61. new SqlParameter("@state", SqlDbType.Int,10),
  62. new SqlParameter("@yongliao", SqlDbType.Decimal,18),
  63. new SqlParameter("@gongfei", SqlDbType.Decimal,18),
  64. new SqlParameter("@id", SqlDbType.Int,4)};
  65. parameters[0].Value = model.paixu;
  66. parameters[1].Value = model.title;
  67. parameters[2].Value = model.state;
  68. parameters[3].Value = model.yongliao;
  69. parameters[4].Value = model.gongfei;
  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_bed_class");
  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.bed_class GetModel(int id)
  106. {
  107. StringBuilder strSql = new StringBuilder();
  108. strSql.Append("select top 1 id,paixu,title,state,yongliao,gongfei from tb_bed_class");
  109. strSql.Append(" where id=@id");
  110. SqlParameter[] parameters = {
  111. new SqlParameter("@id", SqlDbType.Int,4)};
  112. parameters[0].Value = id;
  113. Basic.Model.bed_class model = new Basic.Model.bed_class();
  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]["title"].ToString()))
  126. {
  127. model.title = ds.Tables[0].Rows[0]["title"].ToString();
  128. }
  129. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
  130. {
  131. model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
  132. }
  133. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yongliao"].ToString()))
  134. {
  135. model.yongliao = decimal.Parse(ds.Tables[0].Rows[0]["yongliao"].ToString());
  136. }
  137. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["gongfei"].ToString()))
  138. {
  139. model.gongfei = decimal.Parse(ds.Tables[0].Rows[0]["gongfei"].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,title,state,yongliao,gongfei");
  160. strSql.Append(" from tb_bed_class");
  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 bool Exists(int id)
  172. {
  173. StringBuilder strSql = new StringBuilder();
  174. strSql.Append("select count(1) from tb_bed_class");
  175. strSql.Append(" where id=@id");
  176. SqlParameter[] parameters = {
  177. new SqlParameter("@id", SqlDbType.Int,4)};
  178. parameters[0].Value = id;
  179. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  180. }
  181. #endregion
  182. //���ӵ�==============================================================================================================================
  183. /// <summary>
  184. /// ���ò�ѯ��ҳ����
  185. /// </summary>
  186. public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
  187. {
  188. BasicPage bp = new BasicPage();
  189. StringBuilder str_Sql = new StringBuilder();
  190. str_Sql.Append("select top " + _pageSize + " * from tb_bed_class");
  191. str_Sql.Append(" where ");
  192. str_Sql.Append(_strWhere);
  193. str_Sql.Append(" and id not in ");
  194. str_Sql.Append(" ( ");
  195. str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_bed_class ");
  196. str_Sql.Append(" where ");
  197. str_Sql.Append(_strWhere);
  198. str_Sql.Append(" order by ");
  199. str_Sql.Append(_orderby);
  200. str_Sql.Append(" ) ");
  201. str_Sql.Append(" order by ");
  202. str_Sql.Append(_orderby);
  203. DataSet dst = bp.SelectDataBase("tb_bed_class", str_Sql.ToString());
  204. //
  205. recordCount = totlePage(showTotal(_strWhere), _pageSize);
  206. return dst;
  207. }
  208. //��ҳ��
  209. public int totlePage(int Total, int PageSize)
  210. {
  211. if (Total % PageSize == 0)
  212. {
  213. return Total / PageSize;
  214. }
  215. else
  216. {
  217. return Total / PageSize + 1;
  218. }
  219. }
  220. //������
  221. protected int showTotal(string strSql)
  222. {
  223. BasicPage bp = new BasicPage();
  224. int intTotal = 0;
  225. SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_bed_class where " + strSql);
  226. if (myread.Read())
  227. {
  228. intTotal = Convert.ToInt32(myread["CountId"].ToString());
  229. }
  230. myread.Close();
  231. return intTotal;
  232. }
  233. /// <summary>
  234. /// �޸�һ������
  235. /// </summary>
  236. public void UpdateField(int id, string strValue)
  237. {
  238. StringBuilder strSql = new StringBuilder();
  239. strSql.Append("update tb_bed_class set " + strValue);
  240. strSql.Append(" where id=" + id);
  241. DbHelperSQL.ExecuteSql(strSql.ToString());
  242. }
  243. }
  244. }