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.

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