/// <summary>验证标签</summary> private XmlMetadataTag ValidateTag(XmlMetadataTag oldTag) { var newTag = new XmlMetadataTag(); if (!this.Presenter.Validate(this.txtTagName, ref newTag.Name, "标签名称不允许为空!")) { return(null); } if (oldTag == null || !newTag.Name.Equals(oldTag.Name, StringComparison.OrdinalIgnoreCase)) { if (this.Presenter.Config.MetadataTags.Any(v => v.Name.Equals(newTag.Name, StringComparison.OrdinalIgnoreCase))) { this.Presenter.WorkItem.Alert("标签名称已经存在!"); return(null); } } newTag.Enabled = this.chkTagVisible.Checked; if (!this.Presenter.ValidateInt(this.txtTagWidth, ref newTag.Width, "标签宽度")) { return(null); } newTag.DefaultValue = this.txtTagDefaultValue.Text.Trim(); newTag.EnumValues = string.Join(",", this.txtTagValues.Lines.Select(e => e.Trim()).Distinct().ToArray()); return(newTag); }
/// <summary>加载元数据标签</summary> private void LoadMetadataTags(MetadataDefinition[] tags) { var xmlTags = this.Config.MetadataTags; foreach (var tag in tags) { var config = xmlTags.FirstOrDefault(e => e.Name == tag.Name); if (config != null) { config.Refer = tag; if (config.Width >= 100) { config.Width = 13; if (tag.Type == MetadataTagType.Date.ToString()) { config.Width = 21; } } continue; } config = new XmlMetadataTag(); config.Name = tag.Name; config.Refer = tag; config.Enabled = true; config.Width = 13; if (tag.Type == MetadataTagType.Date.ToString()) { config.Width = 21; } if (tag.Items.IsNullOrEmpty()) { config.EnumValues = string.Empty; } else { var enumValues = tag.Items.Select(e => e.Text.Trim()).ToList(); config.EnumValues = string.Join(",", enumValues); } this.Config.MetadataTags.Add(config); } for (int i = 0; i < this.Config.MetadataTags.Count;) { if (this.Config.MetadataTags[i].Refer == null) { this.Config.MetadataTags.RemoveAt(i); continue; } i++; } BindMetadataTagDefaultValue(MetadataConsts.ShowType, $"{SubmissionConsts.ShowType.NormalizeVariable()}"); BindMetadataTagDefaultValue(MetadataConsts.Title, $"{SubmissionConsts.ProductFileName.NormalizeVariable()}"); BindMetadataTagDefaultValue(MetadataConsts.ResourceKey, $"/{SubmissionConsts.ToolName.NormalizeVariable()}/{SubmissionConsts.ExcelFileName.NormalizeVariable()}/{SubmissionConsts.Guid.NormalizeVariable()}"); }