//处理检查结果 public void GeoDataChecker_DataErrTreat(object sender, DataErrTreatEvent e) { //用户界面上表现出错误信息 DevComponents.DotNetBar.Controls.DataGridViewX pDataGrid = sender as DevComponents.DotNetBar.Controls.DataGridViewX; if (_ResultTable == null) { return; } DataRow newRow = _ResultTable.NewRow(); newRow["检查功能名"] = e.ErrInfo.FunctionName; newRow["错误类型"] = GeoDataChecker.GetErrorTypeString(Enum.Parse(typeof(enumErrorType), e.ErrInfo.ErrID.ToString()).ToString()); newRow["错误描述"] = e.ErrInfo.ErrDescription; newRow["数据图层1"] = e.ErrInfo.OriginClassName; newRow["要素OID1"] = e.ErrInfo.OriginFeatOID; newRow["数据图层2"] = e.ErrInfo.DestinationClassName; newRow["要素OID2"] = e.ErrInfo.DestinationFeatOID; newRow["检查时间"] = e.ErrInfo.OperatorTime; newRow["定位点X"] = e.ErrInfo.MapX; newRow["定位点Y"] = e.ErrInfo.MapY; newRow["数据文件名"] = e.ErrInfo.DataFileName; _ResultTable.Rows.Add(newRow); pDataGrid.Update(); //将结果输出excle InsertRowToExcel(e); }
public void DataCheckRealize_DataErrTreat(object sender, DataErrTreatEvent e) { e.ErrInfo.FunctionCategoryName = "批量检查"; e.ErrInfo.FunctionName = "线线重合检查"; e.ErrInfo.ErrID = enumErrorType.线线重合检查.GetHashCode(); DataErrTreat(sender, e); }
/// <summary> /// 获得错误列表,等高线点线矛盾 /// </summary> /// <param name="pFeatureDataset"></param> /// <param name="pFeatureCls"></param> /// <param name="feaClsname"></param> /// <param name="pFeature"></param> /// <param name="eErrorID"></param> /// <param name="eError"></param> private void GetErrorList(IArcgisDataCheckHook hook, IFeatureDataset pFeatureDataset, IFeatureClass pOriFeatureCls, IFeature pOriFeature, IFeatureClass pDesFeatureCls, IFeature pDesFeature, int eErrorID, string eErrorDes, out Exception eError) { eError = null; try { double pMapx = 0.0; double pMapy = 0.0; IPoint pPoint = null; //高程值不在给定的高程范围内,将错误结果保存下来 if (pOriFeatureCls.ShapeType != esriGeometryType.esriGeometryPoint) { pPoint = TopologyCheckClass.GetPointofFeature(pOriFeature); } else { pPoint = pOriFeature.Shape as IPoint; } pMapx = pPoint.X; pMapy = pPoint.Y; List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("等高线点线矛盾检查"); //功能名称 if (pFeatureDataset == null) { ErrorLst.Add(""); //数据文件名 } else { ErrorLst.Add((pFeatureDataset as IDataset).Workspace.PathName); //数据文件名 } ErrorLst.Add(eErrorID); //错误id; ErrorLst.Add(eErrorDes); //错误描述 ErrorLst.Add(pMapx); //... ErrorLst.Add(pMapy); //... ErrorLst.Add((pOriFeatureCls as IDataset).Name); ErrorLst.Add(pOriFeature.OID); ErrorLst.Add((pDesFeatureCls as IDataset).Name); ErrorLst.Add(pDesFeature.OID); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent); } catch (Exception ex) { eError = ex; } }
//将数据检查结果存入ACCESS中 private static void InsertRowToAccess(DbConnection dbCon, string tableName, DataErrTreatEvent e) { SysCommon.DataBase.SysTable sysTable = new SysCommon.DataBase.SysTable(); sysTable.DbConn = dbCon; sysTable.DBConType = SysCommon.enumDBConType.OLEDB; sysTable.DBType = SysCommon.enumDBType.ACCESS; string sql = "insert into " + tableName + "(数据文件路径,检查功能名,错误类型,错误描述,数据图层1,数据OID1,数据图层2,数据OID2,定位点X,定位点Y,检查时间) values(" + "'" + e.ErrInfo.DataFileName + "','" + e.ErrInfo.FunctionName + "','" + GeoDataChecker.GetErrorTypeString(Enum.Parse(typeof(enumErrorType), e.ErrInfo.ErrID.ToString()).ToString()) + "','" + e.ErrInfo.ErrDescription + "','" + e.ErrInfo.OriginClassName + "','" + e.ErrInfo.OriginFeatOID.ToString() + "','" + e.ErrInfo.DestinationClassName + "','" + e.ErrInfo.DestinationFeatOID.ToString() + "'," + e.ErrInfo.MapX + "," + e.ErrInfo.MapY + ",'" + e.ErrInfo.OperatorTime + "')"; Exception errEx = null; sysTable.UpdateTable(sql, out errEx); }
//处理检查结果 public static void GeoDataChecker_DataErrTreat(object sender, DataErrTreatEvent e) { IArcgisDataCheckParaSet dataCheckParaSet = sender as IArcgisDataCheckParaSet; if (dataCheckParaSet == null) { return; } if (dataCheckParaSet.DbConnRes != null) { eErrorCount += 1; _CheckForm.Invoke(new ShowErrorCount(showECount), new object[] { eErrorCount }); InsertRowToAccess(dataCheckParaSet.DbConnRes, dataCheckParaSet.ErrResTableName, e); } }
//将数据检查结果存入Excel中 private void InsertRowToExcel(DataErrTreatEvent e) { if (_ErrDbCon != null && _ErrTableName != "") { SysCommon.DataBase.SysTable sysTable = new SysCommon.DataBase.SysTable(); sysTable.DbConn = _ErrDbCon; sysTable.DBConType = SysCommon.enumDBConType.OLEDB; sysTable.DBType = SysCommon.enumDBType.ACCESS; string sql = "insert into " + _ErrTableName + "(数据文件路径,检查功能名,错误类型,错误描述,数据图层1,数据OID1,数据图层2,数据OID2,定位点X,定位点Y,检查时间) values(" + "'" + e.ErrInfo.DataFileName + "','" + e.ErrInfo.FunctionName + "','" + GeoDataChecker.GetErrorTypeString(Enum.Parse(typeof(enumErrorType), e.ErrInfo.ErrID.ToString()).ToString()) + "','" + e.ErrInfo.ErrDescription + "','" + e.ErrInfo.OriginClassName + "','" + e.ErrInfo.OriginFeatOID.ToString() + "','" + e.ErrInfo.DestinationClassName + "','" + e.ErrInfo.DestinationFeatOID.ToString() + "'," + e.ErrInfo.MapX + "," + e.ErrInfo.MapY + ",'" + e.ErrInfo.OperatorTime + "')"; Exception errEx = null; sysTable.UpdateTable(sql, out errEx); if (errEx != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "写入Excel文件出错!"); return; } } }
public void DataCheckLogic_DataErrTreat(object sender, DataErrTreatEvent e) { DataErrTreat(sender, e); }
/// <summary> /// 分类代码检查---检查主函数 /// </summary> public void ExcuteCheck() { Exception eError = null; string pClassifyName = GetClassifyName1(out eError); if (eError != null || pClassifyName == "") { return; } //用来存储MapControl上的图层的分类代码的相关信息 Dictionary <string, Dictionary <string, List <long> > > DicFea = new Dictionary <string, Dictionary <string, List <long> > >(); foreach (IFeatureLayer pFeaLayer in m_LstFeaLayer) { IFeatureClass pFeatureClass = pFeaLayer.FeatureClass; IDataset pDT = pFeatureClass as IDataset; if (pDT == null) { return; } string pFeaClsName = pDT.Name.Trim(); #region 首先检查Mapcontrol上的要素类是否具有分类代码这个字段 int index = -1; //分类代码索引 index = pFeatureClass.Fields.FindField(pClassifyName); if (index == -1) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不存在分类代码字段!"); return; } #endregion #region 将MapControl上的图层相关信息用字典存储起来 IFeatureCursor pFeaCursor = pFeatureClass.Search(null, false); if (pFeaCursor == null) { return; } IFeature pFeature = pFeaCursor.NextFeature(); if (pFeature == null) { continue; } while (pFeature != null) { string pGISID = pFeature.get_Value(index).ToString().Trim(); //分类代码 int pOID = pFeature.OID; //OID if (!DicFea.ContainsKey(pFeaClsName)) { //用来保存GISID和对应的OID Dictionary <string, List <long> > DicCode = new Dictionary <string, List <long> >(); List <long> LstOID = new List <long>(); LstOID.Add(pOID); DicCode.Add(pGISID, LstOID); DicFea.Add(pFeaClsName, DicCode); } else { if (!DicFea[pFeaClsName].ContainsKey(pGISID)) { List <long> LstOID = new List <long>(); LstOID.Add(pOID); DicFea[pFeaClsName].Add(pGISID, LstOID); } else { DicFea[pFeaClsName][pGISID].Add(pOID); } } pFeature = pFeaCursor.NextFeature(); } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor); #endregion } #region 进行分类代码检查 //ErrorEventArgs ErrEvent = new ErrorEventArgs(); if (_AppHk.DataTree == null) { return; } _AppHk.DataTree.Nodes.Clear(); //创建处理树图 IntialTree(_AppHk.DataTree); //设置树节点颜色 setNodeColor(_AppHk.DataTree); _AppHk.DataTree.Tag = false; //遍历图层 foreach (KeyValuePair <string, Dictionary <string, List <long> > > FeaCls in DicFea) { string pFeaClsNameStr = FeaCls.Key; if (pFeaClsNameStr.Contains(".")) { pFeaClsNameStr = pFeaClsNameStr.Substring(pFeaClsNameStr.IndexOf('.') + 1); } //创建树图节点(以图层名作为根结点) DevComponents.AdvTree.Node pNode = new DevComponents.AdvTree.Node(); pNode = (DevComponents.AdvTree.Node)CreateAdvTreeNode(_AppHk.DataTree.Nodes, pFeaClsNameStr, pFeaClsNameStr, _AppHk.DataTree.ImageList.Images[6], true);//图层名节点 ////添加树图节点列 //CreateAdvTreeCell(pNode, "", null); ////设置初始进度条 int tempValue = 0; //ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, 0, FeaCls.Value.Count, tempValue); //遍历分类代码值,进行检查 foreach (KeyValuePair <string, List <long> > pGISIDItem in FeaCls.Value) { //分类代码的值 string ppGISID = pGISIDItem.Key; string sqlStr = "select * from GeoCheckCode where 分类代码 ='" + ppGISID + "'"; //执行检查 int pResult = CodeStandardizeCheck(sqlStr); #region 对检查结果进行判断 if (pResult == -1) { return; } if (pResult == 1) { //该分类代码正确 tempValue += 1;//进度条的值加1 continue; } if (pResult == 0) { //该分类代码不正确 #region 保存错误结果 //字段属性为空,与标准不一致,将结果保存起来 //遍历该分类代码对应的要素OID集合 long[] OIDs = new long[pGISIDItem.Value.Count]; for (int m = 0; m < pGISIDItem.Value.Count; m++) { OIDs[m] = pGISIDItem.Value[m]; //ErrEvent.FeatureClassName = pFeaClsNameStr; //ErrEvent.OIDs = OIDs; //ErrEvent.ErrorName = "分类代码不存在"; //ErrEvent.ErrDescription = "在模板库中找不到分类代码:" + ppGISID; //ErrEvent.CheckTime = System.DateTime.Now.ToString(); //double pMapx = 0.0; //double pMapy = 0.0; //IPoint pPoint = new PointClass(); //if (pFeaCls.ShapeType != esriGeometryType.esriGeometryPoint) //{ // pPoint = TopologyCheckClass.GetPointofFeature(pFeature); //} //else //{ // pPoint = pFeature.Shape as IPoint; //} //pMapx = pPoint.X; //pMapy = pPoint.Y; List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("分类代码检查"); //功能名称 ErrorLst.Add(""); //数据文件名 ErrorLst.Add(enumErrorType.分类代码不存在.GetHashCode()); //错误id; ErrorLst.Add("模板中图层" + pFeaClsNameStr + "中不存在分类代码" + ppGISID); //错误描述 ErrorLst.Add(0); //... ErrorLst.Add(0); //... ErrorLst.Add(pFeaClsNameStr); ErrorLst.Add(OIDs[m]); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(_AppHk.DataCheckGrid as object, dataErrTreatEvent); } #endregion } #endregion //引发事件 //this.OnErrorFind(_AppHk, ErrEvent); tempValue += 1;//进度条的值加1 //引发进度条事件 this.OnProgressStep(_AppHk, tempValue, FeaCls.Value.Count); //ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, -1, -1, tempValue); } //改变树图运行状态 ChangeTreeSelectNode(pNode, "完成" + FeaCls.Value.Count + "个分类代码的检查", false); } #endregion SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "检查完成!"); }
/// <summary> /// 代码图层检查---检查主函数 /// </summary> public void ExcuteLayerCheck() { Exception eError = null; //用来存储MapControl上的图层的分类代码的相关信息 Dictionary <IFeatureClass, Dictionary <string, List <long> > > DicFea = new Dictionary <IFeatureClass, Dictionary <string, List <long> > >(); ////用来存储图层名和类型字典对 //Dictionary<string, string> DicFeaType = new Dictionary<string, string>(); string pClassifyName = GetClassifyName1(out eError); if (eError != null || pClassifyName == "") { return; } foreach (IFeatureLayer pFeaLayer in m_LstFeaLayer) { IFeatureClass pFeatureClass = pFeaLayer.FeatureClass; #region 首先检查Mapcontrol上的要素类是否具有分类代码这个字段 int index = -1; //分类代码索引 index = pFeatureClass.Fields.FindField(pClassifyName); if (index == -1) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不存在分类代码字段!"); return; } #endregion #region 将MapControl上的图层相关信息用字典存储起来 IFeatureCursor pFeaCursor = pFeatureClass.Search(null, false); if (pFeaCursor == null) { return; } IFeature pFeature = pFeaCursor.NextFeature(); if (pFeature == null) { continue; } while (pFeature != null) { string pGISID = pFeature.get_Value(index).ToString().Trim(); //分类代码 int pOID = pFeature.OID; //OID if (!DicFea.ContainsKey(pFeatureClass)) { //用来保存GISID和对应的OID Dictionary <string, List <long> > DicCode = new Dictionary <string, List <long> >(); List <long> LstOID = new List <long>(); LstOID.Add(pOID); DicCode.Add(pGISID, LstOID); DicFea.Add(pFeatureClass, DicCode); } else { if (!DicFea[pFeatureClass].ContainsKey(pGISID)) { List <long> LstOID = new List <long>(); LstOID.Add(pOID); DicFea[pFeatureClass].Add(pGISID, LstOID); } else { DicFea[pFeatureClass][pGISID].Add(pOID); } } pFeature = pFeaCursor.NextFeature(); } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor); #endregion } #region 进行分类代码检查 //ErrorEventArgs ErrEvent = new ErrorEventArgs(); //声明表格用来保存检查结果 //DataTable pResultTable = CreateTable(); if (_AppHk.DataTree == null) { return; } _AppHk.DataTree.Nodes.Clear(); //创建处理树图 IntialTree(_AppHk.DataTree); //设置树节点颜色 setNodeColor(_AppHk.DataTree); _AppHk.DataTree.Tag = false; //遍历图层 foreach (KeyValuePair <IFeatureClass, Dictionary <string, List <long> > > FeaCls in DicFea) { IFeatureClass pFeaCls = FeaCls.Key; IDataset pDT = pFeaCls as IDataset; if (pDT == null) { return; } //string pFeaClsType=""; //要素类型类型:点、线、面、注记 string pFeaClsNameStr = pDT.Name.Trim(); //要素类名称 if (pFeaClsNameStr.Contains(".")) { pFeaClsNameStr = pFeaClsNameStr.Substring(pFeaClsNameStr.IndexOf('.') + 1); } //创建树图节点(以图层名作为根结点) DevComponents.AdvTree.Node pNode = new DevComponents.AdvTree.Node(); pNode = (DevComponents.AdvTree.Node)CreateAdvTreeNode(_AppHk.DataTree.Nodes, pFeaClsNameStr, pFeaClsNameStr, _AppHk.DataTree.ImageList.Images[6], true);//图层名节点 //显示进度条 ShowProgressBar(true); ////添加树图节点列 //CreateAdvTreeCell(pNode, "", null); //设置初始进度条 int tempValue = 0; #region 检查图层名类型是否正确 #region 对检查结果进行判断 ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, 0, FeaCls.Value.Count, tempValue); #region 检查分类代码与图层的对应关系 //遍历分类代码值,进行检查 foreach (KeyValuePair <string, List <long> > pGISIDItem in FeaCls.Value) { //分类代码的值 string ppGISID = pGISIDItem.Key; string sqlStr = "select * from GeoCheckCode where 分类代码 ='" + ppGISID + "'"; int pResult = CodeStandardizeCheck(sqlStr); //检查该分类代码是否存在于模板库中 if (pResult == -1) { return; } if (pResult == 1) { //分类代码存在 #region 检查分类代码与图层名的对应关系是否正确 //若能够找到该分类代码,则检查分类代码对应的图层名是否正确 string sqlStr2 = "select * from GeoCheckCode where 分类代码 ='" + ppGISID + "' and 图层='" + pFeaClsNameStr + "'"; int pResult2 = CodeStandardizeCheck(sqlStr2); //检查分类代码对应的图层名是否正确 if (pResult2 == -1) { return; } if (pResult2 == 1) { //在模板中能够找到该分类代码对应的图层名,说明分类代码对应的图层名正确 tempValue += 1;//进度条的值加1 ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, -1, -1, tempValue); continue; } if (pResult2 == 0) { //在模板中找不到该分类代码对应的图层名,说明分类代码对应的图层名不正确 #region 保存错误结果 //遍历该分类代码对应的要素OID集合 long[] OIDs = new long[pGISIDItem.Value.Count]; for (int m = 0; m < pGISIDItem.Value.Count; m++) { OIDs[m] = pGISIDItem.Value[m]; List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("代码图层检查"); //功能名称 ErrorLst.Add(""); //数据文件名 ErrorLst.Add(enumErrorType.分类代码与图层名对应关系不正确.GetHashCode()); //错误id; ErrorLst.Add("模板中图层" + pFeaClsNameStr + "中与分类代码" + ppGISID + "的对应关系不正确!"); //错误描述 ErrorLst.Add(0); //... ErrorLst.Add(0); //... ErrorLst.Add(pFeaClsNameStr); ErrorLst.Add(OIDs[m]); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(_AppHk.DataCheckGrid as object, dataErrTreatEvent); } //ErrEvent.FeatureClassName = pFeaClsNameStr; //ErrEvent.OIDs = OIDs; //ErrEvent.ErrorName = "分类代码与图层名对应不正确"; //ErrEvent.ErrDescription = "在模板中分类代码" + ppGISID + "对应的图层名不是" + pFeaClsNameStr; //ErrEvent.CheckTime = System.DateTime.Now.ToString(); #endregion } #endregion } if (pResult == 0) { //分类代码不存在 #region 保存错误结果 //遍历该分类代码对应的要素OID集合 long[] OIDs = new long[pGISIDItem.Value.Count]; for (int m = 0; m < pGISIDItem.Value.Count; m++) { OIDs[m] = pGISIDItem.Value[m]; List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("代码图层检查"); //功能名称 ErrorLst.Add(""); //数据文件名 ErrorLst.Add(enumErrorType.分类代码不存在.GetHashCode()); //错误id; ErrorLst.Add("模板中图层" + pFeaClsNameStr + "中不存在分类代码" + ppGISID); //错误描述 ErrorLst.Add(0); //... ErrorLst.Add(0); //... ErrorLst.Add(pFeaClsNameStr); ErrorLst.Add(OIDs[m]); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(_AppHk.DataCheckGrid as object, dataErrTreatEvent); } //ErrEvent.FeatureClassName = pFeaClsNameStr; //ErrEvent.OIDs = OIDs; //ErrEvent.ErrorName = "分类代码不存在"; //ErrEvent.ErrDescription = "在模板库中找不到分类代码:" + ppGISID; //ErrEvent.CheckTime = System.DateTime.Now.ToString(); #endregion } //引发事件 //this.OnErrorFind(_AppHk, ErrEvent); tempValue += 1;//进度条的值加1 ChangeProgressBar((_AppHk as Plugin.Application.IAppFormRef).ProgressBar, -1, -1, tempValue); } #endregion #endregion #endregion //改变树图运行状态 ChangeTreeSelectNode(pNode, "完成" + FeaCls.Value.Count + "个代码图层的检查", false); } #endregion SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "检查完成!"); //隐藏进度条 ShowProgressBar(false); }
public void DataCheckRealize_DataErrTreat(object sender, DataErrTreatEvent e) { }
public void OnDataCheck() { if (Hook == null) { return; } IArcgisDataCheckParaSet dataCheckParaSet = Hook.DataCheckParaSet as IArcgisDataCheckParaSet; if (dataCheckParaSet == null) { return; } if (dataCheckParaSet.Workspace == null) { return; } //获取所有数据集 SysCommon.Gis.SysGisDataSet sysGisDataSet = new SysCommon.Gis.SysGisDataSet(dataCheckParaSet.Workspace); List <IDataset> featureDatasets = sysGisDataSet.GetAllFeatureClass(); ISchemeProject m_pProject = null; //数据库结构文件对象 int m_DBScale = 0; //默认比例尺 int m_DSScale = 0; //数据集比例尺 Dictionary <string, IFeatureClass> pLayerDic = new Dictionary <string, IFeatureClass>(); //记录加载到map上的图层对象 foreach (IDataset var in featureDatasets) { string FCName = var.Name; if (FCName.Contains(".")) { FCName = FCName.Substring(FCName.IndexOf('.') + 1); } IFeatureClass FC = var as IFeatureClass; if (FC != null && !pLayerDic.ContainsKey(FCName)) { pLayerDic.Add(FCName, FC); } } ///读取配置方案到对象 /// m_pProject = new SchemeProjectClass(); //创建实例 m_pProject.Load(GeoDataChecker.DBSchemaPath, e_FileType.GO_SCHEMEFILETYPE_MDB); //加载schema文件 if (m_pProject != null) { #region 获得比例尺信息 string DBScale = m_pProject.get_MetaDataValue("Scale") as string; //获取比例尺信息(总工程中的默认比例尺) string[] DBPScaleArayy = DBScale.Split(':'); m_DBScale = Convert.ToInt32(DBPScaleArayy[1]); #endregion IChildItemList pProjects = m_pProject as IChildItemList; //获取属性库集合信息 ISchemeItem pDBList = pProjects.get_ItemByName("ATTRDB"); IChildItemList pDBLists = pDBList as IChildItemList; //遍历属性库集合 long DBNum = pDBLists.GetCount(); for (int i = 0; i < DBNum; i++) { m_DSScale = 0; //比例尺信息 //取得属性库信息 ISchemeItem pDB = pDBLists.get_ItemByIndex(i); ///获取数据集的比例尺信息,如果获取失败则,取默认比例尺信息 IAttribute pa = pDB.AttributeList.get_AttributeByName("Scale") as IAttribute; if (pa == null) { m_DSScale = m_DBScale; } else { string[] DBScaleArayy = pa.Value.ToString().Split(':'); m_DSScale = Convert.ToInt32(DBScaleArayy[1]); } IChildItemList pDBs = pDB as IChildItemList; string pDatasetName = pDB.Name; ////遍历属性表 int TabNum = pDBs.GetCount(); for (int j = 0; j < TabNum; j++) { //获取属性表信息 ISchemeItem pTable = pDBs.get_ItemByIndex(j); //获取属性表对象 string pFeatureClassName = pTable.Name; //要素类名称 ///检查图层是否存在 if (!pLayerDic.ContainsKey(pFeatureClassName)) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.目标要素类缺失.GetHashCode(), "要素类在标准中存在,却在目标数据集中未找到", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); continue; } #region 检查要素类类型是否与配置方案一致 string pFeatureClassType = pTable.Value as string; //要素类类型 ///检查图层类型是否一致 /// IFeatureClass pfeatureclass; bool GetlyrSeccess = pLayerDic.TryGetValue(pFeatureClassName, out pfeatureclass); if (GetlyrSeccess) { //IFeatureLayer pFeatureLayer = player as IFeatureLayer; switch (pFeatureClassType) { case "ANNO": if (pfeatureclass.FeatureType != esriFeatureType.esriFTAnnotation) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.要素类类型不一致.GetHashCode(), "目标要素类应为 注记 类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "POINT": if (pfeatureclass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.要素类类型不一致.GetHashCode(), "目标要素类应为 点 类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "LINE": if (pfeatureclass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.要素类类型不一致.GetHashCode(), "目标要素类应为 线 类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "AREA": if (pfeatureclass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.要素类类型不一致.GetHashCode(), "目标要素类应为 面 类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; default: break; } } else { continue; } #endregion //遍历字段 IAttributeList pAttrs = pTable.AttributeList; long FNum = pAttrs.GetCount(); //检查非GIS平台定义的字段 IFields fields = pfeatureclass.Fields; //循环属性表中的字段,添加到arcgis的字段对象中 for (int k = 0; k < FNum; k++) { //添加自定义属性字段 CheckFields(pAttrs, k, fields, pFeatureClassName, dataCheckParaSet); } } } } else { return; } }
/// <summary> /// 根据输入的字段属性对象,检查属性字段是否与标准中定义的一致 /// </summary> /// <param name="pAttrs"></param> /// <param name="k"></param> /// <param name="fields"></param> private void CheckFields(IAttributeList pAttrs, int k, IFields fields, string pFeatureClassName, IArcgisDataCheckParaSet dataCheckParaSet) { //获取基本属性信息 IAttribute pAttr = pAttrs.get_AttributeByIndex(k); //获取扩展属性信息 IAttributeDes pAttrDes = pAttr.Description; ///检查是否存在该名称的字段 /// int i = fields.FindField(pAttr.Name); if (i < 0) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.属性字段缺失.GetHashCode(), "目标要素类的 " + pAttr.Name + " 字段缺失", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); return; } IField pField = fields.get_Field(i); #region 字段类型检查 ///检查字段类型是否一致 /// string pfieldType = pAttr.Type.ToString(); switch (pfieldType) { case "GO_VALUETYPE_STRING": if (pField.Type != esriFieldType.esriFieldTypeString) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.属性字段类型不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段应为字符串类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "GO_VALUETYPE_LONG": if (pField.Type != esriFieldType.esriFieldTypeInteger) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.属性字段类型不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段应为长整类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "GO_VALUETYPE_BOOL": break; case "GO_VALUETYPE_DATE": if (pField.Type != esriFieldType.esriFieldTypeDate) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.属性字段类型不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段应为日期类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "GO_VALUETYPE_FLOAT": if (pField.Type != esriFieldType.esriFieldTypeSingle) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.属性字段类型不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段应为浮点类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; case "GO_VALUETYPE_DOUBLE": if (pField.Type != esriFieldType.esriFieldTypeDouble) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.属性字段类型不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段应为双精度类型", 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } break; default: break; } #endregion #region 字段长度检查 if (pfieldType != "GO_VALUETYPE_DOUBLE") { if (pField.Length != Convert.ToInt32(pAttrDes.InputWidth)) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.字段扩展属性不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段长度应" + Convert.ToInt32(pAttrDes.InputWidth).ToString(), 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } } #endregion #region 字段可否为空检查 if (pField.IsNullable != pAttrDes.AllowNull) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.字段扩展属性不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段是否为空属性应为" + pAttrDes.AllowNull.ToString(), 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } #endregion #region 字段是否必须存在检查 if (pField.Required != bool.Parse(pAttrDes.Necessary.ToString())) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.字段扩展属性不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段是否必须属性应为" + pAttrDes.Necessary.ToString(), 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } #endregion #region 字段是否可编辑检查 #endregion #region 字段值域是否可变检查 #endregion #region 字段精度检查 //双精度类型不可设置精度(在PDB和GDB中不会出现错误,但是在SDE中会抛出“无效的列”错误) if (pfieldType != "GO_VALUETYPE_DOUBLE") { if (pField.Precision != Convert.ToInt32(pAttrDes.PrecisionEx)) { //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(new List <object>(new object[] { "批量检查", "数据结构检查", dataCheckParaSet.Workspace.PathName, enumErrorType.字段扩展属性不一致.GetHashCode(), "目标要素类的 " + pField.Name + " 字段精度应为" + pAttrDes.PrecisionEx.ToString(), 0, 0, pFeatureClassName, 0, "", 0, false, System.DateTime.Now.ToString() })); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } } #endregion }
private void ExcuteCheck(List <IDataset> LstDataset, string path) { Exception eError = null; string pClassifyName = GetClassifyName1(out eError); if (eError != null || pClassifyName == "") { return; } //用来存储MapControl上的图层的分类代码的相关信息 Dictionary <IFeatureClass, Dictionary <string, List <int> > > DicFea = new Dictionary <IFeatureClass, Dictionary <string, List <int> > >(); foreach (IDataset pDT in LstDataset) { IFeatureClass pFeatureClass = pDT as IFeatureClass; if (pFeatureClass == null) { return; } string pFeaClsName = pDT.Name.Trim(); #region 首先检查Mapcontrol上的要素类是否具有分类代码这个字段 int index = -1; //分类代码索引 index = pFeatureClass.Fields.FindField(pClassifyName); if (index == -1) { //SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不存在分类代码字段!"); //return; continue; } #endregion #region 将MapControl上的图层相关信息用字典存储起来 IFeatureCursor pFeaCursor = pFeatureClass.Search(null, false); if (pFeaCursor == null) { return; } IFeature pFeature = pFeaCursor.NextFeature(); if (pFeature == null) { continue; } while (pFeature != null) { string pGISID = pFeature.get_Value(index).ToString().Trim(); //分类代码 int pOID = pFeature.OID; //OID if (!DicFea.ContainsKey(pFeatureClass)) { //用来保存GISID和对应的OID Dictionary <string, List <int> > DicCode = new Dictionary <string, List <int> >(); List <int> LstOID = new List <int>(); LstOID.Add(pOID); DicCode.Add(pGISID, LstOID); DicFea.Add(pFeatureClass, DicCode); } else { if (!DicFea[pFeatureClass].ContainsKey(pGISID)) { List <int> LstOID = new List <int>(); LstOID.Add(pOID); DicFea[pFeatureClass].Add(pGISID, LstOID); } else { DicFea[pFeatureClass][pGISID].Add(pOID); } } pFeature = pFeaCursor.NextFeature(); } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCursor); #endregion } //设置进度条 ProgressChangeEvent eInfo = new ProgressChangeEvent(); eInfo.Max = DicFea.Count; int pValue = 0; //int pMax =DicFea.Count; //int pValue = 0; //GeoDataChecker._CheckForm.Invoke(new GeoDataChecker.IntiProgressBar(GeoDataChecker.intiaProgress), new object[] { pMax }); #region 进行分类代码检查 //遍历要素类 foreach (KeyValuePair <IFeatureClass, Dictionary <string, List <int> > > FeaCls in DicFea) { IFeatureClass pFeaCls = FeaCls.Key; IDataset pDataset = pFeaCls as IDataset; if (pDataset == null) { return; } string pFeaClsNameStr = pDataset.Name; if (pFeaClsNameStr.Contains(".")) { pFeaClsNameStr = pFeaClsNameStr.Substring(pFeaClsNameStr.IndexOf('.') + 1); } //遍历分类代码值,进行检查 foreach (KeyValuePair <string, List <int> > pGISIDItem in FeaCls.Value) { //分类代码的值 string ppGISID = pGISIDItem.Key; string sqlStr = "select * from GeoCheckCode where 分类代码 ='" + ppGISID + "'"; //执行检查 int pResult = CodeStandardizeCheck(sqlStr); #region 对检查结果进行判断 if (pResult == -1) { return; } if (pResult == 1) { continue; } if (pResult == 0) { //该分类代码不存在 #region 保存错误结果 //遍历该分类代码对应的要素OID集合 for (int m = 0; m < pGISIDItem.Value.Count; m++) { int pOID = pGISIDItem.Value[m]; IFeature pFeature = pFeaCls.GetFeature(pOID); IPoint pPoint = ModCommonFunction.GetPntOfFeature(pFeature); double pMapx = 0; // pPoint.X; ; double pMapy = 0; // pPoint.Y; if (pPoint != null) { pMapx = pPoint.X; pMapy = pPoint.Y; } //用来保存错误结果 List <object> ErrorLst = new List <object>(); ErrorLst.Add("批量检查"); ErrorLst.Add("分类代码检查"); ErrorLst.Add(path); ErrorLst.Add(enumErrorType.分类代码不存在.GetHashCode()); ErrorLst.Add("分类代码" + ppGISID + "不存在!"); ErrorLst.Add(pMapx); //... ErrorLst.Add(pMapy); //... ErrorLst.Add(pFeaClsNameStr); ErrorLst.Add(pOID); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(Hook.DataCheckParaSet as object, dataErrTreatEvent); } #endregion } #endregion } //进度条加1 //进度条加1 pValue++; eInfo.Value = pValue; //GeoDataChecker._CheckForm.Invoke(new GeoDataChecker.GEODataCheckerProgressShow(GeoDataChecker.GeoDataChecker_ProgressShow), new object[] { (object)GeoDataChecker._ProgressBarInner, eInfo }); GeoDataChecker.GeoDataChecker_ProgressShow((object)GeoDataChecker._ProgressBarInner, eInfo); //pValue++; //GeoDataChecker._CheckForm.Invoke(new GeoDataChecker.ChangeProgressBar(GeoDataChecker.changeProgress), new object[] {pValue}); } #endregion }
/// <summary> /// 注记高程值一致性检查 /// </summary> /// <param name="hook"></param> /// <param name="feaClsLst"></param> /// <param name="codeName">分类代码字段名</param> /// <param name="oriFeaClsName">源要素类名称</param> /// <param name="oriCodeValue">源要素类分类代码值</param> /// <param name="oriElevFieldName">源高程值字段名</param> /// <param name="desFeaClsName">目标要素类名称</param> /// <param name="desCodeValue">目标要素类分类代码值</param> /// <param name="labelFieldName">目标要素类高程值</param> /// <param name="radius">搜索半径</param> /// <param name="precision">精度控制</param> /// <param name="outError"></param> public void ElevAccordanceCheck(IArcgisDataCheckHook hook, List <IDataset> feaClsLst, string codeName, string oriFeaClsName, string oriCodeValue, string oriElevFieldName, string desFeaClsName, string desCodeValue, string labelFieldName, double radius, long precision, out Exception outError) { outError = null; try { //源要素类 IFeatureClass pOriFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(oriFeaClsName); foreach (IDataset pDT in feaClsLst) { string tempName = pDT.Name; if (tempName.Contains(".")) { tempName = tempName.Substring(tempName.IndexOf('.') + 1); } if (tempName == oriFeaClsName) { pOriFeaCls = pDT as IFeatureClass; break; } } if (pOriFeaCls == null) { return; } //源要素类高程字段索引值 int oriEleIndex = pOriFeaCls.Fields.FindField(oriElevFieldName); if (oriEleIndex == -1) { outError = new Exception("要素类" + oriFeaClsName + "字段" + oriElevFieldName + "不存在!"); return; } //目标要素类 IFeatureClass pDesFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(desFeaClsName); foreach (IDataset pDT in feaClsLst) { string tempName = pDT.Name; if (tempName.Contains(".")) { tempName = tempName.Substring(tempName.IndexOf('.') + 1); } if (tempName == desFeaClsName) { pDesFeaCls = pDT as IFeatureClass; break; } } if (pDesFeaCls == null) { return; } //目标要素类高程字段索引值 int desElevIndex = pDesFeaCls.Fields.FindField(labelFieldName); if (desElevIndex == -1) { outError = new Exception("要素类" + desFeaClsName + "字段" + labelFieldName + "不存在!"); return; } //查找源要素类中符合分类代码限制条件的要素 string whereStr = ""; if (oriCodeValue != "") { whereStr = codeName + " ='" + oriCodeValue + "'"; } IQueryFilter pFilter = new QueryFilterClass(); pFilter.WhereClause = whereStr; IFeatureCursor pCursor = pOriFeaCls.Search(pFilter, false); if (pCursor == null) { return; } IFeature pOriFea = pCursor.NextFeature(); //遍历源要素,进行比较 while (pOriFea != null) { #region 进行检查 string oriElevValue = pOriFea.get_Value(oriEleIndex).ToString(); //根据原高程值求出精度允许的高程值用于比较 if (oriElevValue.Contains(".")) { //原高程值包含小数点 int oriDotIndex = oriElevValue.IndexOf('.'); if (precision == 0) { oriElevValue = oriElevValue.Substring(0, oriDotIndex); } else if (oriElevValue.Substring(oriDotIndex + 1).Length > precision && precision > 0) { //原高程值的小数点位数大于精度控制 int oriLen = oriDotIndex + 1 + Convert.ToInt32(precision); oriElevValue = oriElevValue.Substring(0, oriLen); } } IFeature desFeature = GetNearestFeature(pDesFeaCls, codeName, desCodeValue, pOriFea, radius, out outError); if (outError != null) { return; } if (desFeature == null) { pOriFea = pCursor.NextFeature(); continue; } string desElevValue = desFeature.get_Value(desElevIndex).ToString(); if (desElevValue.Contains(".")) { //目标高程值包含小数点 int desDotIndex = desElevValue.IndexOf('.'); if (precision == 0) { desElevValue = desElevValue.Substring(0, desDotIndex); } else if (desElevValue.Substring(desDotIndex + 1).Length > precision && precision > 0) { //目标高程值的小数点位数大于精度 int desLen = desDotIndex + 1 + Convert.ToInt32(precision); desElevValue = desElevValue.Substring(0, desLen); } } //根据精度进行比较,在容许的范围内不相同不算错误 if (Convert.ToDouble(oriElevValue) != Convert.ToDouble(desElevValue)) { //说明点,或线与相应注记的高程值不一致。将错误结果显示出来 double pMapx = 0.0; double pMapy = 0.0; IPoint pPoint = new PointClass(); if (pOriFeaCls.ShapeType != esriGeometryType.esriGeometryPoint) { pPoint = TopologyCheckClass.GetPointofFeature(pOriFea); } else { //点要素类 pPoint = pOriFea.Shape as IPoint; } pMapx = pPoint.X; pMapy = pPoint.Y; List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("点线注记高程值一致性检查"); //功能名称 ErrorLst.Add(""); //数据文件名 ErrorLst.Add(0); //错误id; ErrorLst.Add("图层" + oriFeaClsName + "与图层" + desFeaClsName + "高程值不一致"); //错误描述 ErrorLst.Add(pMapx); //... ErrorLst.Add(pMapy); //... ErrorLst.Add(oriFeaClsName); ErrorLst.Add(pOriFea.OID); ErrorLst.Add(desFeaClsName); ErrorLst.Add(desFeature.OID); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent); } pOriFea = pCursor.NextFeature(); #endregion } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); } catch (Exception ex) { outError = ex; } }
/// <summary> /// 空值检查 /// </summary> /// <param name="hook"></param> /// <param name="pFeatureDataset"></param> /// <param name="FeaClsNameDic">图层名和属性非空的字段名对</param> /// <param name="outError"></param> public void IsNullableCheck(IArcgisDataCheckHook hook, IFeatureDataset pFeatureDataset, Dictionary <string, List <string> > FeaClsNameDic, out Exception outError) { outError = null; try { //设置进度条 ProgressChangeEvent eInfo = new ProgressChangeEvent(); eInfo.Max = FeaClsNameDic.Count; int pValue = 0; foreach (KeyValuePair <string, List <string> > item in FeaClsNameDic) { IFeatureClass pFeaCls = (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(item.Key.Trim()); for (int i = 0; i < item.Value.Count; i++) { string fieldName = item.Value[i].Trim(); int index = pFeaCls.Fields.FindField(fieldName); if (index == -1) { outError = new Exception("找不到字段名为" + fieldName + "的字段"); return; } if (pFeaCls.Fields.get_Field(index).IsNullable == true) { //字段属性为空,与标准不一致,将结果保存起来 List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("空值检查"); //功能名称 ErrorLst.Add((pFeatureDataset as IDataset).Workspace.PathName); //数据文件名 ErrorLst.Add(enumErrorType.空值检查.GetHashCode()); //错误id; ErrorLst.Add("图层" + item.Key + "的字段" + fieldName + "属性值不允许为空"); //错误描述 ErrorLst.Add(0); //... ErrorLst.Add(0); //... ErrorLst.Add(item.Key); ErrorLst.Add(-1); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent); } else { IFeatureCursor pFeaCusor = pFeaCls.Search(null, false); if (pFeaCusor == null) { return; } IFeature pFeature = pFeaCusor.NextFeature(); if (pFeature == null) { continue; } while (pFeature != null) { object fieldValue = pFeature.get_Value(index); if (fieldValue == null || fieldValue.ToString() == "") { //字段值不能为空,将检查结果保存起来 double pMapx = 0.0; double pMapy = 0.0; IPoint pPoint = new PointClass(); if (pFeaCls.ShapeType != esriGeometryType.esriGeometryPoint) { pPoint = TopologyCheckClass.GetPointofFeature(pFeature); } else { pPoint = pFeature.Shape as IPoint; } pMapx = pPoint.X; pMapy = pPoint.Y; List <object> ErrorLst = new List <object>(); ErrorLst.Add("要素属性检查"); //功能组名称 ErrorLst.Add("空值检查"); //功能名称 ErrorLst.Add((pFeatureDataset as IDataset).Workspace.PathName); //数据文件名 ErrorLst.Add(enumErrorType.空值检查.GetHashCode()); //错误id; ErrorLst.Add("图层" + item.Key + "的字段" + fieldName + "的值不能为空"); //错误描述 ErrorLst.Add(pMapx); //... ErrorLst.Add(pMapy); //... ErrorLst.Add(item.Key); ErrorLst.Add(pFeature.OID); ErrorLst.Add(""); ErrorLst.Add(-1); ErrorLst.Add(false); ErrorLst.Add(System.DateTime.Now.ToString()); //传递错误日志 IDataErrInfo dataErrInfo = new DataErrInfo(ErrorLst); DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo); DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent); } pFeature = pFeaCusor.NextFeature(); } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCusor); } } //进度条加1 pValue++; eInfo.Value = pValue; GeoDataChecker.GeoDataChecker_ProgressShow((object)GeoDataChecker._ProgressBarInner, eInfo); } } catch (Exception ex) { outError = ex; } }