private static string DateControl(Tk5FieldInfoEx field, string icon, string name, string value, string format, int size, bool needId, bool isSearchCtrl) { HtmlAttributeBuilder groupBuilder = new HtmlAttributeBuilder(); groupBuilder.Add("data-control", field.InternalControl.Control); groupBuilder.Add("data-date-format", format); groupBuilder.Add("data-date", value); HtmlAttributeBuilder inputBuilder = new HtmlAttributeBuilder(); inputBuilder.Add("type", "text"); inputBuilder.Add("size", size); string deletestr; if (!field.ContainAttribute("unreadonly", true)) { inputBuilder.Add((HtmlAttribute)"readonly"); deletestr = Html.DateTimeDelete; } else { deletestr = string.Empty; } AddInputAttribute(field, inputBuilder, isSearchCtrl); AddNormalAttribute(field, inputBuilder, name, needId); inputBuilder.Add("value", value); return(string.Format(ObjectUtil.SysCulture, Html.Datetime, groupBuilder.CreateAttribute(), inputBuilder.CreateAttribute(), icon, ERROR_LABEL, deletestr)); }
public static string HiddenKey(INormalTableData table, IFieldValueProvider provider, bool needId) { TkDebug.AssertArgumentNull(table, "table", null); var keys = from item in table.HiddenList.Union(table.DataList) where item.IsKey select item; StringBuilder builder = new StringBuilder(); HtmlAttributeBuilder attrBuilder = new HtmlAttributeBuilder(); foreach (Tk5FieldInfoEx item in keys) { attrBuilder.Clear(); string value = provider == null ? string.Empty : provider[item.NickName].ToString(); attrBuilder.Add("value", value); attrBuilder.Add("type", "hidden"); string name = "OLD_" + item.NickName; if (needId) { attrBuilder.Add("id", name); } attrBuilder.Add("name", name); builder.AppendFormat("<input {0}/>", attrBuilder.CreateAttribute()); builder.AppendLine(); } return(builder.ToString()); }
public static string Detail(this Tk5FieldInfoEx field, IFieldValueProvider row, bool showHint, bool needId) { TkDebug.AssertArgumentNull(field, "field", null); HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); AddNormalAttribute(field, builder, field.NickName, needId, true); object fieldValue = row[field.NickName]; builder.Add("data-value", fieldValue.ToString()); HtmlAttribute classAttr = builder["class"]; if (classAttr == null) { builder.Add("class", "detail-content"); } else { classAttr.Value = HtmlCommonUtil.MergeClass(classAttr.Value, "detail-content"); } string displayValue = DisplayUtil.GetDisplayString(field.ListDetail.DetailDisplay, fieldValue, field, row); return(string.Format(ObjectUtil.SysCulture, "<div {0}>{1}</div>", builder.CreateAttribute(), displayValue)); }
public static string ShowSearchCheckBox(SearchDataMethod method) { HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); builder.Add("type", "checkbox"); builder.Add("id", "_searchMethod"); string caption; bool isHide = false; if (((int)method & 4) == 4) { builder.Add("class", "vam"); caption = "精确"; } else { isHide = true; builder.Add("class", "hide"); caption = string.Empty; } if ((method & SearchDataMethod.Exactly) == SearchDataMethod.Exactly) { builder.Add((HtmlAttribute)"checked"); } string html = string.Format(ObjectUtil.SysCulture, Html.CheckBox, builder.CreateAttribute(), caption); if (isHide) { return($"<div class=\"hide\">{html}</div>"); } return(html); }
private static string InternalInput(this Tk5FieldInfoEx field, string name, string value, bool needId, bool isSearchCtrl) { TkDebug.AssertArgumentNull(field, "field", null); HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); TkDebug.AssertNotNull(field.InternalControl, "field的InternalControl不能为空", field); builder.Add("type", field.InternalControl.Control); builder.Add("value", value); AddInputAttribute(field, builder, isSearchCtrl); AddNormalAttribute(field, builder, name, needId); if (field.HintPosition == HintPosition.PlaceHolder || string.IsNullOrEmpty(field.Hint)) { return(string.Format(ObjectUtil.SysCulture, "<input {0}/>{1}", builder.CreateAttribute(), ERROR_LABEL)); } else { string format; if (field.HintPosition == HintPosition.Front) { format = Html.InputHintBefore; } else { format = Html.InputHintAfter; } return(string.Format(ObjectUtil.SysCulture, format, builder.CreateAttribute(), ERROR_LABEL, field.Hint)); } }
private static string InternalHidden(Tk5FieldInfoEx field, string value, bool needId) { HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); builder.Add("type", "hidden"); builder.Add("value", value); AddNormalAttribute(field, builder, field.NickName, needId, true); return(string.Format(ObjectUtil.SysCulture, "<input {0}/>", builder.CreateAttribute())); }
public static string Button(string caption, string @class, BootcssButton buttonType, bool block, IEnumerable <HtmlAttribute> attributes) { TkDebug.AssertArgumentNullOrEmpty(caption, "caption", null); HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); string totalClass = GetTotalClass(@class, buttonType, block); builder.Add("type", "button"); builder.Add("class", totalClass); builder.AddRange(attributes); return(string.Format(ObjectUtil.SysCulture, "<button {1}>{0}</button>", caption, builder.CreateAttribute())); }
private static string InternalMultiEasySearch(Tk5FieldInfoEx field, string nickName, IFieldValueProvider row, bool needId) { HtmlAttributeBuilder textBuilder = new HtmlAttributeBuilder(); textBuilder.Add("type", "text"); textBuilder.Add("data-regName", field.Decoder.RegName); AddInputAttribute(field, textBuilder, false); AddNormalAttribute(field, textBuilder, nickName, needId); SimpleFieldDecoder decoder = field.Decoder as SimpleFieldDecoder; if (decoder != null && decoder.RefFields != null) { EasySearchRefConfig[] config = decoder.RefFields.ToArray(); textBuilder.Add("data-refFields", config.WriteJson(WriteSettings.Default)); } StringBuilder multiItems = new StringBuilder(); string decodeValue = row[DecoderConst.DECODER_TAG + nickName].ToString(); 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 = "c/source/C/EasySearch".AppVirutalPath(); string dialogUrl = ("c/~source/C/EasySearchRedirect?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, IFieldValueProvider row, bool needId, bool isSearchCtrl) { HtmlAttributeBuilder hiddenBuilder = new HtmlAttributeBuilder(); hiddenBuilder.Add("type", "hidden"); hiddenBuilder.Add("value", row[nickName].ToString()); 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, isSearchCtrl); AddNormalAttribute(field, textBuilder, nickName, needId); textBuilder.Add("value", row[DecoderConst.DECODER_TAG + nickName]); SimpleFieldDecoder decoder = field.Decoder as SimpleFieldDecoder; if (decoder != null) { if (decoder.RefFields != null) { EasySearchRefConfig[] config = decoder.RefFields.ToArray(); textBuilder.Add("data-refFields", config.WriteJson(WriteSettings.Default)); } if (decoder.Additions != null) { textBuilder.Add("data-addition", decoder.Additions.WriteJson(WriteSettings.Default)); } } string easyUrl = "c/source/C/EasySearch".AppVirutalPath(); string dialogUrl = ("c/~source/C/EasySearchRedirect?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, IFieldValueProvider 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[field.NickName].ConvertToString() == checkValue) { builder.Add((HtmlAttribute)"checked"); } AddNormalAttribute(field, builder, field.NickName, needId, true); return(builder); }
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)); }
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()); }
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()); }
private static void AddInputAttribute(Tk5FieldInfoEx field, HtmlAttributeBuilder builder, bool isSearchCtrl) { string hint = string.IsNullOrEmpty(field.Hint) || field.HintPosition != HintPosition.PlaceHolder ? field.DisplayName : field.Hint; if (!field.IsEmpty) { builder.Add((HtmlAttribute)"required"); if (!isSearchCtrl) { hint += ", 必填"; } } if (field.PlaceHolder) { builder.Add("placeholder", hint); } if (field.Edit != null && field.Edit.ReadOnly) { builder.Add((HtmlAttribute)"readonly"); } }
private static void AddNormalAttribute(Tk5FieldInfoEx field, HtmlAttributeBuilder builder, string name, bool needId, bool isHidden = false) { if (needId) { builder.Add("id", name); } builder.Add("name", name); string editClass = field.Edit == null ? null : field.Edit.Class; if (!isHidden) { builder.Add("class", HtmlCommonUtil.MergeClass("form-control", editClass)); builder.Add("data-title", field.DisplayName); } else if (!string.IsNullOrEmpty(editClass)) { builder.Add("class", editClass); } if (field.Edit != null) { builder.AddRange(field.Edit.AttributeList); } }
private static string InternalTextArea(Tk5FieldInfoEx field, IFieldValueProvider row, HtmlAttribute addition, bool needId) { TkDebug.AssertArgumentNull(field, "field", null); HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); AddInputAttribute(field, builder, false); AddNormalAttribute(field, builder, field.NickName, needId); builder.Add(addition); return(string.Format(ObjectUtil.SysCulture, "<textarea {0}>{1}</textarea>{2}", builder.CreateAttribute(), StringUtil.EscapeHtml(row[field.NickName].ToString()), ERROR_LABEL)); }
private static string CreateRowOperator(IFieldValueProvider row, HtmlAttributeBuilder attrBuilder, Operator operRow) { string caption = operRow.Caption; string urlContent = operRow.Content; if (string.IsNullOrEmpty(urlContent)) { return(string.Format(ObjectUtil.SysCulture, "<li>{0}</li>", caption)); } else { attrBuilder.Clear(); attrBuilder.Add("href", "#"); string info = operRow.Info ?? string.Empty; bool isJs = info.Contains("JS"); if (isJs) { string js = "javascript:" + HtmlCommonUtil.ResolveString(row, urlContent); attrBuilder.Add("onClick", js); } else { string attrUrl; if (info.Contains("Dialog")) { string dialogTitle = HtmlCommonUtil.ResolveString(row, operRow.DialogTitle); attrBuilder.Add("data-title", dialogTitle); attrUrl = "data-dialog-url"; } else if (info.Contains("AjaxUrl")) { attrUrl = "data-ajax-url"; } else { attrUrl = "data-url"; } attrBuilder.Add(attrUrl, HtmlUtil.ParseLinkUrl(row, urlContent)); string dataConfirm = operRow.ConfirmData; if (!string.IsNullOrEmpty(dataConfirm)) { attrBuilder.Add("data-confirm", dataConfirm); } } if (info.Contains("_blank")) { attrBuilder.Add("data-target", "_blank"); } return(string.Format(ObjectUtil.SysCulture, "<li><a {0}>{1}</a></li>", attrBuilder.CreateAttribute(), caption)); } }
public static string Upload(this Tk5FieldInfoEx field, IFieldValueProvider provider, 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); int maxSize = upload.MaxSize; if (maxSize == 0) { maxSize = BaseGlobalVariable.Current.DefaultValue .GetSimpleDefaultValue("DefaultMaxUploadSize").Value <int>(DEFAULT_UPLOAD_SIZE); } builder.Add("data-maxSize", maxSize); IUploadProcessor2 processor = upload.CreateUploadProcessor2(); UploadInfo info = provider == null ? null : processor.CreateValue(upload, provider); if (info != null) { builder.Add("data-value", info.ToJson()); } IUploadExtension extension = processor as IUploadExtension; if (extension != null) { string uploadUrl = extension.UploadUrl; if (!string.IsNullOrEmpty(uploadUrl)) { builder.Add("data-url", uploadUrl); } } return(string.Format(ObjectUtil.SysCulture, Html.Upload, builder.CreateAttribute(), ERROR_LABEL)); }
private static string ListButtonFromConfig(Operator optr, IFieldValueProvider receiver) { string icon; if (!string.IsNullOrEmpty(optr.IconClass)) { icon = string.Format(ObjectUtil.SysCulture, "<i class=\"{0} mr5\"></i>", optr.IconClass); } else { icon = string.Empty; } HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); string totalClass = BootcssCommonUtil.GetTotalClass("mr10", BootcssButton.Default, false); builder.Add("type", "button"); builder.Add("class", totalClass); string info = optr.Info ?? string.Empty; string attrUrl; bool isJs = info.Contains("JS"); if (isJs) { string js = "javascript:" + HtmlCommonUtil.ResolveString(receiver, optr.Content); builder.Add("onClick", js); } else { if (info.Contains("Dialog")) { attrUrl = "data-dialog-url"; string dialogTitle = HtmlCommonUtil.ResolveString(receiver, optr.DialogTitle); builder.Add("data-title", dialogTitle); } else if (info.Contains("AjaxUrl")) { attrUrl = "data-ajax-url"; if (info.Contains("Post")) { builder.Add("data-method", "post"); } } else { attrUrl = "data-url"; } builder.Add(attrUrl, HtmlUtil.ParseLinkUrl(receiver, optr.Content)); if (!string.IsNullOrEmpty(optr.ConfirmData)) { builder.Add("data-confirm", optr.ConfirmData); } } string button = string.Format(ObjectUtil.SysCulture, "<button {1}>{2}{0}</button>", optr.Caption, builder.CreateAttribute(), icon); return(button); }