OnceRunPowerMattersProvider.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using Dapper;
  7. using Winsoft.GOV.Framework.Model;
  8. namespace Winsoft.GOV.Framework.Provider
  9. {
  10. public class OnceRunPowerMattersProvider : BaseProvider<PowerMattersBase>
  11. {
  12. private static OnceRunPowerMattersProvider instance;
  13. private static string cols = " `QL_INNER_CODE`, "
  14. + "`QL_NAME` ";
  15. public void CreateTable()
  16. {
  17. string sql = "create table if not exists OnceRunPowerMatters("
  18. + "QL_NAME varchar(200),"
  19. + "QL_INNER_CODE varchar(50),"
  20. + "QL_DEP varchar(50),"
  21. + "OUGUID varchar(50)"
  22. + "); "
  23. + "call add_index('OnceRunPowerMatters', 'index1', 'index1(QL_INNER_CODE, OUGUID)'); "
  24. + "call add_index('OnceRunPowerMatters', 'index2', 'index2(QL_INNER_CODE)'); "
  25. + "call add_index('OnceRunPowerMatters', 'index3', 'index3(OUGUID)'); ";
  26. //+ "call add_index('PowerMattersBase', 'index4', 'index4(QL_NAME)'); ";
  27. using (var con = GetDbConnection())
  28. {
  29. con.Execute(sql);
  30. }
  31. }
  32. public OnceRunPowerMattersProvider() : base("gov")
  33. {
  34. }
  35. public static OnceRunPowerMattersProvider Instance
  36. {
  37. get
  38. {
  39. CreateInstance(ref instance);
  40. return instance;
  41. }
  42. }
  43. public void DeleteAll()
  44. {
  45. using (IDbConnection connection = GetDbConnection())
  46. {
  47. connection.Execute("delete from OnceRunPowerMatters");
  48. }
  49. }
  50. public void Insert(IList<PowerMattersBase> list)
  51. {
  52. string select = "select count(*) from OnceRunPowerMatters where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID;";
  53. string update = "update OnceRunPowerMatters set QL_NAME=@QL_NAME, QL_DEP=@QL_DEP where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID;";
  54. string insert = "insert OnceRunPowerMatters(QL_NAME, QL_INNER_CODE, OUGUID, QL_DEP) values(@QL_NAME, @QL_INNER_CODE, @OUGUID, @QL_DEP);";
  55. using (var conn = GetDbConnection())
  56. {
  57. foreach (PowerMattersBase p in list)
  58. {
  59. try
  60. {
  61. //int count = conn.QueryFirstOrDefault<int>(select, p);
  62. //if (count <= 0)
  63. conn.Execute(insert, p);
  64. //else
  65. // conn.Execute(update, p);
  66. }
  67. catch (Exception e)
  68. {
  69. }
  70. }
  71. }
  72. }
  73. public void Insert(PowerMattersBase p)
  74. {
  75. string select = "select count(*) from OnceRunPowerMatters where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID;";
  76. string update = "update OnceRunPowerMatters set QL_NAME=@QL_NAME, QL_DEP=@QL_DEP where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID;";
  77. string insert = "delete from OnceRunPowerMatters where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID; "
  78. + "insert OnceRunPowerMatters(QL_NAME, QL_INNER_CODE, OUGUID, QL_DEP) values(@QL_NAME, @QL_INNER_CODE, @OUGUID, @QL_DEP);";
  79. using (var conn = GetDbConnection())
  80. {
  81. try
  82. {
  83. //int count = conn.QueryFirstOrDefault<int>(select, p);
  84. //if (count <= 0)
  85. conn.Execute(insert, p);
  86. //else
  87. // conn.Execute(update, p);
  88. }
  89. catch (Exception e)
  90. {
  91. }
  92. }
  93. }
  94. public PowerMattersBase FindByQLNameAndOUORGCODE(string ql_name, string ouguid)
  95. {
  96. string sql = "select " + cols + " from OnceRunPowerMatters where ql_name=@ql_name and ouguid=@ouguid";
  97. using (IDbConnection connection = GetDbConnection())
  98. {
  99. return connection.QueryFirstOrDefault<PowerMattersBase>(sql, new { ouguid = ouguid, ql_name = ql_name });
  100. }
  101. }
  102. public IEnumerable<PowerMattersBase> FindOnceRunPowerMattersByBranchGUID(string guid)
  103. {
  104. string sql = "select " + cols + " from oncerunpowermatters where ouguid=@guid";
  105. using (IDbConnection connection = GetDbConnection())
  106. {
  107. return connection.Query<PowerMattersBase>(sql, new { guid = guid });
  108. }
  109. }
  110. public IEnumerable<PowerMattersBase> FindByBranchGUIDAndApplyType(string guid, int type)
  111. {
  112. string sql = " SELECT QL_INNER_CODE, QL_NAME FROM powerMatterType WHERE ouguid=@ouguid and ApplyCode=@code";
  113. using (IDbConnection connection = GetDbConnection())
  114. {
  115. return connection.Query<PowerMattersBase>(sql, new { code = type, ouguid = guid });
  116. }
  117. //if (type > -1 && type < ApplyType.Names.Length)
  118. //{
  119. // string sql = "select " + cols + " from oncerunpowermatters where ouguid=@ouguid and QL_INNER_CODE in (SELECT QL_INNER_CODE FROM powerMatterType WHERE ouguid=@ouguid and ApplyCode=@code)";
  120. // using (IDbConnection connection = GetDbConnection())
  121. // {
  122. // return connection.Query<PowerMattersBase>(sql, new { code = type, ouguid = guid });
  123. // }
  124. //}
  125. //else
  126. //{
  127. // string sql = "select " + cols + " from oncerunpowermatters where ouguid=@ouguid and QL_INNER_CODE not in (SELECT QL_INNER_CODE FROM powerMatterType WHERE ouguid=@ouguid)";
  128. // using (IDbConnection connection = GetDbConnection())
  129. // {
  130. // return connection.Query<PowerMattersBase>(sql, new { ouguid = guid });
  131. // }
  132. //}
  133. }
  134. }
  135. }