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