DAL_iNethinkCMS_Channel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Data;
  14. using System.Text;
  15. using System.Data.SqlClient;
  16. using iNethinkCMS.Helper;
  17. namespace iNethinkCMS.DAL
  18. {
  19. /// <summary>
  20. /// 数据访问类:DAL_iNethinkCMS_Channel
  21. /// </summary>
  22. public partial class DAL_iNethinkCMS_Channel
  23. {
  24. public DAL_iNethinkCMS_Channel()
  25. {
  26. }
  27. #region Method
  28. /// <summary>
  29. /// 得到最大ID
  30. /// </summary>
  31. public int GetMaxID()
  32. {
  33. int vMaxID = 0;
  34. SqlDataReader sr = Helper.SQLHelper.ExecuteReader("select max(id) from iNethinkCMS_Channel");
  35. if (sr.Read())
  36. {
  37. vMaxID = Convert.ToInt32(sr[0]);
  38. }
  39. sr.Close();
  40. return vMaxID;
  41. }
  42. /// <summary>
  43. /// 是否存在该记录
  44. /// </summary>
  45. public bool Exists(int ID)
  46. {
  47. StringBuilder strSql = new StringBuilder();
  48. strSql.Append("select count(1) from iNethinkCMS_Channel");
  49. strSql.Append(" where ID=@ID ");
  50. SqlParameter[] parameters = {
  51. new SqlParameter("@ID", SqlDbType.Int,4) };
  52. parameters[0].Value = ID;
  53. return SQLHelper.Exists(strSql.ToString(), parameters);
  54. }
  55. /// <summary>
  56. /// 获得父栏目深度
  57. /// </summary>
  58. public int GetDeepPath(int FatherID)
  59. {
  60. StringBuilder strSql = new StringBuilder();
  61. strSql.Append("select DeepPath from iNethinkCMS_Channel");
  62. strSql.Append(" where ID=@FatherID ");
  63. SqlParameter[] parameters = {
  64. new SqlParameter("@FatherID", SqlDbType.Int,4) };
  65. parameters[0].Value = FatherID;
  66. object obj = SQLHelper.GetSingle(strSql.ToString(), parameters);
  67. if (obj == null)
  68. {
  69. return 0;
  70. }
  71. else
  72. {
  73. return Convert.ToInt32(obj);
  74. }
  75. }
  76. /// <summary>
  77. /// 增加一条数据
  78. /// </summary>
  79. public bool Add(iNethinkCMS.Model.Model_iNethinkCMS_Channel model)
  80. {
  81. StringBuilder strSql = new StringBuilder();
  82. strSql.Append("insert into iNethinkCMS_Channel(");
  83. strSql.Append("Mold,Cid,FatherID,ChildID,ChildIDs,DeepPath,Name,OrderNum,Domain,OutSideLink,Templatechannel,Templateclass,Templateview,Picture,Contents,Keywords,Description,Display)");
  84. strSql.Append(" values (");
  85. strSql.Append("@Mold,@Cid,@FatherID,@ChildID,@ChildIDs,@DeepPath,@Name,@OrderNum,@Domain,@OutSideLink,@Templatechannel,@Templateclass,@Templateview,@Picture,@Contents,@Keywords,@Description,@Display)");
  86. SqlParameter[] parameters = {
  87. //new SqlParameter("@ID", SqlDbType.Int,4),
  88. new SqlParameter("@Mold", SqlDbType.SmallInt,2),
  89. new SqlParameter("@Cid", SqlDbType.Int,4),
  90. new SqlParameter("@FatherID", SqlDbType.Int,4),
  91. new SqlParameter("@ChildID", SqlDbType.NText),
  92. new SqlParameter("@ChildIDs", SqlDbType.NText),
  93. new SqlParameter("@DeepPath", SqlDbType.Int,4),
  94. new SqlParameter("@Name", SqlDbType.NVarChar,500),
  95. new SqlParameter("@OrderNum", SqlDbType.Int,4),
  96. new SqlParameter("@Domain", SqlDbType.NVarChar,200),
  97. new SqlParameter("@OutSideLink", SqlDbType.Int,4),
  98. new SqlParameter("@Templatechannel", SqlDbType.NVarChar,200),
  99. new SqlParameter("@Templateclass", SqlDbType.NVarChar,200),
  100. new SqlParameter("@Templateview", SqlDbType.NVarChar,200),
  101. new SqlParameter("@Picture", SqlDbType.NVarChar,200),
  102. new SqlParameter("@Contents", SqlDbType.Text),
  103. new SqlParameter("@Keywords", SqlDbType.NVarChar,200),
  104. new SqlParameter("@Description", SqlDbType.NVarChar,500),
  105. new SqlParameter("@Display", SqlDbType.Int,4)};
  106. //parameters[0].Value = model.ID;
  107. parameters[0].Value = model.Mold;
  108. parameters[1].Value = model.Cid;
  109. parameters[2].Value = model.FatherID;
  110. parameters[3].Value = model.ChildID;
  111. parameters[4].Value = model.ChildIDs;
  112. parameters[5].Value = model.DeepPath;
  113. parameters[6].Value = model.Name;
  114. parameters[7].Value = model.OrderNum;
  115. parameters[8].Value = model.Domain;
  116. parameters[9].Value = model.OutSideLink;
  117. parameters[10].Value = model.Templatechannel;
  118. parameters[11].Value = model.Templateclass;
  119. parameters[12].Value = model.Templateview;
  120. parameters[13].Value = model.Picture;
  121. parameters[14].Value = model.Contents;
  122. parameters[15].Value = model.Keywords;
  123. parameters[16].Value = model.Description;
  124. parameters[17].Value = model.Display;
  125. int rows = SQLHelper.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 Update(iNethinkCMS.Model.Model_iNethinkCMS_Channel model)
  139. {
  140. StringBuilder strSql = new StringBuilder();
  141. strSql.Append("update iNethinkCMS_Channel set ");
  142. strSql.Append("Mold=@Mold,");
  143. strSql.Append("Cid=@Cid,");
  144. strSql.Append("FatherID=@FatherID,");
  145. strSql.Append("ChildID=@ChildID,");
  146. strSql.Append("ChildIDs=@ChildIDs,");
  147. strSql.Append("DeepPath=@DeepPath,");
  148. strSql.Append("Name=@Name,");
  149. strSql.Append("OrderNum=@OrderNum,");
  150. strSql.Append("Domain=@Domain,");
  151. strSql.Append("OutSideLink=@OutSideLink,");
  152. strSql.Append("Templatechannel=@Templatechannel,");
  153. strSql.Append("Templateclass=@Templateclass,");
  154. strSql.Append("Templateview=@Templateview,");
  155. strSql.Append("Picture=@Picture,");
  156. strSql.Append("Contents=@Contents,");
  157. strSql.Append("Keywords=@Keywords,");
  158. strSql.Append("Description=@Description,");
  159. strSql.Append("Display=@Display");
  160. strSql.Append(" where ID=@ID ");
  161. SqlParameter[] parameters = {
  162. new SqlParameter("@Mold", SqlDbType.SmallInt,2),
  163. new SqlParameter("@Cid", SqlDbType.Int,4),
  164. new SqlParameter("@FatherID", SqlDbType.Int,4),
  165. new SqlParameter("@ChildID", SqlDbType.NText),
  166. new SqlParameter("@ChildIDs", SqlDbType.NText),
  167. new SqlParameter("@DeepPath", SqlDbType.Int,4),
  168. new SqlParameter("@Name", SqlDbType.NVarChar,500),
  169. new SqlParameter("@OrderNum", SqlDbType.Int,4),
  170. new SqlParameter("@Domain", SqlDbType.NVarChar,200),
  171. new SqlParameter("@OutSideLink", SqlDbType.Int,4),
  172. new SqlParameter("@Templatechannel", SqlDbType.NVarChar,200),
  173. new SqlParameter("@Templateclass", SqlDbType.NVarChar,200),
  174. new SqlParameter("@Templateview", SqlDbType.NVarChar,200),
  175. new SqlParameter("@Picture", SqlDbType.NVarChar,200),
  176. new SqlParameter("@Contents", SqlDbType.Text),
  177. new SqlParameter("@Keywords", SqlDbType.NVarChar,200),
  178. new SqlParameter("@Description", SqlDbType.NVarChar,500),
  179. new SqlParameter("@Display", SqlDbType.Int,4),
  180. new SqlParameter("@ID", SqlDbType.Int,4)};
  181. parameters[0].Value = model.Mold;
  182. parameters[1].Value = model.Cid;
  183. parameters[2].Value = model.FatherID;
  184. parameters[3].Value = model.ChildID;
  185. parameters[4].Value = model.ChildIDs;
  186. parameters[5].Value = model.DeepPath;
  187. parameters[6].Value = model.Name;
  188. parameters[7].Value = model.OrderNum;
  189. parameters[8].Value = model.Domain;
  190. parameters[9].Value = model.OutSideLink;
  191. parameters[10].Value = model.Templatechannel;
  192. parameters[11].Value = model.Templateclass;
  193. parameters[12].Value = model.Templateview;
  194. parameters[13].Value = model.Picture;
  195. parameters[14].Value = model.Contents;
  196. parameters[15].Value = model.Keywords;
  197. parameters[16].Value = model.Description;
  198. parameters[17].Value = model.Display;
  199. parameters[18].Value = model.ID;
  200. int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
  201. if (rows > 0)
  202. {
  203. return true;
  204. }
  205. else
  206. {
  207. return false;
  208. }
  209. }
  210. /// <summary>
  211. /// 删除一条数据
  212. /// </summary>
  213. public bool Delete(int ID)
  214. {
  215. StringBuilder strSql = new StringBuilder();
  216. strSql.Append("delete from iNethinkCMS_Channel ");
  217. strSql.Append(" where ID=@ID ");
  218. SqlParameter[] parameters = {
  219. new SqlParameter("@ID", SqlDbType.Int,4) };
  220. parameters[0].Value = ID;
  221. int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
  222. if (rows > 0)
  223. {
  224. return true;
  225. }
  226. else
  227. {
  228. return false;
  229. }
  230. }
  231. /// <summary>
  232. /// 批量删除数据
  233. /// </summary>
  234. public bool DeleteList(string IDlist)
  235. {
  236. StringBuilder strSql = new StringBuilder();
  237. strSql.Append("delete from iNethinkCMS_Channel ");
  238. strSql.Append(" where ID in (" + IDlist + ") ");
  239. int rows = SQLHelper.ExecuteSql(strSql.ToString());
  240. if (rows > 0)
  241. {
  242. return true;
  243. }
  244. else
  245. {
  246. return false;
  247. }
  248. }
  249. /// <summary>
  250. /// 得到一个对象实体
  251. /// </summary>
  252. public iNethinkCMS.Model.Model_iNethinkCMS_Channel GetModel(int ID)
  253. {
  254. StringBuilder strSql = new StringBuilder();
  255. strSql.Append("select top 1 ID,Mold,Cid,FatherID,ChildID,ChildIDs,DeepPath,Name,OrderNum,Domain,OutSideLink,Templatechannel,Templateclass,Templateview,Picture,Contents,Keywords,Description,Display from iNethinkCMS_Channel ");
  256. strSql.Append(" where ID=@ID ");
  257. SqlParameter[] parameters = {
  258. new SqlParameter("@ID", SqlDbType.Int,4) };
  259. parameters[0].Value = ID;
  260. iNethinkCMS.Model.Model_iNethinkCMS_Channel model = new iNethinkCMS.Model.Model_iNethinkCMS_Channel();
  261. DataSet ds = SQLHelper.Query(strSql.ToString(), parameters);
  262. if (ds.Tables[0].Rows.Count > 0)
  263. {
  264. if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
  265. {
  266. model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
  267. }
  268. if (ds.Tables[0].Rows[0]["Mold"] != null && ds.Tables[0].Rows[0]["Mold"].ToString() != "")
  269. {
  270. model.Mold = int.Parse(ds.Tables[0].Rows[0]["Mold"].ToString());
  271. }
  272. if (ds.Tables[0].Rows[0]["Cid"] != null && ds.Tables[0].Rows[0]["Cid"].ToString() != "")
  273. {
  274. model.Cid = int.Parse(ds.Tables[0].Rows[0]["Cid"].ToString());
  275. }
  276. if (ds.Tables[0].Rows[0]["FatherID"] != null && ds.Tables[0].Rows[0]["FatherID"].ToString() != "")
  277. {
  278. model.FatherID = int.Parse(ds.Tables[0].Rows[0]["FatherID"].ToString());
  279. }
  280. if (ds.Tables[0].Rows[0]["ChildID"] != null && ds.Tables[0].Rows[0]["ChildID"].ToString() != "")
  281. {
  282. model.ChildID = ds.Tables[0].Rows[0]["ChildID"].ToString();
  283. }
  284. if (ds.Tables[0].Rows[0]["ChildIDs"] != null && ds.Tables[0].Rows[0]["ChildIDs"].ToString() != "")
  285. {
  286. model.ChildIDs = ds.Tables[0].Rows[0]["ChildIDs"].ToString();
  287. }
  288. if (ds.Tables[0].Rows[0]["DeepPath"] != null && ds.Tables[0].Rows[0]["DeepPath"].ToString() != "")
  289. {
  290. model.DeepPath = int.Parse(ds.Tables[0].Rows[0]["DeepPath"].ToString());
  291. }
  292. if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "")
  293. {
  294. model.Name = ds.Tables[0].Rows[0]["Name"].ToString();
  295. }
  296. if (ds.Tables[0].Rows[0]["OrderNum"] != null && ds.Tables[0].Rows[0]["OrderNum"].ToString() != "")
  297. {
  298. model.OrderNum = int.Parse(ds.Tables[0].Rows[0]["OrderNum"].ToString());
  299. }
  300. if (ds.Tables[0].Rows[0]["Domain"] != null && ds.Tables[0].Rows[0]["Domain"].ToString() != "")
  301. {
  302. model.Domain = ds.Tables[0].Rows[0]["Domain"].ToString();
  303. }
  304. if (ds.Tables[0].Rows[0]["OutSideLink"] != null && ds.Tables[0].Rows[0]["OutSideLink"].ToString() != "")
  305. {
  306. model.OutSideLink = int.Parse(ds.Tables[0].Rows[0]["OutSideLink"].ToString());
  307. }
  308. if (ds.Tables[0].Rows[0]["Templatechannel"] != null && ds.Tables[0].Rows[0]["Templatechannel"].ToString() != "")
  309. {
  310. model.Templatechannel = ds.Tables[0].Rows[0]["Templatechannel"].ToString();
  311. }
  312. if (ds.Tables[0].Rows[0]["Templateclass"] != null && ds.Tables[0].Rows[0]["Templateclass"].ToString() != "")
  313. {
  314. model.Templateclass = ds.Tables[0].Rows[0]["Templateclass"].ToString();
  315. }
  316. if (ds.Tables[0].Rows[0]["Templateview"] != null && ds.Tables[0].Rows[0]["Templateview"].ToString() != "")
  317. {
  318. model.Templateview = ds.Tables[0].Rows[0]["Templateview"].ToString();
  319. }
  320. if (ds.Tables[0].Rows[0]["Picture"] != null && ds.Tables[0].Rows[0]["Picture"].ToString() != "")
  321. {
  322. model.Picture = ds.Tables[0].Rows[0]["Picture"].ToString();
  323. }
  324. if (ds.Tables[0].Rows[0]["Contents"] != null && ds.Tables[0].Rows[0]["Contents"].ToString() != "")
  325. {
  326. model.Contents = ds.Tables[0].Rows[0]["Contents"].ToString();
  327. }
  328. if (ds.Tables[0].Rows[0]["Keywords"] != null && ds.Tables[0].Rows[0]["Keywords"].ToString() != "")
  329. {
  330. model.Keywords = ds.Tables[0].Rows[0]["Keywords"].ToString();
  331. }
  332. if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "")
  333. {
  334. model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
  335. }
  336. if (ds.Tables[0].Rows[0]["Display"] != null && ds.Tables[0].Rows[0]["Display"].ToString() != "")
  337. {
  338. model.Display = int.Parse(ds.Tables[0].Rows[0]["Display"].ToString());
  339. }
  340. return model;
  341. }
  342. else
  343. {
  344. return null;
  345. }
  346. }
  347. /// <summary>
  348. /// 获得数据列表
  349. /// </summary>
  350. public DataSet GetList(string strWhere)
  351. {
  352. StringBuilder strSql = new StringBuilder();
  353. strSql.Append("select ID,Mold,Cid,FatherID,ChildID,ChildIDs,DeepPath,Name,OrderNum,Domain,OutSideLink,Templatechannel,Templateclass,Templateview,Picture,Contents,Keywords,Description,Display ");
  354. strSql.Append(" FROM iNethinkCMS_Channel ");
  355. if (strWhere.Trim() != "")
  356. {
  357. strSql.Append(" where " + strWhere);
  358. }
  359. return SQLHelper.Query(strSql.ToString());
  360. }
  361. /// <summary>
  362. /// 获得前几行数据
  363. /// </summary>
  364. public DataSet GetList(int Top, string strWhere, string filedOrder)
  365. {
  366. StringBuilder strSql = new StringBuilder();
  367. strSql.Append("select ");
  368. if (Top > 0)
  369. {
  370. strSql.Append(" top " + Top.ToString());
  371. }
  372. strSql.Append(" ID,Mold,Cid,FatherID,ChildID,ChildIDs,DeepPath,Name,OrderNum,Domain,OutSideLink,Templatechannel,Templateclass,Templateview,Picture,Contents,Keywords,Description,Display ");
  373. strSql.Append(" FROM iNethinkCMS_Channel ");
  374. if (strWhere.Trim() != "")
  375. {
  376. strSql.Append(" where " + strWhere);
  377. }
  378. strSql.Append(" order by " + filedOrder);
  379. return SQLHelper.Query(strSql.ToString());
  380. }
  381. /// <summary>
  382. /// 获取记录总数
  383. /// </summary>
  384. public int GetRecordCount(string strWhere)
  385. {
  386. StringBuilder strSql = new StringBuilder();
  387. strSql.Append("select count(1) FROM iNethinkCMS_Channel ");
  388. if (strWhere.Trim() != "")
  389. {
  390. strSql.Append(" where " + strWhere);
  391. }
  392. object obj = SQLHelper.GetSingle(strSql.ToString());
  393. if (obj == null)
  394. {
  395. return 0;
  396. }
  397. else
  398. {
  399. return Convert.ToInt32(obj);
  400. }
  401. }
  402. /// <summary>
  403. /// 分页获取数据列表
  404. /// </summary>
  405. public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
  406. {
  407. if (!string.IsNullOrEmpty(strWhere.Trim()))
  408. {
  409. strWhere = " Where " + strWhere;
  410. }
  411. if (!string.IsNullOrEmpty(orderby.Trim()))
  412. {
  413. orderby = " Order By " + orderby;
  414. }
  415. //startIndex = startIndex - 1;
  416. StringBuilder strSql = new StringBuilder();
  417. strSql.Append("SELECT * FROM iNethinkCMS_Channel Where ID Not IN ");
  418. strSql.Append("(Select Top " + startIndex + " ID From iNethinkCMS_Channel" + strWhere + orderby + ")");
  419. strSql.Append(" And ID In ");
  420. strSql.Append("(Select Top " + endIndex + " ID From iNethinkCMS_Channel" + strWhere + orderby + ")");
  421. strSql.Append(orderby);
  422. return SQLHelper.Query(strSql.ToString());
  423. }
  424. #endregion Method
  425. }
  426. }