private HtmlComposite BuildTableFooter <T>(ClassSelectResult <T> result) { HtmlComposite footer = new HtmlComposite("tfoot"); HtmlComposite footerDiv = footer .AppendComposite("tr") .AppendComposite("td", new HtmlAttribute("colspan", "100")) .AppendComposite("div", new HtmlAttribute("class", "row-fluid")); if (result.RecordCount == 0) { footerDiv.AppendComposite("div", new HtmlAttribute("class", "span6")) .AppendText("None, nothing, nadia"); } else { footerDiv.AppendComposite("div", new HtmlAttribute("class", "span6")) .AppendText(string.Format("Showing {0:N0} to {1:N0} of {2:N0}", result.FirstRecordOrdinal, result.LastRecordOrdinal, result.RecordCount)); } HtmlComposite pagingList = footerDiv.AppendComposite("div", new HtmlAttribute("class", "span6")) .AppendComposite("div", new HtmlAttribute("class", "pull-right")) .AppendComposite("ul", new HtmlAttribute("class", "pagination")); pagingList .AppendComposite("li", new HtmlAttribute("class", result.PageCount > 1 && result.PageOrdinal > 0 ? "" : "disabled")) .AppendSimple("a", "«", new HtmlAttribute("href", "javascript:void(0)"), new HtmlAttribute("onclick", "EixoX.pageGrid(this,'0')")); pagingList .AppendComposite("li", new HtmlAttribute("class", result.PageCount > 1 && result.PageOrdinal > 0 ? "" : "disabled")) .AppendSimple("a", "<", new HtmlAttribute("href", "javascript:void(0)"), new HtmlAttribute("onclick", string.Concat("EixoX.pageGrid(this,'", result.PageOrdinal - 1, "')"))); pagingList .AppendComposite("li") .AppendComposite( "button", new HtmlAttribute("class", "btn btn-default"), new HtmlAttribute("type", "submit")) .AppendText("pages: " + result.PageCount); pagingList .AppendComposite("li", new HtmlAttribute("class", result.PageCount > 1 && result.PageOrdinal < (result.PageCount - 1) ? "" : "disabled")) .AppendSimple("a", ">", new HtmlAttribute("href", "javascript:void(0)"), new HtmlAttribute("onclick", string.Concat("EixoX.pageGrid(this,'", result.PageOrdinal + 1, "')"))); pagingList .AppendComposite("li", new HtmlAttribute("class", result.PageCount > 1 && result.PageOrdinal < (result.PageCount - 1) ? "" : "disabled")) .AppendSimple("a", "»", new HtmlAttribute("href", "javascript:void(0)"), new HtmlAttribute("onclick", string.Concat("EixoX.pageGrid(this,'", result.PageCount - 1, "')"))); return(footer); }
private ClassSelectResult <T> ExecuteSelect <T>(ClassSelect <T> select) { if (!string.IsNullOrEmpty(this.OrderBy)) { select.OrderBy(this.OrderByDirection, this.OrderBy); } select.Page(this.PageSize, this.PageOrdinal); ClassFilterExpression filter = null; foreach (BootstrapQueryHelperColumn col in this.columns) { if (!string.IsNullOrEmpty(col.Filter)) { filter = filter == null ? new ClassFilterExpression(select.Aspect, col.Name, FilterComparison.Like, "%" + col.Filter.Replace(" ", "%") + "%") : filter.And(col.Name, FilterComparison.Like, "%" + col.Filter.Replace(" ", "%") + "%"); } } if (filter != null) { select.And(filter); } ClassSelectResult <T> result = select.ToResult(); this.RecordCount = result.RecordCount; return(result); }
public BootstrapClassSelectResult(ClassStorage <T> storage, string formName, NameValueCollection form, ClassFilter filter) { this.FormName = formName; PopulateDefaultParameterKeys(); this._SearchFilter = GetValueFromCollection <string>(form, this.DefaultParameterKeys["Filter"], null); this._PageOrdinal = GetValueFromCollection <int>(form, this.DefaultParameterKeys["PageOrdinal"], 0); this._PageSize = GetValueFromCollection <int>(form, this.DefaultParameterKeys["PageSize"], 20); this._OrderBy = GetValueFromCollection <int>(form, this.DefaultParameterKeys["OrderBy"], -1); this._SortDirection = GetValueFromCollection <SortDirection>(form, this.DefaultParameterKeys["SortDirection"], EixoX.Data.SortDirection.Ascending); ClassSelect <T> select = null; if (string.IsNullOrEmpty(_SearchFilter.Value)) { select = storage.Select(); if (filter != null) { select.Where(filter); } } else { select = storage.Search(_SearchFilter.Value); if (filter != null) { select.And(filter); } } if (_OrderBy.Value >= 0) { select.OrderBy(_OrderBy.Value, _SortDirection.Value); } else { select.OrderBy(0, EixoX.Data.SortDirection.Descending); } select.Page(_PageSize.Value, _PageOrdinal.Value); this.Result = new ClassSelectResult <T>(select); }
public HtmlComposite Execute <T>(ClassSelect <T> select, NameValueCollection parameters) { ClassSelectResult <T> result = ExecuteSelect <T>(select); HtmlComposite form = new HtmlComposite( "form", new HtmlAttribute("method", "get")); form.AppendStandalone("input", new HtmlAttribute("type", "hidden"), new HtmlAttribute("name", "orderBy"), new HtmlAttribute("value", this.OrderBy)); form.AppendStandalone("input", new HtmlAttribute("type", "hidden"), new HtmlAttribute("name", "orderByDirection"), new HtmlAttribute("value", this.OrderByDirection)); form.AppendStandalone("input", new HtmlAttribute("type", "hidden"), new HtmlAttribute("name", "page"), new HtmlAttribute("value", "0")); if (parameters != null) { AppendUnrelatedFilters(form, select.Aspect, parameters); } HtmlComposite table = form.AppendComposite( "table", new HtmlAttribute("class", "table table-condensed table-striped table-bordered table-hover") ); table.Children.AddLast(BuildTableHeader <T>()); table.Children.AddLast(BuildTableBody <T>(result)); table.Children.AddLast(BuildTableFooter <T>(result)); return(form); }
private HtmlComposite BuildTableBody <T>(ClassSelectResult <T> result) { ClassSchema <T> aspect = ClassSchema <T> .Instance; HtmlComposite tbody = new HtmlComposite("tbody"); AspectMember[] onclickMembers = OnClickColumns != null && OnClickColumns.Length > 0 ? new AspectMember[OnClickColumns.Length] : null; if (onclickMembers != null) { for (int i = 0; i < onclickMembers.Length; i++) { onclickMembers[i] = aspect[OnClickColumns[i]]; } } object[] onclickValues = OnClickColumns != null && OnClickColumns.Length > 0 ? new object[OnClickColumns.Length] : null; AspectMember[] members = new AspectMember[columns.Count]; for (int i = 0; i < members.Length; i++) { members[i] = aspect[columns[i].Name]; } foreach (T child in result) { HtmlComposite tr = tbody.AppendComposite("tr"); if (!string.IsNullOrEmpty(this.OnClickFormatString)) { if (onclickValues != null) { for (int i = 0; i < onclickValues.Length; i++) { onclickValues[i] = onclickMembers[i].GetValue(child); } tr .AppendAttribute("style", "cursor:pointer") .AppendAttribute("onclick", string.Format(this.OnClickFormatString, onclickValues)); } else { tr .AppendAttribute("style", "cursor:pointer") .AppendAttribute("onclick", this.OnClickFormatString); } } for (int i = 0; i < members.Length; i++) { BootstrapQueryHelperColumn col = columns[i]; HtmlComposite td = tr.AppendComposite("td"); if (!string.IsNullOrEmpty(col.CssStyle)) { td.AppendAttribute("style", col.CssStyle); } if (!string.IsNullOrEmpty(col.CssClass)) { td.AppendAttribute("class", col.CssClass); } object value = members[i].GetValue(child); string content = col.Formatter.Format(value, CultureInfo.CurrentUICulture); if (col.IsHtmlRaw) { td.Children.AddLast(new HtmlRaw(content)); } else { td.AppendText(content); } } } return(tbody); }