public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, bool?isChecked = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?maxLength = null, bool readOnly = false, int?size = null, string style = null, int?tabIndex = null, string title = null) { var htmlAttributes = InputAttributes(cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title); return(isChecked.HasValue ? InputExtensions.CheckBox(htmlHelper, name, isChecked.Value, htmlAttributes) : InputExtensions.CheckBox(htmlHelper, name, htmlAttributes)); }
public static MvcHtmlString BSFGForMetaData <TModel>( this HtmlHelper <TModel> html, MetaProduct meta, int num, int col_sm) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<div class=\"form-group\">"); var name = (typeof(TypeOfMetaProduct).GetMember(meta.Type.ToString()).First().GetCustomAttributes(typeof(DisplayAttribute), true).First() as DisplayAttribute).Name; sb.AppendLine(LabelExtensions .Label(html, name, new { @class = String.Format("col-sm-{0} control-label", 12 - col_sm) }).ToHtmlString()); sb.AppendLine(String.Format("<div class=\"col-sm-{0}\">", col_sm)); sb.AppendLine("<div class=\"input-group\">"); sb.AppendLine(InputExtensions .Hidden(html, String .Format("MetaData[{0}].Type", num), meta.Type.ToString()).ToHtmlString()); switch (meta.Type) { case TypeOfMetaProduct.Author: case TypeOfMetaProduct.Country: case TypeOfMetaProduct.Director: case TypeOfMetaProduct.FromURI: case TypeOfMetaProduct.Genre: case TypeOfMetaProduct.InRole: case TypeOfMetaProduct.Name: case TypeOfMetaProduct.PosterFromURI: case TypeOfMetaProduct.Type: case TypeOfMetaProduct.View: case TypeOfMetaProduct.NumberOfEpisode: sb.AppendLine(InputExtensions .TextBox(html, String .Format("MetaData[{0}].String", num), meta.String, new { @class = "form-control" }).ToHtmlString()); break; case TypeOfMetaProduct.Begin: case TypeOfMetaProduct.End: sb.AppendLine(InputExtensions .TextBox(html, String .Format("MetaData[{0}].DateTime", num), meta.Date.ToShortDateString(), new { @class = "form-control" }).ToHtmlString()); break; case TypeOfMetaProduct.Ended: sb.AppendLine(InputExtensions .CheckBox(html, String .Format("MetaData[{0}].Bool", num), meta.Bool, new { @class = "form-control" }).ToHtmlString()); break; } sb.AppendLine("<span class=\"input-group-btn\">"); sb.AppendLine(String.Format( "<input name =\"MetaData[{0}].String\" type=\"submit\" value=\"Удалить\" class=\"btn btn-success\">", num)); sb.AppendLine("</span>"); sb.AppendLine("</div>"); sb.AppendLine("</div>"); sb.AppendLine("</div>"); return(new MvcHtmlString(sb.ToString())); }
public static MvcHtmlString Grid <T>(this HtmlHelper html, IEnumerable <T> items, string defaultSort, string gridCaption, bool canPage = false, int rowPerPage = 50, int rowCount = 0, int activePage = 1, string idGrid = "grid", bool isWindowMode = false, List <KeyValuePair <string, object> > parameters = null) { StringBuilder output = new StringBuilder(); if (items.Count() > 0) { List <GridColumnOrder> columns = new List <GridColumnOrder>(); if (parameters == null) { parameters = new List <KeyValuePair <string, object> >(); } parameters.Add(new KeyValuePair <string, object>("windowMode", isWindowMode)); if (rowCount == 0) { rowCount = items.Count(); } if (canPage) { output.AppendLine(CreatePageNavigator(html, rowPerPage, rowCount, activePage: activePage, parameters: parameters).ToHtmlString()); } var grid = new WebGrid((IEnumerable <dynamic>)items, canPage: false, canSort: false, rowsPerPage: rowPerPage, defaultSort: defaultSort); foreach (var property in typeof(T).GetProperties()) { bool showColumn = true; var attributes = (property.GetCustomAttributes(typeof(GridConfigAttribute), false)); if (attributes != null) { foreach (var attribute in attributes) { string propertyName = property.Name; var attr = (GridConfigAttribute)attribute; string style = attr.Style; showColumn = !attr.Hidden; if (showColumn) { showColumn = !(isWindowMode && attr.HiddenOnWindowMode); } if (showColumn) { showColumn = attr.Index > 0; } if (attr.CreateCheckBox && !isWindowMode) { columns.Add(new GridColumnOrder(attr.Index, new WebGridColumn() { Format = (dynamic item) => { var entity = (T)(((WebGridRow)item).Value); var objectValue = entity.GetType().GetProperty(propertyName).GetValue(entity, null); return(InputExtensions.CheckBox(html, String.Format("chk{0}", propertyName), new { @class = "checkable", value = objectValue })); }, Style = style })); } if (attr.CreateImage && !isWindowMode) { columns.Add(new GridColumnOrder(attr.Index, new WebGridColumn() { //Header = SpongeSolutions.ServicoDireto.Internationalization.Label.ResourceManager.GetString(propertyName), Format = (dynamic item) => { var entity = (T)(((WebGridRow)item).Value); var objectValue = entity.GetType().GetProperty(propertyName).GetValue(entity, null); objectValue = String.Concat(SpongeSolutions.ServicoDireto.Admin.SiteContext.LayoutPath, objectValue); return(new MvcHtmlString(String.Format("<img src='{0}'/>", objectValue))); }, Style = style })); } if (attr.CreateEditLink) { columns.Add(new GridColumnOrder(attr.Index, new WebGridColumn() { Format = (item) => { var entity = (T)(((WebGridRow)item).Value); try { string objectValue = entity.GetType().GetProperty(propertyName).GetValue(entity, null).ToString(); string objectDescription = null; if (attr.RelatedFieldName != null && attr.RelatedFieldName.Count() > 0) { foreach (var fieldName in attr.RelatedFieldName) { objectDescription += String.Format("{0}-", entity.GetType().GetProperty(fieldName).GetValue(entity, null)); } objectDescription = objectDescription.Remove(objectDescription.Length - 1, 1); } if (objectDescription == null) { objectDescription = objectValue; } if (isWindowMode) { return(new HtmlString(String.Format("<a href=\"javascript:AddSelected('{0}','{1}')\">{2}</a>", objectValue, objectDescription, SpongeSolutions.ServicoDireto.Internationalization.Label.Select))); } else { return(LinkExtensions.ActionLink(html, SpongeSolutions.ServicoDireto.Internationalization.Label.Edit, "create", new { id = objectValue })); } } catch (Exception) { return(string.Empty); } }, Style = style })); } if (attr.EnumType != null) { columns.Add(new GridColumnOrder(attr.Index, new WebGridColumn() { Style = style, ColumnName = property.Name, Header = SpongeSolutions.ServicoDireto.Internationalization.Label.ResourceManager.GetString(property.Name), Format = (item) => { var entity = (T)(((WebGridRow)item).Value); var objectValue = entity.GetType().GetProperty(propertyName).GetValue(entity, null); //var enumSource = Activator.CreateInstance(attr.EnumType); //TODO: COLOCAR DE MODO DINAMICO return(SpongeSolutions.Core.Translation.EnumTranslator.Translate <Enums.StatusType>(SpongeSolutions.Core.Helpers.EnumHelper.TryParse <Enums.StatusType>(objectValue)).DisplayName); } })); showColumn = false; } if (showColumn) { columns.Add(new GridColumnOrder(attr.Index, new WebGridColumn() { ColumnName = property.Name, Header = SpongeSolutions.ServicoDireto.Internationalization.Label.ResourceManager.GetString(property.Name) , Style = style })); } } } } output.AppendLine(MvcHtmlString.Create(grid.GetHtml( tableStyle: "grid", caption: gridCaption, alternatingRowStyle: "alternating", htmlAttributes: new { id = idGrid }, columns: columns.OrderBy(p => p.Index).Select(p => p.Column).ToArray()).ToHtmlString()).ToHtmlString()); if (canPage) { output.AppendLine(CreatePageNavigator(html, rowPerPage, rowCount, activePage: activePage, parameters: parameters).ToHtmlString()); } } else { var container = new TagBuilder("div"); container.AddCssClass("notice"); container.SetInnerText(Internationalization.Label.Records_Not_Found); output.Append(container.ToString()); } return(MvcHtmlString.Create(output.ToString())); }
public static MvcHtmlString WizardStepBody(this HtmlHelper html, WizardManager wm, object stepModel) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("\r\n"); PropertyInfo[] properties = stepModel.GetType().GetProperties(); for (int i = 0; i < properties.Length; i++) { PropertyInfo propertyInfo = properties[i]; object obj_ = propertyInfo.GetGetMethod().Invoke(stepModel, null); if (obj_ == null) { obj_ = ""; } TagBuilder tagBuilder = new TagBuilder("div"); tagBuilder.MergeAttribute("class", "wizardfield"); if (propertyInfo.PropertyType == typeof(bool)) { tagBuilder.InnerHtml = propertyInfo.Name + ": " + InputExtensions.CheckBox(html, propertyInfo.Name, obj_).ToHtmlString(); } else { if (propertyInfo.PropertyType.IsSubclassOf(typeof(Enum))) { List <SelectListItem> list = new List <SelectListItem>(); IEnumerator enumerator = Enum.GetValues(propertyInfo.PropertyType).GetEnumerator(); try { while (enumerator.MoveNext()) { Enum @enum = (Enum)enumerator.Current; List <SelectListItem> varJWA0 = list; SelectListItem selectListItem = new SelectListItem(); selectListItem.Selected = false; selectListItem.Text = @enum.ToString(); selectListItem.Value = @enum.ToString(); varJWA0.Add(selectListItem); } } finally { IDisposable disposable_ = enumerator as IDisposable; if (disposable_ != null) { disposable_.Dispose(); } } tagBuilder.InnerHtml = propertyInfo.Name + ": " + SelectExtensions.DropDownList(html, propertyInfo.Name, list).ToHtmlString(); } else { tagBuilder.InnerHtml = propertyInfo.Name + ": " + InputExtensions.TextBox(html, propertyInfo.Name, obj_).ToHtmlString(); } } stringBuilder.Append(tagBuilder.ToString()).Append("\r\n"); } TagBuilder tagBuilder2 = new TagBuilder("div"); tagBuilder2.MergeAttribute("class", "wizardbody"); tagBuilder2.InnerHtml = stringBuilder.ToString(); return(MvcHtmlString.Create(tagBuilder2.ToString())); }