private void AutoSave_Save() { if (!CheckRequirements()) { return; } if (!IsSaveable()) { return; } ITrackCancel trackcancel = new CancelTrackerClass(); IProgressDialogFactory progressdialogfactory = new ProgressDialogFactoryClass(); IStepProgressor stepprogressor = progressdialogfactory.Create(trackcancel, _application.hWnd); stepprogressor.MinRange = 0; stepprogressor.MaxRange = 1; stepprogressor.StepValue = 1; stepprogressor.Message = "Saving..."; IProgressDialog2 progressdialog = (IProgressDialog2)stepprogressor; // Creates and displays progressdialog.CancelEnabled = true; progressdialog.Description = "Saving..."; progressdialog.Title = "Saving..."; progressdialog.Animation = esriProgressAnimationTypes.esriDownloadFile; try { ILayer layer = _utilitiesArcmap.Layer(this.cboTargetLayer.Text); IFeatureLayer featurelayer = layer as IFeatureLayer; if (!(featurelayer == null)) { IFeatureClass featureclass = featurelayer.FeatureClass; IWorkspace2 workspace = ((IDataset)featureclass).Workspace as IWorkspace2; IWorkspaceEdit2 workspaceedit = (IWorkspaceEdit2)workspace; workspaceedit.StopEditing(true); workspaceedit.StartEditing(true); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ABE Calculators", MessageBoxButtons.OK, MessageBoxIcon.Stop); } finally { trackcancel = null; stepprogressor = null; progressdialog.HideDialog(); progressdialog = null; this.btnClose.Enabled = true; } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { #region 处理各种交互情况 switch (m_sketchshape) { case "polygon": { IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay; IPoint newPoint = new PointClass(); newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { //左单击画多边形添加点: if (m_NewPolygonFeedback == null) { m_NewPolygonFeedback = new NewPolygonFeedbackClass(); m_NewPolygonFeedback.Display = iSDisplay; m_NewPolygonFeedback.Start(newPoint); } else { m_NewPolygonFeedback.AddPoint(newPoint); } } if (e.button == 2) { if (m_NewPolygonFeedback == null) { return; } //右键结束绘制: m_NewPolygonFeedback.AddPoint(newPoint); m_NewPolygon = m_NewPolygonFeedback.Stop(); //若是逆时针创建,反转一下,变为顺时针: IArea feedBackArea = m_NewPolygon as IArea; if (feedBackArea.Area < 0) { m_NewPolygon.ReverseOrientation(); } IGeometry newGeometry = m_NewPolygon as IGeometry; IFeatureWorkspace checkWorkspace = m_GlobalWorkspace as IFeatureWorkspace; IFeatureClass checkFeatureClass = checkWorkspace.OpenFeatureClass("CheckArea"); if (!(m_EditWorkspace.IsBeingEdited())) { m_EditWorkspace.StartEditing(false); } m_EditWorkspace.StartEditOperation(); int OID = CheckFeatueEditor.InsertNewFeature(newGeometry, checkFeatureClass, AppManager.GetInstance().TaskName); m_EditWorkspace.StopEditOperation(); //ISelectionEnvironment selectionEnv = new SelectionEnvironmentClass(); //selectionEnv.AreaSelectionMethod = esriSpatialRelEnum.esriSpatialRelOverlaps; //selectionEnv.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, null, true); //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, selectionEnv, true); //m_MapCtrls.Map.SelectByShape(m_NewPolygon, null, true); ILayer iLayer = m_MapCtrls.Layer[0]; IFeature iFeature = checkFeatureClass.GetFeature(OID); clearFeatureSelection(); m_MapCtrls.Map.SelectFeature(iLayer, iFeature); m_NewPolygonFeedback = null; m_MapCtrls.ActiveView.Refresh(); } break; } case "rectangle": { IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay; IPoint newPoint = new PointClass(); newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { if (m_RecFeedback == null) { m_RecFeedback = new NewRectangleFeedbackClass(); m_RecFeedback.Display = iSDisplay; m_RecFeedback.Angle = 90; m_RecFeedback.Start(newPoint); newPoint.Y = newPoint.Y + 20; m_RecFeedback.SetPoint(newPoint); } else { m_RecFeedback.SetPoint(newPoint); } } if (e.button == 2) { if (m_RecFeedback != null) { m_NewPolygon = m_RecFeedback.Stop(newPoint) as IPolygon; //若是逆时针创建,反转一下,变为顺时针: IArea feedBackArea = m_NewPolygon as IArea; if (feedBackArea.Area < 0) { m_NewPolygon.ReverseOrientation(); } IGeometry newGeometry = m_NewPolygon as IGeometry; IFeatureWorkspace checkWorkspace = m_GlobalWorkspace as IFeatureWorkspace; IFeatureClass checkFeatureClass = checkWorkspace.OpenFeatureClass("CheckArea"); if (!(m_EditWorkspace.IsBeingEdited())) { m_EditWorkspace.StartEditing(false); } m_EditWorkspace.StartEditOperation(); int OID = CheckFeatueEditor.InsertNewFeature(newGeometry, checkFeatureClass, AppManager.GetInstance().TaskName); m_EditWorkspace.StopEditOperation(); ILayer iLayer = m_MapCtrls.Layer[0]; IFeature iFeature = checkFeatureClass.GetFeature(OID); clearFeatureSelection(); m_MapCtrls.Map.SelectFeature(iLayer, iFeature); m_MapCtrls.ActiveView.Refresh(); m_RecFeedback = null; } } break; } } #endregion }
public bool CheckIn(IWorkspace store, string versionName, string dbpath, string gridFeatureClass, string gridCodeFieldName) { //创建子版本 IVersion ver_store = store as IVersion; IVersion new_version = ver_store.CreateVersion(versionName); new_version.Access = esriVersionAccess.esriVersionAccessPublic; IFeatureWorkspace target_ws = new_version as IFeatureWorkspace; IWorkspaceEdit2 wse = target_ws as IWorkspaceEdit2; //删除TaskGridLog ITable grid_tbl = target_ws.OpenTable("TaskGridLog"); IQueryFilter grid_filter = new QueryFilterClass(); grid_filter.WhereClause = "TaskName = '" + versionName + "'"; wse.StartEditing(false); grid_tbl.DeleteSearchedRows(grid_filter); wse.StopEditing(true); //删除CheckItem IQueryFilter checkItems_filter = new QueryFilterClass(); checkItems_filter.WhereClause = "versionName = '" + versionName + "'"; ITable checkItems = target_ws.OpenTable("CheckItemPtn"); checkItems.DeleteSearchedRows(checkItems_filter); checkItems = target_ws.OpenTable("CheckItemLn"); checkItems.DeleteSearchedRows(checkItems_filter); checkItems = target_ws.OpenTable("CheckItemPoly"); checkItems.DeleteSearchedRows(checkItems_filter); IFeatureClass grid_fc = target_ws.OpenFeatureClass(gridFeatureClass); int gridCodeFld_idx = grid_fc.FindField(gridCodeFieldName); Dictionary <string, int[]> updateGridCodes = new Dictionary <string, int[]>(); ISpatialFilter gridFilter = new SpatialFilter(); gridFilter.GeometryField = grid_fc.ShapeFieldName; gridFilter.AddField(gridCodeFieldName); gridFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; //总更新网格面积 double totalUpdateGridsArea = 0; double totalUpdateGrids = 0; double totalUpdateItems = 0; double totalAddItems = 0; double totalDeleteItems = 0; wse.StartEditing(true); try { Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance (factoryType); IWorkspace source = workspaceFactory.OpenFromFile(dbpath, 0); IDataset ds = source as IDataset; List <String> fcNames = new List <string>(); Util.GetAllFeatureClassNames(ds, ref fcNames); IFeatureWorkspace source_ws = source as IFeatureWorkspace; foreach (string fcname in fcNames) { IWorkspace2 target_ws2 = target_ws as IWorkspace2; if (!target_ws2.get_NameExists(esriDatasetType.esriDTFeatureClass, fcname)) { continue; } IFeatureClass source_fc = source_ws.OpenFeatureClass(fcname); IFeatureClass target_fc = target_ws.OpenFeatureClass(fcname); int syncid_idx = source_fc.FindField("SyncID"); Dictionary <int, int> field_idxs = new Dictionary <int, int>(); for (int i = 0; i < source_fc.Fields.FieldCount; i++) { IField source_field = source_fc.Fields.get_Field(i); if (source_field.Name == "SyncID") { continue; } if (source_field.Name == "SyncTimeStamp") { continue; } if (source_field.Name == "SyncStatus") { continue; } if (source_field.Name == "SyncEditable") { continue; } if (source_field.Name == source_fc.OIDFieldName) { continue; } int j = target_fc.FindField(source_field.Name); if (j != -1) { field_idxs.Add(i, j); } } string checkItemName; switch (target_fc.ShapeType) { case esriGeometryType.esriGeometryPoint: checkItemName = "CheckItemPtn"; break; case esriGeometryType.esriGeometryPolyline: checkItemName = "CheckItemLn"; break; case esriGeometryType.esriGeometryPolygon: checkItemName = "CheckItemPoly"; break; default: checkItemName = "CheckItemPoly"; break; } IFeatureClass checkItem_fc = target_ws.OpenFeatureClass(checkItemName); int checkItem_f1 = checkItem_fc.FindField("FeatureClassName"); int checkItem_f2 = checkItem_fc.FindField("FeatureID"); int checkItem_f3 = checkItem_fc.FindField("VersionName"); int checkItem_f4 = checkItem_fc.FindField(checkItem_fc.ShapeFieldName); IGeoDataset checkItem_gds = checkItem_fc as IGeoDataset; //同步更新 wse.StartEditOperation(); IQueryFilter filter = new QueryFilterClass(); filter.WhereClause = "[SyncStatus]='U'"; IFeatureCursor source_cur = source_fc.Search(filter, false); IFeature source_fea = source_cur.NextFeature(); while (source_fea != null) { int id = Convert.ToInt32(source_fea.get_Value(syncid_idx)); IFeature target_fea = target_fc.GetFeature(id); foreach (KeyValuePair <int, int> field_idx in field_idxs) { target_fea.set_Value(field_idx.Value, source_fea.get_Value(field_idx.Key)); } target_fea.Store(); //添加check item IFeature checkItem_fea = checkItem_fc.CreateFeature(); checkItem_fea.set_Value(checkItem_f1, fcname); checkItem_fea.set_Value(checkItem_f2, id); checkItem_fea.set_Value(checkItem_f3, versionName); IGeometry shape = target_fea.ShapeCopy; shape.Project(checkItem_gds.SpatialReference); checkItem_fea.set_Value(checkItem_f4, shape); checkItem_fea.Store(); //添加TaskGridLog gridFilter.Geometry = target_fea.Shape; IFeatureCursor grid_cur = grid_fc.Search(gridFilter, true); IFeature grid_fea = grid_cur.NextFeature(); while (grid_fea != null) { string gridid = grid_fea.get_Value(gridCodeFld_idx).ToString(); if (updateGridCodes.ContainsKey(gridid)) { updateGridCodes[gridid][0] += 1; } else { int[] c = new int[2] { 1, 0 }; updateGridCodes.Add(gridid, c); } IArea area = grid_fea.Shape as IArea; totalUpdateGridsArea += area.Area; grid_fea = grid_cur.NextFeature(); } totalUpdateItems += 1; source_fea = source_cur.NextFeature(); } wse.StopEditOperation(); //同步删除 wse.StartEditOperation(); List <int> lst_del = new List <int>(); TaskManager tm = TaskManager.GetInstance(); ISpatialFilter target_filter = new SpatialFilterClass(); target_filter.Geometry = tm.GetTaskLocation(versionName); target_filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; target_filter.SubFields = ""; using (ComReleaser comReleaser = new ComReleaser()) { IFeatureCursor target_fea_cur = target_fc.Search(target_filter, false); comReleaser.ManageLifetime(target_fea_cur); IFeature target_fea_del = target_fea_cur.NextFeature(); while (target_fea_del != null) { filter = new QueryFilterClass(); filter.WhereClause = "[SyncID]=" + target_fea_del.OID.ToString(); using (ComReleaser comReleaser2 = new ComReleaser()) { IFeatureCursor source_cur_del = source_fc.Search(filter, true); comReleaser2.ManageLifetime(source_cur_del); source_fea = source_cur_del.NextFeature(); if (source_fea == null) { lst_del.Add(target_fea_del.OID); totalDeleteItems += 1; } } target_fea_del = target_fea_cur.NextFeature(); } } foreach (int id in lst_del) { IFeature target_fea_del = target_fc.GetFeature(id); target_fea_del.Delete(); } wse.StopEditOperation(); //同步新建 wse.StartEditOperation(); filter = new QueryFilterClass(); filter.WhereClause = "[SyncID] is null"; source_cur = source_fc.Search(filter, false); source_fea = source_cur.NextFeature(); while (source_fea != null) { IFeature target_fea = target_fc.CreateFeature(); foreach (KeyValuePair <int, int> field_idx in field_idxs) { target_fea.set_Value(field_idx.Value, source_fea.get_Value(field_idx.Key)); } target_fea.Store(); //添加check item IFeature checkItem_fea = checkItem_fc.CreateFeature(); checkItem_fea.set_Value(checkItem_f1, fcname); checkItem_fea.set_Value(checkItem_f2, target_fea.OID); checkItem_fea.set_Value(checkItem_f3, versionName); IGeometry shape = target_fea.ShapeCopy; shape.Project(checkItem_gds.SpatialReference); checkItem_fea.set_Value(checkItem_f4, shape); checkItem_fea.Store(); //添加TaskGridLog gridFilter.Geometry = target_fea.Shape; IFeatureCursor grid_cur = grid_fc.Search(gridFilter, true); IFeature grid_fea = grid_cur.NextFeature(); while (grid_fea != null) { string gridid = grid_fea.get_Value(gridCodeFld_idx).ToString(); if (updateGridCodes.ContainsKey(gridid)) { updateGridCodes[gridid][1] += 1; } else { int[] c = new int[2] { 0, 1 }; updateGridCodes.Add(gridid, c); } IArea area = grid_fea.Shape as IArea; totalUpdateGridsArea += area.Area; grid_fea = grid_cur.NextFeature(); } totalAddItems += 1; source_fea = source_cur.NextFeature(); } wse.StopEditOperation(); } //添加TaskGridLog wse.StartEditOperation(); using (ComReleaser comR = new ComReleaser()) { ICursor tgl_cur = grid_tbl.Insert(true); IRowBuffer tgl_rowBF = grid_tbl.CreateRowBuffer(); comR.ManageLifetime(tgl_rowBF); comR.ManageLifetime(tgl_cur); foreach (string gridcode in updateGridCodes.Keys) { tgl_rowBF.set_Value(1, versionName); tgl_rowBF.set_Value(2, gridcode); tgl_rowBF.set_Value(4, updateGridCodes[gridcode][1]); tgl_rowBF.set_Value(5, updateGridCodes[gridcode][0]); tgl_cur.InsertRow(tgl_rowBF); } tgl_cur.Flush(); } wse.StopEditOperation(); //设置Task的内容更新信息 totalUpdateGrids = updateGridCodes.Keys.Count; wse.StartEditOperation(); IFeatureClass task_fc = target_ws.OpenFeatureClass("TaskLog"); IQueryFilter task_filter = new QueryFilterClass(); task_filter.WhereClause = "TaskName = '" + versionName + "'"; IFeatureCursor cur = task_fc.Update(task_filter, true); IFeature task_fea = cur.NextFeature(); if (task_fea != null) { task_fea.set_Value(task_fc.FindField("totalAddItems"), totalAddItems); task_fea.set_Value(task_fc.FindField("totalUpdateItems"), totalUpdateItems); task_fea.set_Value(task_fc.FindField("totalDeleteItems"), totalDeleteItems); task_fea.set_Value(task_fc.FindField("totalGrids"), totalUpdateGrids); task_fea.set_Value(task_fc.FindField("totalGridsArea"), totalUpdateGridsArea); task_fea.Store(); } wse.StopEditOperation(); } catch (Exception ex) { return(false); } finally { wse.StopEditing(true); } return(true); }
public override void StartEditing(bool withUndo) { IWorkspaceEdit2 workspaceEdit = GetEditingWorkspace; workspaceEdit.StartEditing(withUndo); }
private void btnInserir_Click(object sender, EventArgs e) { // valida os campos if (!this.ValidarCampos()) { return; } // workspace IWorkspace workspace = ArcMapUtils.GetFeatureLayerWorkspace(this._layerDeUnidadesDeSaude); IWorkspaceEdit2 workspaceEdit = workspace as IWorkspaceEdit2; if (workspaceEdit.IsBeingEdited()) { MessageBox.Show(this, "O workspace está em edição. Aguarde.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } // filtro para achar o bairro e o distrito sanitário a que a unidade de saúde pertence ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = this._featureParaCopia.ShapeCopy; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; // pegar o código do bairro IFeatureCursor featCursorBairros = this._layerDeBairros.Search(spatialFilter, false); IFeature featureBairro = featCursorBairros.NextFeature(); int nomeIndex = this._layerDeBairros.FeatureClass.FindField("nome"); int codigoBairro = featureBairro.OID; string nomeBairro = (string)featureBairro.get_Value(nomeIndex); //pegar o código do distrito sanitário IFeatureCursor featCursorDistritos = this._layerDeDistritos.Search(spatialFilter, false); IFeature featureDistrito = featCursorDistritos.NextFeature(); int nomeIndex1 = this._layerDeDistritos.FeatureClass.FindField("nome"); int codigoDistrito = featureDistrito.OID; string nomeDistrito = (string)featureDistrito.get_Value(nomeIndex1); this.Cursor = Cursors.WaitCursor; //cadastra a nova unidade de saúde try { // inicia edição workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); // dados da nova Unidade de Saúde UnidadeSaude unidadeDeSaude = new UnidadeSaude(); unidadeDeSaude.Nome = txtNomeUS.Text.ToString(); unidadeDeSaude.Endereco = txtEnderecoUS.Text.ToString(); unidadeDeSaude.Bairro = txtBairroUS.Text.ToString(); unidadeDeSaude.DistritoSanitario = txtDistritoUS.Text.ToString(); unidadeDeSaude.CodigoBairro = (int)codigoBairro; unidadeDeSaude.CodigoDistritoSanitario = (int)codigoDistrito; // criação da nova feature IFeature featureUnidadeDeSaude = this._layerDeUnidadesDeSaude.FeatureClass.CreateFeature(); featureUnidadeDeSaude.Shape = _featureParaCopia.ShapeCopy; unidadeDeSaude.ToFeature(featureUnidadeDeSaude); // finaliza edição workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); MessageBox.Show(this, "Unidade de Saúde inserida com sucesso !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // limpa seleção ArcMap.Document.FocusMap.ClearSelection(); // fecha o formulário this.Close(); } catch { // cancela edição if (workspaceEdit.IsInEditOperation) { workspaceEdit.AbortEditOperation(); } workspaceEdit.StopEditing(false); MessageBox.Show(this, "Não foi possível realizar a inserção de uma nova unidade de saúde !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { // refresh IActiveView activeView = ArcMap.Document.FocusMap as IActiveView; activeView.Refresh(); // cursor this.Cursor = Cursors.Default; } }
//private static IFeatureWorkspace m_FeatureWorkspace; /// <summary> /// 数据编码(自动赋值编码) /// </summary> /// <param name="source">源要素类</param> /// <param name="target">目标要素类</param> /// <param name="relation">匹配结果表</param> /// <param name="updateRela">欲更新的属性表字段</param> /// <param name="pProgressBarX"></param> /// <param name="targetFeatureWorkspace">待匹配图层路径</param> /// <returns></returns> //public static bool UpdateData(IFeatureClass sourceFcls, IFeatureClass targetFcls, ITable resultTable, Dictionary<string, string> updateRela // , ProgressBarX pProgressBarX, IFeatureWorkspace targetFeatureWorkspace) public static bool UpdateData(IFeatureClass sourceFcls, IFeatureClass targetFcls, ITable resultTable, ProgressBarX pProgressBarX, IFeatureWorkspace targetFeatureWorkspace) { ClsBarSync progressBar = new ClsBarSync(pProgressBarX); progressBar.SetStep(1); progressBar.SetMax(resultTable.RowCount(null)); //检查参数 if (sourceFcls == null || targetFcls == null || resultTable == null) { return(false); } #region 原注释 //当欲更新字段在目标要素类中不存在时,新建字段 //foreach (string item in fields) //{ // if (target.FindField(item) == -1) // { // IField addedField = source.Fields.get_Field(source.FindField(item)); // target.AddField(addedField); // } //} #endregion //20170914 注释掉 ////当欲更新字段在目标要素类中不存在时,新建字段 //foreach (KeyValuePair<string, string> item in updateRela) //{ // if (targetFcls.FindField(item.Value) == -1) // { // IField addedField = new FieldClass(); // IFieldEdit pFieldEdit = addedField as IFieldEdit; // pFieldEdit.Name_2 = item.Value; // pFieldEdit.AliasName_2 = item.Value; // pFieldEdit.Editable_2 = true; // pFieldEdit.Required_2 = false; // pFieldEdit.IsNullable_2 = true; // targetFcls.AddField(addedField); // } //} IWorkspaceEdit2 pWorkspaceEdit = targetFeatureWorkspace as IWorkspaceEdit2; pWorkspaceEdit.StartEditing(false); pWorkspaceEdit.StartEditOperation(); #region 20170515注释掉 //ClsUpdateCommon.EnableAchive(target.AliasName, targetFeatureWorkspace); //IHistoricalWorkspace pHistoricalWorkspace = targetFeatureWorkspace as IHistoricalWorkspace; //DateTime dTime=DateTime.Now; //pHistoricalWorkspace.AddHistoricalMarker(dTime.ToString(), dTime);//严格应该为数据库时间 #endregion #region 原来注释 //foreach (KeyValuePair<string, string> item in updateRela) //{ // if (target.FindField(item.Value) == -1) // { // IField addedField = new FieldClass(); // IFieldEdit pFieldEdit = addedField as IFieldEdit; // pFieldEdit.Name_2 = item.Value; // pFieldEdit.AliasName_2 = item.Value; // pFieldEdit.Editable_2 = true; // pFieldEdit.Required_2 = false; // pFieldEdit.IsNullable_2 = true; // target.AddField(addedField); // } //} #endregion //源图层要素的oid——1 int pSrcOIDIndex = resultTable.FindField("源OID"); //待匹配图层要素的oid——2 int pTarOIDIndex = resultTable.FindField("待匹配OID"); //变化标记的oid——3 int pChangeTagIndex = resultTable.FindField("变化标记"); ICursor rowCursor = resultTable.Search(null, false); IRow tempRow = null; tempRow = rowCursor.NextRow(); while (tempRow != null) { //当没有匹配的项时或者未发生变化时不做任何更改 if (tempRow.get_Value(pTarOIDIndex) == null || tempRow.get_Value(pChangeTagIndex).ToString() == "0") { progressBar.PerformOneStep(); continue; } //获取源图层要素 IFeature sourceFeature = sourceFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pSrcOIDIndex))); //变化标记字段值 string pChangeContent = tempRow.get_Value(pChangeTagIndex).ToString(); //获取源图层要素 string[] fromids = tempRow.get_Value(pTarOIDIndex).ToString().Split(';'); if (!(fromids.Length == 1 && fromids[0].Trim().Length == 0)) { //查找匹配与待匹配的要素 IFeature targetFeature = null; //点和线匹配名称 string pSourceName = sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].NameField)).ToString(); string pTargetName = string.Empty; //面匹配分类码 //string pSourceFCODE = sourceFeature.get_Value(sourceFeature.Fields.FindField("FCODE")).ToString().Trim(); string pTargetFCODE = string.Empty; //不同形状的数据 if (sourceFcls.ShapeType != targetFcls.ShapeType) { if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { //根据不同的匹配类型进行相关操作 switch (pChangeContent) { case "图形变化": //图形变化 //case "一对一": case ClsConstant.One2One: //targetFeature.Shape = sourceFeature.Shape; //plistString.Add(sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID")).ToString()); //test targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex))); string test3 = ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField; pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); //test string test1 = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID)).ToString(); string test2 = sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID)).ToString(); if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1) { targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); } //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID"))); break; //case "新增要素"://新添加要素 case ClsConstant.One2Zero: //新添加要素 //targetFeature = target.CreateFeature(); //targetFeature.Shape = sourceFeature.ShapeCopy; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "一对多": case ClsConstant.One2More: //for (int i = 0; i < fromids.Length; i++) //{ // string test = fromids[i]; // int test3 = Convert.ToInt32(fromids[i]); // targetFeature = target.GetFeature(Convert.ToInt32(fromids[i])); // pTargetName = targetFeature.get_Value(targetFeature.Fields.FindFieldByAliasName("名称")).ToString(); // //targetFeature.Shape = sourceFeature.Shape; // if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1) // { // if (targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")).ToString().Trim().Length == 0) // { // targetFeature.set_Value(targetFeature.Fields.FindField("ENTIID"), sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID"))); // targetFeature.Store(); // } // } //} //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //return false; break; case "属性变化": //属性变化 //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; case "属性图形变化": //都变化 //targetFeature.Shape = sourceFeature.Shape; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "多对一"://多尺度更新 case ClsConstant.More2One: //多尺度更新 //targetFeature.Shape = finalGeometry; break; default: break; } } else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { //根据不同的匹配类型进行相关操作 switch (pChangeContent) { case "图形变化": //图形变化 //case "一对一": case ClsConstant.One2One: targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex))); pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); //targetFeature.Shape = sourceFeature.Shape; if (pSourceName == pTargetName) { targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); } //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID"))); break; //case "新增要素"://新添加要素 case ClsConstant.One2Zero: //新添加要素 //targetFeature = target.CreateFeature(); //targetFeature.Shape = sourceFeature.ShapeCopy; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "一对多": case ClsConstant.One2More: //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //return false; for (int i = 0; i < fromids.Length; i++) { string test = fromids[i]; int test2 = Convert.ToInt32(fromids[i]); targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i])); pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); //targetFeature.Shape = sourceFeature.Shape; if (pSourceName == pTargetName) { if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID)).ToString().Trim().Length == 0) { targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); } } } break; case "属性变化": //属性变化 //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; case "属性图形变化": //都变化 //targetFeature.Shape = sourceFeature.Shape; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "多对一"://多尺度更新 case ClsConstant.More2One: //多尺度更新 //targetFeature.Shape = finalGeometry; break; default: break; } } else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { //根据不同的匹配类型进行相关操作 switch (pChangeContent) { case "图形变化": //图形变化 //case "一对一": case ClsConstant.One2One: targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex))); pTargetFCODE = targetFeature.get_Value(targetFeature.Fields.FindField("FCODE")).ToString().Trim(); //targetFeature.Shape = sourceFeature.Shape; //if (pSourceFCODE == pTargetFCODE) //{ targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); //} //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID"))); break; //case "新增要素"://新添加要素 case ClsConstant.One2Zero: //新添加要素 //targetFeature = target.CreateFeature(); //targetFeature.Shape = sourceFeature.ShapeCopy; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "一对多": case ClsConstant.One2More: //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //return false; //for (int i = 0; i < fromids.Length; i++) //{ // string test = fromids[i]; // int test2 = Convert.ToInt32(fromids[i]); // targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i])); // pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); // //targetFeature.Shape = sourceFeature.Shape; // if (pSourceName == pTargetName) // { // if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID)).ToString().Trim().Length == 0) // { // targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); // targetFeature.Store(); // } // } //} break; case "属性变化": //属性变化 //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; case "属性图形变化": //都变化 //targetFeature.Shape = sourceFeature.Shape; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "多对一"://多尺度更新 case ClsConstant.More2More: //多尺度更新 //targetFeature.Shape = finalGeometry; break; default: break; } } } //相同形状的数据 else { if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { //根据不同的匹配类型进行相关操作 switch (pChangeContent) { case "图形变化": //图形变化 //case "一对一": case ClsConstant.One2One: //targetFeature.Shape = sourceFeature.Shape; //plistString.Add(sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID")).ToString()); //test targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex))); //string test3 = ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField; string test3 = ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField; pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); //test string test1 = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID)).ToString(); string test2 = sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID)).ToString(); //if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1) //{ targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); //} //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID"))); break; //case "新增要素"://新添加要素 case ClsConstant.One2Zero: //新添加要素 //targetFeature = target.CreateFeature(); //targetFeature.Shape = sourceFeature.ShapeCopy; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "一对多": case ClsConstant.One2More: //for (int i = 0; i < fromids.Length; i++) //{ // string test = fromids[i]; // int test3 = Convert.ToInt32(fromids[i]); // targetFeature = target.GetFeature(Convert.ToInt32(fromids[i])); // pTargetName = targetFeature.get_Value(targetFeature.Fields.FindFieldByAliasName("名称")).ToString(); // //targetFeature.Shape = sourceFeature.Shape; // if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1) // { // if (targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")).ToString().Trim().Length == 0) // { // targetFeature.set_Value(targetFeature.Fields.FindField("ENTIID"), sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID"))); // targetFeature.Store(); // } // } //} //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //return false; break; case "属性变化": //属性变化 //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; case "属性图形变化": //都变化 //targetFeature.Shape = sourceFeature.Shape; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "多对一"://多尺度更新 case ClsConstant.More2One: //多尺度更新 //targetFeature.Shape = finalGeometry; break; default: break; } } else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { //根据不同的匹配类型进行相关操作 switch (pChangeContent) { case "图形变化": //图形变化 //case "一对一": case ClsConstant.One2One: targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex))); pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); //targetFeature.Shape = sourceFeature.Shape; //if (pSourceName == pTargetName) //{ targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); //} //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID"))); break; //case "新增要素"://新添加要素 case ClsConstant.One2Zero: //新添加要素 //targetFeature = target.CreateFeature(); //targetFeature.Shape = sourceFeature.ShapeCopy; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "一对多": case ClsConstant.One2More: //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //return false; for (int i = 0; i < fromids.Length; i++) { string test = fromids[i]; int test2 = Convert.ToInt32(fromids[i]); targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i])); pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); //targetFeature.Shape = sourceFeature.Shape; if (pSourceName == pTargetName) { if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID)).ToString().Trim().Length == 0) { targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); } } } break; case "属性变化": //属性变化 //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; case "属性图形变化": //都变化 //targetFeature.Shape = sourceFeature.Shape; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "多对一"://多尺度更新 case ClsConstant.More2One: //多尺度更新 //targetFeature.Shape = finalGeometry; break; default: break; } } else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { //根据不同的匹配类型进行相关操作 switch (pChangeContent) { case "图形变化": //图形变化 //case "一对一": case ClsConstant.One2One: targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex))); pTargetFCODE = targetFeature.get_Value(targetFeature.Fields.FindField("FCODE")).ToString().Trim(); //targetFeature.Shape = sourceFeature.Shape; //if (pSourceFCODE == pTargetFCODE) //{ targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); targetFeature.Store(); //} //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID"))); break; //case "新增要素"://新添加要素 case ClsConstant.One2Zero: //新添加要素 //targetFeature = target.CreateFeature(); //targetFeature.Shape = sourceFeature.ShapeCopy; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "一对多": case ClsConstant.One2More: //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //return false; //for (int i = 0; i < fromids.Length; i++) //{ // string test = fromids[i]; // int test2 = Convert.ToInt32(fromids[i]); // targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i])); // pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].NameField)).ToString(); // //targetFeature.Shape = sourceFeature.Shape; // if (pSourceName == pTargetName) // { // if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID)).ToString().Trim().Length == 0) // { // targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls as IDataset).Name].EntityID))); // targetFeature.Store(); // } // } //} break; case "属性变化": //属性变化 //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; case "属性图形变化": //都变化 //targetFeature.Shape = sourceFeature.Shape; //UpdateAttribute(sourceFeature, targetFeature, updateRela); break; //case "多对一"://多尺度更新 case ClsConstant.More2More: //多尺度更新 //targetFeature.Shape = finalGeometry; break; default: break; } } } //targetFeature.Store(); } progressBar.PerformOneStep(); tempRow = rowCursor.NextRow(); } //对待匹配图层中剩余的点()进行编码 //CreatePOICodeRest(target, "ENTIID", plistString); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); return(true); }
public void LinkElevation() { if (_pointClassInfo == null || _lineClassInfo == null) { return; } IDataset pDS = _lineClassInfo.PipeClass as IDataset; IWorkspace2 pWorkspace2 = pDS.Workspace as IWorkspace2; IWorkspaceEdit2 pWorkspaceEdit = pWorkspace2 as IWorkspaceEdit2; if (pWorkspaceEdit == null) { return; } pWorkspaceEdit.StartEditing(false); pWorkspaceEdit.StartEditOperation(); try { IFeatureCursor pCursor = _lineClassInfo.PipeClass.Search(null, false); IFeature pLineFeature = null; ISpatialFilter pSearchFilter = new SpatialFilterClass(); while ((pLineFeature = pCursor.NextFeature()) != null) { IPolyline pLine = pLineFeature.Shape as IPolyline; if (pLine == null) { continue; } IPoint pStartPoint = pLine.FromPoint; IPoint pEndPoint = pLine.ToPoint; //开始发现起点的点 IEnvelope envelope = pStartPoint.Envelope; envelope.Expand(_searchTolerance, _searchTolerance, false); pSearchFilter.Geometry = envelope; pSearchFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; IFeatureCursor pFindCursor = _pointClassInfo.PipeClass.Search(((IQueryFilter)pSearchFilter), false); IFeature pPointFeature = pFindCursor.NextFeature(); if (pPointFeature != null) { double elevation = Convert.ToDouble(pPointFeature.Value[_pointClassInfo.PointElevationField.Index] is DBNull ? 0 : pPointFeature.Value[_pointClassInfo.PointElevationField.Index]); double depth = Convert.ToDouble(pLineFeature.Value[_lineClassInfo.StartUnderGroundElevationField.Index] is DBNull ? 0 : pLineFeature.Value[_lineClassInfo.StartUnderGroundElevationField.Index]); pLineFeature.Value[_lineClassInfo.StartGroundElevationField.Index] = elevation - depth; } Marshal.ReleaseComObject(pFindCursor); envelope = pEndPoint.Envelope; envelope.Expand(_searchTolerance, _searchTolerance, false); pSearchFilter.Geometry = envelope; pSearchFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; pFindCursor = _pointClassInfo.PipeClass.Search(((IQueryFilter)pSearchFilter), false); pPointFeature = pFindCursor.NextFeature(); if (pPointFeature != null) { double elevation = Convert.ToDouble(pPointFeature.Value[_pointClassInfo.PointElevationField.Index] is DBNull ? 0 : pPointFeature.Value[_pointClassInfo.PointElevationField.Index]); double depth = Convert.ToDouble(pLineFeature.Value[_lineClassInfo.EndUnderGroundElevationField.Index] is DBNull ? 0 : pLineFeature.Value[_lineClassInfo.EndUnderGroundElevationField.Index]); pLineFeature.Value[_lineClassInfo.EndGroundElevationField.Index] = elevation - depth; } pLineFeature.Store(); Marshal.ReleaseComObject(pFindCursor); } Marshal.ReleaseComObject(pCursor); } finally { pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } }
protected override void OnClick() { try { if (_wkspHelper.CurrentWorkspace == null) { MessageBox.Show("You must select and open a telecom workspace before running this tool"); return; } DialogResult res = MessageBox.Show(null, "This test may run for a considerable time (15+ minutes) and may make modifications to the database to resolve issues. \n\nConsider taking a backup before doing this. \n\nDo you wish to proceed?", "DB Integrity Check", MessageBoxButtons.OKCancel); if (res != DialogResult.OK) { return; } IFeatureClass cableFc = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName); if (cableFc == null) { return; } IFeatureWorkspace fworkspace = _wkspHelper.CurrentWorkspace; if (fworkspace == null) { return; } // -------------------------------------------- // Check the integrity of the cable feature class // -------------------------------------------- IRelationshipClass fiberCableToFiberRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToFiberRelClassName); IRelationshipClass fiberCableToBufferRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToBufferRelClassName); IFeature feature; bool badCable = false; bool badBuffers = false; bool badFibers = false; bool conversionRequired = false; IWorkspaceEdit2 edit = fworkspace as IWorkspaceEdit2; ITransactions transaction = edit as ITransactions; edit.StartEditing(true); edit.StartEditOperation(); IQueryFilter qf = new QueryFilter(); qf.AddField(ConfigUtil.NumberOfBuffersFieldName); qf.AddField(ConfigUtil.NumberOfFibersFieldName); qf.AddField(ConfigUtil.IpidFieldName); using (ComReleaser comReleaser = new ComReleaser()) { IFeatureCursor fCursor = (IFeatureCursor)cableFc.Update(qf, false); ICursor pCursor = fCursor as ICursor; comReleaser.ManageLifetime(fCursor); int buffersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfBuffersFieldName); int fibersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfFibersFieldName); int ipidFieldIdx = cableFc.FindField(ConfigUtil.IpidFieldName); int count = 0; while ((feature = fCursor.NextFeature()) != null) { // Cables should have non null field values if (feature.get_Value(ipidFieldIdx) == DBNull.Value) { badCable = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL IPID value"); continue; } if (feature.get_Value(buffersFieldIdx) == DBNull.Value) { badBuffers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } if (feature.get_Value(fibersFieldIdx) == DBNull.Value) { badFibers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL fiber field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } int bufferCount = (int)feature.get_Value(buffersFieldIdx); int fiberCount = (int)feature.get_Value(fibersFieldIdx); // Cables should have non zero values if (bufferCount == 0) { badBuffers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } if (fiberCount == 0) { badFibers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 strand field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } // Cables should have relationships int rcBufferCount = fiberCableToBufferRc.GetObjectsRelatedToObject(feature).Count; if (rcBufferCount == 0) { badBuffers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related buffers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } int rcFiberCount = fiberCableToFiberRc.GetObjectsRelatedToObject(feature).Count; if (rcFiberCount == 0) { badFibers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related fibers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } // Buffer field count & relationships to buffers not matching if (bufferCount != rcBufferCount) { badBuffers = true; String output = "Expected: " + bufferCount + " Found: " + rcBufferCount + " Cable ID: " + feature.get_Value(ipidFieldIdx).ToString(); _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with buffer count->relationship mismatch", output); continue; } // other checks if (rcFiberCount % rcBufferCount != 0) { badFibers = true; _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Fiber Cable with invalid strand count - (relationships % buffercount) is non zero", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); continue; } // we must be dealing with a total count (convert to per buffer tube value) if (fiberCount == rcFiberCount && bufferCount > 1) { count++; Debug.Write(count + " Strand Total to Strands Per Buffer conversion", " Cable ID: " + feature.get_Value(ipidFieldIdx).ToString() + "\n"); conversionRequired = true; // _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Strand Total to Strands Per Buffer conversion", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString()); feature.set_Value(fibersFieldIdx, rcFiberCount / rcBufferCount); feature.Store(); } } } edit.StopEditOperation(); edit.StopEditing(true); if (badCable) { MessageBox.Show("Database integrity issues were detected. Found invalid Fiber Cable. Please see the log file for more details"); } if (badBuffers) { MessageBox.Show("Database integrity issues were detected. Found Fiber Cable with buffer count issues. Please see the log file for more details"); } if (badFibers) { MessageBox.Show("Database integrity issues were detected. Found Fiber Cable with strands count issues. Please see the log file for more details"); } if (conversionRequired) { MessageBox.Show("Database integrity issues were detected. Strand Total to Strands Per Buffer conversion was done."); } } catch (Exception e) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Integrity Check Error", e.Message); } MessageBox.Show("The results of the DB checks are listed in the tools Log window"); }