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.

142 lines
2.8 KiB

4 years ago
  1. using Common.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. namespace JMEAgentSystem.Component.AutoComplete
  10. {
  11. public partial class SwiftTextBox : System.Web.UI.UserControl
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. }
  16. private string _url;
  17. public string URL
  18. {
  19. set { _url = value; }
  20. get
  21. {
  22. if (string.IsNullOrWhiteSpace(_url))
  23. {
  24. return DefaultURL + GetSuffix();
  25. }
  26. return _url + GetSuffix();
  27. }
  28. }
  29. public string Width { set; get; }
  30. public string Value
  31. {
  32. set { aValue.Value = value; }
  33. get
  34. {
  35. return aValue.Value;
  36. }
  37. }
  38. public string Text
  39. {
  40. set { aText.Text = value; }
  41. get
  42. {
  43. return aText.Text;
  44. }
  45. }
  46. private string DefaultURL = GetStatic.GetUrlRoot().TrimEnd('/') + "/Component/AutoComplete/DataSource.asmx/GetList";
  47. public string Category { set; get; }
  48. public string Param1 { set; get; }
  49. public string Param2 { set; get; }
  50. public string Param3 { set; get; }
  51. public string Param4 { set; get; }
  52. protected String GetData()
  53. {
  54. var sb = new StringBuilder();
  55. sb.Append("'category' : '" + Category.Replace("'", "").Replace(",", "") + "'");
  56. if (!string.IsNullOrWhiteSpace(Param1))
  57. {
  58. var data = ParseParam("param1", Param1);
  59. sb.Append("," + data);
  60. }
  61. if (!string.IsNullOrWhiteSpace(Param2))
  62. {
  63. var data = ParseParam("param2", Param2);
  64. sb.Append("," + data);
  65. }
  66. if (!string.IsNullOrWhiteSpace(Param3))
  67. {
  68. var data = ParseParam("param3", Param3);
  69. sb.Append("," + data);
  70. }
  71. if (!string.IsNullOrWhiteSpace(Param4))
  72. {
  73. var data = ParseParam("param4", Param4);
  74. sb.Append("," + data);
  75. }
  76. return sb.ToString();
  77. }
  78. string ParseParam(string key, string data)
  79. {
  80. if (data.StartsWith("@"))
  81. {
  82. return @"'" + key + @"':'"" + " + data.Substring(1) + @" + ""'";
  83. }
  84. else
  85. {
  86. return "'" + key + "':'" + data.Replace("'", "").Replace(",", "") + "'";
  87. }
  88. }
  89. private string GetSuffix()
  90. {
  91. string suffix = "";
  92. if (!string.IsNullOrWhiteSpace(Param1))
  93. {
  94. suffix = "1";
  95. }
  96. if (!string.IsNullOrWhiteSpace(Param2))
  97. {
  98. suffix = "2";
  99. }
  100. if (!string.IsNullOrWhiteSpace(Param3))
  101. {
  102. suffix = "3";
  103. }
  104. if (!string.IsNullOrWhiteSpace(Param4))
  105. {
  106. suffix = "4";
  107. }
  108. return suffix;
  109. }
  110. public string InitFunction()
  111. {
  112. var sb = new StringBuilder();
  113. sb.Append("LoadAutoCompleteTextBox(");
  114. sb.Append(@"""" + URL + @"""");
  115. sb.Append(@",""#" + ClientID + @"""");
  116. sb.Append(@",""" + Width + @"""");
  117. sb.Append(@",""" + GetData() + @""");");
  118. return sb.ToString();
  119. }
  120. }
  121. }