Brak opisu

T_RepositoryLog.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. using CallCenterApi.DB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace CallCenterApi.DAL
  10. {
  11. /// <summary>
  12. /// 数据访问类:T_RepositoryLog
  13. /// </summary>
  14. public partial class T_RepositoryLog
  15. {
  16. public T_RepositoryLog()
  17. { }
  18. #region BasicMethod
  19. /// <summary>
  20. /// 是否存在该记录
  21. /// </summary>
  22. public bool Exists(int F_LogId)
  23. {
  24. StringBuilder strSql = new StringBuilder();
  25. strSql.Append("select count(1) from T_RepositoryLog");
  26. strSql.Append(" where F_LogId=@F_LogId");
  27. SqlParameter[] parameters = {
  28. new SqlParameter("@F_LogId", SqlDbType.Int,4)
  29. };
  30. parameters[0].Value = F_LogId;
  31. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  32. }
  33. /// <summary>
  34. /// 增加一条数据
  35. /// </summary>
  36. public int Add(CallCenterApi.Model.T_RepositoryLog model)
  37. {
  38. StringBuilder strSql = new StringBuilder();
  39. strSql.Append("insert into T_RepositoryLog(");
  40. strSql.Append("F_RepositoryId,F_Action,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_CreateOn,F_CreateBy,F_Expand1,F_Expand2,F_IntExpand1,F_IntExpand2)");
  41. strSql.Append(" values (");
  42. strSql.Append("@F_RepositoryId,@F_Action,@F_Title,@F_Content,@F_Description,@F_Url,@F_KeyWords,@F_CreateOn,@F_CreateBy,@F_Expand1,@F_Expand2,@F_IntExpand1,@F_IntExpand2)");
  43. strSql.Append(";select @@IDENTITY");
  44. SqlParameter[] parameters = {
  45. new SqlParameter("@F_RepositoryId", SqlDbType.Int,4),
  46. new SqlParameter("@F_Action", SqlDbType.Int,4),
  47. new SqlParameter("@F_Title", SqlDbType.NVarChar,200),
  48. new SqlParameter("@F_Content", SqlDbType.NText),
  49. new SqlParameter("@F_Description", SqlDbType.NText),
  50. new SqlParameter("@F_Url", SqlDbType.NText),
  51. new SqlParameter("@F_KeyWords", SqlDbType.NVarChar,500),
  52. new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
  53. new SqlParameter("@F_CreateBy", SqlDbType.Int,4),
  54. new SqlParameter("@F_Expand1", SqlDbType.NVarChar,100),
  55. new SqlParameter("@F_Expand2", SqlDbType.NVarChar,200),
  56. new SqlParameter("@F_IntExpand1", SqlDbType.SmallInt,2),
  57. new SqlParameter("@F_IntExpand2", SqlDbType.Int ,4)
  58. };
  59. parameters[0].Value = model.F_RepositoryId;
  60. parameters[1].Value = model.F_Action;
  61. parameters[2].Value = model.F_Title;
  62. parameters[3].Value = model.F_Content;
  63. parameters[4].Value = model.F_Description;
  64. parameters[5].Value = model.F_Url;
  65. parameters[6].Value = model.F_KeyWords;
  66. parameters[7].Value = model.F_CreateOn;
  67. parameters[8].Value = model.F_CreateBy;
  68. parameters[9].Value = model.F_Expand1;
  69. parameters[10].Value = model.F_Expand2;
  70. parameters[11].Value = model.F_IntExpand1;
  71. parameters[12].Value = model.F_IntExpand2;
  72. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  73. if (obj == null)
  74. {
  75. return 0;
  76. }
  77. else
  78. {
  79. return Convert.ToInt32(obj);
  80. }
  81. }
  82. /// <summary>
  83. /// 更新一条数据
  84. /// </summary>
  85. public bool Update(CallCenterApi.Model.T_RepositoryLog model)
  86. {
  87. StringBuilder strSql = new StringBuilder();
  88. strSql.Append("update T_RepositoryLog set ");
  89. strSql.Append("F_RepositoryId=@F_RepositoryId,");
  90. strSql.Append("F_Action=@F_Action,");
  91. strSql.Append("F_Title=@F_Title,");
  92. strSql.Append("F_Content=@F_Content,");
  93. strSql.Append("F_Description=@F_Description,");
  94. strSql.Append("F_Url=@F_Url,");
  95. strSql.Append("F_KeyWords=@F_KeyWords,");
  96. strSql.Append("F_CreateOn=@F_CreateOn,");
  97. strSql.Append("F_CreateBy=@F_CreateBy,");
  98. strSql.Append("F_Expand1=@F_Expand1,");
  99. strSql.Append("F_Expand2=@F_Expand2,");
  100. strSql.Append("F_IntExpand1=@F_IntExpand1");
  101. strSql.Append(" where F_LogId=@F_LogId");
  102. SqlParameter[] parameters = {
  103. new SqlParameter("@F_RepositoryId", SqlDbType.Int,4),
  104. new SqlParameter("@F_Action", SqlDbType.Int,4),
  105. new SqlParameter("@F_Title", SqlDbType.NVarChar,200),
  106. new SqlParameter("@F_Content", SqlDbType.NText),
  107. new SqlParameter("@F_Description", SqlDbType.NText),
  108. new SqlParameter("@F_Url", SqlDbType.NText),
  109. new SqlParameter("@F_KeyWords", SqlDbType.NVarChar,500),
  110. new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
  111. new SqlParameter("@F_CreateBy", SqlDbType.Int,4),
  112. new SqlParameter("@F_Expand1", SqlDbType.NVarChar,100),
  113. new SqlParameter("@F_Expand2", SqlDbType.NVarChar,200),
  114. new SqlParameter("@F_IntExpand1", SqlDbType.SmallInt,2),
  115. new SqlParameter("@F_LogId", SqlDbType.Int,4)};
  116. parameters[0].Value = model.F_RepositoryId;
  117. parameters[1].Value = model.F_Action;
  118. parameters[2].Value = model.F_Title;
  119. parameters[3].Value = model.F_Content;
  120. parameters[4].Value = model.F_Description;
  121. parameters[5].Value = model.F_Url;
  122. parameters[6].Value = model.F_KeyWords;
  123. parameters[7].Value = model.F_CreateOn;
  124. parameters[8].Value = model.F_CreateBy;
  125. parameters[9].Value = model.F_Expand1;
  126. parameters[10].Value = model.F_Expand2;
  127. parameters[11].Value = model.F_IntExpand1;
  128. parameters[12].Value = model.F_LogId;
  129. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  130. if (rows > 0)
  131. {
  132. return true;
  133. }
  134. else
  135. {
  136. return false;
  137. }
  138. }
  139. /// <summary>
  140. /// 删除一条数据
  141. /// </summary>
  142. public bool Delete(int F_LogId)
  143. {
  144. StringBuilder strSql = new StringBuilder();
  145. strSql.Append("delete from T_RepositoryLog ");
  146. strSql.Append(" where F_LogId=@F_LogId");
  147. SqlParameter[] parameters = {
  148. new SqlParameter("@F_LogId", SqlDbType.Int,4)
  149. };
  150. parameters[0].Value = F_LogId;
  151. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  152. if (rows > 0)
  153. {
  154. return true;
  155. }
  156. else
  157. {
  158. return false;
  159. }
  160. }
  161. /// <summary>
  162. /// 批量删除数据
  163. /// </summary>
  164. public bool DeleteList(string F_LogIdlist)
  165. {
  166. StringBuilder strSql = new StringBuilder();
  167. strSql.Append("delete from T_RepositoryLog ");
  168. strSql.Append(" where F_LogId in (" + F_LogIdlist + ") ");
  169. int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
  170. if (rows > 0)
  171. {
  172. return true;
  173. }
  174. else
  175. {
  176. return false;
  177. }
  178. }
  179. /// <summary>
  180. /// 得到一个对象实体
  181. /// </summary>
  182. public CallCenterApi.Model.T_RepositoryLog GetModel(int F_LogId)
  183. {
  184. StringBuilder strSql = new StringBuilder();
  185. strSql.Append("select top 1 F_IntExpand2,F_LogId,F_RepositoryId,F_Action,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_CreateOn,F_CreateBy,F_Expand1,F_Expand2,F_IntExpand1 from T_RepositoryLog ");
  186. strSql.Append(" where F_LogId=@F_LogId");
  187. SqlParameter[] parameters = {
  188. new SqlParameter("@F_LogId", SqlDbType.Int,4)
  189. };
  190. parameters[0].Value = F_LogId;
  191. CallCenterApi.Model.T_RepositoryLog model = new CallCenterApi.Model.T_RepositoryLog();
  192. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  193. if (ds.Tables[0].Rows.Count > 0)
  194. {
  195. return DataRowToModel(ds.Tables[0].Rows[0]);
  196. }
  197. else
  198. {
  199. return null;
  200. }
  201. }
  202. /// <summary>
  203. /// 得到一个对象实体
  204. /// </summary>
  205. public CallCenterApi.Model.T_RepositoryLog DataRowToModel(DataRow row)
  206. {
  207. CallCenterApi.Model.T_RepositoryLog model = new CallCenterApi.Model.T_RepositoryLog();
  208. if (row != null)
  209. {
  210. if (row["F_LogId"] != null && row["F_LogId"].ToString() != "")
  211. {
  212. model.F_LogId = int.Parse(row["F_LogId"].ToString());
  213. }
  214. if (row["F_RepositoryId"] != null && row["F_RepositoryId"].ToString() != "")
  215. {
  216. model.F_RepositoryId = int.Parse(row["F_RepositoryId"].ToString());
  217. }
  218. if (row["F_Action"] != null && row["F_Action"].ToString() != "")
  219. {
  220. model.F_Action = int.Parse(row["F_Action"].ToString());
  221. }
  222. if (row["F_Title"] != null)
  223. {
  224. model.F_Title = row["F_Title"].ToString();
  225. }
  226. if (row["F_Content"] != null)
  227. {
  228. model.F_Content = row["F_Content"].ToString();
  229. }
  230. if (row["F_Description"] != null)
  231. {
  232. model.F_Description = row["F_Description"].ToString();
  233. }
  234. if (row["F_Url"] != null)
  235. {
  236. model.F_Url = row["F_Url"].ToString();
  237. }
  238. if (row["F_KeyWords"] != null)
  239. {
  240. model.F_KeyWords = row["F_KeyWords"].ToString();
  241. }
  242. if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "")
  243. {
  244. model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString());
  245. }
  246. if (row["F_CreateBy"] != null && row["F_CreateBy"].ToString() != "")
  247. {
  248. model.F_CreateBy = int.Parse(row["F_CreateBy"].ToString());
  249. }
  250. if (row["F_Expand1"] != null)
  251. {
  252. model.F_Expand1 = row["F_Expand1"].ToString();
  253. }
  254. if (row["F_Expand2"] != null)
  255. {
  256. model.F_Expand2 = row["F_Expand2"].ToString();
  257. }
  258. if (row["F_IntExpand1"] != null && row["F_IntExpand1"].ToString() != "")
  259. {
  260. model.F_IntExpand1 = int.Parse(row["F_IntExpand1"].ToString());
  261. }
  262. if (row["F_IntExpand2"] != null && row["F_IntExpand2"].ToString() != "")
  263. {
  264. model.F_IntExpand2 = int.Parse(row["F_IntExpand2"].ToString());
  265. }
  266. }
  267. return model;
  268. }
  269. /// <summary>
  270. /// 获得数据列表
  271. /// </summary>
  272. public DataSet GetList(string strWhere)
  273. {
  274. StringBuilder strSql = new StringBuilder();
  275. strSql.Append("select F_LogId,F_RepositoryId,F_IntExpand2,F_Action,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_CreateOn,F_CreateBy,F_Expand1,F_Expand2,F_IntExpand1 ");
  276. strSql.Append(" FROM T_RepositoryLog ");
  277. if (strWhere.Trim() != "")
  278. {
  279. strSql.Append(" where " + strWhere);
  280. }
  281. return DbHelperSQL.Query(strSql.ToString());
  282. }
  283. /// <summary>
  284. /// 获得前几行数据
  285. /// </summary>
  286. public DataSet GetList(int Top, string strWhere, string filedOrder)
  287. {
  288. StringBuilder strSql = new StringBuilder();
  289. strSql.Append("select ");
  290. if (Top > 0)
  291. {
  292. strSql.Append(" top " + Top.ToString());
  293. }
  294. strSql.Append(" F_LogId,F_RepositoryId,F_Action,F_IntExpand2,F_Title,F_Content,F_Description,F_Url,F_KeyWords,F_CreateOn,F_CreateBy,F_Expand1,F_Expand2,F_IntExpand1 ");
  295. strSql.Append(" FROM T_RepositoryLog ");
  296. if (strWhere.Trim() != "")
  297. {
  298. strSql.Append(" where " + strWhere);
  299. }
  300. strSql.Append(" order by " + filedOrder);
  301. return DbHelperSQL.Query(strSql.ToString());
  302. }
  303. /// <summary>
  304. /// 获取记录总数
  305. /// </summary>
  306. public int GetRecordCount(string strWhere)
  307. {
  308. StringBuilder strSql = new StringBuilder();
  309. strSql.Append("select count(1) FROM T_RepositoryLog ");
  310. if (strWhere.Trim() != "")
  311. {
  312. strSql.Append(" where " + strWhere);
  313. }
  314. object obj = DbHelperSQL.GetSingle(strSql.ToString());
  315. if (obj == null)
  316. {
  317. return 0;
  318. }
  319. else
  320. {
  321. return Convert.ToInt32(obj);
  322. }
  323. }
  324. /// <summary>
  325. /// 分页获取数据列表
  326. /// </summary>
  327. public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
  328. {
  329. StringBuilder strSql = new StringBuilder();
  330. strSql.Append("SELECT * FROM ( ");
  331. strSql.Append(" SELECT ROW_NUMBER() OVER (");
  332. if (!string.IsNullOrEmpty(orderby.Trim()))
  333. {
  334. strSql.Append("order by T." + orderby);
  335. }
  336. else
  337. {
  338. strSql.Append("order by T.F_LogId desc");
  339. }
  340. strSql.Append(")AS Row, T.* from T_RepositoryLog T ");
  341. if (!string.IsNullOrEmpty(strWhere.Trim()))
  342. {
  343. strSql.Append(" WHERE " + strWhere);
  344. }
  345. strSql.Append(" ) TT");
  346. strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
  347. return DbHelperSQL.Query(strSql.ToString());
  348. }
  349. #endregion BasicMethod
  350. #region ExtensionMethod
  351. #endregion ExtensionMethod
  352. }
  353. }