DAL_iNethinkCMS_Special.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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_Special
  21. /// </summary>
  22. public partial class DAL_iNethinkCMS_Special
  23. {
  24. public DAL_iNethinkCMS_Special()
  25. {
  26. }
  27. #region Method
  28. /// <summary>
  29. /// 是否存在该记录
  30. /// </summary>
  31. public bool Exists(int ID)
  32. {
  33. StringBuilder strSql = new StringBuilder();
  34. strSql.Append("select count(1) from iNethinkCMS_Special");
  35. strSql.Append(" where ID=@ID");
  36. SqlParameter[] parameters = {
  37. new SqlParameter("@ID", SqlDbType.Int,4)
  38. };
  39. parameters[0].Value = ID;
  40. return SQLHelper.Exists(strSql.ToString(), parameters);
  41. }
  42. /// <summary>
  43. /// MaxID
  44. /// </summary>
  45. public int GetMaxID()
  46. {
  47. int vMaxID = 0;
  48. SqlDataReader sr = Helper.SQLHelper.ExecuteReader("select max(id) from iNethinkCMS_Special");
  49. if (sr.Read())
  50. {
  51. vMaxID = Convert.ToInt32(sr[0]);
  52. }
  53. sr.Close();
  54. return vMaxID;
  55. }
  56. /// <summary>
  57. /// 增加一条数据
  58. /// </summary>
  59. public int Add(iNethinkCMS.Model.Model_iNethinkCMS_Special model)
  60. {
  61. StringBuilder strSql = new StringBuilder();
  62. strSql.Append("insert into iNethinkCMS_Special(");
  63. strSql.Append("SpecialName,SpecialTitle,SpecialKeyword,SpecialDescription,SpecialTemplate,SpecialUrl,SpecialPic,SpecialContent,Display,OrderNum)");
  64. strSql.Append(" values (");
  65. strSql.Append("@SpecialName,@SpecialTitle,@SpecialKeyword,@SpecialDescription,@SpecialTemplate,@SpecialUrl,@SpecialPic,@SpecialContent,@Display,@OrderNum)");
  66. strSql.Append(";select @@IDENTITY");
  67. SqlParameter[] parameters = {
  68. new SqlParameter("@SpecialName", SqlDbType.NVarChar,200),
  69. new SqlParameter("@SpecialTitle", SqlDbType.NVarChar,200),
  70. new SqlParameter("@SpecialKeyword", SqlDbType.NVarChar,200),
  71. new SqlParameter("@SpecialDescription", SqlDbType.NVarChar,500),
  72. new SqlParameter("@SpecialTemplate", SqlDbType.NVarChar,200),
  73. new SqlParameter("@SpecialUrl", SqlDbType.NVarChar,200),
  74. new SqlParameter("@SpecialPic", SqlDbType.NVarChar,200),
  75. new SqlParameter("@SpecialContent", SqlDbType.Text),
  76. new SqlParameter("@Display", SqlDbType.SmallInt,2),
  77. new SqlParameter("@OrderNum", SqlDbType.Int,4)};
  78. parameters[0].Value = model.SpecialName;
  79. parameters[1].Value = model.SpecialTitle;
  80. parameters[2].Value = model.SpecialKeyword;
  81. parameters[3].Value = model.SpecialDescription;
  82. parameters[4].Value = model.SpecialTemplate;
  83. parameters[5].Value = model.SpecialUrl;
  84. parameters[6].Value = model.SpecialPic;
  85. parameters[7].Value = model.SpecialContent;
  86. parameters[8].Value = model.Display;
  87. parameters[9].Value = model.OrderNum;
  88. object obj = SQLHelper.GetSingle(strSql.ToString(), parameters);
  89. if (obj == null)
  90. {
  91. return 0;
  92. }
  93. else
  94. {
  95. return Convert.ToInt32(obj);
  96. }
  97. }
  98. /// <summary>
  99. /// 更新一条数据
  100. /// </summary>
  101. public bool Update(iNethinkCMS.Model.Model_iNethinkCMS_Special model)
  102. {
  103. StringBuilder strSql = new StringBuilder();
  104. strSql.Append("update iNethinkCMS_Special set ");
  105. strSql.Append("SpecialName=@SpecialName,");
  106. strSql.Append("SpecialTitle=@SpecialTitle,");
  107. strSql.Append("SpecialKeyword=@SpecialKeyword,");
  108. strSql.Append("SpecialDescription=@SpecialDescription,");
  109. strSql.Append("SpecialTemplate=@SpecialTemplate,");
  110. strSql.Append("SpecialUrl=@SpecialUrl,");
  111. strSql.Append("SpecialPic=@SpecialPic,");
  112. strSql.Append("SpecialContent=@SpecialContent,");
  113. strSql.Append("Display=@Display,");
  114. strSql.Append("OrderNum=@OrderNum");
  115. strSql.Append(" where ID=@ID");
  116. SqlParameter[] parameters = {
  117. new SqlParameter("@SpecialName", SqlDbType.NVarChar,200),
  118. new SqlParameter("@SpecialTitle", SqlDbType.NVarChar,200),
  119. new SqlParameter("@SpecialKeyword", SqlDbType.NVarChar,200),
  120. new SqlParameter("@SpecialDescription", SqlDbType.NVarChar,500),
  121. new SqlParameter("@SpecialTemplate", SqlDbType.NVarChar,200),
  122. new SqlParameter("@SpecialUrl", SqlDbType.NVarChar,200),
  123. new SqlParameter("@SpecialPic", SqlDbType.NVarChar,200),
  124. new SqlParameter("@SpecialContent", SqlDbType.Text),
  125. new SqlParameter("@Display", SqlDbType.SmallInt,2),
  126. new SqlParameter("@OrderNum", SqlDbType.Int,4),
  127. new SqlParameter("@ID", SqlDbType.Int,4)};
  128. parameters[0].Value = model.SpecialName;
  129. parameters[1].Value = model.SpecialTitle;
  130. parameters[2].Value = model.SpecialKeyword;
  131. parameters[3].Value = model.SpecialDescription;
  132. parameters[4].Value = model.SpecialTemplate;
  133. parameters[5].Value = model.SpecialUrl;
  134. parameters[6].Value = model.SpecialPic;
  135. parameters[7].Value = model.SpecialContent;
  136. parameters[8].Value = model.Display;
  137. parameters[9].Value = model.OrderNum;
  138. parameters[10].Value = model.ID;
  139. int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
  140. if (rows > 0)
  141. {
  142. return true;
  143. }
  144. else
  145. {
  146. return false;
  147. }
  148. }
  149. /// <summary>
  150. /// 删除一条数据
  151. /// </summary>
  152. public bool Delete(int ID)
  153. {
  154. StringBuilder strSql = new StringBuilder();
  155. strSql.Append("delete from iNethinkCMS_Special ");
  156. strSql.Append(" where ID=@ID");
  157. SqlParameter[] parameters = {
  158. new SqlParameter("@ID", SqlDbType.Int,4)
  159. };
  160. parameters[0].Value = ID;
  161. int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
  162. if (rows > 0)
  163. {
  164. return true;
  165. }
  166. else
  167. {
  168. return false;
  169. }
  170. }
  171. /// <summary>
  172. /// 批量删除数据
  173. /// </summary>
  174. public bool DeleteList(string IDlist)
  175. {
  176. StringBuilder strSql = new StringBuilder();
  177. strSql.Append("delete from iNethinkCMS_Special ");
  178. strSql.Append(" where ID in (" + IDlist + ") ");
  179. int rows = SQLHelper.ExecuteSql(strSql.ToString());
  180. if (rows > 0)
  181. {
  182. return true;
  183. }
  184. else
  185. {
  186. return false;
  187. }
  188. }
  189. /// <summary>
  190. /// 得到一个对象实体
  191. /// </summary>
  192. public iNethinkCMS.Model.Model_iNethinkCMS_Special GetModel(int ID)
  193. {
  194. StringBuilder strSql = new StringBuilder();
  195. strSql.Append("select top 1 ID,SpecialName,SpecialTitle,SpecialKeyword,SpecialDescription,SpecialTemplate,SpecialUrl,SpecialPic,SpecialContent,Display,OrderNum from iNethinkCMS_Special ");
  196. strSql.Append(" where ID=@ID");
  197. SqlParameter[] parameters = {
  198. new SqlParameter("@ID", SqlDbType.Int,4)
  199. };
  200. parameters[0].Value = ID;
  201. iNethinkCMS.Model.Model_iNethinkCMS_Special model = new iNethinkCMS.Model.Model_iNethinkCMS_Special();
  202. DataSet ds = SQLHelper.Query(strSql.ToString(), parameters);
  203. if (ds.Tables[0].Rows.Count > 0)
  204. {
  205. if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
  206. {
  207. model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
  208. }
  209. if (ds.Tables[0].Rows[0]["SpecialName"] != null && ds.Tables[0].Rows[0]["SpecialName"].ToString() != "")
  210. {
  211. model.SpecialName = ds.Tables[0].Rows[0]["SpecialName"].ToString();
  212. }
  213. if (ds.Tables[0].Rows[0]["SpecialTitle"] != null && ds.Tables[0].Rows[0]["SpecialTitle"].ToString() != "")
  214. {
  215. model.SpecialTitle = ds.Tables[0].Rows[0]["SpecialTitle"].ToString();
  216. }
  217. if (ds.Tables[0].Rows[0]["SpecialKeyword"] != null && ds.Tables[0].Rows[0]["SpecialKeyword"].ToString() != "")
  218. {
  219. model.SpecialKeyword = ds.Tables[0].Rows[0]["SpecialKeyword"].ToString();
  220. }
  221. if (ds.Tables[0].Rows[0]["SpecialDescription"] != null && ds.Tables[0].Rows[0]["SpecialDescription"].ToString() != "")
  222. {
  223. model.SpecialDescription = ds.Tables[0].Rows[0]["SpecialDescription"].ToString();
  224. }
  225. if (ds.Tables[0].Rows[0]["SpecialTemplate"] != null && ds.Tables[0].Rows[0]["SpecialTemplate"].ToString() != "")
  226. {
  227. model.SpecialTemplate = ds.Tables[0].Rows[0]["SpecialTemplate"].ToString();
  228. }
  229. if (ds.Tables[0].Rows[0]["SpecialUrl"] != null && ds.Tables[0].Rows[0]["SpecialUrl"].ToString() != "")
  230. {
  231. model.SpecialUrl = ds.Tables[0].Rows[0]["SpecialUrl"].ToString();
  232. }
  233. if (ds.Tables[0].Rows[0]["SpecialPic"] != null && ds.Tables[0].Rows[0]["SpecialPic"].ToString() != "")
  234. {
  235. model.SpecialPic = ds.Tables[0].Rows[0]["SpecialPic"].ToString();
  236. }
  237. if (ds.Tables[0].Rows[0]["SpecialContent"] != null && ds.Tables[0].Rows[0]["SpecialContent"].ToString() != "")
  238. {
  239. model.SpecialContent = ds.Tables[0].Rows[0]["SpecialContent"].ToString();
  240. }
  241. if (ds.Tables[0].Rows[0]["Display"] != null && ds.Tables[0].Rows[0]["Display"].ToString() != "")
  242. {
  243. model.Display = int.Parse(ds.Tables[0].Rows[0]["Display"].ToString());
  244. }
  245. if (ds.Tables[0].Rows[0]["OrderNum"] != null && ds.Tables[0].Rows[0]["OrderNum"].ToString() != "")
  246. {
  247. model.OrderNum = int.Parse(ds.Tables[0].Rows[0]["OrderNum"].ToString());
  248. }
  249. return model;
  250. }
  251. else
  252. {
  253. return null;
  254. }
  255. }
  256. /// <summary>
  257. /// 获得数据列表
  258. /// </summary>
  259. public DataSet GetList(string strWhere)
  260. {
  261. StringBuilder strSql = new StringBuilder();
  262. strSql.Append("select ID,SpecialName,SpecialTitle,SpecialKeyword,SpecialDescription,SpecialTemplate,SpecialUrl,SpecialPic,SpecialContent,Display,OrderNum ");
  263. strSql.Append(" FROM iNethinkCMS_Special ");
  264. if (strWhere.Trim() != "")
  265. {
  266. strSql.Append(" where " + strWhere);
  267. }
  268. return SQLHelper.Query(strSql.ToString());
  269. }
  270. /// <summary>
  271. /// 获得前几行数据
  272. /// </summary>
  273. public DataSet GetList(int Top, string strWhere, string filedOrder)
  274. {
  275. StringBuilder strSql = new StringBuilder();
  276. strSql.Append("select ");
  277. if (Top > 0)
  278. {
  279. strSql.Append(" top " + Top.ToString());
  280. }
  281. strSql.Append(" ID,SpecialName,SpecialTitle,SpecialKeyword,SpecialDescription,SpecialTemplate,SpecialUrl,SpecialPic,SpecialContent,Display,OrderNum ");
  282. strSql.Append(" FROM iNethinkCMS_Special ");
  283. if (strWhere.Trim() != "")
  284. {
  285. strSql.Append(" where " + strWhere);
  286. }
  287. strSql.Append(" order by " + filedOrder);
  288. return SQLHelper.Query(strSql.ToString());
  289. }
  290. /// <summary>
  291. /// 获取记录总数
  292. /// </summary>
  293. public int GetRecordCount(string strWhere)
  294. {
  295. StringBuilder strSql = new StringBuilder();
  296. strSql.Append("select count(1) FROM iNethinkCMS_Special ");
  297. if (strWhere.Trim() != "")
  298. {
  299. strSql.Append(" where " + strWhere);
  300. }
  301. object obj = SQLHelper.GetSingle(strSql.ToString());
  302. if (obj == null)
  303. {
  304. return 0;
  305. }
  306. else
  307. {
  308. return Convert.ToInt32(obj);
  309. }
  310. }
  311. /// <summary>
  312. /// 分页获取数据列表
  313. /// </summary>
  314. public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
  315. {
  316. if (!string.IsNullOrEmpty(strWhere.Trim()))
  317. {
  318. strWhere = " Where " + strWhere;
  319. }
  320. if (!string.IsNullOrEmpty(orderby.Trim()))
  321. {
  322. orderby = " Order By " + orderby;
  323. }
  324. //startIndex = startIndex - 1;
  325. StringBuilder strSql = new StringBuilder();
  326. strSql.Append("SELECT * FROM iNethinkCMS_Special Where ID Not IN ");
  327. strSql.Append("(Select Top " + startIndex + " ID From iNethinkCMS_Special" + strWhere + orderby + ")");
  328. strSql.Append(" And ID In ");
  329. strSql.Append("(Select Top " + endIndex + " ID From iNethinkCMS_Special" + strWhere + orderby + ")");
  330. strSql.Append(orderby);
  331. return SQLHelper.Query(strSql.ToString());
  332. }
  333. #endregion Method
  334. }
  335. }