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

384 řádky
16 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. /// ���ݷ��ʲ�nav
  9. /// </summary>
  10. public partial class nav
  11. {
  12. /// <summary>
  13. /// ����һ������
  14. /// </summary>
  15. public int Add(Basic.Model.nav model)
  16. {
  17. StringBuilder strSql = new StringBuilder();
  18. strSql.Append("insert into tb_nav(");
  19. strSql.Append("paixu,title,class_id,parent_id,class_list,class_layer,path,url,target,state,remark,seo_title,seo_keywords,seo_description,add_time)");
  20. strSql.Append(" values (");
  21. strSql.Append("@paixu,@title,@class_id,@parent_id,@class_list,@class_layer,@path,@url,@target,@state,@remark,@seo_title,@seo_keywords,@seo_description,@add_time)");
  22. strSql.Append(";select @@IDENTITY");
  23. SqlParameter[] parameters = {
  24. new SqlParameter("@paixu", SqlDbType.Int,10),
  25. new SqlParameter("@title", SqlDbType.NVarChar,255),
  26. new SqlParameter("@class_id", SqlDbType.Int,10),
  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("@path", SqlDbType.NVarChar,255),
  31. new SqlParameter("@url", SqlDbType.NVarChar,255),
  32. new SqlParameter("@target", SqlDbType.Int,10),
  33. new SqlParameter("@state", SqlDbType.Int,10),
  34. new SqlParameter("@remark", SqlDbType.NVarChar,500),
  35. new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
  36. new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
  37. new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
  38. new SqlParameter("@add_time", SqlDbType.DateTime,23)};
  39. parameters[0].Value = model.paixu;
  40. parameters[1].Value = model.title;
  41. parameters[2].Value = model.class_id;
  42. parameters[3].Value = model.parent_id;
  43. parameters[4].Value = model.class_list;
  44. parameters[5].Value = model.class_layer;
  45. parameters[6].Value = model.path;
  46. parameters[7].Value = model.url;
  47. parameters[8].Value = model.target;
  48. parameters[9].Value = model.state;
  49. parameters[10].Value = model.remark;
  50. parameters[11].Value = model.seo_title;
  51. parameters[12].Value = model.seo_keywords;
  52. parameters[13].Value = model.seo_description;
  53. parameters[14].Value = model.add_time;
  54. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  55. if (obj == null)
  56. {
  57. return 0;
  58. }
  59. else
  60. {
  61. return Convert.ToInt32(obj);
  62. }
  63. }
  64. /// <summary>
  65. /// ����һ������
  66. /// </summary>
  67. public bool Update(Basic.Model.nav model)
  68. {
  69. StringBuilder strSql = new StringBuilder();
  70. strSql.Append("update tb_nav set ");
  71. strSql.Append("paixu=@paixu,");
  72. strSql.Append("title=@title,");
  73. strSql.Append("class_id=@class_id,");
  74. strSql.Append("parent_id=@parent_id,");
  75. strSql.Append("class_list=@class_list,");
  76. strSql.Append("class_layer=@class_layer,");
  77. strSql.Append("path=@path,");
  78. strSql.Append("url=@url,");
  79. strSql.Append("target=@target,");
  80. strSql.Append("state=@state,");
  81. strSql.Append("remark=@remark,");
  82. strSql.Append("seo_title=@seo_title,");
  83. strSql.Append("seo_keywords=@seo_keywords,");
  84. strSql.Append("seo_description=@seo_description,");
  85. strSql.Append("add_time=@add_time");
  86. strSql.Append(" where id=@id");
  87. SqlParameter[] parameters = {
  88. new SqlParameter("@paixu", SqlDbType.Int,10),
  89. new SqlParameter("@title", SqlDbType.NVarChar,255),
  90. new SqlParameter("@class_id", SqlDbType.Int,10),
  91. new SqlParameter("@parent_id", SqlDbType.Int,10),
  92. new SqlParameter("@class_list", SqlDbType.NVarChar,500),
  93. new SqlParameter("@class_layer", SqlDbType.Int,10),
  94. new SqlParameter("@path", SqlDbType.NVarChar,255),
  95. new SqlParameter("@url", SqlDbType.NVarChar,255),
  96. new SqlParameter("@target", SqlDbType.Int,10),
  97. new SqlParameter("@state", SqlDbType.Int,10),
  98. new SqlParameter("@remark", SqlDbType.NVarChar,500),
  99. new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
  100. new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
  101. new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
  102. new SqlParameter("@add_time", SqlDbType.DateTime,23),
  103. new SqlParameter("@id", SqlDbType.Int,4)};
  104. parameters[0].Value = model.paixu;
  105. parameters[1].Value = model.title;
  106. parameters[2].Value = model.class_id;
  107. parameters[3].Value = model.parent_id;
  108. parameters[4].Value = model.class_list;
  109. parameters[5].Value = model.class_layer;
  110. parameters[6].Value = model.path;
  111. parameters[7].Value = model.url;
  112. parameters[8].Value = model.target;
  113. parameters[9].Value = model.state;
  114. parameters[10].Value = model.remark;
  115. parameters[11].Value = model.seo_title;
  116. parameters[12].Value = model.seo_keywords;
  117. parameters[13].Value = model.seo_description;
  118. parameters[14].Value = model.add_time;
  119. parameters[15].Value = model.id;
  120. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  121. if (rows > 0)
  122. {
  123. return true;
  124. }
  125. else
  126. {
  127. return false;
  128. }
  129. }
  130. /// <summary>
  131. /// ɾ��һ������
  132. /// </summary>
  133. public bool Delete(int id)
  134. {
  135. StringBuilder strSql = new StringBuilder();
  136. strSql.Append("delete from tb_nav");
  137. strSql.Append(" where id=@id");
  138. SqlParameter[] parameters = {
  139. new SqlParameter("@id", SqlDbType.Int,4)};
  140. parameters[0].Value = id;
  141. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  142. if (rows > 0)
  143. {
  144. return true;
  145. }
  146. else
  147. {
  148. return false;
  149. }
  150. }
  151. /// <summary>
  152. /// �õ�һ������ʵ��
  153. /// </summary>
  154. public Basic.Model.nav GetModel(int id)
  155. {
  156. StringBuilder strSql = new StringBuilder();
  157. strSql.Append("select top 1 id,paixu,title,class_id,parent_id,class_list,class_layer,path,url,target,state,remark,seo_title,seo_keywords,seo_description,add_time from tb_nav");
  158. strSql.Append(" where id=@id");
  159. SqlParameter[] parameters = {
  160. new SqlParameter("@id", SqlDbType.Int,4)};
  161. parameters[0].Value = id;
  162. Basic.Model.nav model = new Basic.Model.nav();
  163. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  164. if (ds.Tables[0].Rows.Count > 0)
  165. {
  166. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
  167. {
  168. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  169. }
  170. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
  171. {
  172. model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
  173. }
  174. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
  175. {
  176. model.title = ds.Tables[0].Rows[0]["title"].ToString();
  177. }
  178. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
  179. {
  180. model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
  181. }
  182. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
  183. {
  184. model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
  185. }
  186. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_list"].ToString()))
  187. {
  188. model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString();
  189. }
  190. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_layer"].ToString()))
  191. {
  192. model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString());
  193. }
  194. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
  195. {
  196. model.path = ds.Tables[0].Rows[0]["path"].ToString();
  197. }
  198. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
  199. {
  200. model.url = ds.Tables[0].Rows[0]["url"].ToString();
  201. }
  202. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["target"].ToString()))
  203. {
  204. model.target = int.Parse(ds.Tables[0].Rows[0]["target"].ToString());
  205. }
  206. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
  207. {
  208. model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
  209. }
  210. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString()))
  211. {
  212. model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
  213. }
  214. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_title"].ToString()))
  215. {
  216. model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString();
  217. }
  218. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_keywords"].ToString()))
  219. {
  220. model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString();
  221. }
  222. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_description"].ToString()))
  223. {
  224. model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString();
  225. }
  226. if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
  227. {
  228. model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
  229. }
  230. return model;
  231. }
  232. else
  233. {
  234. return null;
  235. }
  236. }
  237. /// <summary>
  238. /// ����ǰ��������
  239. /// </summary>
  240. public DataSet GetList(int Top, string strWhere, string filedOrder)
  241. {
  242. StringBuilder strSql = new StringBuilder();
  243. strSql.Append("select ");
  244. if (Top > 0)
  245. {
  246. strSql.Append(" top " + Top.ToString());
  247. }
  248. strSql.Append("id,paixu,title,class_id,parent_id,class_list,class_layer,path,url,target,state,remark,seo_title,seo_keywords,seo_description,add_time");
  249. strSql.Append(" from tb_nav");
  250. if (strWhere.Trim() != "")
  251. {
  252. strSql.Append(" where " + strWhere);
  253. }
  254. strSql.Append(" order by " + filedOrder);
  255. return DbHelperSQL.Query(strSql.ToString());
  256. }
  257. /// <summary>
  258. /// �Ƿ����ڸü�¼
  259. /// </summary>
  260. public bool Exists(int id)
  261. {
  262. StringBuilder strSql = new StringBuilder();
  263. strSql.Append("select count(1) from tb_nav");
  264. strSql.Append(" where id=@id");
  265. SqlParameter[] parameters = {
  266. new SqlParameter("@id", SqlDbType.Int,4)};
  267. parameters[0].Value = id;
  268. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  269. }
  270. /// <summary>
  271. /// �޸�һ������
  272. /// </summary>
  273. public void UpdateField(int id, string strValue)
  274. {
  275. StringBuilder strSql = new StringBuilder();
  276. strSql.Append("update tb_nav set " + strValue);
  277. strSql.Append(" where id=" + id);
  278. DbHelperSQL.ExecuteSql(strSql.ToString());
  279. }
  280. /// <summary>
  281. /// ȡ�����������б�
  282. /// </summary>
  283. /// <param name="parent_id">��ID</param>
  284. /// <param name="class_id">����ID</param>
  285. /// <returns></returns>
  286. public DataTable GetList(int parent_id, int class_id)
  287. {
  288. StringBuilder strSql = new StringBuilder();
  289. strSql.Append("select * from tb_nav");
  290. if (class_id > 0)
  291. {
  292. strSql.Append(" where class_id=" + class_id);
  293. }
  294. strSql.Append(" order by paixu desc,id asc");
  295. DataSet ds = DbHelperSQL.Query(strSql.ToString());
  296. DataTable oldData = ds.Tables[0] as DataTable;
  297. if (oldData == null)
  298. {
  299. return null;
  300. }
  301. //���ƽṹ
  302. DataTable newData = oldData.Clone();
  303. //���õ������ϳ�DAGATABLE
  304. GetChilds(oldData, newData, parent_id, class_id);
  305. return newData;
  306. }
  307. /// <summary>
  308. /// ���ڴ���ȡ�������¼������б�������������
  309. /// </summary>
  310. private void GetChilds(DataTable oldData, DataTable newData, int parent_id, int channel_id)
  311. {
  312. DataRow[] dr = oldData.Select("parent_id=" + parent_id);
  313. for (int i = 0; i < dr.Length; i++)
  314. {
  315. //����һ������
  316. DataRow row = newData.NewRow();
  317. row["id"] = int.Parse(dr[i]["id"].ToString());
  318. row["paixu"] = int.Parse(dr[i]["paixu"].ToString());
  319. row["title"] = dr[i]["title"].ToString();
  320. row["class_id"] = int.Parse(dr[i]["class_id"].ToString());
  321. row["parent_id"] = int.Parse(dr[i]["parent_id"].ToString());
  322. row["class_layer"] = int.Parse(dr[i]["class_layer"].ToString());
  323. row["class_list"] = dr[i]["class_list"].ToString();
  324. row["path"] = dr[i]["path"].ToString();
  325. row["url"] = dr[i]["url"].ToString();
  326. row["target"] = int.Parse(dr[i]["target"].ToString());
  327. row["state"] = int.Parse(dr[i]["state"].ToString());
  328. row["remark"] = dr[i]["remark"].ToString();
  329. row["seo_title"] = dr[i]["seo_title"].ToString();
  330. row["seo_keywords"] = dr[i]["seo_keywords"].ToString();
  331. row["seo_description"] = dr[i]["seo_description"].ToString();
  332. row["add_time"] = DateTime.Parse(dr[i]["add_time"].ToString());
  333. newData.Rows.Add(row);
  334. //������������
  335. this.GetChilds(oldData, newData, int.Parse(dr[i]["id"].ToString()), channel_id);
  336. }
  337. }
  338. /// <summary>
  339. /// ���ص�һ��class_id
  340. /// </summary>
  341. public int GetClass_Id()
  342. {
  343. int class_id = 0;
  344. BasicPage bp = new BasicPage();
  345. SqlDataReader myread = bp.getRead("select top 1 class_id from tb_nav");
  346. if (myread.Read())
  347. {
  348. class_id = int.Parse(myread[0].ToString());
  349. }
  350. myread.Close();
  351. return class_id;
  352. }
  353. /// <summary>
  354. /// ���ص�������
  355. /// </summary>
  356. //public string GetNav(int _id)
  357. //{
  358. // int class_id = 0;
  359. // BasicPage bp = new BasicPage();
  360. // SqlDataReader myread = bp.getRead("select top 1 class_id from tb_nav");
  361. // if (myread.Read())
  362. // {
  363. // class_id = int.Parse(myread[0].ToString());
  364. // }
  365. // myread.Close();
  366. // return class_id;
  367. //}
  368. }
  369. }