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.

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