public static List <string> CheckLayer(LayerArgs lyrArgs, DicInfoReader dicInfo) { List <string> rlts = new List <string>(); TxLayerInfo txLyrInfo = dicInfo.TxLyrList.First(t => t.DataLayer == lyrArgs.DataLayer); //t.TxName == lyrArgs.TxName && t.TjName == lyrArgs.TjName && t.LayerName == lyrArgs.LayerName && t.DataLayer == lyrArgs.DataLayer); //List<LayerAttInfo> attInfoList = dicInfo.LyrAttList.Where(t => t.TxName == txLyrInfo.TxName).Where(t => t.TjName == txLyrInfo.TjName).Where(t => t.LayerName == txLyrInfo.LayerName).ToList(); List <LayerAttInfo> attInfoList = dicInfo.LyrAttList.Where(t => t.DataLayer == txLyrInfo.DataLayer).ToList(); DataTable tbl = ShpUtility.GetRecords(lyrArgs.LayerPath, null); // 检查列名是否有特殊字符 for (int i = 0; i < tbl.Columns.Count; i++) { if (tbl.Columns[i].ColumnName.IndexOf('?') != -1) { string info = string.Format("数据检查:列名长度不符合ArcGIS规范:{0}", tbl.Columns[i].ColumnName); rlts.Add(info); } } //检查字段及名称是否齐全 List <string> logs = CheckFiledNums(tbl, attInfoList); if (logs != null && logs.Count > 0) { rlts.AddRange(logs); } //检查字段值是否溢出(超过限定长度或不在给定阈值范围) logs = CheckFiledValueRange(tbl, attInfoList); if (logs != null && logs.Count > 0) { rlts.AddRange(logs); } //检查字段字典项 for (int i = 0; i < attInfoList.Count; i++) { LayerAttInfo lyrAtt = attInfoList[i]; logs = CheckDicAtt(tbl, lyrAtt, dicInfo); if (logs != null && logs.Count > 0) { rlts.AddRange(logs); } } return(rlts); }
//检查字段值是否溢出(超过限定长度或不在给定阈值范围) private static List <string> CheckFiledValueRange(DataTable tbl, List <LayerAttInfo> attInfoList) { List <string> rlts = new List <string>(); List <string> cols = new List <string>(); for (int i = 0; i < tbl.Columns.Count; i++) { cols.Add(tbl.Columns[i].ColumnName); } for (int i = 0; i < tbl.Rows.Count; i++) { for (int j = 0; j < attInfoList.Count; j++) { LayerAttInfo attInfo = attInfoList[j]; object obj = null; if (cols.Contains(attInfo.DataCode)) // 原来if (cols.Contains(attInfo.DataName)) { obj = tbl.Rows[i][attInfo.DataCode]; // obj = tbl.Rows[i][attInfo.DataName]; } if (obj == null) { continue; } bool overflow = IsFileValueOverflow(obj, attInfo.DataType); if (overflow) { string info = string.Format("数据检查:第{0}行“{1}”字段值超过“{2}”长度限制", i, attInfo.DataName, attInfo.DataType); rlts.Add(info); } overflow = IsFileValueOverRange(obj, attInfo.ValueType); if (overflow) { string info = string.Format("数据检查:第{0}行“{1}”字段值不在“{2}”值域范围内", i, attInfo.DataName, attInfo.ValueType); rlts.Add(info); } } } return(rlts); }
private void GetData() { InfoEarthFrame.Data.IDatabase DBAccess = InfoEarthFrame.Data.Factory.GetDBAccess(ConfigurationManager.ConnectionStrings["Default"].ConnectionString, InfoEarthFrame.Data.AccessDBType.Oracle); _txLyrList.Clear(); _lyrAttList.Clear(); _attValueList.Clear(); //图系图层信息 //string sqlStr = "select trim(GUID) as GUID,trim(TXNAME) AS TXNAME,trim(TJNAME) AS TJNAME ,trim(LAYERNAME) AS LAYERNAME,trim(JHTZ) AS JHTZ from DIC_TX_LAYER order by SERIALNUM"; string sqlStr = "select Max(\"Id\") as GUID,\"TXName\",\"TJName\" ,\"LayerName\", \"DataLayer\" from DIC_TX_LAYERPROPERTY group by \"TXName\",\"TJName\" ,\"LayerName\", \"DataLayer\""; DataSet dataset = DBAccess.GetDataSetFromExcuteCommand(sqlStr, null); if (dataset != null && dataset.Tables.Count > 0) { DataTable tbl = dataset.Tables[0]; for (int i = 0; i < tbl.Rows.Count; i++) { TxLayerInfo info = new TxLayerInfo() { Guid = tbl.Rows[i]["GUID"] as string, TxName = tbl.Rows[i]["TXNAME"] as string, TjName = tbl.Rows[i]["TJNAME"] as string, LayerName = tbl.Rows[i]["LAYERNAME"] as string, DataLayer = tbl.Rows[i]["DataLayer"] as string, GeoType = "",//tbl.Rows[i]["JHTZ"] as string, }; _txLyrList.Add(info); } } //图层属性信息 //sqlStr = "select trim(GUID) as GUID,trim(LAYERID) AS LAYERID,trim(DATANAME) AS DATANAME ,trim(DATACODE) AS DATACODE,trim(DES) AS DES,trim(DATATYPE) AS DATATYPE,trim(CONSTRAINT) AS CONSTRAINT,trim(VALUETYPE) AS VALUETYPE,trim(UNIT) AS UNIT,trim(MEMO) AS MEMO from DIC_TX_LAYERPROPERTY order by LAYERID"; sqlStr = "select \"Id\" as GUID,\"TXName\",\"TJName\" ,\"LayerName\",trim(\"FieldName\") AS DATANAME, trim(\"InputControl\") AS INPUTCONTROL, trim(\"DataLayer\") as DATALAYER ,trim(\"FieldCode\") AS DATACODE ,\"FieldType\", \"FieldLen\",\"FieldDec\",trim(\"InputControl\") AS CONSTRAINT from DIC_TX_LAYERPROPERTY"; dataset = DBAccess.GetDataSetFromExcuteCommand(sqlStr, null); if (dataset != null && dataset.Tables.Count > 0) { DataTable tbl = dataset.Tables[0]; for (int i = 0; i < tbl.Rows.Count; i++) { LayerAttInfo info = new LayerAttInfo() { Guid = tbl.Rows[i]["GUID"] as string, TxName = tbl.Rows[i]["TXName"] as string, TjName = tbl.Rows[i]["TJName"] as string, LayerName = tbl.Rows[i]["LayerName"] as string, DataName = tbl.Rows[i]["DATANAME"] as string, DataCode = tbl.Rows[i]["DATACODE"] as string, Des = "", //tbl.Rows[i]["DES"] as string, DataLayer = tbl.Rows[i]["DATALAYER"] as string, DataType = ConvertDataType(tbl.Rows[i]), //tbl.Rows[i]["DATATYPE"] as string, Constraint = tbl.Rows[i]["CONSTRAINT"] as string, ValueType = "自由文本", //tbl.Rows[i]["VALUETYPE"] as string, Unit = "/", //tbl.Rows[i]["U_NAME"] as string, Memo = "/", //tbl.Rows[i]["MEMO"] as string, InputControl = tbl.Rows[i]["INPUTCONTROL"] as string, }; _lyrAttList.Add(info); } } //字典项字段信息 //sqlStr = "select trim(GUID) as GUID,trim(PROPERTYID) AS PROPERTYID,trim(VALUE) AS VALUE ,trim(MEMO) AS MEMO,trim(PARENTPROPERTYID) AS PARENTPROPERTYID from DIC_TX_PROPERTYVALUE"; sqlStr = "select trim(\"Id\") as GUID, trim(\"FieldValue\") AS VALUE from DIC_TX_PROPERTYVALUE"; dataset = DBAccess.GetDataSetFromExcuteCommand(sqlStr, null); if (dataset != null && dataset.Tables.Count > 0) { DataTable tbl = dataset.Tables[0]; for (int i = 0; i < tbl.Rows.Count; i++) { AttValueInfo info = new AttValueInfo() { Guid = tbl.Rows[i]["GUID"] as string, AttId = "", //tbl.Rows[i]["PROPERTYID"] as string, Value = tbl.Rows[i]["VALUE"] as string, Memo = "", //tbl.Rows[i]["MEMO"] as string, ParentId = "", //tbl.Rows[i]["PARENTPROPERTYID"] as string }; _attValueList.Add(info); } } }
//检查字段字典项 private static List <string> CheckDicAtt(DataTable tbl, LayerAttInfo attInfo, DicInfoReader dicInfo) { List <string> rlts = new List <string>(); List <AttValueInfo> attValList = dicInfo.AttValueList.Where(t => t.AttId == attInfo.Guid).ToList(); if (attValList == null || attValList.Count < 1) { return(rlts); } List <string> cols = new List <string>(); for (int i = 0; i < tbl.Columns.Count; i++) { cols.Add(tbl.Columns[i].ColumnName); } if (attValList.Count == 1 && string.IsNullOrEmpty(attValList[0].ParentId) == false) { AttValueInfo attVal = attValList[0]; //检查大类是符合字典项 AttValueInfo pAttVal = dicInfo.AttValueList.First(t => t.Guid == attVal.ParentId); LayerAttInfo pAttInfo = dicInfo.LyrAttList.First(t => t.Guid == pAttVal.AttId); List <string> infoList = CheckDicAtt(tbl, pAttInfo, dicInfo); if (infoList != null && infoList.Count > 0) { rlts.AddRange(infoList.ToArray()); } } //检查是否符合字典项 List <string> valueList = GetDicValues(attValList); for (int i = 0; i < tbl.Rows.Count; i++) { object obj = null; if (cols.Contains(attInfo.DataName)) { obj = tbl.Rows[i][attInfo.DataName]; } if (obj == null) { continue; } string valStr = obj.ToString(); if (attInfo.Constraint.Equals("M", StringComparison.CurrentCultureIgnoreCase) && valueList.Contains(valStr) == false) { string info = string.Format("数据检查:第{0}行“{1}”字段值不在字典项({2})里", i, attInfo.DataName, JoinStr(valueList)); rlts.Add(info); } else if (attInfo.Constraint.Equals("O", StringComparison.CurrentCultureIgnoreCase)) { //有待完善 bool ok = false; for (int j = 0; j < valueList.Count; j++) { if (valStr.Contains(valueList[j])) { ok = true; } } if (ok == false) { string info = string.Format("数据检查:第{0}行{1}字段值不在字典项({2})里", i, attInfo.DataName, JoinStr(valueList)); rlts.Add(info); } } } return(rlts); }