CommonDAL.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Text;
  6. using ZcPeng.PublicLibrary;
  7. namespace CoreEntity.DAL
  8. {
  9. public class CommonDAL
  10. {
  11. //解密
  12. public static string[] getPhoneDecrypt(string[] MemPhones)
  13. {
  14. DataTable dt = new DataTable();
  15. string result;
  16. List<SqlParameter> parameters = new List<SqlParameter>();
  17. StringBuilder sb = new StringBuilder();
  18. sb.Append("select ");
  19. int i = 0;
  20. foreach (string MemPhone in MemPhones) {
  21. if(MemPhone!=null)
  22. sb.Append("(Mall.dbo.DesDecryptFixKey('123456','123456e10adc3949ba59abbe56e057f20f883e','" + MemPhone + "')) as phone"+i+" " );
  23. if (i != MemPhones.Length - 1)
  24. sb.Append(", ");
  25. i++;
  26. }
  27. string[] phones = new string[MemPhones.Length];
  28. bool success = DataAccess.GetValues( sb.ToString(), ref dt, parameters.ToArray(), out result);
  29. if (dt.Rows.Count > 0)
  30. {
  31. DataRow dr = dt.Rows[0];
  32. i = 0;
  33. foreach (string MemPhone in MemPhones)
  34. {
  35. if (MemPhone != null)
  36. phones[i] = Convert.ToString(dr["phone" + i]);
  37. i++;
  38. }
  39. }
  40. return phones;
  41. }
  42. //加密
  43. public static string[] getPhoneEncrypt(string[] MemPhones)
  44. {
  45. DataTable dt = new DataTable();
  46. string result;
  47. List<SqlParameter> parameters = new List<SqlParameter>();
  48. StringBuilder sb = new StringBuilder();
  49. sb.Append("select ");
  50. int i = 0;
  51. foreach (string MemPhone in MemPhones)
  52. {
  53. if (MemPhone != null)
  54. sb.Append("(Mall.dbo.DesEncryptFixKey('123456','123456e10adc3949ba59abbe56e057f20f883e','" + MemPhone + "')) as phone" + i + " ");
  55. if (i != MemPhones.Length - 1)
  56. sb.Append(", ");
  57. i++;
  58. }
  59. string[] phones = new string[MemPhones.Length];
  60. bool success = DataAccess.GetValues(sb.ToString(), ref dt, parameters.ToArray(), out result);
  61. if (dt.Rows.Count > 0)
  62. {
  63. DataRow dr = dt.Rows[0];
  64. i = 0;
  65. foreach (string MemPhone in MemPhones)
  66. {
  67. if (MemPhone != null)
  68. phones[i] = Convert.ToString(dr["phone" + i]);
  69. i++;
  70. }
  71. }
  72. return phones;
  73. }
  74. public static DataTable getRegions(string regionCode)
  75. {
  76. DataTable dt = new DataTable();
  77. string result;
  78. List<SqlParameter> parameters = new List<SqlParameter>();
  79. StringBuilder sb = new StringBuilder();
  80. sb.Append(" select "+
  81. " case when dbo.VBARegexMatch(b.AreaCode, '[^0-9]*[1-9]{1,}$', 1) = 'True' then b.AreaCode else null end as MemUsualAreaCode," +
  82. " case when dbo.VBARegexMatch(b.AreaCode, '[^0-9]*[1-9]{1,}00$', 1) = 'True' then b.AreaCode else b.ParentCode end as MemUsualCityCode," +
  83. " case when dbo.VBARegexMatch(b.AreaCode, '[^0-9]*[1-9]{1,}0000$', 1) = 'True' then b.AreaCode else (case when dbo.VBARegexMatch(b1.AreaCode, '[^0-9]*[1-9]{1,}0000$', 1) = 'True' then b1.AreaCode else b1.ParentCode end) end as MemUsualProvinceCode " +
  84. " from Mall.dbo.AreaRegion b " +
  85. " left join Mall.dbo.AreaRegion b1 on b1.AreaCode = b.ParentCode " +
  86. //" --left join Mall.dbo.AreaRegion c on c.AreaCode = b1.ParentCode " +
  87. " where b.AreaCode = '"+ regionCode + "'");
  88. int i = 0;
  89. bool success = DataAccess.GetValues(sb.ToString(), ref dt, parameters.ToArray(), out result);
  90. return dt;
  91. }
  92. }
  93. }