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.

102 lines
3.6 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. using Swift.web.Component.Grid;
  2. using Swift.web.Component.Grid.gridHelper;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. namespace Swift.web.Library
  9. {
  10. public static class WebUtils
  11. {
  12. public static string LoadSlabGrid(string masterId, string masterIdDesc, string detailIdDesc, string proc)
  13. {
  14. var grid = new SwiftGrid();
  15. grid.ColumnList = new List<GridColumn>
  16. {
  17. new GridColumn("fromAmt", "Amt From", "40", "M"),
  18. new GridColumn("toAmt", "Amt To", "40", "M"),
  19. new GridColumn("pcnt", "Perc", "30", "M"),
  20. new GridColumn("minAmt", "Min Amt", "40", "M"),
  21. new GridColumn("maxAmt", "Max Amt", "40", "M")
  22. };
  23. grid.GridName = "grd_slab";
  24. grid.GridType = 1;
  25. grid.EnableCookie = false;
  26. grid.EnableFilterCookie = false;
  27. grid.DisableJsFilter = true;
  28. grid.DisableSorting = true;
  29. grid.ShowFilterForm = false;
  30. grid.ShowPagingBar = false;
  31. grid.RowIdField = detailIdDesc;
  32. grid.AllowEdit = false;
  33. grid.AllowDelete = false;
  34. grid.GridWidth = 225;
  35. string sql = "EXEC " + proc + " @flag = 's', @" + masterIdDesc + " = " + grid.FilterString(masterId);
  36. grid.SetComma();
  37. return grid.CreateGrid(sql);
  38. }
  39. public static string DecryptString( string cipherText)
  40. {
  41. var key = GetStatic.ReadWebConfig("encryptKey");
  42. byte[] iv = new byte[16];
  43. byte[] buffer = Convert.FromBase64String(cipherText);
  44. using (Aes aes = Aes.Create())
  45. {
  46. aes.Key = Encoding.UTF8.GetBytes(key);
  47. aes.IV = iv;
  48. ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
  49. using (MemoryStream memoryStream = new MemoryStream(buffer))
  50. {
  51. using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Read))
  52. {
  53. using (StreamReader streamReader = new StreamReader((Stream)cryptoStream))
  54. {
  55. return streamReader.ReadToEnd();
  56. }
  57. }
  58. }
  59. }
  60. }
  61. public static string EncryptString(string plainText)
  62. {
  63. var key = GetStatic.ReadWebConfig("encryptKey");
  64. byte[] iv = new byte[16];
  65. byte[] array;
  66. using (Aes aes = Aes.Create())
  67. {
  68. aes.Key = Encoding.UTF8.GetBytes(key);
  69. aes.IV = iv;
  70. ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
  71. using (MemoryStream memoryStream = new MemoryStream())
  72. {
  73. using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, encryptor, CryptoStreamMode.Write))
  74. {
  75. using (StreamWriter streamWriter = new StreamWriter((Stream)cryptoStream))
  76. {
  77. streamWriter.Write(plainText);
  78. }
  79. array = memoryStream.ToArray();
  80. }
  81. }
  82. }
  83. return Convert.ToBase64String(array);
  84. }
  85. }
  86. }