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ů.

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