Esempio n. 1
0
        public static MvcHtmlString ExtNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression, NumberOption option = null, object htmlAttributes = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            html = HtmlAttributeHelper.AddMaxLength(html, maxLength != 0 ? maxLength : 255);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ''",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add($"vMin: '{option.Min.Value}'");
                }
                if (option.Max.HasValue)
                {
                    options.Add($"vMax: '{option.Max.Value}'");
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add($"aSign: '{option.ASign}'");
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add($"pSign: '{option.PSign}'");
                }
                if (!string.IsNullOrEmpty(option.MRound))
                {
                    options.Add($"mRound: '{option.MRound}'");
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add($"mDec : {option.NumberOfDecimal.Value}");
                }
                if (!option.APad)
                {
                    options.Add("aPad : false");
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine($"$('#{controlId}').autoNumeric('init', {{{optionsStr}}});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Esempio n. 2
0
        public static MvcHtmlString ExtTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                   Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            html = HtmlAttributeHelper.AddMaxLength(html, maxLength != 0 ? maxLength : 255);

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     !string.IsNullOrEmpty(format)
                    ? htmlHelper.TextBoxFor(expression, format, html).ToString()
                    : htmlHelper.TextBoxFor(expression, html).ToString(), expression));
        }
Esempio n. 3
0
        public static MvcHtmlString ExtTextAreaFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextAreaFor(expression, html).ToString(), expression));
        }
Esempio n. 4
0
        public static MvcHtmlString ExtDateTimeFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, DateTimeOption option = null, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            // html.Add("onkeydown", "return false");
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            var controlId     = HtmlAttributeHelper.GetControlIdFromExpression(expression);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='input-group date ' id='dv" + controlId + "'>");
            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());



            var options = new List <string>();

            if (option != null)
            {
                if (!string.IsNullOrEmpty(option.ViewMode))
                {
                    options.Add(string.Format("viewMode: '{0}'", option.ViewMode));
                }
                if (!string.IsNullOrEmpty(option.Format))
                {
                    options.Add(string.Format("format: '{0}'", option.Format));
                    if (option.Format == "LT" || option.Format == "HH:mm" || option.Format == "HH:mm:ss")
                    {
                        stringBuilder.AppendLine("<span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span>");
                    }
                    else
                    {
                        stringBuilder.AppendLine("<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>");
                    }
                }
                if (option.DaysOfWeekDisabled != null)
                {
                    options.Add(string.Format("daysOfWeekDisabled: {0}", option.DaysOfWeekDisabled));
                }
                if (!string.IsNullOrEmpty(option.MinDate))
                {
                    options.Add(string.Format("minDate: {0}", option.MinDate));
                }
                else
                {
                    options.Add(string.Format("minDate: {0}", " moment('01/01/1990')"));
                }
                if (!string.IsNullOrEmpty(option.MaxDate))
                {
                    options.Add(string.Format("maxDate: {0}", option.MaxDate));
                }
                if (option.EnabledHours.HasValue)
                {
                    options.Add(string.Format("enabledHours : '{0}'", option.EnabledHours.Value));
                }
                if (option.ViewDate.HasValue)
                {
                    options.Add(string.Format("viewDate : {0}", option.ViewDate.Value));
                }
                if (option.Inline.HasValue)
                {
                    options.Add(string.Format("inline : {0}", option.Inline.Value));
                }
                // options.Add(string.Format("defaultDate:{0}", DateTime.Now.ToString("d")));
            }
            stringBuilder.AppendLine("</div><script>$(function(){");
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#dv{0}').datetimepicker( {{{1}}});", controlId, optionsStr));
            //stringBuilder.AppendLine(string.Format("$('#{0}').datetimepicker('setDate',{1});", controlId,string.Format( "$('#{0}').val()",controlId)));
            stringBuilder.AppendLine("});</script>");

            if (option != null && option.IsValidationMessageSupported)
            {
                return(new MvcHtmlString(stringBuilder.ToString()));
            }
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }