//GetFormXmlString() ///<summary> /// 加载实体对应的表单配置XML ///</summary> ///<param name="entityName"></param> ///<returns></returns> privatestatic XmlDocument GetFormXmlString(IOrganizationService organizationServiceAdmin, string entityName) { var qe = new QueryExpression("new_systemform"); qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0); qe.Criteria.AddCondition("new_entityname", ConditionOperator.Equal, entityName); qe.ColumnSet = new ColumnSet("new_formxml");
var ec = organizationServiceAdmin.RetrieveMultiple(qe); if (ec == null || ec.Entities.Count == 0) { thrownew Exception(string.Format("没有实体名为{0}的数据", entityName)); } var entity = ec.Entities.First(); if (!entity.Contains("new_formxml")) { thrownew Exception(string.Format("没有查询到对应的XML!实体名:【{0}】", entityName)); } var xml = entity.GetAttributeValue<string>("new_formxml");
var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml);
return xmlDoc; } ```
> ParseXmlToSchema调用InputProperty类的LoadFromXml方法
```csharp //ParseXmlToSchema
///<summary> /// 将XML转换成SCHEMA ///</summary> ///<param name="entityName"></param> ///<param name="formXml"></param> ///<returns></returns> privatestatic FormSchema ParseXmlToSchema(IOrganizationService organizationServiceAdmin, string entityName, XmlDocument formXml, int langId) { var schema = new FormSchema(); var sectionNodeList = formXml.SelectNodes("Form/Section"); if (sectionNodeList == null || sectionNodeList.Count == 0) { thrownew Exception("未找到相应的配置结点,结点路径:Form/Section"); } foreach (XmlNode sectionNode in sectionNodeList) { var sectionName = sectionNode.GetStringAttributeValue("name"); if (string.IsNullOrWhiteSpace(sectionName)) { thrownew Exception("Section结点的【name】属性值不能为空"); }
var sectionTitle = sectionNode.GetStringAttributeValue("title"); if (string.IsNullOrWhiteSpace(sectionTitle)) { thrownew Exception("Section结点的【title】属性值不能为空"); }
var fieldNodeList = sectionNode.SelectNodes("Field"); if (fieldNodeList == null || fieldNodeList.Count == 0) { thrownew Exception($"Section结点下面未配置任何字段,SectionName:{sectionName}"); }
var sectionAttributes = new Dictionary<string, InputProperty.InputProperty>(fieldNodeList.Count); foreach (XmlNode fieldNode in fieldNodeList) { var fieldName = fieldNode.GetStringAttributeValue("name"); if (string.IsNullOrWhiteSpace(fieldName)) { thrownew Exception($"Field结点的【name】属性值不能为空"); }
var fieldType = fieldNode.GetStringAttributeValue("type"); if (string.IsNullOrWhiteSpace(fieldName)) { thrownew Exception($"Field结点的【type】属性值不能为空"); }
var inputProperty = InputPropertyFactory.CreateInputProperty(organizationServiceAdmin, fieldType, langId); inputProperty.LoadFromXml(entityName, fieldName, fieldNode);