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

1049 lines
40 KiB

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