public static MvcHtmlString KingRadioButtonListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string name, IEnumerable <SelectListItem> dataScource, ValidateOptions validateOption = null, RepeatDirection repeatDirection = 0, object htmlAttributes = null, bool IsDefaultStyle = true, bool readOnly = false)
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, htmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            IDictionary <string, object> unobtrusiveValidationAttributes = htmlHelper.GetUnobtrusiveValidationAttributes(expressionText, metadata);
            string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);
            string defaultValue      = "";

            if (ValidateCommon.GetModelType(metadata.ModelType) == typeof(bool))
            {
                if (metadata.Model != null)
                {
                    defaultValue = ((bool)metadata.Model) ? "1" : "0";
                }
                else
                {
                    defaultValue = "0";
                }
            }
            else
            {
                defaultValue = (metadata.Model == null) ? "" : metadata.Model.ToString();
            }
            return(MvcHtmlString.Create(GenerateHtml(name, dataScource, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), repeatDirection, defaultValue, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
        private static string GetSelect(HtmlHelper html, string name, string Value, bool IsShowEmptyItem, object htmlAttribute, IEnumerable <SelectListItem> list, ValidateOptions validateOptions, string onselect)
        {
            TagBuilder    builder2;
            ComboboxModel model = new ComboboxModel {
                Name         = name.Replace(".", "_"),
                SelectedFunc = (onselect == null) ? "" : onselect
            };

            html.RenderPartial("~/Views/ControlScripts/_ComboboxScripts.cshtml", model);
            TagBuilder builder = new TagBuilder("select");

            builder.GenerateId(name);
            builder.MergeAttribute("name", name);
            builder.MergeAttributes <string, object>(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute));
            if (validateOptions != null)
            {
                builder.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            if (IsShowEmptyItem)
            {
                builder2 = new TagBuilder("option");
                if (string.IsNullOrEmpty(Value))
                {
                    builder2.MergeAttribute("selected", "selected");
                }
                builder2.MergeAttribute("value", " ");
                builder2.SetInnerText("--请选择--");
                builder.InnerHtml = builder.InnerHtml + builder2.ToString();
            }
            foreach (SelectListItem item in list)
            {
                builder2 = new TagBuilder("option");
                builder2.MergeAttribute("value", item.Value);
                builder2.SetInnerText(item.Text);
                if (string.IsNullOrEmpty(Value) && item.Selected)
                {
                    Value = item.Value;
                }
                if (item.Value == Value)
                {
                    builder2.MergeAttribute("selected", "selected");
                }
                builder.InnerHtml = builder.InnerHtml + builder2.ToString();
            }
            bool flag = false;

            if ((validateOptions != null) && validateOptions.Required)
            {
                flag = true;
            }
            return((flag ? "<span class='star'>*</span>" : "<span class='star'>&nbsp</span>") + builder.ToString());
        }
        private static string GetTextBoxMvcHtml(string name, string value, IDictionary <string, object> htmlAttribute, ValidateOptions validateOptions, bool readOnly)
        {
            TagBuilder builder = new TagBuilder("input");

            builder.GenerateId(name);
            builder.MergeAttribute("name", name);
            builder.MergeAttribute("type", "text");
            if (!string.IsNullOrEmpty(value))
            {
                builder.MergeAttribute("value", value);
            }
            if (readOnly)
            {
                builder.MergeAttribute("readonly", "readonly");
                string str = string.Empty;
                if ((htmlAttribute != null) && (htmlAttribute.Count > 0))
                {
                    if (htmlAttribute.ContainsKey("style"))
                    {
                        object obj2 = null;
                        if (htmlAttribute.TryGetValue("style", out obj2))
                        {
                            str = obj2.ToString().TrimEnd(new char[] { ';' });
                        }
                        str = str + ";background-color: #DFDFDF;";
                        htmlAttribute.Remove("style");
                        htmlAttribute.Add("style", str);
                    }
                    else
                    {
                        htmlAttribute.Add("style", "background-color: #DFDFDF");
                    }
                }
                else
                {
                    htmlAttribute.Add("style", "background-color: #DFDFDF");
                }
            }
            builder.MergeAttributes <string, object>(htmlAttribute);
            bool flag = false;

            if (validateOptions != null)
            {
                builder.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (validateOptions.Required)
                {
                    flag = true;
                }
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            return((flag ? "<span class='star'>*</span>" : "<span class='star'>&nbsp</span>") + builder.ToString());
        }
Exemplo n.º 4
0
        public static string GenerateCheckBoxHtml(string name, string id, string labelText, string value, bool isChecked, IDictionary <string, object> htmlAttributes, ValidateOptions validateOptions, bool readOnly)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("<div class='checkbox_label'>");
            TagBuilder builder2 = new TagBuilder("label");

            builder2.MergeAttribute("for", id);
            builder2.SetInnerText(labelText);
            TagBuilder builder3 = new TagBuilder("input");

            builder3.GenerateId(id);
            builder3.MergeAttribute("name", name);
            builder3.MergeAttribute("custom", "big");
            builder3.MergeAttribute("type", "checkbox");
            builder3.MergeAttribute("value", value);
            if (readOnly)
            {
                builder3.MergeAttribute("disabled", "disabled");
            }
            builder3.MergeAttributes <string, object>(htmlAttributes);
            if (readOnly)
            {
                builder3.MergeAttribute("onclick", "return false;");
            }
            if (isChecked)
            {
                builder3.MergeAttribute("checked", "checked");
            }
            if (validateOptions != null)
            {
                builder3.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder3.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            builder.AppendLine("<span>" + builder3.ToString() + "</span>");
            builder.AppendLine(builder2.ToString());
            builder.AppendLine("</div>");
            return(builder.ToString());
        }
        public static MvcHtmlString KingRadioButtonListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string name, ValidateOptions validateOption = null, RepeatDirection repeatDirection = 0, object htmlAttributes = null, bool IsDefaultStyle = true, bool readOnly = false)
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, htmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            IDictionary <string, object> unobtrusiveValidationAttributes = htmlHelper.GetUnobtrusiveValidationAttributes(expressionText, metadata);
            string fullHtmlFieldName           = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);
            IEnumerable <SelectListItem> items = null;
            string defaultValue = "";
            Type   modelType    = ValidateCommon.GetModelType(metadata.ModelType);

            if (modelType.IsEnum)
            {
                items = new SelectList(MvcHtmlStringCommon.GetEnumToSelectList(modelType).AsEnumerable <SelectListItem>(), "Value", "Text");
            }
            else if (modelType == typeof(bool))
            {
                if (metadata.Model != null)
                {
                    defaultValue = ((bool)metadata.Model) ? "1" : "0";
                }
                else
                {
                    defaultValue = "0";
                }
                SelectListItem item = new SelectListItem {
                    Value = "1",
                    Text  = "是"
                };
                SelectListItem item2 = new SelectListItem {
                    Value = "0",
                    Text  = "否"
                };
                items = new List <SelectListItem> {
                    item,
                    item2
                };
            }
            return(MvcHtmlString.Create(GenerateHtml(name, items, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), repeatDirection, defaultValue, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
Exemplo n.º 6
0
        private static MvcHtmlString GetDatePickerHtml(HtmlHelper html, string name, DateEnum dateEnum, string value, ValidateOptions validateOptions)
        {
            DatePicketModel model = new DatePicketModel {
                Name     = name,
                DateType = dateEnum
            };

            html.RenderPartial("~/Views/ControlScripts/_DatePicketScripts.cshtml", model);
            List <string> keyList  = new List <string>();
            StringBuilder builder  = new StringBuilder();
            TagBuilder    builder2 = new TagBuilder("input");

            builder2.GenerateId(name);
            builder2.MergeAttribute("type", "text");
            builder2.MergeAttribute("name", name);
            builder2.MergeAttribute("readonly", "readonly");
            if (!string.IsNullOrEmpty(value))
            {
                builder2.MergeAttribute("value", value);
            }
            bool flag = false;

            if (validateOptions != null)
            {
                builder2.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (validateOptions.Required)
                {
                    flag = true;
                }
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder2.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            builder.AppendLine(builder2.ToString());
            builder.AppendLine(CtrlScripts.RenderScript(html, keyList));
            return(MvcHtmlString.Create((flag ? "<span class='star'>*</span>" : "<span class='star'>&nbsp</span>") + builder.ToString()));
        }
Exemplo n.º 7
0
        public static MvcHtmlString KingCheckBoxListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, string name = null, object Value = null, ValidateOptions validateOptions = null, bool IsDefaultStyle = true, object htmlAttribute = null, bool readOnly = false)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TValue>(expression, htmlHelper.ViewData);

            if (string.IsNullOrEmpty(name))
            {
                name = ExpressionHelper.GetExpressionText(expression);
            }
            IEnumerable <SelectListItem> items = null;

            if (Value == null)
            {
                Value = metadata.Model;
            }
            Type modelType = ValidateCommon.GetModelType(metadata.ModelType);

            if (modelType.IsEnum)
            {
                items = new SelectList(MvcHtmlStringCommon.GetEnumToSelectList(modelType).AsEnumerable <SelectListItem>(), "Value", "Text");
            }
            else if (modelType == typeof(bool))
            {
                SelectListItem item = new SelectListItem {
                    Text  = "",
                    Value = "1"
                };
                List <SelectListItem> list = new List <SelectListItem> {
                    item
                };
                if (metadata.Model != null)
                {
                    Value = ((bool)metadata.Model) ? "1" : "0";
                }
                items = new SelectList(list, "Value", "Text");
            }
            return(MvcHtmlString.Create(GenerateHtml(name, items, htmlAttribute, Value, validateOptions, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
        public static MvcHtmlString KingComboboxFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, string name = null, string Value = null, bool IsShowEmptyItem = true, ValidateOptions validateOptions = null, object htmlAttribute = null, string onselect = null)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TValue>(expression, html.ViewData);

            if (string.IsNullOrEmpty(name))
            {
                name = ExpressionHelper.GetExpressionText(expression);
            }
            if (string.IsNullOrEmpty(Value) && (metadata.Model != null))
            {
                Value = metadata.Model.ToString();
            }
            IEnumerable <SelectListItem> list = null;
            Type modelType = ValidateCommon.GetModelType(metadata.ModelType);

            if (modelType.IsEnum)
            {
                list = MvcHtmlStringCommon.GetEnumToSelectList(modelType);
            }
            else if (modelType == typeof(bool))
            {
                SelectListItem item = new SelectListItem {
                    Value = "1",
                    Text  = "是"
                };
                SelectListItem item2 = new SelectListItem {
                    Value = "0",
                    Text  = "否"
                };
                list = new List <SelectListItem> {
                    item,
                    item2
                };
            }
            return(MvcHtmlString.Create(GetSelect(html, name, Value, IsShowEmptyItem, htmlAttribute, list, validateOptions, onselect) + AddJs <TModel, TValue>(html)));
        }
        private static MvcHtmlString GetSelectUserHtml(HtmlHelper html, string name, List <ITreeData> data, string GetLeafURL, string CallBackMethod, UserStyle userStyle, OpenNoteEnum openNote, ValidateOptions validateOptions, string value)
        {
            BizDataContext       context;
            List <string>        keyList    = new List <string>();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            StringBuilder        builder    = new StringBuilder();
            TagBuilder           builder2   = new TagBuilder("div");

            builder2.GenerateId(name);
            builder2.AddCssClass("treeDiv");
            TagBuilder builder3 = GetTagBuilder("ul", name, "ztree");

            builder3.MergeAttribute("style", "display : none;");
            builder2.InnerHtml = builder2.InnerHtml + builder3;
            TagBuilder builder4 = GetTagBuilder("div", name, "dataHF");

            builder4.MergeAttribute("style", "display:none;");
            if ((data != null) && (data.Count > 0))
            {
                data = DealWithNoteOpenState(data, openNote);
                builder4.InnerHtml = builder4.InnerHtml + serializer.Serialize(data);
            }
            else
            {
                using (context = new BizDataContext(true))
                {
                    ParameterExpression expression;
                    // List<ITreeData> list2 = DealWithNoteOpenState(context.Set<T_Department>().
                    //    Select<T_Department, TreeData>(Expression.Lambda<Func<T_Department, TreeData>>(Expression.MemberInit(Expression.New((ConstructorInfo) methodof(TreeData..ctor), new Expression[0]), new MemberBinding[] { Expression.Bind((MethodInfo) methodof(TreeData.set_id), Expression.Property(expression = Expression.Parameter(typeof(T_Department), "u"), (MethodInfo) methodof(T_Department.get_Department_ID))), Expression.Bind((MethodInfo) methodof(TreeData.set_name), Expression.Property(expression, (MethodInfo) methodof(T_Department.get_Department_Name))), Expression.Bind((MethodInfo) methodof(TreeData.set_open), Expression.Constant(false, typeof(bool))), Expression.Bind((MethodInfo) methodof(TreeData.set_pId), Expression.Coalesce(Expression.Property(expression, (MethodInfo) methodof(T_Department.get_Parent_ID)), Expression.Constant(-1, typeof(int)))) }), new ParameterExpression[] { expression })).ToList<ITreeData>(), openNote);
                    //builder4.InnerHtml = builder4.InnerHtml + serializer.Serialize(list2);
                }
            }
            builder2.InnerHtml = builder2.InnerHtml + builder4;
            TagBuilder builder5 = GetTagBuilder("input", name, "resultInput");

            if (userStyle == UserStyle.Normal)
            {
                builder5.MergeAttribute("style", "float: left;");
            }
            else
            {
                builder5.MergeAttribute("style", "float: left;display:none");
            }
            builder5.MergeAttribute("type", "text");
            if (validateOptions != null)
            {
                builder5.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder5.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            builder5.MergeAttribute("readonly", "true");
            TagBuilder builder6 = GetTagBuilder("input", name, "resultHf");

            builder6.MergeAttribute("type", "hidden");
            builder2.InnerHtml = builder2.InnerHtml + builder5;
            builder2.InnerHtml = builder2.InnerHtml + builder6;
            TagBuilder builder7 = GetTagBuilder("input", name, "treeButton");

            builder7.MergeAttribute("type", "button");
            builder7.MergeAttribute("value", "选择");
            builder7.MergeAttribute("treeName", name);
            builder2.InnerHtml = builder2.InnerHtml + builder7;
            TagBuilder builder8 = GetTagBuilder("input", name, "selectedIDHf");

            builder8.MergeAttribute("type", "hidden");
            string str = string.Empty;

            if (!string.IsNullOrEmpty(value))
            {
                string[] strArray = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                using (context = new BizDataContext(true))
                {
                    IEnumerable <string> values = from u in context.FetchAll <T_User>()
                                                  join suid in strArray on u.User_ID.ToString() equals suid
                                                  select u.User_Name;

                    str = string.Join(",", values);
                }
                builder8.MergeAttribute("value", value);
            }
            builder2.InnerHtml = builder2.InnerHtml + builder8;
            TagBuilder builder9 = GetTagBuilder("input", name, "selectedNameHF");

            builder9.MergeAttribute("type", "hidden");
            builder9.MergeAttribute("value", str);
            builder2.InnerHtml = builder2.InnerHtml + builder9;
            TagBuilder builder10 = GetTagBuilder("input", name, "configDataHF");

            builder10.MergeAttribute("type", "hidden");
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("GetLeafURL", GetLeafURL);
            dictionary.Add("CallBackMethod", CallBackMethod);
            builder10.MergeAttribute("value", serializer.Serialize(dictionary));
            builder2.InnerHtml = builder2.InnerHtml + builder10;
            builder.AppendLine(builder2.ToString());
            builder.AppendLine(CtrlScripts.RenderScript(html, keyList));
            return(MvcHtmlString.Create(builder.ToString()));
        }