PowerMatterTypeProvider.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Winsoft.GOV.Framework.Model;
  7. using Dapper;
  8. using MySql.Data.MySqlClient;
  9. using System.Security.Cryptography;
  10. namespace Winsoft.GOV.Framework.Provider
  11. {
  12. public class PowerMatterTypeProvider : BaseProvider<PowerMattersBase>
  13. {
  14. private static string cols = " `QL_NAME`, "
  15. + "`QL_INNER_CODE`, "
  16. + "`QL_DEP`, "
  17. + "`OUGUID`, "
  18. + "`ApplyCode` ";
  19. public void CreateTable()
  20. {
  21. string sql = "create table if not exists powermattertype("
  22. + "QL_NAME varchar(200),"
  23. + "QL_INNER_CODE varchar(50),"
  24. + "QL_DEP varchar(50),"
  25. + "OUGUID varchar(50),"
  26. + "ApplyCode int"
  27. + "); "
  28. + "call add_index('powermattertype', 'index1', 'index1(QL_INNER_CODE, OUGUID)'); "
  29. + "call add_index('powermattertype', 'index2', 'index2(OUGUID)'); "
  30. + "call add_index('powermattertype', 'index3', 'index3(OUGUID, ApplyCode)'); "
  31. + "call add_index('powermattertype', 'index4', 'index4(ApplyCode)'); ";///ApplyCode///
  32. using (var con = GetDbConnection())
  33. {
  34. con.Execute(sql);
  35. }
  36. }
  37. public PowerMatterTypeProvider(County county) : base(county)
  38. {
  39. }
  40. public PowerMattersBase FindById(string ql_inner_code)
  41. {
  42. string sql = "select * from powermattertype where QL_INNER_CODE=@ql_inner_code; ";
  43. using (var con = GetDbConnection())
  44. {
  45. return con.QueryFirstOrDefault<PowerMattersBase>(sql, new { ql_inner_code = ql_inner_code });
  46. }
  47. }
  48. public void Insert(IEnumerable<PowerMattersBase> list, ref IList<PowerMattersBase> failslist)
  49. {
  50. if (failslist == null)
  51. failslist = new List<PowerMattersBase>();
  52. string sql = "delete from powermattertype where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID; "
  53. + "insert powermattertype(" + cols + ")" + "values(@QL_NAME, @QL_INNER_CODE, @QL_DEP, @OUGUID, @ApplyCode);";
  54. using (var con = GetDbConnection())
  55. {
  56. foreach (PowerMattersBase p in list)
  57. {
  58. PowerMattersBase p2 =ProvidersFactory.GetOnceRunPowerMattersProvider(_county).FindByQLNameAndOUORGCODE(p.QL_NAME, p.OUGUID);
  59. if (p2 != null)
  60. {
  61. p.QL_INNER_CODE = p2.QL_INNER_CODE;
  62. }
  63. else
  64. {
  65. byte[] result = Encoding.Default.GetBytes(p.QL_NAME.Trim()); //tbPass为输入密码的文本框
  66. MD5 md5 = new MD5CryptoServiceProvider();
  67. byte[] output = md5.ComputeHash(result);
  68. p.QL_INNER_CODE = BitConverter.ToString(output);
  69. ProvidersFactory.GetOnceRunPowerMattersProvider(_county).Insert(p);
  70. }
  71. con.Execute(sql, p);
  72. }
  73. }
  74. }
  75. }
  76. }