using KGIS.Framework.Utils; using Kingo.Plugin.AttributeMaintain.ModelEntity; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Xml; namespace Kingo.Plugin.AttributeMaintain.Config { public class DataCheckTableMappingConfig { /// /// 变更---根据表名获取检查表映射,lstTableName若参数为空则查询出所有的表映射 /// /// /// public static List BGGetListRuleTableEntity(List lstTableName = null) { List lstRuleTableEntity = new List(); try { XmlDocument doc = new XmlDocument(); string strPath = SysAppPath.BG_GetMappingConfigPath(); doc.Load(strPath); if (doc != null) { #region 获取规则检查TableMapping XmlNodeList nodeTableMappingList = doc.SelectNodes("CheckTableMapping"); if (nodeTableMappingList != null && nodeTableMappingList.Count > 0) { foreach (XmlNode checkTableNode in nodeTableMappingList) { foreach (XmlNode tableNode in checkTableNode.ChildNodes) { if (tableNode.Attributes["TableName"] == null || string.IsNullOrWhiteSpace(tableNode.Attributes["TableName"].Value)) { continue; } //如果参数不为空,则只返回参数里的表结构 if (lstTableName != null && lstTableName.Count > 0 && !lstTableName.Contains(tableNode.Attributes["TableName"].Value)) { continue; } RuleTableEntity pRuleTableEntity = new RuleTableEntity(); pRuleTableEntity.Columns = new List(); pRuleTableEntity.TableName = tableNode.Attributes["TableName"].Value; if (tableNode.Attributes["Name"] != null) { pRuleTableEntity.TableAliasName = tableNode.Attributes["Name"].Value; } if (tableNode.Attributes["Type"] != null) { pRuleTableEntity.Type = tableNode.Attributes["Type"].Value; } if (tableNode.Attributes["YSDM"] != null) { pRuleTableEntity.YSDM = tableNode.Attributes["YSDM"].Value; } if (tableNode.Attributes["CDM"] != null) { pRuleTableEntity.CDM = tableNode.Attributes["CDM"].Value; } if (tableNode.Attributes["IsNecessary"] != null) { bool b = false; if (bool.TryParse(tableNode.Attributes["IsNecessary"].Value, out b)) { } pRuleTableEntity.IsNecessary = b; } #region 表结构的列 foreach (XmlNode columnNode in tableNode.ChildNodes) { RuleColumnEntity pRuleColumnEntity = new RuleColumnEntity(); if (columnNode.Attributes["Name"] != null) { pRuleColumnEntity.ColumnName = columnNode.Attributes["Name"].Value.Trim(); } if (columnNode.Attributes["AliasName"] != null) { pRuleColumnEntity.AliasName = columnNode.Attributes["AliasName"].Value.Trim(); } if (columnNode.Attributes["Range"] != null) { pRuleColumnEntity.Range = columnNode.Attributes["Range"].Value; } if (columnNode.Attributes["ToolTip"] != null) { pRuleColumnEntity.ToolTip = columnNode.Attributes["ToolTip"].Value; } if (columnNode.Attributes["Pic"] != null) { pRuleColumnEntity.Pic = columnNode.Attributes["Pic"].Value; } pRuleColumnEntity.AllowDBNull = false; //字段是否可为空:如果未配置则默认为false:标识当前字段为必填项,不可为空 if (columnNode.Attributes["AllowDBNull"] != null) { bool b = false; if (bool.TryParse(columnNode.Attributes["AllowDBNull"].Value.Trim(), out b)) { } pRuleColumnEntity.AllowDBNull = b; } pRuleColumnEntity.IsUnique = false; //字段值是否必须唯一:如果未配置则默认为false:表示当前字段不是必须唯一,可重复 if (columnNode.Attributes["IsUnique"] != null) { bool b = false; if (bool.TryParse(columnNode.Attributes["IsUnique"].Value.Trim(), out b)) { } pRuleColumnEntity.IsUnique = b; } pRuleColumnEntity.DataType = "string"; if (columnNode.Attributes["DataType"] != null) { pRuleColumnEntity.DataType = columnNode.Attributes["DataType"].Value.Trim(); } pRuleColumnEntity.IllegalityCheck = true; //如果不是字符串类型的字段则不检查 //字段值非法字符检查:如果未配置则默认为false:表示需要检查非法字符 if (pRuleColumnEntity.DataType != "string") { pRuleColumnEntity.IllegalityCheck = false; } else { pRuleColumnEntity.IllegalityCheck = true; } if (columnNode.Attributes["IllegalityNotCheck"] != null) { bool b = false; if (bool.TryParse(columnNode.Attributes["IllegalityNotCheck"].Value.Trim(), out b)) { } pRuleColumnEntity.IllegalityCheck = b; } if (columnNode.Attributes["MaxLength"] != null) { int max = 0; if (int.TryParse(columnNode.Attributes["MaxLength"].Value.Trim(), out max)) { } pRuleColumnEntity.MaxLength = max; } if (columnNode.Attributes["Precision"] != null) { int precision = 0; if (int.TryParse(columnNode.Attributes["Precision"].Value.Trim(), out precision)) { } pRuleColumnEntity.Precision = precision; } if (columnNode.Attributes["Dic"] != null) { pRuleColumnEntity.DIC = columnNode.Attributes["Dic"].Value.Trim(); } pRuleColumnEntity.IsEllipsoidArea = false; if (columnNode.Attributes["IsEllipsoidArea"] != null) { bool b = false; if (bool.TryParse(columnNode.Attributes["IsEllipsoidArea"].Value.Trim(), out b)) { } pRuleColumnEntity.IsEllipsoidArea = b; } pRuleColumnEntity.ExtendField = false; if (columnNode.Attributes["ExtendField"] != null) { bool b = false; if (bool.TryParse(columnNode.Attributes["ExtendField"].Value.Trim(), out b)) { } pRuleColumnEntity.ExtendField = b; } pRuleTableEntity.Columns.Add(pRuleColumnEntity); } #endregion lstRuleTableEntity.Add(pRuleTableEntity); } } } #endregion } return lstRuleTableEntity; } catch (Exception ex) { LogAPI.Debug("加载CheckConfig的CheckTableMapping配置文件失败:" + ex.Message); throw new ArgumentNullException("加载CheckConfig的CheckTableMapping配置文件失败"); } } } }