纽威
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.

956 lines
36 KiB

3 years ago
  1. using NFine.Code;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Data.Common;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace NFine.Repository
  11. {
  12. public class Repository<T> : IRepository<T> where T : new()
  13. {
  14. #region 事务
  15. /// <summary>
  16. /// 事务开始
  17. /// </summary>
  18. /// <returns></returns>
  19. public DbTransaction BeginTrans()
  20. {
  21. return DataFactory.Database().BeginTrans();
  22. }
  23. /// <summary>
  24. /// 提交事务
  25. /// </summary>
  26. public void Commit()
  27. {
  28. DataFactory.Database().Commit();
  29. }
  30. /// <summary>
  31. /// 回滚事务
  32. /// </summary>
  33. public void Rollback()
  34. {
  35. DataFactory.Database().Rollback();
  36. }
  37. /// <summary>
  38. /// 关闭数据库连接
  39. /// </summary>
  40. public void Close()
  41. {
  42. DataFactory.Database().Close();
  43. }
  44. #endregion
  45. #region SqlBulkCopy大批量数据插入
  46. /// <summary>
  47. /// 大批量数据插入
  48. /// </summary>
  49. /// <param name="datatable">资料表</param>
  50. /// <returns></returns>
  51. public bool BulkInsert(DataTable datatable)
  52. {
  53. return DataFactory.Database().BulkInsert(datatable);
  54. }
  55. #endregion
  56. #region 执行SQL语句
  57. /// <summary>
  58. /// 执行SQL语句
  59. /// </summary>
  60. /// <param name="strSql">Sql语句</param>
  61. /// <returns></returns>
  62. public int ExecuteBySql(StringBuilder strSql)
  63. {
  64. return DataFactory.Database().ExecuteBySql(strSql);
  65. }
  66. /// <summary>
  67. /// 执行SQL语句
  68. /// </summary>
  69. /// <param name="strSql">Sql语句</param>
  70. /// <param name="isOpenTrans">事务对象</param>
  71. /// <returns></returns>
  72. public int ExecuteBySql(StringBuilder strSql, DbTransaction isOpenTrans)
  73. {
  74. return DataFactory.Database().ExecuteBySql(strSql, isOpenTrans);
  75. }
  76. /// <summary>
  77. /// 执行SQL语句
  78. /// </summary>
  79. /// <param name="strSql">Sql语句</param>
  80. /// <param name="parameters">sql语句对应参数</param>
  81. /// <returns></returns>
  82. public int ExecuteBySql(StringBuilder strSql, DbParameter[] parameters)
  83. {
  84. return DataFactory.Database().ExecuteBySql(strSql, parameters);
  85. }
  86. /// <summary>
  87. /// 执行SQL语句
  88. /// </summary>
  89. /// <param name="strSql">Sql语句</param>
  90. /// <param name="parameters">sql语句对应参数</param>
  91. /// <param name="isOpenTrans">事务对象</param>
  92. /// <returns></returns>
  93. public int ExecuteBySql(StringBuilder strSql, DbParameter[] parameters, DbTransaction isOpenTrans)
  94. {
  95. return DataFactory.Database().ExecuteBySql(strSql, parameters, isOpenTrans);
  96. }
  97. #endregion
  98. #region 执行存储过程
  99. /// <summary>
  100. /// 执行存储过程
  101. /// </summary>
  102. /// <param name="procName">存储过程</param>
  103. /// <returns></returns>
  104. public int ExecuteByProc(string procName)
  105. {
  106. return DataFactory.Database().ExecuteByProc(procName);
  107. }
  108. /// <summary>
  109. /// 执行存储过程
  110. /// </summary>
  111. /// <param name="procName">存储过程</param>
  112. /// <param name="isOpenTrans">事务对象</param>
  113. /// <returns></returns>
  114. public int ExecuteByProc(string procName, DbTransaction isOpenTrans)
  115. {
  116. return DataFactory.Database().ExecuteByProc(procName, isOpenTrans);
  117. }
  118. /// <summary>
  119. /// 执行存储过程
  120. /// </summary>
  121. /// <param name="procName">存储过程</param>
  122. /// <param name="parameters">sql语句对应参数</param>
  123. /// <returns></returns>
  124. public int ExecuteByProc(string procName, DbParameter[] parameters)
  125. {
  126. return DataFactory.Database().ExecuteByProc(procName, parameters);
  127. }
  128. /// <summary>
  129. /// 执行存储过程
  130. /// </summary>
  131. /// <param name="procName">存储过程</param>
  132. /// <param name="parameters">sql语句对应参数</param>
  133. /// <param name="isOpenTrans">事务对象</param>
  134. /// <returns></returns>
  135. public int ExecuteByProc(string procName, DbParameter[] parameters, DbTransaction isOpenTrans)
  136. {
  137. return DataFactory.Database().ExecuteByProc(procName, parameters, isOpenTrans);
  138. }
  139. #endregion
  140. #region 插入数据
  141. /// <summary>
  142. /// 插入数据
  143. /// </summary>
  144. /// <param name="entity">实体类对象</param>
  145. /// <returns></returns>
  146. public int Insert(T entity)
  147. {
  148. return DataFactory.Database().Insert<T>(entity);
  149. }
  150. /// <summary>
  151. /// 插入数据
  152. /// </summary>
  153. /// <param name="entity">实体类对象</param>
  154. /// <param name="isOpenTrans">事务对象</param>
  155. /// <returns></returns>
  156. public int Insert(T entity, DbTransaction isOpenTrans)
  157. {
  158. return DataFactory.Database().Insert<T>(entity, isOpenTrans);
  159. }
  160. /// <summary>
  161. /// 批量插入数据
  162. /// </summary>
  163. /// <param name="entity">实体类对象</param>
  164. /// <returns></returns>
  165. public int Insert(List<T> entity)
  166. {
  167. return DataFactory.Database().Insert<T>(entity);
  168. }
  169. /// <summary>
  170. /// 批量插入数据
  171. /// </summary>
  172. /// <param name="entity">实体类对象</param>
  173. /// <param name="isOpenTrans">事务对象</param>
  174. /// <returns></returns>
  175. public int Insert(List<T> entity, DbTransaction isOpenTrans)
  176. {
  177. return DataFactory.Database().Insert<T>(entity, isOpenTrans);
  178. }
  179. #endregion
  180. #region 修改数据
  181. /// <summary>
  182. /// 修改数据
  183. /// </summary>
  184. /// <param name="entity">实体对象</param>
  185. /// <returns></returns>
  186. public int Update(T entity)
  187. {
  188. return DataFactory.Database().Update<T>(entity);
  189. }
  190. /// <summary>
  191. /// 修改数据
  192. /// </summary>
  193. /// <param name="entity">实体对象</param>
  194. /// <param name="isOpenTrans">事务对象</param>
  195. /// <returns></returns>
  196. public int Update(T entity, DbTransaction isOpenTrans)
  197. {
  198. return DataFactory.Database().Update<T>(entity, isOpenTrans);
  199. }
  200. /// <summary>
  201. /// 修改数据
  202. /// </summary>
  203. /// <param name="propertyName">实体属性名称</param>
  204. /// <param name="propertyValue">字段值</param>
  205. /// <returns></returns>
  206. public int Update(string propertyName, string propertyValue)
  207. {
  208. return DataFactory.Database().Update<T>(propertyName, propertyValue);
  209. }
  210. /// <summary>
  211. /// 修改数据
  212. /// </summary>
  213. /// <param name="propertyName">实体属性名称</param>
  214. /// <param name="propertyValue">字段值</param>
  215. /// <param name="isOpenTrans">事务对象</param>
  216. /// <returns></returns>
  217. public int Update(string propertyName, string propertyValue, DbTransaction isOpenTrans)
  218. {
  219. return DataFactory.Database().Update<T>(propertyName, propertyValue, isOpenTrans);
  220. }
  221. /// <summary>
  222. /// 批量修改数据
  223. /// </summary>
  224. /// <param name="entity">实体对象</param>
  225. /// <returns></returns>
  226. public int Update(List<T> entity)
  227. {
  228. return DataFactory.Database().Update<T>(entity);
  229. }
  230. /// <summary>
  231. /// 批量修改数据
  232. /// </summary>
  233. /// <param name="entity">实体对象</param>
  234. /// <param name="isOpenTrans">事务对象</param>
  235. /// <returns></returns>
  236. public int Update(List<T> entity, DbTransaction isOpenTrans)
  237. {
  238. return DataFactory.Database().Update<T>(entity, isOpenTrans);
  239. }
  240. #endregion
  241. #region 删除数据
  242. /// <summary>
  243. /// 删除数据
  244. /// </summary>
  245. /// <param name="entity">实体类</param>
  246. /// <returns></returns>
  247. public int Delete(T entity)
  248. {
  249. return DataFactory.Database().Delete<T>(entity);
  250. }
  251. /// <summary>
  252. /// 删除数据
  253. /// </summary>
  254. /// <param name="entity">实体类</param>
  255. /// <param name="isOpenTrans">事务对象</param>
  256. /// <returns></returns>
  257. public int Delete(T entity, DbTransaction isOpenTrans)
  258. {
  259. return DataFactory.Database().Delete<T>(entity, isOpenTrans);
  260. }
  261. /// <summary>
  262. /// 删除数据
  263. /// </summary>
  264. /// <param name="propertyValue">主键值</param>
  265. /// <returns></returns>
  266. public int Delete(object propertyValue)
  267. {
  268. return DataFactory.Database().Delete<T>(propertyValue);
  269. }
  270. /// <summary>
  271. /// 删除数据
  272. /// </summary>
  273. /// <param name="propertyValue">主键值</param>
  274. /// <param name="isOpenTrans">事务对象</param>
  275. /// <returns></returns>
  276. public int Delete(object propertyValue, DbTransaction isOpenTrans)
  277. {
  278. return DataFactory.Database().Delete<T>(propertyValue, isOpenTrans);
  279. }
  280. /// <summary>
  281. /// 删除数据
  282. /// </summary>
  283. /// <param name="propertyName">实体属性名称</param>
  284. /// <param name="propertyValue">字段值</param>
  285. /// <returns></returns>
  286. public int Delete(string propertyName, string propertyValue)
  287. {
  288. return DataFactory.Database().Delete<T>(propertyName, propertyValue);
  289. }
  290. /// <summary>
  291. /// 删除数据
  292. /// </summary>
  293. /// <param name="propertyName">实体属性名称</param>
  294. /// <param name="propertyValue">字段值</param>
  295. /// <param name="isOpenTrans">事务对象</param>
  296. /// <returns></returns>
  297. public int Delete(string propertyName, string propertyValue, DbTransaction isOpenTrans)
  298. {
  299. return DataFactory.Database().Delete<T>(propertyName, propertyValue, isOpenTrans);
  300. }
  301. /// <summary>
  302. /// 删除数据
  303. /// </summary>
  304. /// <param name="tableName">表名</param>
  305. /// <param name="ht">键值生成SQL条件</param>
  306. /// <returns></returns>
  307. public int Delete(string tableName, Hashtable ht)
  308. {
  309. return DataFactory.Database().Delete(tableName, ht);
  310. }
  311. /// <summary>
  312. /// 删除数据
  313. /// </summary>
  314. /// <param name="tableName">表名</param>
  315. /// <param name="ht">键值生成SQL条件</param>
  316. /// <param name="isOpenTrans">事务对象</param>
  317. /// <returns></returns>
  318. public int Delete(string tableName, Hashtable ht, DbTransaction isOpenTrans)
  319. {
  320. return DataFactory.Database().Delete(tableName, ht, isOpenTrans);
  321. }
  322. /// <summary>
  323. /// 批量删除数据
  324. /// </summary>
  325. /// <param name="propertyValue">主键值:数组1,2,3,4,5,6.....</param>
  326. /// <returns></returns>
  327. public int Delete(object[] propertyValue)
  328. {
  329. return DataFactory.Database().Delete<T>(propertyValue);
  330. }
  331. /// <summary>
  332. /// 批量删除数据
  333. /// </summary>
  334. /// <param name="propertyValue">主键值:数组1,2,3,4,5,6.....</param>
  335. /// <param name="isOpenTrans">事务对象</param>
  336. /// <returns></returns>
  337. public int Delete(object[] propertyValue, DbTransaction isOpenTrans)
  338. {
  339. return DataFactory.Database().Delete<T>(propertyValue, isOpenTrans);
  340. }
  341. /// <summary>
  342. /// 批量删除数据
  343. /// </summary>
  344. /// <param name="propertyName">实体属性名称</param>
  345. /// <param name="propertyValue">字段值:数组1,2,3,4,5,6.....</param>
  346. /// <returns></returns>
  347. public int Delete(string propertyName, object[] propertyValue)
  348. {
  349. return DataFactory.Database().Delete<T>(propertyName, propertyValue);
  350. }
  351. /// <summary>
  352. /// 批量删除数据
  353. /// </summary>
  354. /// <param name="propertyName">实体属性名称</param>
  355. /// <param name="propertyValue">字段值:数组1,2,3,4,5,6.....</param>
  356. /// <param name="isOpenTrans">事务对象</param>
  357. /// <returns></returns>
  358. public int Delete(string propertyName, object[] propertyValue, DbTransaction isOpenTrans)
  359. {
  360. return DataFactory.Database().Delete<T>(propertyName, propertyValue, isOpenTrans);
  361. }
  362. #endregion
  363. #region 查询数据列表、返回List
  364. /// <summary>
  365. /// 查询数据列表、返回List
  366. /// </summary>
  367. /// <param name="Top">显示条数</param>
  368. /// <returns></returns>
  369. public List<T> FindListTop(int Top)
  370. {
  371. return DataFactory.Database().FindListTop<T>(Top);
  372. }
  373. /// <summary>
  374. /// 查询数据列表、返回List
  375. /// </summary>
  376. /// <param name="Top">显示条数</param>
  377. /// <param name="propertyName">实体属性名称</param>
  378. /// <param name="propertyValue">字段值</param>
  379. /// <returns></returns>
  380. public List<T> FindListTop(int Top, string propertyName, string propertyValue)
  381. {
  382. return DataFactory.Database().FindListTop<T>(Top, propertyName, propertyValue);
  383. }
  384. /// <summary>
  385. /// 查询数据列表、返回List
  386. /// </summary>
  387. /// <param name="Top">显示条数</param>
  388. /// <param name="WhereSql">条件</param>
  389. /// <returns></returns>
  390. public List<T> FindListTop(int Top, string WhereSql)
  391. {
  392. return DataFactory.Database().FindListTop<T>(Top, WhereSql);
  393. }
  394. /// <summary>
  395. /// 查询数据列表、返回List
  396. /// </summary>
  397. /// <param name="Top">显示条数</param>
  398. /// <param name="WhereSql">条件</param>
  399. /// <param name="parameters">sql语句对应参数</param>
  400. /// <returns></returns>
  401. public List<T> FindListTop(int Top, string WhereSql, DbParameter[] parameters)
  402. {
  403. return DataFactory.Database().FindListTop<T>(Top, WhereSql, parameters);
  404. }
  405. /// <summary>
  406. /// 查询数据列表、返回List
  407. /// </summary>
  408. /// <returns></returns>
  409. public List<T> FindList()
  410. {
  411. return DataFactory.Database().FindList<T>();
  412. }
  413. /// <summary>
  414. /// 查询数据列表、返回List
  415. /// </summary>
  416. /// <param name="propertyName">实体属性名称</param>
  417. /// <param name="propertyValue">字段值</param>
  418. /// <returns></returns>
  419. public List<T> FindList(string propertyName, string propertyValue)
  420. {
  421. return DataFactory.Database().FindList<T>(propertyName, propertyValue);
  422. }
  423. /// <summary>
  424. /// 查询数据列表、返回List
  425. /// </summary>
  426. /// <param name="WhereSql">条件</param>
  427. /// <returns></returns>
  428. public List<T> FindList(string WhereSql)
  429. {
  430. return DataFactory.Database().FindList<T>(WhereSql);
  431. }
  432. /// <summary>
  433. /// 查询数据列表、返回List
  434. /// </summary>
  435. /// <param name="WhereSql">条件</param>
  436. /// <param name="parameters">sql语句对应参数</param>
  437. /// <returns></returns>
  438. public List<T> FindList(string WhereSql, DbParameter[] parameters)
  439. {
  440. return DataFactory.Database().FindList<T>(WhereSql, parameters);
  441. }
  442. /// <summary>
  443. /// 查询数据列表、返回List
  444. /// </summary>
  445. /// <param name="strSql">Sql语句</param>
  446. /// <returns></returns>
  447. public List<T> FindListBySql(string strSql)
  448. {
  449. return DataFactory.Database().FindListBySql<T>(strSql);
  450. }
  451. /// <summary>
  452. /// 查询数据列表、返回List
  453. /// </summary>
  454. /// <param name="strSql">Sql语句</param>
  455. /// <param name="parameters">sql语句对应参数</param>
  456. /// <returns></returns>
  457. public List<T> FindListBySql(string strSql, DbParameter[] parameters)
  458. {
  459. return DataFactory.Database().FindListBySql<T>(strSql, parameters);
  460. }
  461. /// <summary>
  462. /// 查询数据列表、返回List
  463. /// </summary>
  464. /// <param name="Pagination">分页参数</param>
  465. /// <returns></returns>
  466. public List<T> FindListPage(ref Pagination Pagination)
  467. {
  468. string orderField = Pagination.sidx;
  469. string orderType = Pagination.sord;
  470. int pageIndex = Pagination.page;
  471. int pageSize = Pagination.rows;
  472. int totalRow = Pagination.records;
  473. List<T> List = DataFactory.Database().FindListPage<T>(orderField, orderType, pageIndex, pageSize, ref totalRow);
  474. Pagination.records = totalRow;
  475. return List;
  476. }
  477. /// <summary>
  478. /// 查询数据列表、返回List
  479. /// </summary>
  480. /// <param name="WhereSql">条件</param>
  481. /// <param name="Pagination">分页参数</param>
  482. /// <returns></returns>
  483. public List<T> FindListPage(string WhereSql, ref Pagination Pagination)
  484. {
  485. string orderField = Pagination.sidx;
  486. string orderType = Pagination.sord;
  487. int pageIndex = Pagination.page;
  488. int pageSize = Pagination.rows;
  489. int totalRow = Pagination.records;
  490. List<T> List = DataFactory.Database().FindListPage<T>(WhereSql, orderField, orderType, pageIndex, pageSize, ref totalRow);
  491. Pagination.records = totalRow;
  492. return List;
  493. }
  494. /// <summary>
  495. /// 查询数据列表、返回List
  496. /// </summary>
  497. /// <param name="WhereSql">条件</param>
  498. /// <param name="parameters">sql语句对应参数</param>
  499. /// <param name="Pagination">分页参数</param>
  500. /// <returns></returns>
  501. public List<T> FindListPage(string WhereSql, DbParameter[] parameters, ref Pagination Pagination)
  502. {
  503. string orderField = Pagination.sidx;
  504. string orderType = Pagination.sord;
  505. int pageIndex = Pagination.page;
  506. int pageSize = Pagination.rows;
  507. int totalRow = Pagination.records;
  508. List<T> List = DataFactory.Database().FindListPage<T>(WhereSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow);
  509. Pagination.records = totalRow;
  510. return List;
  511. }
  512. /// <summary>
  513. /// 查询数据列表、返回List
  514. /// </summary>
  515. /// <param name="strSql">Sql语句</param>
  516. /// <param name="Pagination">分页参数</param>
  517. /// <returns></returns>
  518. public List<T> FindListPageBySql(string strSql, ref Pagination Pagination)
  519. {
  520. string orderField = Pagination.sidx;
  521. string orderType = Pagination.sord;
  522. int pageIndex = Pagination.page;
  523. int pageSize = Pagination.rows;
  524. int totalRow = Pagination.records;
  525. List<T> List = DataFactory.Database().FindListPageBySql<T>(strSql, orderField, orderType, pageIndex, pageSize, ref totalRow);
  526. Pagination.records = totalRow;
  527. return List;
  528. }
  529. /// <summary>
  530. /// 查询数据列表、返回List
  531. /// </summary>
  532. /// <param name="strSql">Sql语句</param>
  533. /// <param name="Pagination">分页参数</param>
  534. /// <returns></returns>
  535. public List<T> FindListPageBySql(string strSql, DbParameter[] parameters, ref Pagination Pagination)
  536. {
  537. string orderField = Pagination.sidx;
  538. string orderType = Pagination.sord;
  539. int pageIndex = Pagination.page;
  540. int pageSize = Pagination.rows;
  541. int totalRow = Pagination.records;
  542. List<T> List = DataFactory.Database().FindListPageBySql<T>(strSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow);
  543. Pagination.records = totalRow;
  544. return List;
  545. }
  546. #endregion
  547. #region 查询数据列表、返回DataTable
  548. /// <summary>
  549. /// 查询数据列表、返回 DataTable
  550. /// </summary>
  551. /// <param name="Top">显示条数</param>
  552. /// <returns></returns>
  553. public DataTable FindTableTop(int Top)
  554. {
  555. return DataFactory.Database().FindTableTop<T>(Top);
  556. }
  557. /// <summary>
  558. /// 查询数据列表、返回 DataTable
  559. /// </summary>
  560. /// <param name="Top">显示条数</param>
  561. /// <param name="WhereSql">条件</param>
  562. /// <returns></returns>
  563. public DataTable FindTableTop(int Top, string WhereSql)
  564. {
  565. return DataFactory.Database().FindTableTop<T>(Top, WhereSql);
  566. }
  567. /// <summary>
  568. /// 查询数据列表、返回 DataTable
  569. /// </summary>
  570. /// <param name="Top">显示条数</param>
  571. /// <param name="WhereSql">条件</param>
  572. /// <param name="parameters">sql语句对应参数</param>
  573. /// <returns></returns>
  574. public DataTable FindTableTop(int Top, string WhereSql, DbParameter[] parameters)
  575. {
  576. return DataFactory.Database().FindTableTop<T>(Top, WhereSql, parameters);
  577. }
  578. /// <summary>
  579. /// 查询数据列表、返回 DataTable
  580. /// </summary>
  581. /// <returns></returns>
  582. public DataTable FindTable()
  583. {
  584. return DataFactory.Database().FindTable<T>();
  585. }
  586. /// <summary>
  587. /// 查询数据列表、返回 DataTable
  588. /// </summary>
  589. /// <param name="WhereSql">条件</param>
  590. /// <returns></returns>
  591. public DataTable FindTable(string WhereSql)
  592. {
  593. return DataFactory.Database().FindTable<T>(WhereSql);
  594. }
  595. /// <summary>
  596. /// 查询数据列表、返回 DataTable
  597. /// </summary>
  598. /// <param name="WhereSql">条件</param>
  599. /// <param name="parameters">sql语句对应参数</param>
  600. /// <returns></returns>
  601. public DataTable FindTable(string WhereSql, DbParameter[] parameters)
  602. {
  603. return DataFactory.Database().FindTable<T>(WhereSql, parameters);
  604. }
  605. /// <summary>
  606. /// 查询数据列表、返回 DataTable
  607. /// </summary>
  608. /// <param name="strSql">Sql语句</param>
  609. /// <returns></returns>
  610. public DataTable FindTableBySql(string strSql)
  611. {
  612. return DataFactory.Database().FindTableBySql(strSql);
  613. }
  614. /// <summary>
  615. /// 查询数据列表、返回 DataTable
  616. /// </summary>
  617. /// <param name="strSql">Sql语句</param>
  618. /// <param name="parameters">sql语句对应参数</param>
  619. /// <returns></returns>
  620. public DataTable FindTableBySql(string strSql, DbParameter[] parameters)
  621. {
  622. return DataFactory.Database().FindTableBySql(strSql, parameters);
  623. }
  624. /// <summary>
  625. /// 查询数据列表、返回 DataTable
  626. /// </summary>
  627. /// <param name="orderField">排序字段</param>
  628. /// <param name="orderType">排序类型</param>
  629. /// <param name="pageIndex">当前页</param>
  630. /// <param name="pageSize">页大小</param>
  631. /// <param name="recordCount">返回查询条数</param>
  632. /// <returns></returns>
  633. public DataTable FindTablePage(ref Pagination Pagination)
  634. {
  635. string orderField = Pagination.sidx;
  636. string orderType = Pagination.sord;
  637. int pageIndex = Pagination.page;
  638. int pageSize = Pagination.rows;
  639. int totalRow = Pagination.records;
  640. DataTable dt = DataFactory.Database().FindTablePage<T>(orderField, orderType, pageIndex, pageSize, ref totalRow);
  641. Pagination.records = totalRow;
  642. return dt;
  643. }
  644. /// <summary>
  645. /// 查询数据列表、返回 DataTable
  646. /// </summary>
  647. /// <param name="WhereSql">条件</param>
  648. /// <param name="Pagination">分页参数</param>
  649. /// <returns></returns>
  650. public DataTable FindTablePage(string WhereSql, ref Pagination Pagination)
  651. {
  652. string orderField = Pagination.sidx;
  653. string orderType = Pagination.sord;
  654. int pageIndex = Pagination.page;
  655. int pageSize = Pagination.rows;
  656. int totalRow = Pagination.records;
  657. DataTable dt = DataFactory.Database().FindTablePage<T>(WhereSql, orderField, orderType, pageIndex, pageSize, ref totalRow);
  658. Pagination.records = totalRow;
  659. return dt;
  660. }
  661. /// <summary>
  662. /// 查询数据列表、返回 DataTable
  663. /// </summary>
  664. /// <param name="WhereSql">条件</param>
  665. /// <param name="parameters">sql语句对应参数</param>
  666. /// <param name="Pagination">分页参数</param>
  667. /// <returns></returns>
  668. public DataTable FindTablePage(string WhereSql, DbParameter[] parameters, ref Pagination Pagination)
  669. {
  670. string orderField = Pagination.sidx;
  671. string orderType = Pagination.sord;
  672. int pageIndex = Pagination.page;
  673. int pageSize = Pagination.rows;
  674. int totalRow = Pagination.records;
  675. DataTable dt = DataFactory.Database().FindTablePage<T>(WhereSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow);
  676. Pagination.records = totalRow;
  677. return dt;
  678. }
  679. /// <summary>
  680. /// 查询数据列表、返回 DataTable
  681. /// </summary>
  682. /// <param name="strSql">Sql语句</param>
  683. /// <param name="Pagination">分页参数</param>
  684. /// <returns></returns>
  685. public DataTable FindTablePageBySql(string strSql, ref Pagination Pagination)
  686. {
  687. string orderField = Pagination.sidx;
  688. string orderType = Pagination.sord;
  689. int pageIndex = Pagination.page;
  690. int pageSize = Pagination.rows;
  691. int totalRow = Pagination.records;
  692. DataTable dt = DataFactory.Database().FindTablePageBySql(strSql, orderField, orderType, pageIndex, pageSize, ref totalRow);
  693. Pagination.records = totalRow;
  694. return dt;
  695. }
  696. /// <summary>
  697. /// 查询数据列表、返回 DataTable
  698. /// </summary>
  699. /// <param name="strSql">Sql语句</param>
  700. /// <param name="parameters">sql语句对应参数</param>
  701. /// <param name="Pagination">分页参数</param>
  702. /// <returns></returns>
  703. public DataTable FindTablePageBySql(string strSql, DbParameter[] parameters, ref Pagination Pagination)
  704. {
  705. string orderField = Pagination.sidx;
  706. string orderType = Pagination.sord;
  707. int pageIndex = Pagination.page;
  708. int pageSize = Pagination.rows;
  709. int totalRow = Pagination.records;
  710. DataTable dt = DataFactory.Database().FindTablePageBySql(strSql, parameters, orderField, orderType, pageIndex, pageSize, ref totalRow);
  711. Pagination.records = totalRow;
  712. return dt;
  713. }
  714. /// <summary>
  715. /// 查询数据列表、返回 DataTable
  716. /// </summary>
  717. /// <param name="procName">存储过程</param>
  718. /// <returns></returns>
  719. public DataTable FindTableByProc(string procName)
  720. {
  721. return DataFactory.Database().FindTableByProc(procName);
  722. }
  723. /// <summary>
  724. /// 查询数据列表、返回 DataTable
  725. /// </summary>
  726. /// <param name="procName">存储过程</param>
  727. /// <param name="parameters">sql语句对应参数</param>
  728. /// <returns></returns>
  729. public DataTable FindTableByProc(string procName, DbParameter[] parameters)
  730. {
  731. return DataFactory.Database().FindTableByProc(procName, parameters);
  732. }
  733. #endregion
  734. #region 查询数据列表、返回DataSet
  735. /// <summary>
  736. /// 查询数据列表、返回DataSet
  737. /// </summary>
  738. /// <param name="strSql">Sql语句</param>
  739. /// <returns></returns>
  740. public DataSet FindDataSetBySql(string strSql)
  741. {
  742. return DataFactory.Database().FindDataSetBySql(strSql);
  743. }
  744. /// <summary>
  745. /// 查询数据列表、返回DataSet
  746. /// </summary>
  747. /// <param name="strSql">Sql语句</param>
  748. /// <param name="parameters">sql语句对应参数</param>
  749. /// <returns></returns>
  750. public DataSet FindDataSetBySql(string strSql, DbParameter[] parameters)
  751. {
  752. return DataFactory.Database().FindDataSetBySql(strSql, parameters);
  753. }
  754. /// <summary>
  755. /// 查询数据列表、返回DataSet
  756. /// </summary>
  757. /// <param name="strSql">存储过程</param>
  758. /// <returns></returns>
  759. public DataSet FindDataSetByProc(string procName)
  760. {
  761. return DataFactory.Database().FindDataSetByProc(procName);
  762. }
  763. /// <summary>
  764. /// 查询数据列表、返回DataSet
  765. /// </summary>
  766. /// <param name="strSql">存储过程</param>
  767. /// <param name="parameters">sql语句对应参数</param>
  768. /// <returns></returns>
  769. public DataSet FindDataSetByProc(string procName, DbParameter[] parameters)
  770. {
  771. return DataFactory.Database().FindDataSetByProc(procName, parameters);
  772. }
  773. #endregion
  774. #region 查询对象、返回实体
  775. /// <summary>
  776. /// 查询对象、返回实体
  777. /// </summary>
  778. /// <param name="propertyValue">主键值</param>
  779. /// <returns></returns>
  780. public T FindEntity(object propertyValue)
  781. {
  782. return DataFactory.Database().FindEntity<T>(propertyValue);
  783. }
  784. /// <summary>
  785. /// 查询对象、返回实体
  786. /// </summary>
  787. /// <param name="propertyName">实体属性名称</param>
  788. /// <param name="propertyValue">字段值</param>
  789. /// <returns></returns>
  790. public T FindEntity(string propertyName, object propertyValue)
  791. {
  792. return DataFactory.Database().FindEntity<T>(propertyName, propertyValue);
  793. }
  794. /// <summary>
  795. /// 查询对象、返回实体
  796. /// </summary>
  797. /// <param name="WhereSql">条件</param>
  798. /// <returns></returns>
  799. public T FindEntityByWhere(string WhereSql)
  800. {
  801. return DataFactory.Database().FindEntity<T>(WhereSql);
  802. }
  803. /// <summary>
  804. /// 查询对象、返回实体
  805. /// </summary>
  806. /// <param name="WhereSql">条件</param>
  807. /// <param name="parameters">sql语句对应参数</param>
  808. /// <returns></returns>
  809. public T FindEntityByWhere(string WhereSql, DbParameter[] parameters)
  810. {
  811. return DataFactory.Database().FindEntity<T>(WhereSql, parameters);
  812. }
  813. /// <summary>
  814. /// 查询对象、返回实体
  815. /// </summary>
  816. /// <param name="strSql">Sql语句</param>
  817. /// <returns></returns>
  818. public T FindEntityBySql(string strSql)
  819. {
  820. return DataFactory.Database().FindEntityBySql<T>(strSql);
  821. }
  822. /// <summary>
  823. /// 查询对象、返回实体
  824. /// </summary>
  825. /// <param name="strSql">Sql语句</param>
  826. /// <param name="parameters">sql语句对应参数</param>
  827. /// <returns></returns>
  828. public T FindEntityBySql(string strSql, DbParameter[] parameters)
  829. {
  830. return DataFactory.Database().FindEntityBySql<T>(strSql, parameters);
  831. }
  832. #endregion
  833. #region 查询数据、返回条数
  834. /// <summary>
  835. /// 查询数据、返回条数
  836. /// </summary>
  837. /// <returns></returns>
  838. public int FindCount()
  839. {
  840. return DataFactory.Database().FindCount<T>();
  841. }
  842. /// <summary>
  843. /// 查询数据、返回条数
  844. /// <param name="propertyName">实体属性名称</param>
  845. /// <param name="propertyValue">字段值</param>
  846. /// </summary>
  847. /// <returns></returns>
  848. public int FindCount(string propertyName, string propertyValue)
  849. {
  850. return DataFactory.Database().FindCount<T>(propertyName, propertyValue);
  851. }
  852. /// <summary>
  853. /// 查询数据、返回条数
  854. /// </summary>
  855. /// <param name="WhereSql">条件</param>
  856. /// <returns></returns>
  857. public int FindCount(string WhereSql)
  858. {
  859. return DataFactory.Database().FindCount<T>(WhereSql);
  860. }
  861. /// <summary>
  862. /// 查询数据、返回条数
  863. /// </summary>
  864. /// <param name="WhereSql">条件</param>
  865. /// <param name="parameters">sql语句对应参数</param>
  866. /// <returns></returns>
  867. public int FindCount(string WhereSql, DbParameter[] parameters)
  868. {
  869. return DataFactory.Database().FindCount<T>(WhereSql, parameters);
  870. }
  871. /// <summary>
  872. /// 查询数据、返回条数
  873. /// </summary>
  874. /// <param name="strSql">Sql语句</param>
  875. /// <returns></returns>
  876. public int FindCountBySql(string strSql)
  877. {
  878. return DataFactory.Database().FindCountBySql(strSql);
  879. }
  880. /// <summary>
  881. /// 查询数据、返回条数
  882. /// </summary>
  883. /// <param name="strSql">Sql语句</param>
  884. /// <param name="parameters">sql语句对应参数</param>
  885. /// <returns></returns>
  886. public int FindCountBySql(string strSql, DbParameter[] parameters)
  887. {
  888. return DataFactory.Database().FindCountBySql(strSql, parameters);
  889. }
  890. #endregion
  891. #region 查询数据、返回最大数
  892. /// <summary>
  893. /// 查询数据、返回最大数
  894. /// </summary>
  895. /// <param name="propertyName">实体属性名称</param>
  896. /// <returns></returns>
  897. public object FindMax(string propertyName)
  898. {
  899. return DataFactory.Database().FindMax<T>(propertyName);
  900. }
  901. /// <summary>
  902. /// 查询数据、返回最大数
  903. /// </summary>
  904. /// <param name="propertyName">实体属性名称</param>
  905. /// <param name="WhereSql">条件</param>
  906. /// <returns></returns>
  907. public object FindMax(string propertyName, string WhereSql)
  908. {
  909. return DataFactory.Database().FindMax<T>(propertyName, WhereSql);
  910. }
  911. /// <summary>
  912. /// 查询数据、返回最大数
  913. /// </summary>
  914. /// <param name="propertyName">实体属性名称</param>
  915. /// <param name="WhereSql">条件</param>
  916. /// <param name="parameters">sql语句对应参数</param>
  917. /// <returns></returns>
  918. public object FindMax(string propertyName, string WhereSql, DbParameter[] parameters)
  919. {
  920. return DataFactory.Database().FindMax<T>(propertyName, WhereSql, parameters);
  921. }
  922. /// <summary>
  923. /// 查询数据、返回最大数
  924. /// </summary>
  925. /// <param name="strSql">Sql语句</param>
  926. /// <returns></returns>
  927. public object FindMaxBySql(string strSql)
  928. {
  929. return DataFactory.Database().FindMaxBySql(strSql);
  930. }
  931. /// <summary>
  932. /// 查询数据、返回最大数
  933. /// </summary>
  934. /// <param name="strSql">Sql语句</param>
  935. /// <param name="parameters">sql语句对应参数</param>
  936. /// <returns></returns>
  937. public object FindMaxBySql(string strSql, DbParameter[] parameters)
  938. {
  939. return DataFactory.Database().FindMaxBySql(strSql, parameters);
  940. }
  941. #endregion
  942. }
  943. }