public static System.Web.IHtmlString DtxDisplayDay (this System.Web.Mvc.HtmlHelper htmlHelper, long?value) { if (value.HasValue == false) { return(htmlHelper.Raw("--")); } string result = value.Value.ToString().PadLeft(2, '0'); return(htmlHelper.Raw(result)); }
public static System.Web.IHtmlString DtxDeleteButton (this System.Web.Mvc.HtmlHelper html, string deleteButtonCaption = null, string deleteButtonId = null, bool deleteButtonEnabled = true, string deleteButtonCssClass = null) { if (string.IsNullOrWhiteSpace(deleteButtonCaption)) { deleteButtonCaption = Resources.Buttons.Delete; } if (string.IsNullOrWhiteSpace(deleteButtonCssClass)) { deleteButtonCssClass = "btn btn-danger"; } string result = "<div class=\"form-actions no-color\">"; result += DtxSimpleSubmitButton( html: html, id: deleteButtonId, enabled: deleteButtonEnabled, cssClass: deleteButtonCssClass, buttonCaption: deleteButtonCaption ).ToHtmlString(); result += "</div>"; return(html.Raw(result)); }
public static System.Web.IHtmlString DtxDisplayDateTime (this System.Web.Mvc.HtmlHelper htmlHelper, System.DateTime?value, bool displayTime = true) { string result = Convert.DateTime(value: value, displayTime: displayTime); return(htmlHelper.Raw(result)); }
public static System.Web.IHtmlString DtxDisplay (this System.Web.Mvc.HtmlHelper htmlHelper, long?value) { string result = Convert.Number(value: value); return(htmlHelper.Raw(result)); }
public static IHtmlString YourControl (this System.Web.Mvc.HtmlHelper helper, string target, string name) { string strControl = string.Format("<label for='{0}'>{1}<label><input type='text' name='{0}' />", target, name); return(helper.Raw(strControl)); }
public static System.Web.IHtmlString DtxSubmitButton (this System.Web.Mvc.HtmlHelper html, int columnOffset = 3, string submitButtonCaption = null, string submitButtonId = null, bool submitButtonEnabled = true, string submitButtonCssClass = null, bool displayResetButton = true, string resetButtonCaption = null, string resetButtonCssClass = null) { string result = "<div class=\"form-group\">"; if (columnOffset < 0) { columnOffset = 0; } else { if (columnOffset > 11) { columnOffset = 11; } } if (columnOffset == 0) { result += $"<div class=\"col-sm-12\">"; } else { result += $"<div class=\"col-sm-offset-{ columnOffset } col-sm-{ 12 - columnOffset }\">"; } result += DtxSimpleSubmitButton(html: html, buttonCaption: submitButtonCaption, id: submitButtonId, enabled: submitButtonEnabled, cssClass: submitButtonCssClass) .ToHtmlString(); if (displayResetButton) { result += " " + DtxSimpleResetButton(html: html, buttonCaption: resetButtonCaption, cssClass: resetButtonCssClass) .ToHtmlString(); } result += "</div>"; result += "</div>"; return(html.Raw(result)); }
public static System.Web.IHtmlString DtxReset (this System.Web.Mvc.HtmlHelper htmlHelper, string caption) { System.Web.Mvc.TagBuilder button = new System.Web.Mvc.TagBuilder("button"); button.SetInnerText(caption); button.AddCssClass("btn"); button.AddCssClass("btn-default"); button.Attributes.Add("type", "reset"); return(htmlHelper.Raw(button.ToString())); }
public static System.Web.IHtmlString DtxSubHeader (this System.Web.Mvc.HtmlHelper htmlHelper, string text) { text = Dtx.Text.Fix(text: text); if (text == string.Empty) { return(null); } string result = $"<h4>{ text }</h4>"; return(htmlHelper.Raw(result)); }
public static System.Web.IHtmlString DtxTextBox (this System.Web.Mvc.HtmlHelper htmlHelper, string name, object value = null) { System.Web.Mvc.TagBuilder input = new System.Web.Mvc.TagBuilder("input"); input.Attributes.Add("id", name); input.Attributes.Add("name", name); input.Attributes.Add("type", "text"); if (value != null) { input.Attributes.Add("value", value.ToString()); } return(htmlHelper.Raw(input.ToString())); }
public static System.Web.IHtmlString DtxSimpleSubmitButton (this System.Web.Mvc.HtmlHelper html, string buttonCaption = null, string id = null, bool enabled = true, string cssClass = null) { string result = string.Empty; if (string.IsNullOrWhiteSpace(buttonCaption)) { buttonCaption = Resources.Buttons.Submit; } if (string.IsNullOrWhiteSpace(cssClass)) { cssClass = "btn btn-primary"; } if (string.IsNullOrWhiteSpace(id)) { if (enabled) { result = $"<button type=\"submit\" class=\"{ cssClass }\">{ buttonCaption }</button>"; } else { result = $"<button type=\"submit\" class=\"{ cssClass }\" disabled=\"disabled\">{ buttonCaption }</button>"; } } else { if (enabled) { result = $"<button type=\"submit\" class=\"{ cssClass }\" id=\"{ id }\">{ buttonCaption }</button>"; } else { result = $"<button type=\"submit\" class=\"{ cssClass }\" id=\"{ id }\" disabled=\"disabled\">{ buttonCaption }</button>"; } } return(html.Raw(result)); }
public static System.Web.IHtmlString DtxSubmit (this System.Web.Mvc.HtmlHelper htmlHelper, string name, string caption) { System.Web.Mvc.TagBuilder button = new System.Web.Mvc.TagBuilder("button"); button.SetInnerText(caption); button.AddCssClass("btn"); button.AddCssClass("btn-primary"); button.Attributes.Add("id", name); button.Attributes.Add("name", name); button.Attributes.Add("type", "submit"); return(htmlHelper.Raw(button.ToString())); }
public static System.Web.IHtmlString DtxLabel (this System.Web.Mvc.HtmlHelper htmlHelper, string expression, string labelText) { // Solution (1) System.Web.Mvc.TagBuilder label = new System.Web.Mvc.TagBuilder("label"); label.SetInnerText(labelText); label.Attributes.Add("for", expression); return(htmlHelper.Raw(label.ToString())); // /Solution (1) // Solution (2) //System.Web.Mvc.TagBuilder label = // new System.Web.Mvc.TagBuilder("label"); //label.SetInnerText(labelText); //label.Attributes.Add("for", expression); //System.Web.Mvc.TagBuilder div = // new System.Web.Mvc.TagBuilder("div"); //div.AddCssClass("caption"); //div.InnerHtml = label.ToString(); //return (htmlHelper.Raw(div.ToString())); // /Solution (2) // Solution (3) //string label = // htmlHelper.Label(expression: expression, labelText: labelText) // .ToHtmlString(); //System.Web.Mvc.TagBuilder div = // new System.Web.Mvc.TagBuilder("div"); //div.InnerHtml = label; //div.AddCssClass("caption"); //return (htmlHelper.Raw(div.ToString())); // /Solution (3) }
public static System.Web.IHtmlString DtxSimpleResetButton (this System.Web.Mvc.HtmlHelper html, string buttonCaption = null, string cssClass = null) { string result = string.Empty; if (string.IsNullOrWhiteSpace(buttonCaption)) { buttonCaption = Resources.Buttons.Reset; } if (string.IsNullOrWhiteSpace(cssClass)) { cssClass = "btn btn-default"; } result = $"<button type=\"reset\" class=\"{ cssClass }\">{ buttonCaption }</button>"; return(html.Raw(result)); }
public static System.Web.IHtmlString DtxCreateButton (this System.Web.Mvc.HtmlHelper html, int columnOffset = 3, string createButtonCaption = null, string createButtonId = null, bool createButtonEnabled = true, string createButtonCssClass = null, bool displayResetButton = true, string resetButtonCaption = null, string resetButtonCssClass = null) { if (string.IsNullOrWhiteSpace(createButtonCaption)) { createButtonCaption = Resources.Buttons.Create; } string result = DtxSubmitButton (html: html, columnOffset: columnOffset, submitButtonCaption: createButtonCaption, submitButtonId: createButtonId, submitButtonEnabled: createButtonEnabled, submitButtonCssClass: createButtonCssClass, displayResetButton: displayResetButton, resetButtonCaption: resetButtonCaption, resetButtonCssClass: resetButtonCssClass) .ToHtmlString(); return(html.Raw(result)); }
public static System.Web.WebPages.HelperResult RequestTypeFilter(System.Web.Mvc.HtmlHelper html, RequestListModel model, Func <RequestListGetModel, string> reloadUrl) { return(new System.Web.WebPages.HelperResult(__razor_helper_writer => { #line 17 "..\..\App_Code\RequestHelpers.cshtml" var current = model.RequestTypeFilter; #line default #line hidden WriteLiteralTo(@__razor_helper_writer, " <div class=\"ui-dropdown-button ui-has-hint FilterButton"); #line 20 "..\..\App_Code\RequestHelpers.cshtml" WriteTo(@__razor_helper_writer, model.RequestTypeFilter == null ? "" : " Active"); #line default #line hidden WriteLiteralTo(@__razor_helper_writer, "\"\r\n hint-text=\""); #line 21 "..\..\App_Code\RequestHelpers.cshtml" WriteTo(@__razor_helper_writer, current == null ? "Filter by type" : "Showing " + current.RequestType.Name); #line default #line hidden WriteLiteralTo(@__razor_helper_writer, "\"> </div>\r\n"); WriteLiteralTo(@__razor_helper_writer, " <div class=\"ui-dropdown ui-scrolling FilterOptions\" style=\"display: none\">\r\n"); #line 23 "..\..\App_Code\RequestHelpers.cshtml" foreach (var rt in model.UsedRequestTypes.Select(rt => new RequestTypeFilterItem((PluginRequestType)rt)).OrderBy(rt => rt.Name).StartWith(new RequestTypeFilterItem())) { var m = model.List.OriginalRequest; m.RequestTypeFilter = rt.ID; #line default #line hidden WriteLiteralTo(@__razor_helper_writer, " <a href=\""); #line 27 "..\..\App_Code\RequestHelpers.cshtml" WriteTo(@__razor_helper_writer, html.Raw(reloadUrl(m))); #line default #line hidden WriteLiteralTo(@__razor_helper_writer, "\" class=\"GridReloadLink"); #line 27 "..\..\App_Code\RequestHelpers.cshtml" WriteTo(@__razor_helper_writer, rt.ID == model.List.OriginalRequest.RequestTypeFilter ? " Selected" : ""); #line default #line hidden WriteLiteralTo(@__razor_helper_writer, "\">"); #line 27 "..\..\App_Code\RequestHelpers.cshtml" WriteTo(@__razor_helper_writer, rt.Name); #line default #line hidden WriteLiteralTo(@__razor_helper_writer, "</a>\r\n"); #line 28 "..\..\App_Code\RequestHelpers.cshtml" } #line default #line hidden WriteLiteralTo(@__razor_helper_writer, " </div>\r\n"); #line 30 "..\..\App_Code\RequestHelpers.cshtml" #line default #line hidden })); }
public static System.Web.IHtmlString DtxTimeDifference (this System.Web.Mvc.HtmlHelper helper, System.DateTime dateTime) { string strResult = string.Empty; System.DateTime dtmNow = System.DateTime.Now; if (dtmNow <= dateTime) { return(helper.Raw(string.Empty)); } System.TimeSpan dtmDifference = dtmNow - dateTime; if (dtmDifference < new System.TimeSpan(0, 1, 0)) { strResult = string.Format("{0} ثانيه قبل", dtmDifference.Seconds); return(helper.Raw(strResult)); } if (dtmDifference < new System.TimeSpan(1, 0, 0)) { strResult = string.Format("{0} دقيقه قبل", dtmDifference.Minutes); return(helper.Raw(strResult)); } if (dtmDifference < new System.TimeSpan(1, 0, 0, 0)) { strResult = string.Format("{0} ساعت و {1} دقيقه قبل", dtmDifference.Hours, dtmDifference.Minutes); return(helper.Raw(strResult)); } if (dtmDifference < new System.TimeSpan(2, 0, 0, 0)) { strResult = "ديروز"; return(helper.Raw(strResult)); } if (dtmDifference < new System.TimeSpan(7, 0, 0, 0)) { switch (dateTime.DayOfWeek) { case System.DayOfWeek.Saturday: { strResult = "شنبه"; break; } case System.DayOfWeek.Sunday: { strResult = "يکشنبه"; break; } case System.DayOfWeek.Monday: { strResult = "دوشنبه"; break; } case System.DayOfWeek.Tuesday: { strResult = "سه شنبه"; break; } case System.DayOfWeek.Wednesday: { strResult = "چهارشنبه"; break; } case System.DayOfWeek.Thursday: { strResult = "پنجشنبه"; break; } case System.DayOfWeek.Friday: { strResult = "جمعه"; break; } } return(helper.Raw(strResult)); } System.Globalization.PersianCalendar oPersianCalendar = new System.Globalization.PersianCalendar(); int intMonth = oPersianCalendar.GetMonth(dateTime); int intDay = oPersianCalendar.GetDayOfMonth(dateTime); string strMonth = string.Empty; switch (intMonth) { case 1: { strMonth = "فروردين"; break; } case 2: { strMonth = "ارديبهشت"; break; } case 3: { strMonth = "خرداد"; break; } case 4: { strMonth = "تير"; break; } case 5: { strMonth = "مرداد"; break; } case 6: { strMonth = "شهريور"; break; } case 7: { strMonth = "مهر"; break; } case 8: { strMonth = "آبان"; break; } case 9: { strMonth = "آذر"; break; } case 10: { strMonth = "دی"; break; } case 11: { strMonth = "بهمن"; break; } case 12: { strMonth = "اسفند"; break; } } strResult = string.Format("{0} {1}", intDay, strMonth); return(helper.Raw(strResult)); }
/// <summary> /// Translates a text in the admin tool /// </summary> public static IHtmlString TA(this System.Web.Mvc.HtmlHelper html, string text, params Object[] args) { return(html.Raw(args == null ? text.TA() : string.Format(text.TA(), args))); }
public static System.Web.IHtmlString DtxHorizontalLine(this System.Web.Mvc.HtmlHelper htmlHelper) { string result = "<hr />"; return(htmlHelper.Raw(result)); }
//public static System.Web.IHtmlString DtxCaptcha // (this System.Web.Mvc.HtmlHelper html, // int labelColumn = 3) //{ // string result = string.Empty; // if (Settings.Instance.DisplayCaptchaImage) // { // result += // "<div class=\"form-group\">"; // string caption = // Resources.DataDictionary.SecurityCode; // if ((labelColumn >= 1) && (labelColumn <= 12)) // { // result += // $"<label class=\"control-label col-sm-{ labelColumn }\">{ caption }</label>"; // } // else // { // result += // $"<label class=\"control-label\">{ caption }</label>"; // } // result += // $"<div class=\"col-sm-{ 12 - labelColumn }\">"; // result += // html.Captcha(6, MVC.Shared.Views.PartialViews._DisplayCaptchaImage) // .ToHtmlString(); // result += "</div>"; // result += "</div>"; // } // return html.Raw(result); //} public static System.Web.IHtmlString DtxDisplayNameAndValueFor <TModel, TValue> (this System.Web.Mvc.HtmlHelper <TModel> html, System.Linq.Expressions.Expression <System.Func <TModel, TValue> > expression, Enums.DisplayValueType displayValueType = Enums.DisplayValueType.Undefined, int labelColumn = 3, string caption = null //System.Web.Mvc.ActionResult actionResult = null ) { //System.Web.Mvc.IT4MVCActionResult oT4MVCActionResult = null; //if (actionResult != null) //{ // oT4MVCActionResult = // actionResult as System.Web.Mvc.IT4MVCActionResult; // if (oT4MVCActionResult == null) // { // return null; // } //} string result = "<div class='row'>"; System.Web.Mvc.ModelMetadata modelMetadata = System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData); // ************************************************** string labelStyle = "background-color: #f5f5f5; color: black; margin: 0px; padding: 4px; border: 1px solid darkgray"; string htmlFieldName = System.Web.Mvc.ExpressionHelper.GetExpressionText(expression); if (string.IsNullOrWhiteSpace(caption)) { caption = modelMetadata.DisplayName ?? modelMetadata.PropertyName ?? htmlFieldName.Split('.').Last(); } result += string.Format("<div class='col-sm-{0}' style='{1}'>", labelColumn, labelStyle); result += caption; result += "</div>"; // ************************************************** result += string.Format("<div class='col-sm-{0}'>", 12 - labelColumn); object valueObject = modelMetadata.Model; string valueString; if (valueObject == null) { valueString = Dtx.Constant.DISPLAY_NULL_VALUE; } else { switch (displayValueType) { case Enums.DisplayValueType.Number: { valueString = Convert.Number(valueObject); break; } case Enums.DisplayValueType.Percent: { valueString = Convert.Number(valueObject); valueString += " " + Resources.DataDictionary.Percent; break; } case Enums.DisplayValueType.Currency: { valueString = Convert.Number(valueObject); valueString += " " + Resources.DataDictionary.Currency; break; } case Enums.DisplayValueType.Date: { try { System.DateTime dateTime = System.Convert.ToDateTime(valueObject); valueString = Convert.DateTime(dateTime, displayTime: false); } catch (System.Exception ex) { valueString = Dtx.Constant.DISPLAY_NULL_VALUE; //Dtx.Logger.LogError // (type: typeof(CustomHtmlHelper), exception: ex); } break; } case Enums.DisplayValueType.DateTime: { try { System.DateTime dateTime = System.Convert.ToDateTime(valueObject); valueString = Convert.DateTime(dateTime, displayTime: true); } catch (System.Exception ex) { valueString = Dtx.Constant.DISPLAY_NULL_VALUE; //Dtx.Logger.LogError // (type: typeof(CustomHtmlHelper), exception: ex); } break; } case Enums.DisplayValueType.Raw: { valueString = html.Raw(valueObject).ToHtmlString(); break; } case Enums.DisplayValueType.Url: { valueString = string.Format("<a href='{0}'>{0}</a>", valueObject); break; } case Enums.DisplayValueType.EmailAddress: { valueString = string.Format("<a href='mailto:{0}'>{0}</a>", valueObject); break; } default: { valueString = html.DisplayFor(expression).ToHtmlString(); break; } } } result += valueString; //if (actionResult == null) //{ // result += valueString; //} //else //{ // System.Web.Mvc.UrlHelper oUrlHelper = // new System.Web.Mvc.UrlHelper(html.ViewContext.RequestContext); // //strResult += oUrlHelper.Action // // (oT4MVCActionResult.Action, // // oT4MVCActionResult.Controller, // // oT4MVCActionResult.RouteValueDictionary); // result += // html.ActionLink(linkText: valueString, // actionName: oT4MVCActionResult.Action, // controllerName: oT4MVCActionResult.Controller, // routeValues: oT4MVCActionResult.RouteValueDictionary, // htmlAttributes: null); //} result += " </div>"; result += "</div>"; return(html.Raw(result)); }
public static System.Web.IHtmlString DtxLabelAndDropDownListFor <TModel, TValue> (this System.Web.Mvc.HtmlHelper <TModel> html, System.Linq.Expressions.Expression <System.Func <TModel, TValue> > expression, int labelColumn = 3, bool readOnly = false, //bool leftToRight = false, string optionLabel = null) { string result = string.Empty; // ************************************************** string cssClass = "form-control"; //if (leftToRight) //{ // cssClass = // string.Format("{0} ltr", cssClass); //} // ************************************************** result += "<div class=\"form-group\">"; result += DtxLabelFor(html: html, expression: expression, column: labelColumn); result += $"<div class=\"col-sm-{ 12 - labelColumn }\">"; // ************************************************** System.Web.Mvc.ModelMetadata modelMetadata = System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData); string htmlFieldName = System.Web.Mvc.ExpressionHelper.GetExpressionText(expression); // ************************************************** // ************************************************** object htmlAttributes = null; if (readOnly) { optionLabel = null; // TODO: تست شود که کدامیک از دو دستور مناسب است //htmlAttributes = // new { @class = cssClass, disabled = "disabled" }; // TODO: تست شود که کدامیک از دو دستور مناسب است htmlAttributes = new { @class = cssClass, @readonly = "readonly" }; } else { if (modelMetadata.IsRequired == false) { if (optionLabel == null) { optionLabel = Resources.Messages.YouCanSelectAnItem; } htmlAttributes = new { @class = cssClass }; } else { if (optionLabel == null) { optionLabel = Resources.Messages.YouShouldSelectAnItem; } // ************************************************** string errorMessage = Resources.Messages.RequiredValidationErrorMessage; string displayName = modelMetadata.DisplayName ?? modelMetadata.PropertyName ?? htmlFieldName.Split('.').Last(); if (string.IsNullOrWhiteSpace(displayName) == false) { errorMessage = string.Format(Resources.Messages.RequiredValidationErrorMessage, displayName); } // ************************************************** htmlAttributes = new { @class = cssClass, data_val = "true", data_val_required = errorMessage }; } } // ************************************************** string dropDownList = html.DropDownList (name: htmlFieldName, selectList: null, optionLabel: optionLabel, htmlAttributes: htmlAttributes) .ToHtmlString(); result += dropDownList; var validationHtmlAttributes = new { @class = "text-danger" }; string validationMessageFor = html.ValidationMessageFor(expression: expression, validationMessage: string.Empty, htmlAttributes: validationHtmlAttributes) .ToHtmlString(); result += validationMessageFor; result += "</div>"; result += "</div>"; return(html.Raw(result)); }
public static System.Web.IHtmlString DtxLabelAndEditorFor <TModel, TValue> (this System.Web.Mvc.HtmlHelper <TModel> html, System.Linq.Expressions.Expression <System.Func <TModel, TValue> > expression, int labelColumn = 3, bool readOnly = false, //object additionalViewData = null, int hintColumn = 0, string hint = null //bool leftToRight = false ) { string result = string.Empty; System.Web.Mvc.ModelMetadata modelMetadata = System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData); //string htmlFieldName = // System.Web.Mvc.ExpressionHelper.GetExpressionText(expression); bool isBoolean = false; if (modelMetadata.ModelType == typeof(bool)) { isBoolean = true; } //if (leftToRight) //{ // editorAttributes.Add("class", "ltr"); //} result += "<div class=\"form-group\">"; result += DtxLabelFor(html, expression: expression, column: labelColumn); result += $"<div class=\"col-sm-{ 12 - labelColumn - hintColumn }\">"; object htmlAttributes = null; if (readOnly == false) { if (isBoolean == false) { htmlAttributes = new { @class = "form-control", }; } } else { if (isBoolean == false) { htmlAttributes = new { @readonly = "readonly", @class = "form-control", }; } else { htmlAttributes = new { @disabled = "disabled", }; } } var viewData = new { htmlAttributes }; // دستور ذیل در استانداردهای مایکروسافت وجود ندارد ولی در گوشی مبایل خیلی جذاب دیده نمیشود //if (isBoolean) //{ // result += "<div class=\"checkbox\">"; //} string editorFor = html.EditorFor(expression: expression, additionalViewData: viewData) .ToHtmlString(); result += editorFor; var validationHtmlAttributes = new { @class = "text-danger" }; string validationMessageFor = html.ValidationMessageFor(expression: expression, validationMessage: string.Empty, htmlAttributes: validationHtmlAttributes) .ToHtmlString(); result += validationMessageFor; // دستور ذیل در استانداردهای مایکروسافت وجود ندارد ولی در گوشی مبایل خیلی جذاب دیده نمیشود //if (isBoolean) //{ // result += "</div>"; //} result += "</div>"; if (hintColumn > 0) { result += DtxLabel(html, labelText: hint, column: hintColumn); //result += // $"<div class=\"col-sm-{ hintColumn }\">"; //if (string.IsNullOrWhiteSpace(hint) == false) //{ // result += hint.Trim(); //} //result += "</div>"; } result += "</div>"; return(html.Raw(result)); }