QueryItem.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using System.Web.Mvc;
  3. using WeOnlineApp.Views.Shared.SearchForm;
  4. namespace WeOnlineApp.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 SetSelectStr(string str, bool isSelectTree = false)
  44. {
  45. IsSelectTree = isSelectTree;
  46. SelectStr = str;
  47. return this;
  48. }
  49. public QueryItem SetSelectStr(List<SelectListItem> list, bool isSelectTree = false)
  50. {
  51. IsSelectTree = isSelectTree;
  52. var str = "";
  53. foreach (var item in list)
  54. {
  55. str += $"<option value=\"{item.Value}\">{item.Text}</option>";
  56. }
  57. SelectStr = str;
  58. return this;
  59. }
  60. public QueryItem SetSelectStr(Dictionary<string, string> dic, bool isSelectTree = false)
  61. {
  62. IsSelectTree = isSelectTree;
  63. if (dic.ContainsKey(Key))
  64. {
  65. SelectStr = dic[Key];
  66. }
  67. return this;
  68. }
  69. }
  70. }