コード例 #1
0
        private static string InternalCombo(Tk5FieldInfoEx field, string name, IFieldValueProvider row,
                                            bool needId)
        {
            HtmlAttributeBuilder builder = new HtmlAttributeBuilder();

            AddNormalAttribute(field, builder, name, needId);

            TkDebug.AssertNotNull(field.Decoder, "Combo控件需要配置Decoder", field);
            DecoderAdditionInfo[] additions = null;
            if (field.Decoder.Additions != null)
            {
                additions = field.Decoder.Additions.ToArray();
                builder.Add("data-addition", additions.WriteJson());
            }
            //DataTable codeTable = model.Tables[field.Decoder.RegName];
            IEnumerable <IDecoderItem> codeTable = row.GetCodeTable(field.Decoder.RegName);
            StringBuilder options = new StringBuilder();

            if (field.IsEmpty)
            {
                string emptyTitle;
                if (field.Extension != null && field.Extension.EmptyTitle != null)
                {
                    emptyTitle = field.Extension.EmptyTitle;
                }
                else
                {
                    emptyTitle = string.Empty;
                }
                options.Append("<option value=\"\">").Append(emptyTitle).AppendLine("</option>");
            }
            string value = row[name].ToString();

            if (codeTable != null)
            {
                string addition = string.Empty;
                foreach (IDecoderItem codeRow in codeTable)
                {
                    string codeValue = codeRow.Value;
                    if (additions != null)
                    {
                        DecoderAdditionData data = new DecoderAdditionData();
                        data.AddData(codeRow, additions);
                        addition = " " + data.ToJson();
                    }

                    options.AppendFormat(ObjectUtil.SysCulture, "<option value=\"{0}\"{1}{3}>{2}</option>\r\n",
                                         codeValue, codeValue == value ? " selected" : string.Empty, codeRow.Name, addition);
                }
            }

            return(string.Format(ObjectUtil.SysCulture, "<select {0}>{1}</select>{2}",
                                 builder.CreateAttribute(), options, ERROR_LABEL));
        }
コード例 #2
0
        public static string RadioGroup(this Tk5FieldInfoEx field, IFieldValueProvider row,
                                        bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);
            TkDebug.AssertArgumentNull(row, "row", null);

            TkDebug.AssertNotNull(field.Decoder, "RadioGroup控件需要配置Decoder", field);
            var           codeTable = row.GetCodeTable(field.Decoder.RegName);
            StringBuilder options   = new StringBuilder();

            if (codeTable != null)
            {
                HtmlAttributeBuilder divBuilder = new HtmlAttributeBuilder();
                AddNormalAttribute(field, divBuilder, field.NickName, needId, true);
                divBuilder.Add("data-control", "RadioGroup");

                HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
                builder.Add("type", "radio");
                builder.Add("name", field.NickName);
                builder.Add("class", "radio-center");

                string value = row[field.NickName].ToString();
                options.AppendFormat(ObjectUtil.SysCulture, "<div {0}>\r\n", divBuilder.CreateAttribute());
                foreach (var codeRow in codeTable)
                {
                    string codeValue = codeRow.Value;
                    builder.Add("value", codeValue);
                    //options.AppendFormat(ObjectUtil.SysCulture,
                    //    "  <label class=\"checkbox-inline\"><input {0}{1}> {2}</label>\r\n",
                    //    builder.CreateAttribute(), codeValue == value ? " checked" : string.Empty,
                    //    codeRow.Name);
                    options.AppendFormat(ObjectUtil.SysCulture,
                                         "  <div class=\"radio\"><input {0}{1} /><label class=\"radio-label\">{2}</label></div>\r\n",
                                         builder.CreateAttribute(), codeValue == value ? " checked" : string.Empty,
                                         codeRow.Name);
                }
                options.Append("</div>").AppendLine(ERROR_LABEL);
            }
            return(options.ToString());
        }
コード例 #3
0
        public static string CheckBoxList(this Tk5FieldInfoEx field, IFieldValueProvider row, bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);
            TkDebug.AssertArgumentNull(row, "row", null);

            TkDebug.AssertNotNull(field.Decoder, "CheckBoxList控件需要配置Decoder", field);
            var           codeTable = row.GetCodeTable(field.Decoder.RegName);
            StringBuilder options   = new StringBuilder();

            if (codeTable != null)
            {
                HtmlAttributeBuilder divBuilder = new HtmlAttributeBuilder();
                AddNormalAttribute(field, divBuilder, field.NickName, needId, true);
                divBuilder.Add("data-control", "CheckBoxList");

                HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
                //builder.Add("type", "radio");
                //builder.Add("name", field.NickName);
                //builder.Add("class", "radio-center");

                string          value      = row[field.NickName].ToString();
                QuoteStringList quoteValue = QuoteStringList.FromString(value);
                options.AppendFormat(ObjectUtil.SysCulture, "<div {0}>\r\n", divBuilder.CreateAttribute());
                foreach (var codeRow in codeTable)
                {
                    builder.Clear();
                    string codeValue = codeRow.Value;
                    builder.Add("value", codeValue);
                    if (quoteValue.Contains(codeValue))
                    {
                        builder.Add((HtmlAttribute)"checked");
                    }
                    options.AppendFormat(ObjectUtil.SysCulture, Html.CheckBoxListItem,
                                         builder.CreateAttribute(), codeRow.Name);
                }
                options.Append("</div>").AppendLine(ERROR_LABEL);
            }
            return(options.ToString());
        }