TableViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.Collections.Generic;
  2. using ShwasherSys.Models.Layout;
  3. namespace ShwasherSys.Views.Shared.New.Table
  4. {
  5. public class TableViewModel
  6. {
  7. public TableViewModel(string url, string activeMenu, SearchFormViewModal searchForm, string tableId = "table",bool hasBox=true)
  8. {
  9. TableId = tableId;
  10. Url = url;
  11. ActiveMenu = activeMenu;
  12. SearchForm = searchForm;
  13. SingleSelect = true;
  14. PageArray = new[] { 25, 50, 100, 200 };
  15. HasBox = hasBox;
  16. Other = "";
  17. }
  18. public TableViewModel(string url, string activeMenu=null, string tableId = "table", bool hasBox = true)
  19. : this(url, activeMenu, null, tableId, hasBox)
  20. {
  21. TableId = tableId;
  22. Url = url;
  23. ActiveMenu = activeMenu;
  24. SingleSelect = true;
  25. PageArray = new[] { 25, 50, 100, 200 };
  26. Other = "";
  27. }
  28. public TableViewModel(string url, string activeMenu, SearchFormViewModal searchForm, List<FieldItem> fieldItems,
  29. string tableId = "table")
  30. : this(url, activeMenu, searchForm, tableId)
  31. {
  32. TableId = tableId;
  33. Url = url;
  34. ActiveMenu = activeMenu;
  35. FieldItems = fieldItems;
  36. SearchForm = searchForm;
  37. }
  38. public SearchFormViewModal SearchForm { get; set; }
  39. public string TableId { get; set; }
  40. public string Url { get; set; }
  41. public bool HasBox { get; set; }
  42. public string ActiveMenu { get; set; }
  43. public int[] PageArray { get; set; }
  44. public string PageArrayStr => string.Join(",", PageArray);
  45. public bool SingleSelect { get; set; }
  46. public string SingleSelectStr => SingleSelect ? "true" : "false";
  47. public string Other { get; set; }
  48. public string RowAttributes { get; set; }
  49. public List<FieldItem> FieldItems { get; set; }
  50. public TableViewModel SetPageArray(params int[] page)
  51. {
  52. PageArray = page;
  53. return this;
  54. }
  55. public TableViewModel SetMultipleSelect()
  56. {
  57. SingleSelect = false;
  58. return this;
  59. }
  60. public TableViewModel SetOther(string other)
  61. {
  62. Other = other ?? "";
  63. return this;
  64. }
  65. public TableViewModel SetFields(List<FieldItem> filedItems)
  66. {
  67. FieldItems = filedItems;
  68. return this;
  69. }
  70. public TableViewModel AddFields(FieldItem fieldItem)
  71. {
  72. FieldItems = FieldItems ?? new List<FieldItem>();
  73. FieldItems.Add(fieldItem);
  74. return this;
  75. }
  76. }
  77. public class FieldItem
  78. {
  79. public FieldItem(string filed, string displayName, string formatter = "", string align = "center",bool isTip=false,bool isSort=true)
  80. {
  81. Filed = filed;
  82. DisplayName = displayName;
  83. Formatter = formatter;
  84. Align = align;
  85. IsTip = isTip;
  86. IsSort = isSort;
  87. }
  88. public FieldItem SetWidth(int width,string unit="px")
  89. {
  90. Width = width;
  91. WidthUnit = unit;
  92. return this;
  93. }
  94. public FieldItem SetTip()
  95. {
  96. IsTip = true;
  97. return this;
  98. }
  99. public FieldItem SetNotSort()
  100. {
  101. IsSort = false;
  102. return this;
  103. }
  104. public string Filed { get; set; }
  105. public string DisplayName { get; set; }
  106. public string Formatter { get; set; }
  107. public string Align { get; set; }
  108. public int? Width { get; set; }
  109. public string WidthUnit { get; set; }
  110. public string WidthStr => Width != null ? $" data-width=\"{Width}{WidthUnit}\"" : "";
  111. public bool IsSort { get; set; }
  112. public string IsSortStr => IsSort ? " data-sortable=\"true\"" : "";
  113. private bool IsTip { get; set; }
  114. public string IsTipStr => IsTip ? "data-class=\"iwb-tips\"" : "";
  115. }
  116. }