BranchProvider.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Winsoft.GOV.Framework.Model;
  8. using Dapper;
  9. namespace Winsoft.GOV.Framework.Provider
  10. {
  11. public class BranchProvider : BaseProvider<Branch>
  12. {
  13. public BranchProvider(County county) : base(county)
  14. {
  15. }
  16. public Branch Find(string guid)
  17. {
  18. const string sql = "select * from branch where guid=@guid";
  19. using (IDbConnection connection = GetDbConnection())
  20. {
  21. return connection.QueryFirstOrDefault<Branch>(sql, new { guid = guid});
  22. }
  23. }
  24. public void Insert(Branch b)
  25. {
  26. const string sql = "insert branch(guid, shortname, position) values(@guid, @shortname, @position);";
  27. using (IDbConnection connection = GetDbConnection())
  28. {
  29. connection.Execute(sql, b);
  30. }
  31. }
  32. //public PagedResult<Branch> Select(int pageIndex, int pageSize)
  33. //{
  34. // return null;
  35. //}
  36. public IEnumerable<Branch> FindAll()
  37. {
  38. const string sql = "select * from branch order by position";
  39. using (IDbConnection connection = GetDbConnection())
  40. {
  41. return connection.Query<Branch>(sql);
  42. }
  43. }
  44. public IEnumerable<Branch> FindOnceRunBranch()
  45. {
  46. const string sql = "select ouguid as guid, ql_dep as ShortName from oncerunpowermatters group by ouguid, ql_dep order by ouguid";
  47. using (IDbConnection connection = GetDbConnection())
  48. {
  49. return connection.Query<Branch>(sql);
  50. }
  51. }
  52. public IEnumerable<Branch> FindByApplyType(int type)
  53. {
  54. string sql = "(select QL_DEP as ShortName, OUGUID as guid from powermattertype where ApplyCode = @applyCode group by OUGUID, QL_DEP order by ouguid)";
  55. using (IDbConnection connection = GetDbConnection())
  56. {
  57. return connection.Query<Branch>(sql, new { applyCode = type });
  58. }
  59. //if (type > -1 && type < ApplyType.Names.Length)
  60. //{
  61. // string sql = "(select QL_DEP as ShortName, OUGUID as guid from powermattertype where ApplyCode = @applyCode group by OUGUID, QL_DEP)";
  62. // using (IDbConnection connection = GetDbConnection())
  63. // {
  64. // return connection.Query<Branch>(sql, new { applyCode = type });
  65. // }
  66. //}
  67. //else
  68. //{
  69. // string sql = "select QL_DEP as ShortName, OUGUID as guid from oncerunpowermatters where ql_inner_code not in (select ql_inner_code from PowerMatterType) group by OUGUID, ql_dep";
  70. // using (IDbConnection connection = GetDbConnection())
  71. // {
  72. // return connection.Query<Branch>(sql);
  73. // }
  74. //}
  75. }
  76. }
  77. }