Ejemplo n.º 1
0
        public string DisplayValue(object value, Tk5FieldInfoEx field, IFieldValueProvider rowValue)
        {
            TkDebug.AssertArgumentNull(field, "field", this);

            if (DisplayUtil.IsNull(value))
            {
                return(string.Empty);
            }

            if (field.Upload != null)
            {
                Tk5UploadConfig   upload    = field.AssertUpload();
                IUploadProcessor2 processor = upload.CreateUploadProcessor2();
                //IFieldValueProvider provider = new DataRowFieldValueProvider(row, row.Table.DataSet);
                string        url     = processor.Display(upload, rowValue);
                HtmlAttribute cssAttr = string.IsNullOrEmpty(CssClass) ? null
                    : new HtmlAttribute("class", CssClass);
                HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
                builder.Add("src", url);
                builder.Add(cssAttr);

                return(string.Format(ObjectUtil.SysCulture, "<img {0} />", builder.CreateAttribute()));
            }
            return(string.Empty);
        }
        string CreateHeadAttrs(IFieldInfoEx field, int index, int sortField, DataRow sortRow)
        {
            HtmlAttributeBuilder builder  = new HtmlAttributeBuilder();
            Tk5FieldInfoEx       tk5Field = field.Convert <Tk5FieldInfoEx>();

            if (tk5Field.DataType == TkDataType.Text || (tk5Field.ListDetail != null && tk5Field.ListDetail.TextHead))
            {
                builder.Add("class", "text-left text-nowrap");
            }
            else
            {
                builder.Add("data-sort", index.ToString());
                string order     = sortRow.GetString("Order");
                string sortClass = string.Empty;
                if (index == sortField)
                {
                    order     = order == "DESC" ? "ASC" : "DESC";
                    sortClass = "sort-" + order;
                }
                builder.Add("data-order", order);
                builder.Add("class", HtmlUtil.MergeClass("text-left text-nowrap", sortClass.ToLower()));
            }

            return(builder.CreateAttribute());
        }
 string CreateColAttrs(IFieldInfoEx field, int index, int sortField)
 {
     Tk5FieldInfoEx tk5Field = field.Convert<Tk5FieldInfoEx>();
     HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
     if (tk5Field.ListDetail != null && tk5Field.ListDetail.ListWidth > 0)
         builder.Add("width", tk5Field.ListDetail.ListWidth);
     if (index == sortField)
         builder.Add((HtmlAttribute)"selected");
     return builder.CreateAttribute();
 }
        string CreateColAttrs(IFieldInfoEx field, int index, int sortField)
        {
            Tk5FieldInfoEx       tk5Field = field.Convert <Tk5FieldInfoEx>();
            HtmlAttributeBuilder builder  = new HtmlAttributeBuilder();

            if (tk5Field.ListDetail != null && tk5Field.ListDetail.ListWidth > 0)
            {
                builder.Add("width", tk5Field.ListDetail.ListWidth);
            }
            if (index == sortField)
            {
                builder.Add((HtmlAttribute)"selected");
            }
            return(builder.CreateAttribute());
        }
    string CreateHeadAttrs(IFieldInfoEx field, int index, int sortField, ListSortInfo sortRow)
    {
        HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
        Tk5FieldInfoEx tk5Field = field.Convert<Tk5FieldInfoEx>();
        builder.Add("class", "text-left text-nowrap");
        //if (tk5Field.DataType == TkDataType.Text || (tk5Field.ListDetail != null && tk5Field.ListDetail.TextHead))
        //{
        //    builder.Add("class", "text-left text-nowrap");
        //}
        //else
        //{
        //    builder.Add("data-sort", index.ToString());
        //    string order = sortRow.Order;
        //    string sortClass = string.Empty;
        //    if (index == sortField)
        //    {
        //        order = order == "DESC" ? "ASC" : "DESC";
        //        sortClass = "sort-" + order;
        //    }
        //    builder.Add("data-order", order);
        //    builder.Add("class", HtmlUtil.MergeClass("text-left text-nowrap", sortClass.ToLower()));
        //}

        return builder.CreateAttribute();
    }
        private static string InternalTextArea(Tk5FieldInfoEx field, DataRow row, HtmlAttribute addition, bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);

            HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
            AddInputAttribute(field, builder);
            AddNormalAttribute(field, builder, field.NickName, needId);
            builder.Add(addition);

            return string.Format(ObjectUtil.SysCulture, "<textarea {0}>{1}</textarea>{2}",
                builder.CreateAttribute(), StringUtil.EscapeHtml(row.GetString(field.NickName)),
                ERROR_LABEL);
        }
