| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using System.Collections.Generic;
- using System.Web.WebPages;
- using ContractService.Views.Shared.SearchForm;
- namespace ContractService.Views.Shared.Table
- {
- public class TableViewModel
- {
- public TableViewModel()
- {
- IsPage = true;
- IsClickSelect = true;
- IsSingleSelect = true;
- }
- public TableViewModel(string tableId = "table") : this()
- {
- TableId = tableId;
- PageArray = new[] { 25, 50, 100, 200 };
- IsSingleSelect = true;
- }
- public TableViewModel(string url, string currentPage, SearchFormViewModel searchForm, string tableId = "table", bool hasBox = true) : this(tableId)
- {
- TableId = tableId;
- Url = url;
- CurrentPage = currentPage;
- SearchForm = searchForm;
- HasBox = hasBox;
- Other = "";
- }
- public TableViewModel(string url, string currentPage = null, string tableId = "table", bool hasBox = true)
- : this(url, currentPage, null, tableId, hasBox)
- {
- TableId = tableId;
- Url = url;
- CurrentPage = currentPage;
- IsSingleSelect = true;
- PageArray = new[] { 25, 50, 100, 200 };
- Other = "";
- }
- public TableViewModel(string url, string currentPage, SearchFormViewModel searchForm, List<FieldItem> fieldItems,
- string tableId = "table")
- : this(url, currentPage, searchForm, tableId)
- {
- TableId = tableId;
- Url = url;
- CurrentPage = currentPage;
- FieldItems = fieldItems;
- SearchForm = searchForm;
- }
- public SearchFormViewModel SearchForm { get; set; }
- public string TableId { get; set; }
- public string _fieldId;
- public string FieldId => _fieldId.IsEmpty() ? "id" : _fieldId;
- public string Url { get; set; }
- public bool HasBox { get; set; }
- public string CurrentPage { get; set; }
- public bool IsPage { get; set; }
- public string PageStr => IsPage ? "true" : "false";
- public int[] PageArray { get; set; }
- public string PageArrayStr => string.Join(",", PageArray);
- public bool IsSingleSelect { get; set; }
- public string SingleSelectStr => IsSingleSelect ? "true" : "false";
- public bool IsClickSelect { get; set; }
- public string ClickSelectStr => IsClickSelect ? "true" : "false";
- public bool IsLocalData { get; set; }
- public string LocalDataStr => IsLocalData ? "" : "data-method=\"post\" data-side-pagination=\"server\"";
- public string Other { get; set; }
- public string RowAttributes { get; set; }
- public List<FieldItem> FieldItems { get; set; }
- public TableViewModel SetTable(string active, string url = "", bool hasBox = true, string id = "table")
- {
- CurrentPage = active;
- TableId = id;
- Url = url;
- HasBox = HasBox;
- return this;
- }
- public TableViewModel SetId(string id)
- {
- TableId = id;
- return this;
- }
- public TableViewModel SetFieldId(string fieldId)
- {
- _fieldId = fieldId;
- return this;
- }
- public TableViewModel SetNotBox()
- {
- HasBox = false;
- return this;
- }
- public TableViewModel SetSearchForm(SearchFormViewModel search)
- {
- SearchForm = search;
- return this;
- }
- public TableViewModel SetNotPage()
- {
- IsPage = false;
- return this;
- }
- public TableViewModel SetPageArray(params int[] page)
- {
- IsPage = true;
- PageArray = page;
- return this;
- }
- public TableViewModel SetMultipleSelect()
- {
- IsSingleSelect = false;
- return this;
- }
- public TableViewModel SetRowAttributes(string rowAttributes)
- {
- RowAttributes = rowAttributes ?? "";
- return this;
- }
- public TableViewModel SetOther(string other)
- {
- Other = other ?? "";
- return this;
- }
- public TableViewModel SetFields(List<FieldItem> filedItems)
- {
- FieldItems = filedItems;
- return this;
- }
- public TableViewModel AddFields(List<FieldItem> filedItems)
- {
- FieldItems = FieldItems ?? new List<FieldItem>();
- FieldItems.AddRange(filedItems);
- return this;
- }
- public TableViewModel AddField(FieldItem fieldItem)
- {
- FieldItems = FieldItems ?? new List<FieldItem>();
- FieldItems.Add(fieldItem);
- return this;
- }
- public TableViewModel SetLocalData()
- {
- IsLocalData = true;
- return this;
- }
- public TableViewModel SetClickSelect(bool isClickSelect = true)
- {
- IsClickSelect = isClickSelect;
- return this;
- }
- public TableViewModel SetSingleSelect(bool isSingleSelect = true)
- {
- IsSingleSelect = isSingleSelect;
- return this;
- }
- }
- public class FieldItem
- {
- public FieldItem(string filed, string displayName, string formatter = "", string align = "center", bool isTip = false, bool isSort = false)
- {
- Filed = filed;
- DisplayName = displayName;
- Formatter = formatter;
- Align = align;
- IsTip = isTip;
- IsSort = isSort;
- }
- public FieldItem SetWidth(int width, string unit = "px")
- {
- Width = width;
- WidthUnit = unit;
- return this;
- }
- public FieldItem SetTip()
- {
- IsTip = true;
- return this;
- }
- public FieldItem SetSort()
- {
- IsSort = true;
- return this;
- }
- public FieldItem SetRight()
- {
- Align = "right";
- return this;
- }
- public FieldItem SetLeft()
- {
- Align = "left";
- return this;
- }
- public string Filed { get; set; }
- public string DisplayName { get; set; }
- public string Formatter { get; set; }
- public string FormatterStr => string.IsNullOrEmpty(Formatter) ? "" : "data-formatter=\"" + Formatter + "\"";
- public string Align { get; set; }
- public int? Width { get; set; }
- public string WidthUnit { get; set; }
- public string WidthStr => Width != null ? $" data-width=\"{Width}{WidthUnit}\"" : "";
- public bool IsSort { get; set; }
- public string IsSortStr => IsSort ? " data-sortable=\"true\"" : "";
- private bool IsTip { get; set; }
- public string IsTipStr => IsTip ? "data-class=\"iwb-tips\"" : "";
- }
- }
|