QueryItem.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections.Generic;
  2. using System.Web.Mvc;
  3. using ContractService.Views.Shared.SearchForm;
  4. namespace ContractService.Views.Shared.Query
  5. {
  6. public class QueryItem
  7. {
  8. public QueryItem(string key, string name, bool isSearch = false, bool isDisabled = false, bool isHidden = false, FieldType fieldType = FieldType.S,
  9. ExpType expType = ExpType.Contains, string formatter = "")
  10. {
  11. Key = key;
  12. Name = name;
  13. IsSearch = isSearch;
  14. IsDisabled = isDisabled;
  15. IsHidden = isHidden;
  16. FieldType = fieldType;
  17. ExpType = expType;
  18. Formatter = formatter;
  19. }
  20. public string Key { get; set; }
  21. public string Name { get; set; }
  22. public string Formatter { get; set; }
  23. public bool IsSearch { get; set; }
  24. public bool IsHidden { get; set; }
  25. public string HiddenStr => IsHidden ? "display:none;" : "";
  26. public bool IsDisabled { get; set; }
  27. public string DisabledStr => IsDisabled ? "disable" : "";
  28. public FieldType FieldType { get; set; }
  29. public ExpType ExpType { get; set; }
  30. public bool IsSelectTree { get; set; }
  31. public string SelectTreeClass => IsSelectTree ? " select2tree" : "";
  32. public string SelectStr { get; set; }
  33. public QueryItem SetHidden()
  34. {
  35. IsHidden = true;
  36. return this;
  37. }
  38. public QueryItem SetDisabled()
  39. {
  40. IsDisabled = true;
  41. return this;
  42. }
  43. public QueryItem SetFormatter(string formatter)
  44. {
  45. Formatter = formatter;
  46. return this;
  47. }
  48. public QueryItem SetSelectStr(string str, bool isSelectTree = false)
  49. {
  50. IsSelectTree = isSelectTree;
  51. SelectStr = str;
  52. return this;
  53. }
  54. public QueryItem SetSelectList(Dictionary<string, List<SelectListItem>> dic, bool isSelectTree = false)
  55. {
  56. IsSelectTree = isSelectTree;
  57. var str = "";
  58. if (dic.ContainsKey(Key))
  59. {
  60. var list = dic[Key];
  61. foreach (var item in list)
  62. {
  63. str += $"<option value=\"{item.Value}\">{item.Text}</option>";
  64. }
  65. SelectStr = str;
  66. }
  67. return this;
  68. }
  69. public QueryItem SetSelectStr(Dictionary<string, string> dic, bool isSelectTree = false)
  70. {
  71. IsSelectTree = isSelectTree;
  72. if (dic.ContainsKey(Key))
  73. {
  74. SelectStr = dic[Key];
  75. }
  76. return this;
  77. }
  78. }
  79. }