Ejemplo n.º 7
0
        public string DisplayValue(object value, Tk5FieldInfoEx field,
                                   IFieldValueProvider rowValue, string linkedValue)
        {
            if (rowValue == null)
            {
                return(linkedValue);
            }

            string linkUrl = HrefDisplayConfig.ResolveRowValue(rowValue, Content);

            if (string.IsNullOrEmpty(linkUrl))
            {
                return(linkedValue);
            }
            else
            {
                linkUrl = AppUtil.ResolveUrl(linkUrl);
            }
            HtmlAttributeBuilder builder = new HtmlAttributeBuilder();

            if (!string.IsNullOrEmpty(Target))
            {
                builder.Add("target", Target);
            }
            builder.Add("href", "#");
            string urlName = Mode == DisplayMode.Normal ? "data-url" : "data-dialog-url";

            builder.Add(urlName, linkUrl);
            if (Mode == DisplayMode.Dialog && !string.IsNullOrEmpty(DialogTitle))
            {
                string title = HrefDisplayConfig.ResolveRowValue(rowValue, DialogTitle);
                builder.Add("data-title", title);
            }

            return(string.Format(ObjectUtil.SysCulture, "<a {0}>{1}</a>", builder.CreateAttribute(),
                                 StringUtil.EscapeHtml(linkedValue)));
        }
        public static string Upload(this Tk5FieldInfoEx field, DataRow row, bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);

            var upload = field.AssertUpload();

            HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
            builder.Add("data-control", "Upload");
            builder.Add("data-fileSize", upload.SizeField);
            builder.Add("data-serverPath", upload.ServerPathField);
            builder.Add("data-contentType", upload.MimeTypeField);
            AddNormalAttribute(field, builder, field.NickName, needId, true);

            IUploadProcessor processor = upload.CreateUploadProcessor();
            UploadInfo info = row == null ? null : processor.CreateValue(upload, row);
            if (info != null)
                builder.Add("data-value", info.ToJson());

            return string.Format(ObjectUtil.SysCulture, Html.Upload, builder.CreateAttribute(),
                ERROR_LABEL);
        }
        public static string Detail(this Tk5FieldInfoEx field, DataRow row, bool showHint, bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);

            HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
            AddNormalAttribute(field, builder, field.NickName, needId, true);
            builder.Add("data-value", row.GetString(field.NickName));
            HtmlAttribute classAttr = builder["class"];
            if (classAttr == null)
                builder.Add("class", "detail-content");
            else
                classAttr.Value = HtmlUtil.MergeClass(classAttr.Value, "detail-content");
            return string.Format(ObjectUtil.SysCulture, "<div {0}>{1}</div>",
                builder.CreateAttribute(), DisplayValue(field, row, showHint));
        }
        private static string InternalMultiEasySearch(Tk5FieldInfoEx field, string nickName, DataRow row, bool needId)
        {
            HtmlAttributeBuilder textBuilder = new HtmlAttributeBuilder();
            textBuilder.Add("type", "text");
            textBuilder.Add("data-regName", field.Decoder.RegName);
            AddInputAttribute(field, textBuilder);
            AddNormalAttribute(field, textBuilder, nickName, needId);
            StringBuilder multiItems = new StringBuilder();
            string decodeValue = row.GetString(nickName + "_Name");
            if (string.IsNullOrEmpty(decodeValue))
                multiItems.AppendFormat(Html.MultiEasySearchItem, "hidden", string.Empty, string.Empty);
            else
            {
                MultipleDecoderData data = MultipleDecoderData.ReadFromString(decodeValue);
                HtmlAttributeBuilder decodeBuilder = new HtmlAttributeBuilder();
                foreach (var item in data)
                {
                    decodeBuilder.Clear();
                    decodeBuilder.Add("data-id", item.Value);
                    decodeBuilder.Add("data-name", item.Name);

                    multiItems.AppendFormat(Html.MultiEasySearchItem, "multi-item", 
                        item.Name, decodeBuilder.CreateAttribute());
                }
            }

            string easyUrl = "Library/WebModuleContentPage.tkx?Source=EasySearch&useSource=true".AppVirutalPath();
            string dialogUrl = ("Library/WebModuleRedirectPage.tkx?Source=EasySearchRedirect&useSource=true&RegName="
                + field.Decoder.RegName).AppVirutalPath();

            return string.Format(ObjectUtil.SysCulture, Html.MultipleEasySearch,
                multiItems, textBuilder.CreateAttribute(), ERROR_LABEL,
                StringUtil.EscapeHtmlAttribute(easyUrl), StringUtil.EscapeHtmlAttribute(dialogUrl));
        }
        private static string InternalEasySearch(Tk5FieldInfoEx field, string nickName, DataRow row, bool needId)
        {
            HtmlAttributeBuilder hiddenBuilder = new HtmlAttributeBuilder();
            hiddenBuilder.Add("type", "hidden");
            hiddenBuilder.Add("value", row.GetString(nickName));
            string hiddenName = "hd" + nickName;
            if (needId)
                hiddenBuilder.Add("id", hiddenName);
            hiddenBuilder.Add("name", hiddenName);
            HtmlAttributeBuilder textBuilder = new HtmlAttributeBuilder();
            textBuilder.Add("type", "text");
            textBuilder.Add("data-regName", field.Decoder.RegName);
            AddInputAttribute(field, textBuilder);
            AddNormalAttribute(field, textBuilder, nickName, needId);
            textBuilder.Add("value", row.GetString(nickName + "_Name"));

            string easyUrl = "Library/WebModuleContentPage.tkx?Source=EasySearch&useSource=true".AppVirutalPath();
            string dialogUrl = ("Library/WebModuleRedirectPage.tkx?Source=EasySearchRedirect&useSource=true&RegName="
                + field.Decoder.RegName).AppVirutalPath();

            return string.Format(ObjectUtil.SysCulture, Html.EasySearch,
                hiddenBuilder.CreateAttribute(), textBuilder.CreateAttribute(), ERROR_LABEL,
                StringUtil.EscapeHtmlAttribute(easyUrl), StringUtil.EscapeHtmlAttribute(dialogUrl));
        }
 private static HtmlAttributeBuilder InternalCheckBox(Tk5FieldInfoEx field, DataRow row, bool needId)
 {
     string checkValue;
     string uncheckValue;
     GetCheckValue(field, out checkValue, out uncheckValue);
     HtmlAttributeBuilder builder = new HtmlAttributeBuilder();
     builder.Add("type", "checkbox");
     builder.Add("value", checkValue);
     builder.Add("data-uncheck-value", uncheckValue);
     if (row.GetString(field.NickName) == checkValue)
         builder.Add((HtmlAttribute)"checked");
     AddNormalAttribute(field, builder, field.NickName, needId, true);
     return builder;
 }
        public static string CheckBoxList(this Tk5FieldInfoEx field, DataRow row, DataSet model, bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);
            TkDebug.AssertArgumentNull(model, "model", null);

            TkDebug.AssertNotNull(field.Decoder, "CheckBoxList控件需要配置Decoder", field);
            DataTable codeTable = model.Tables[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.GetString(field.NickName);
                QuoteStringList quoteValue = QuoteStringList.FromString(value);
                options.AppendFormat(ObjectUtil.SysCulture, "<div {0}>\r\n", divBuilder.CreateAttribute());
                foreach (DataRow codeRow in codeTable.Rows)
                {
                    builder.Clear();
                    string codeValue = codeRow.GetString("Value");
                    builder.Add("value", codeValue);
                    if (quoteValue.Contains(codeValue))
                        builder.Add((HtmlAttribute)"checked");
                    options.AppendFormat(ObjectUtil.SysCulture, Html.CheckBoxListItem,
                        builder.CreateAttribute(), codeRow.GetString("Name"));
                }
                options.Append("</div>").AppendLine(ERROR_LABEL);
            }
            return options.ToString();
        }
        public static string RadioGroup(this Tk5FieldInfoEx field, DataRow row, DataSet model, bool needId)
        {
            TkDebug.AssertArgumentNull(field, "field", null);
            TkDebug.AssertArgumentNull(model, "model", null);

            TkDebug.AssertNotNull(field.Decoder, "RadioGroup控件需要配置Decoder", field);
            DataTable codeTable = model.Tables[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.GetString(field.NickName);
                options.AppendFormat(ObjectUtil.SysCulture, "<div {0}>\r\n", divBuilder.CreateAttribute());
                foreach (DataRow codeRow in codeTable.Rows)
                {
                    string codeValue = codeRow.GetString("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.GetString("Name"));
                }
                options.Append("</div>").AppendLine(ERROR_LABEL);
            }
            return options.ToString();
        }