/// <summary> /// Gets a cursor helper given a filter /// </summary> /// <param name="classIndex">ignore - feature datasets unsupported</param> /// <param name="env">Optional bounding box</param> /// <param name="strictSearch">ignore this parameter</param> /// <param name="whereClause">Optional where clause - unsupported</param> /// <param name="fidSet">Optional list of OIDs to select</param> /// <param name="fieldMap">Which fields are included in results</param> /// <returns></returns> public IPlugInCursorHelper FetchWithFilter(int classIndex, IEnvelope env, bool strictSearch, string WhereClause, IFIDSet fidSet, object fieldMap) { // without a OID list perform fetch by envelope if (null == fidSet) { return(this.FetchByEnvelope(classIndex, env, strictSearch, WhereClause, fieldMap)); } //to-do write SQL to IMongoQuery translator and assign to conditions if where clause is non-null IMongoQuery conditions = null; // build a mongo IN query of all OIDs int count = fidSet.Count(); BsonArray ba = new BsonArray(count); fidSet.Reset(); for (int i = 0; i < count; i++) { int oid; fidSet.Next(out oid); ba.Add(BsonValue.Create(oid)); } if (conditions == null) { conditions = Query.In(CommonConst.OID, ba); } else { conditions = Query.And(new IMongoQuery[] { Query.In(CommonConst.OID, ba), conditions }); } return(new MongoDBCursor(m_Connection[m_Entry.Name], env, conditions, CommonConst.SHAPEFIELD, (System.Array)fieldMap, m_Entry.Fields)); }
public IFIDSet AppendCadastralXML(ICadastralFabric Fabric, ICadastralJob CadastralJob, IProjectedCoordinateSystem TargetProjectedCoordinateSystem, string CadastralXMLPath) { try { string sTempPath = System.IO.Path.GetTempPath(); string sCopiedCadastralXMLFile = System.IO.Path.Combine(sTempPath, CadastralJob.Name.Replace('/', '_').Replace(':', '_') + ".xml"); //rename ALL oID tags so that they're ignored ReplaceInFile(CadastralXMLPath, sCopiedCadastralXMLFile, "oID>", "old_xxX>"); //Possible TODO for merge-point workaround: analyze coordinates of incoming file and if any are identical to existing fabric coordinates, then make the oID tag match //the oID of the existing point in the target fabric. This will trigger point merging of identical points ITrackCancel pTrkCan = new CancelTracker(); // Create and display the Progress Dialog IProgressDialogFactory pProDlgFact = new ProgressDialogFactory(); IProgressDialog2 pProDlg = pProDlgFact.Create(pTrkCan, 0) as IProgressDialog2; //Set the properties of the Progress Dialog pProDlg.CancelEnabled = false; pProDlg.Description = " "; pProDlg.Title = "Append"; pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe; // do an extract to set the spatial reference ((ICadastralFabric3)Fabric).ExtractCadastralPacket(CadastralJob.Name, TargetProjectedCoordinateSystem, null, true); IXMLStream pStream = new XMLStream(); pStream.LoadFromFile(sCopiedCadastralXMLFile); IFIDSet pFIDSet = null;//new FIDSet(); (Fabric as ICadastralFabric3).PostCadastralPacket(pStream, pTrkCan, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pFIDSet); //(Fabric as ICadastralFabric3).InsertCadastralPacket(CadastralJob, pStream, pTrkCan, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pFIDSet); int setCnt = pFIDSet.Count(); RefreshFabricLayers(ArcMap.Document.ActiveView.FocusMap, Fabric); File.Delete(sCopiedCadastralXMLFile); if (pProDlg != null) { pProDlg.HideDialog(); } return(pFIDSet); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
void AddEmptyPlansToList(ICadastralFabric Fabric, IFIDSet EmptyPlansFIDSet, dlgEmptyPlansList EmptyPlansList) { ITable pPlansTable = Fabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans); CheckedListBox list = EmptyPlansList.checkedListBox1; IArray array = new ArrayClass(); for (int idx = 0; idx <= (EmptyPlansFIDSet.Count() - 1); idx++) { // Add the name of the plan to the list Int32 i_x; Int32 iPlanName; iPlanName = pPlansTable.FindField("NAME"); EmptyPlansFIDSet.Next(out i_x); array.Add(i_x); string sPlanName = (string)pPlansTable.GetRow(i_x).get_Value(iPlanName); list.Items.Add(sPlanName, true); } // Bind array of plan ids with the list list.Tag = (object)array; if (list.Items.Count > 0) { EmptyPlansList.checkedListBox1_SelectedValueChanged(null, null); } }
protected override void OnClick() { m_pApp = (IApplication)ArcMap.Application; if (m_pApp == null) { //if the app is null then could be running from ArcCatalog m_pApp = (IApplication)ArcCatalog.Application; } if (m_pApp == null) { MessageBox.Show("Could not access the application.", "No Application found"); return; } IGxApplication pGXApp = (IGxApplication)m_pApp; stdole.IUnknown pUnk = null; try { pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open(); } catch (COMException ex) { if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE || ex.ErrorCode == -2147220944) { MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset"); } else { MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset"); } return; } if (pUnk is ICadastralFabric) { m_pCadaFab = (ICadastralFabric)pUnk; } else { MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric"); return; } IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); clsFabricUtils FabricUTILS = new clsFabricUtils(); IProgressDialog2 pProgressorDialog = null; ITable pTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels); IDataset pDS = (IDataset)pTable; IWorkspace pWS = pDS.Workspace; bool bIsFileBasedGDB = true; bool bIsUnVersioned = true; FabricUTILS.GetFabricPlatform(pWS, m_pCadaFab, out bIsFileBasedGDB, out bIsUnVersioned); if (!bIsFileBasedGDB && !bIsUnVersioned) { MessageBox.Show("Truncate operates on non-versioned fabrics." + Environment.NewLine + "Please unversion the fabric and try again.", "Tables are versioned"); return; } //Do a Start and Stop editing to make sure truncate it not running within an edit session if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) {//if start editing fails then bail Cleanup(pProgressorDialog, pMouseCursor); return; } FabricUTILS.StopEditing(pWS); dlgTruncate pTruncateDialog = new dlgTruncate(); IArray TableArray = new ESRI.ArcGIS.esriSystem.ArrayClass(); pTruncateDialog.TheFabric = m_pCadaFab; pTruncateDialog.TheTableArray = TableArray; //Display the dialog DialogResult pDialogResult = pTruncateDialog.ShowDialog(); if (pDialogResult != DialogResult.OK) { pTruncateDialog = null; if (TableArray != null) { TableArray.RemoveAll(); } return; } m_pProgressorDialogFact = new ProgressDialogFactoryClass(); m_pTrackCancel = new CancelTrackerClass(); m_pStepProgressor = m_pProgressorDialogFact.Create(m_pTrackCancel, m_pApp.hWnd); pProgressorDialog = (IProgressDialog2)m_pStepProgressor; m_pStepProgressor.MinRange = 0; m_pStepProgressor.MaxRange = pTruncateDialog.DropRowCount; m_pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; bool bSuccess = false; int iControlRowCount = 0; //look in registry to get flag on whether to run truncate on standard tables, or to delete by row. string sDesktopVers = FabricUTILS.GetDesktopVersionFromRegistry(); if (sDesktopVers.Trim() == "") { sDesktopVers = "Desktop10.0"; } else { sDesktopVers = "Desktop" + sDesktopVers; } bool bDeleteTablesByRowInsteadOfTruncate = false; string sValues = FabricUTILS.ReadFromRegistry(RegistryHive.CurrentUser, "Software\\ESRI\\" + sDesktopVers + "\\ArcMap\\Cadastral", "AddIn.DeleteFabricRecords_Truncate"); if (sValues.Trim().ToLower() == "deletebytruncateonstandardtables" || bIsFileBasedGDB) { bDeleteTablesByRowInsteadOfTruncate = false; } if (sValues.Trim().ToLower() == "deletebyrowonstandardtables") { bDeleteTablesByRowInsteadOfTruncate = true; } if (pTruncateDialog.TruncateControl && !pTruncateDialog.TruncateParcelsLinesPoints) { // get the control point count ITable pControlTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTControl); iControlRowCount = pControlTable.RowCount(null); } try { //Work on the table array pTable = null; m_pFIDSet = new FIDSetClass(); for (int i = 0; i <= TableArray.Count - 1; i++) { //if (TableArray.get_Element(i) is ITable) ...redundant { pTable = (ITable)TableArray.get_Element(i); IDataset pDataSet = (IDataset)pTable; //Following code uses the truncate method //*** if (pTable is IFeatureClass || !bDeleteTablesByRowInsteadOfTruncate) { ITableWrite2 pTableWr = (ITableWrite2)pTable; m_pStepProgressor.Message = "Deleting all rows in " + pDataSet.Name; int RowCnt = pTable.RowCount(null); pTableWr.Truncate(); m_pStepProgressor.MaxRange -= RowCnt; //now re-insert the default plan string sName = pDataSet.Name.ToUpper().Trim(); if (sName.EndsWith("_PLANS")) { int idxPlanName = pTable.FindField("Name"); int idxPlanDescription = pTable.FindField("Description"); int idxPlanAngleUnits = pTable.FindField("AngleUnits"); int idxPlanAreaUnits = pTable.FindField("AreaUnits"); int idxPlanDistanceUnits = pTable.FindField("DistanceUnits"); int idxPlanDirectionFormat = pTable.FindField("DirectionFormat"); int idxPlanLineParameters = pTable.FindField("LineParameters"); int idxPlanCombinedGridFactor = pTable.FindField("CombinedGridFactor"); int idxPlanTrueMidBrg = pTable.FindField("TrueMidBrg"); int idxPlanAccuracy = pTable.FindField("Accuracy"); int idxPlanInternalAngles = pTable.FindField("InternalAngles"); ICursor pCur = pTableWr.InsertRows(false); IRowBuffer pRowBuff = pTable.CreateRowBuffer(); double dOneMeterEquals = FabricUTILS.ConvertMetersToFabricUnits(1, m_pCadaFab); bool bIsMetric = (dOneMeterEquals == 1); //write category 1 pRowBuff.set_Value(idxPlanName, "<map>"); pRowBuff.set_Value(idxPlanDescription, "System default plan"); pRowBuff.set_Value(idxPlanAngleUnits, 3); // if (bIsMetric) { pRowBuff.set_Value(idxPlanAreaUnits, 5); pRowBuff.set_Value(idxPlanDistanceUnits, 9001); pRowBuff.set_Value(idxPlanDirectionFormat, 1); } else { pRowBuff.set_Value(idxPlanAreaUnits, 4); pRowBuff.set_Value(idxPlanDistanceUnits, 9003); pRowBuff.set_Value(idxPlanDirectionFormat, 4); } pRowBuff.set_Value(idxPlanLineParameters, 4); pRowBuff.set_Value(idxPlanCombinedGridFactor, 1); //pRowBuff.set_Value(idxPlanTrueMidBrg, 1); pRowBuff.set_Value(idxPlanAccuracy, 4); pRowBuff.set_Value(idxPlanInternalAngles, 0); pCur.InsertRow(pRowBuff); pCur.Flush(); if (pRowBuff != null) { Marshal.ReleaseComObject(pRowBuff); } if (pCur != null) { Marshal.ReleaseComObject(pCur); } } } } } } catch (COMException ex) { MessageBox.Show(ex.Message + ": " + Convert.ToString(ex.ErrorCode)); Cleanup(pProgressorDialog, pMouseCursor); return; } //do the loop again, this time within the edit transaction and using the delete function for the chosen tables try { //Start an Edit Transaction if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) {//if start editing fails then bail Cleanup(pProgressorDialog, pMouseCursor); return; } for (int i = 0; i <= TableArray.Count - 1; i++) { //if (TableArray.get_Element(i) is ITable) { pTable = (ITable)TableArray.get_Element(i); IDataset pDataSet = (IDataset)pTable; if (pTable is IFeatureClass || !bDeleteTablesByRowInsteadOfTruncate) { } else { //The following code is in place to workaround a limitation of truncate for fabric classes //without a shapefield. It uses an alternative method for removing all the rows //with the Delete function. //General note: This method could be used exclusively, without needing the truncate method. //One advantage is that it allows the option to cancel the whole //operation using the cancel tracker. Truncate is faster, but is problematic if //the truncate fails, and leaves a partially deleted fabric. For example, if the //lines table is deleted but the points table truncate fails, the fabric would be in a //corrupt state. //**** m_pFIDSet.SetEmpty(); string sName = pDataSet.Name.ToUpper().Trim(); m_pStepProgressor.Message = "Loading rows from " + pDataSet.Name; if (sName.EndsWith("_PLANS")) {//for Plans table make sure the default plan is not deleted IQueryFilter pQF = new QueryFilterClass(); string sPref; string sSuff; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); string sFieldName = "NAME"; //pQF.WhereClause = sPref + sFieldName + sSuff + " <> '<map>'"; pQF.WhereClause = sFieldName + " <> '<map>'"; if (!BuildFIDSetFromTable(pTable, pQF, ref m_pFIDSet)) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } } else { if (!BuildFIDSetFromTable(pTable, null, ref m_pFIDSet)) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } } if (m_pFIDSet.Count() == 0) { continue; } m_pStepProgressor.Message = "Deleting all rows in " + pDataSet.Name; bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pTable, m_pFIDSet, m_pStepProgressor, m_pTrackCancel); if (!bSuccess) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } } } } //now need to Fix control-to-point associations if one table was truncated //and the other was not if (pTruncateDialog.TruncateControl && !pTruncateDialog.TruncateParcelsLinesPoints) { IQueryFilter pQF = new QueryFilterClass(); string sPref; string sSuff; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ITable PointTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints); m_pStepProgressor.Message = "Resetting control associations on points...please wait."; int idxFld = PointTable.FindField("NAME"); string sFieldName = PointTable.Fields.get_Field(idxFld).Name; //NAME IS NOT NULL AND (NAME <>'' OR NAME <>' ') //pQF.WhereClause = sPref + sFieldName + sSuff + " IS NOT NULL AND (" + // sPref + sFieldName + sSuff + "<>'' OR " + sPref + sFieldName + sSuff + " <>' ')"; //pQF.WhereClause = sFieldName + " IS NOT NULL AND (" + sFieldName + "<>'' OR " + sFieldName + " <>' ')"; pQF.WhereClause = sFieldName + " IS NOT NULL AND " + sFieldName + " > ''"; //changed 1/14/2016 ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)m_pCadaFab; pSchemaEd.ReleaseReadOnlyFields(PointTable, esriCadastralFabricTable.esriCFTPoints); m_pStepProgressor.MinRange = 0; m_pStepProgressor.MaxRange = iControlRowCount; if (!ResetPointAssociations(PointTable, pQF, true, m_pStepProgressor, m_pTrackCancel)) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); } else if (pTruncateDialog.TruncateParcelsLinesPoints && !pTruncateDialog.TruncateControl) { IQueryFilter pQF = new QueryFilterClass(); string sPref; string sSuff; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); //POINTID >=0 AND POINTID IS NOT NULL m_pStepProgressor.Message = "Resetting associations on control points...please wait."; ITable ControlTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTControl); int idxFld = ControlTable.FindField("POINTID"); string sFieldName = ControlTable.Fields.get_Field(idxFld).Name; //pQF.WhereClause = sPref + sFieldName + sSuff + " IS NOT NULL AND " + // sPref + sFieldName + sSuff + " >=0"; pQF.WhereClause = sFieldName + " IS NOT NULL AND " + sFieldName + " >=0"; ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)m_pCadaFab; pSchemaEd.ReleaseReadOnlyFields(ControlTable, esriCadastralFabricTable.esriCFTControl); if (!FabricUTILS.ResetControlAssociations(ControlTable, null, true)) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl); FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl); } //now need to re-assign default accuracy table values, if the option was checked if (pTruncateDialog.ResetAccuracyTableDefaults) { double dCat1 = FabricUTILS.ConvertMetersToFabricUnits(0.001, m_pCadaFab); double dCat2 = FabricUTILS.ConvertMetersToFabricUnits(0.01, m_pCadaFab); double dCat3 = FabricUTILS.ConvertMetersToFabricUnits(0.02, m_pCadaFab); double dCat4 = FabricUTILS.ConvertMetersToFabricUnits(0.05, m_pCadaFab); double dCat5 = FabricUTILS.ConvertMetersToFabricUnits(0.2, m_pCadaFab); double dCat6 = FabricUTILS.ConvertMetersToFabricUnits(1, m_pCadaFab); double dCat7 = FabricUTILS.ConvertMetersToFabricUnits(10, m_pCadaFab); ITable pAccTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTAccuracy); int idxBrgSD = pAccTable.FindField("BrgSD"); int idxDistSD = pAccTable.FindField("DistSD"); int idxPPM = pAccTable.FindField("PPM"); int idxCategory = pAccTable.FindField("Category"); int idxDescription = pAccTable.FindField("Description"); ITableWrite2 pTableWr = (ITableWrite2)pAccTable; ICursor pCur = pTableWr.InsertRows(false); IRowBuffer pRowBuff = pAccTable.CreateRowBuffer(); //write category 1 pRowBuff.set_Value(idxCategory, 1); pRowBuff.set_Value(idxBrgSD, 5); pRowBuff.set_Value(idxDistSD, dCat1); pRowBuff.set_Value(idxPPM, 5); pRowBuff.set_Value(idxDescription, "1 - Highest"); pCur.InsertRow(pRowBuff); //write category 2 pRowBuff.set_Value(idxCategory, 2); pRowBuff.set_Value(idxBrgSD, 30); pRowBuff.set_Value(idxDistSD, dCat2); pRowBuff.set_Value(idxPPM, 25); pRowBuff.set_Value(idxDescription, "2 - After 1980"); pCur.InsertRow(pRowBuff); //write category 3 pRowBuff.set_Value(idxCategory, 3); pRowBuff.set_Value(idxBrgSD, 60); pRowBuff.set_Value(idxDistSD, dCat3); pRowBuff.set_Value(idxPPM, 50); pRowBuff.set_Value(idxDescription, "3 - 1908 to 1980"); pCur.InsertRow(pRowBuff); //write category 4 pRowBuff.set_Value(idxCategory, 4); pRowBuff.set_Value(idxBrgSD, 120); pRowBuff.set_Value(idxDistSD, dCat4); pRowBuff.set_Value(idxPPM, 125); pRowBuff.set_Value(idxDescription, "4 - 1881 to 1907"); pCur.InsertRow(pRowBuff); //write category 5 pRowBuff.set_Value(idxCategory, 5); pRowBuff.set_Value(idxBrgSD, 300); pRowBuff.set_Value(idxDistSD, dCat5); pRowBuff.set_Value(idxPPM, 125); pRowBuff.set_Value(idxDescription, "5 - Before 1881"); pCur.InsertRow(pRowBuff); //write category 6 pRowBuff.set_Value(idxCategory, 6); pRowBuff.set_Value(idxBrgSD, 3600); pRowBuff.set_Value(idxDistSD, dCat6); pRowBuff.set_Value(idxPPM, 1000); pRowBuff.set_Value(idxDescription, "6 - 1800"); pCur.InsertRow(pRowBuff); //write category 7 pRowBuff.set_Value(idxCategory, 7); pRowBuff.set_Value(idxBrgSD, 6000); pRowBuff.set_Value(idxDistSD, dCat7); pRowBuff.set_Value(idxPPM, 5000); pRowBuff.set_Value(idxDescription, "7 - Lowest"); pCur.InsertRow(pRowBuff); pCur.Flush(); if (pRowBuff != null) { Marshal.ReleaseComObject(pRowBuff); } if (pCur != null) { Marshal.ReleaseComObject(pCur); } } //now need to cleanup the IDSequence table if ALL the tables were truncated if (pTruncateDialog.TruncateControl && pTruncateDialog.TruncateParcelsLinesPoints && pTruncateDialog.TruncateJobs && pTruncateDialog.TruncateAdjustments) { IWorkspace2 pWS2 = (IWorkspace2)pWS; IDataset TheFabricDS = (IDataset)m_pCadaFab; string sFabricName = TheFabricDS.Name; string sName = sFabricName + "_IDSequencer"; bool bExists = pWS2.get_NameExists(esriDatasetType.esriDTTable, sName); IFeatureWorkspace pFWS = (IFeatureWorkspace)pWS; ITable pSequencerTable; if (bExists) { pSequencerTable = pFWS.OpenTable(sName); IFIDSet pFIDSet = new FIDSetClass(); if (BuildFIDSetFromTable(pSequencerTable, null, ref pFIDSet)) { FabricUTILS.DeleteRowsUnversioned(pWS, pSequencerTable, pFIDSet, null, null); } } } Cleanup(pProgressorDialog, pMouseCursor); if (TableArray != null) { TableArray.RemoveAll(); } FabricUTILS.StopEditing(pWS); } catch (Exception ex) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); MessageBox.Show(Convert.ToString(ex.Message)); } }
public void FIDsetToLongArray(IFIDSet InFIDSet, ref ILongArray OutLongArray, IStepProgressor StepProgressor) { Int32 pfID = -1; InFIDSet.Reset(); double dMax = InFIDSet.Count(); int iMax = (int)(dMax); for (Int32 pCnt = 0; pCnt <= (InFIDSet.Count() - 1); pCnt++) { InFIDSet.Next(out pfID); OutLongArray.Add(pfID); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } } return; }
void AddEmptyPlansToList(ICadastralFabric Fabric, IFIDSet EmptyPlansFIDSet, dlgEmptyPlansList EmptyPlansList) { ITable pPlansTable = Fabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans); CheckedListBox list = EmptyPlansList.checkedListBox1; IArray array = new ArrayClass(); for (int idx = 0; idx <= (EmptyPlansFIDSet.Count() - 1); idx++) { // Add the name of the plan to the list Int32 i_x; Int32 iPlanName; iPlanName = pPlansTable.FindField("NAME"); EmptyPlansFIDSet.Next(out i_x); array.Add(i_x); string sPlanName = (string)pPlansTable.GetRow(i_x).get_Value(iPlanName); list.Items.Add(sPlanName, true); } // Bind array of plan ids with the list list.Tag = (object)array; if(list.Items.Count>0) EmptyPlansList.checkedListBox1_SelectedValueChanged(null, null); }
protected override void OnClick() { m_pApp = (IApplication)ArcMap.Application; if (m_pApp == null) //if the app is null then could be running from ArcCatalog m_pApp = (IApplication)ArcCatalog.Application; if (m_pApp == null) { MessageBox.Show("Could not access the application.", "No Application found"); return; } IGxApplication pGXApp = (IGxApplication)m_pApp; stdole.IUnknown pUnk = null; try { pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open(); } catch (COMException ex) { if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE || ex.ErrorCode == -2147220944) MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset"); else MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset"); return; } if (pUnk is ICadastralFabric) m_pCadaFab = (ICadastralFabric)pUnk; else { MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric"); return; } IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); clsFabricUtils FabricUTILS = new clsFabricUtils(); IProgressDialog2 pProgressorDialog = null; ITable pTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels); IDataset pDS = (IDataset)pTable; IWorkspace pWS = pDS.Workspace; bool bIsFileBasedGDB = true; bool bIsUnVersioned = true; FabricUTILS.GetFabricPlatform(pWS, m_pCadaFab, out bIsFileBasedGDB, out bIsUnVersioned); if (!bIsFileBasedGDB && !bIsUnVersioned) { MessageBox.Show("Truncate operates on non-versioned fabrics." + Environment.NewLine + "Please unversion the fabric and try again.", "Tables are versioned"); return; } //Do a Start and Stop editing to make sure truncate it not running within an edit session if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) {//if start editing fails then bail Cleanup(pProgressorDialog, pMouseCursor); return; } FabricUTILS.StopEditing(pWS); dlgTruncate pTruncateDialog = new dlgTruncate(); IArray TableArray = new ESRI.ArcGIS.esriSystem.ArrayClass(); pTruncateDialog.TheFabric = m_pCadaFab; pTruncateDialog.TheTableArray = TableArray; //Display the dialog DialogResult pDialogResult = pTruncateDialog.ShowDialog(); if (pDialogResult != DialogResult.OK) { pTruncateDialog = null; if (TableArray != null) { TableArray.RemoveAll(); } return; } m_pProgressorDialogFact = new ProgressDialogFactoryClass(); m_pTrackCancel = new CancelTrackerClass(); m_pStepProgressor = m_pProgressorDialogFact.Create(m_pTrackCancel, m_pApp.hWnd); pProgressorDialog = (IProgressDialog2)m_pStepProgressor; m_pStepProgressor.MinRange = 0; m_pStepProgressor.MaxRange = pTruncateDialog.DropRowCount; m_pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; bool bSuccess = false; int iControlRowCount=0; //look in registry to get flag on whether to run truncate on standard tables, or to delete by row. string sDesktopVers = FabricUTILS.GetDesktopVersionFromRegistry(); if (sDesktopVers.Trim() == "") sDesktopVers = "Desktop10.0"; else sDesktopVers = "Desktop" + sDesktopVers; bool bDeleteTablesByRowInsteadOfTruncate = false; string sValues = FabricUTILS.ReadFromRegistry(RegistryHive.CurrentUser, "Software\\ESRI\\" + sDesktopVers + "\\ArcMap\\Cadastral", "AddIn.DeleteFabricRecords_Truncate"); if (sValues.Trim().ToLower() == "deletebytruncateonstandardtables" || bIsFileBasedGDB) bDeleteTablesByRowInsteadOfTruncate = false; if (sValues.Trim().ToLower() == "deletebyrowonstandardtables") bDeleteTablesByRowInsteadOfTruncate = true; if (pTruncateDialog.TruncateControl && !pTruncateDialog.TruncateParcelsLinesPoints) { // get the control point count ITable pControlTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTControl); iControlRowCount = pControlTable.RowCount(null); } try { //Work on the table array pTable = null; m_pFIDSet = new FIDSetClass(); for (int i = 0; i <= TableArray.Count - 1; i++) { //if (TableArray.get_Element(i) is ITable) ...redundant { pTable = (ITable)TableArray.get_Element(i); IDataset pDataSet = (IDataset)pTable; //Following code uses the truncate method //*** if (pTable is IFeatureClass || !bDeleteTablesByRowInsteadOfTruncate) { ITableWrite2 pTableWr = (ITableWrite2)pTable; m_pStepProgressor.Message = "Deleting all rows in " + pDataSet.Name; int RowCnt=pTable.RowCount(null); pTableWr.Truncate(); m_pStepProgressor.MaxRange -= RowCnt; //now re-insert the default plan string sName = pDataSet.Name.ToUpper().Trim(); if (sName.EndsWith("_PLANS")) { int idxPlanName = pTable.FindField("Name"); int idxPlanDescription = pTable.FindField("Description"); int idxPlanAngleUnits = pTable.FindField("AngleUnits"); int idxPlanAreaUnits = pTable.FindField("AreaUnits"); int idxPlanDistanceUnits = pTable.FindField("DistanceUnits"); int idxPlanDirectionFormat = pTable.FindField("DirectionFormat"); int idxPlanLineParameters = pTable.FindField("LineParameters"); int idxPlanCombinedGridFactor = pTable.FindField("CombinedGridFactor"); int idxPlanTrueMidBrg = pTable.FindField("TrueMidBrg"); int idxPlanAccuracy = pTable.FindField("Accuracy"); int idxPlanInternalAngles = pTable.FindField("InternalAngles"); ICursor pCur = pTableWr.InsertRows(false); IRowBuffer pRowBuff = pTable.CreateRowBuffer(); double dOneMeterEquals = FabricUTILS.ConvertMetersToFabricUnits(1, m_pCadaFab); bool bIsMetric = (dOneMeterEquals==1); //write category 1 pRowBuff.set_Value(idxPlanName, "<map>"); pRowBuff.set_Value(idxPlanDescription, "System default plan"); pRowBuff.set_Value(idxPlanAngleUnits, 3); // if (bIsMetric) { pRowBuff.set_Value(idxPlanAreaUnits, 5); pRowBuff.set_Value(idxPlanDistanceUnits, 9001); pRowBuff.set_Value(idxPlanDirectionFormat, 1); } else { pRowBuff.set_Value(idxPlanAreaUnits, 4); pRowBuff.set_Value(idxPlanDistanceUnits, 9003); pRowBuff.set_Value(idxPlanDirectionFormat, 4); } pRowBuff.set_Value(idxPlanLineParameters, 4); pRowBuff.set_Value(idxPlanCombinedGridFactor, 1); //pRowBuff.set_Value(idxPlanTrueMidBrg, 1); pRowBuff.set_Value(idxPlanAccuracy, 4); pRowBuff.set_Value(idxPlanInternalAngles, 0); pCur.InsertRow(pRowBuff); pCur.Flush(); if (pRowBuff != null) Marshal.ReleaseComObject(pRowBuff); if (pCur != null) Marshal.ReleaseComObject(pCur); } } } } } catch(COMException ex) { MessageBox.Show(ex.Message + ": " + Convert.ToString(ex.ErrorCode)); Cleanup(pProgressorDialog, pMouseCursor); return; } //do the loop again, this time within the edit transaction and using the delete function for the chosen tables try { //Start an Edit Transaction if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) {//if start editing fails then bail Cleanup(pProgressorDialog, pMouseCursor); return; } for (int i = 0; i <= TableArray.Count - 1; i++) { //if (TableArray.get_Element(i) is ITable) { pTable = (ITable)TableArray.get_Element(i); IDataset pDataSet = (IDataset)pTable; if (pTable is IFeatureClass || !bDeleteTablesByRowInsteadOfTruncate) { } else { //The following code is in place to workaround a limitation of truncate for fabric classes //without a shapefield. It uses an alternative method for removing all the rows //with the Delete function. //General note: This method could be used exclusively, without needing the truncate method. //One advantage is that it allows the option to cancel the whole //operation using the cancel tracker. Truncate is faster, but is problematic if //the truncate fails, and leaves a partially deleted fabric. For example, if the //lines table is deleted but the points table truncate fails, the fabric would be in a //corrupt state. //**** m_pFIDSet.SetEmpty(); string sName = pDataSet.Name.ToUpper().Trim(); m_pStepProgressor.Message = "Loading rows from " + pDataSet.Name; if (sName.EndsWith("_PLANS")) {//for Plans table make sure the default plan is not deleted IQueryFilter pQF = new QueryFilterClass(); string sPref; string sSuff; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); string sFieldName = "NAME"; //pQF.WhereClause = sPref + sFieldName + sSuff + " <> '<map>'"; pQF.WhereClause = sFieldName + " <> '<map>'"; if (!BuildFIDSetFromTable(pTable, pQF, ref m_pFIDSet)) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } } else { if (!BuildFIDSetFromTable(pTable, null, ref m_pFIDSet)) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } } if (m_pFIDSet.Count() == 0) continue; m_pStepProgressor.Message = "Deleting all rows in " + pDataSet.Name; bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pTable, m_pFIDSet, m_pStepProgressor, m_pTrackCancel); if (!bSuccess) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } } } } //now need to Fix control-to-point associations if one table was truncated //and the other was not if (pTruncateDialog.TruncateControl && !pTruncateDialog.TruncateParcelsLinesPoints) { IQueryFilter pQF = new QueryFilterClass(); string sPref; string sSuff; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ITable PointTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints); m_pStepProgressor.Message = "Resetting control associations on points...please wait."; int idxFld = PointTable.FindField("NAME"); string sFieldName = PointTable.Fields.get_Field(idxFld).Name; //NAME IS NOT NULL AND (NAME <>'' OR NAME <>' ') //pQF.WhereClause = sPref + sFieldName + sSuff + " IS NOT NULL AND (" + // sPref + sFieldName + sSuff + "<>'' OR " + sPref + sFieldName + sSuff + " <>' ')"; //pQF.WhereClause = sFieldName + " IS NOT NULL AND (" + sFieldName + "<>'' OR " + sFieldName + " <>' ')"; pQF.WhereClause = sFieldName + " IS NOT NULL AND " + sFieldName + " > ''"; //changed 1/14/2016 ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)m_pCadaFab; pSchemaEd.ReleaseReadOnlyFields(PointTable, esriCadastralFabricTable.esriCFTPoints); m_pStepProgressor.MinRange = 0; m_pStepProgressor.MaxRange = iControlRowCount; if (!ResetPointAssociations(PointTable, pQF, true, m_pStepProgressor, m_pTrackCancel)) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); } else if (pTruncateDialog.TruncateParcelsLinesPoints && !pTruncateDialog.TruncateControl) { IQueryFilter pQF = new QueryFilterClass(); string sPref; string sSuff; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); //POINTID >=0 AND POINTID IS NOT NULL m_pStepProgressor.Message = "Resetting associations on control points...please wait."; ITable ControlTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTControl); int idxFld = ControlTable.FindField("POINTID"); string sFieldName = ControlTable.Fields.get_Field(idxFld).Name; //pQF.WhereClause = sPref + sFieldName + sSuff + " IS NOT NULL AND " + // sPref + sFieldName + sSuff + " >=0"; pQF.WhereClause = sFieldName + " IS NOT NULL AND " + sFieldName + " >=0"; ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)m_pCadaFab; pSchemaEd.ReleaseReadOnlyFields(ControlTable, esriCadastralFabricTable.esriCFTControl); if (!FabricUTILS.ResetControlAssociations(ControlTable, null, true)) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl); FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); return; } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl); } //now need to re-assign default accuracy table values, if the option was checked if (pTruncateDialog.ResetAccuracyTableDefaults) { double dCat1 = FabricUTILS.ConvertMetersToFabricUnits(0.001, m_pCadaFab); double dCat2 = FabricUTILS.ConvertMetersToFabricUnits(0.01, m_pCadaFab); double dCat3 = FabricUTILS.ConvertMetersToFabricUnits(0.02, m_pCadaFab); double dCat4 = FabricUTILS.ConvertMetersToFabricUnits(0.05, m_pCadaFab); double dCat5 = FabricUTILS.ConvertMetersToFabricUnits(0.2, m_pCadaFab); double dCat6 = FabricUTILS.ConvertMetersToFabricUnits(1, m_pCadaFab); double dCat7 = FabricUTILS.ConvertMetersToFabricUnits(10, m_pCadaFab); ITable pAccTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTAccuracy); int idxBrgSD = pAccTable.FindField("BrgSD"); int idxDistSD = pAccTable.FindField("DistSD"); int idxPPM = pAccTable.FindField("PPM"); int idxCategory = pAccTable.FindField("Category"); int idxDescription = pAccTable.FindField("Description"); ITableWrite2 pTableWr = (ITableWrite2)pAccTable; ICursor pCur = pTableWr.InsertRows(false); IRowBuffer pRowBuff = pAccTable.CreateRowBuffer(); //write category 1 pRowBuff.set_Value(idxCategory, 1); pRowBuff.set_Value(idxBrgSD, 5); pRowBuff.set_Value(idxDistSD, dCat1); pRowBuff.set_Value(idxPPM, 5); pRowBuff.set_Value(idxDescription, "1 - Highest"); pCur.InsertRow(pRowBuff); //write category 2 pRowBuff.set_Value(idxCategory, 2); pRowBuff.set_Value(idxBrgSD, 30); pRowBuff.set_Value(idxDistSD, dCat2); pRowBuff.set_Value(idxPPM, 25); pRowBuff.set_Value(idxDescription, "2 - After 1980"); pCur.InsertRow(pRowBuff); //write category 3 pRowBuff.set_Value(idxCategory, 3); pRowBuff.set_Value(idxBrgSD, 60); pRowBuff.set_Value(idxDistSD, dCat3); pRowBuff.set_Value(idxPPM, 50); pRowBuff.set_Value(idxDescription, "3 - 1908 to 1980"); pCur.InsertRow(pRowBuff); //write category 4 pRowBuff.set_Value(idxCategory, 4); pRowBuff.set_Value(idxBrgSD, 120); pRowBuff.set_Value(idxDistSD, dCat4); pRowBuff.set_Value(idxPPM, 125); pRowBuff.set_Value(idxDescription, "4 - 1881 to 1907"); pCur.InsertRow(pRowBuff); //write category 5 pRowBuff.set_Value(idxCategory, 5); pRowBuff.set_Value(idxBrgSD, 300); pRowBuff.set_Value(idxDistSD, dCat5); pRowBuff.set_Value(idxPPM, 125); pRowBuff.set_Value(idxDescription, "5 - Before 1881"); pCur.InsertRow(pRowBuff); //write category 6 pRowBuff.set_Value(idxCategory, 6); pRowBuff.set_Value(idxBrgSD, 3600); pRowBuff.set_Value(idxDistSD, dCat6); pRowBuff.set_Value(idxPPM, 1000); pRowBuff.set_Value(idxDescription, "6 - 1800"); pCur.InsertRow(pRowBuff); //write category 7 pRowBuff.set_Value(idxCategory, 7); pRowBuff.set_Value(idxBrgSD, 6000); pRowBuff.set_Value(idxDistSD, dCat7); pRowBuff.set_Value(idxPPM, 5000); pRowBuff.set_Value(idxDescription, "7 - Lowest"); pCur.InsertRow(pRowBuff); pCur.Flush(); if (pRowBuff != null) Marshal.ReleaseComObject(pRowBuff); if (pCur != null) Marshal.ReleaseComObject(pCur); } //now need to cleanup the IDSequence table if ALL the tables were truncated if(pTruncateDialog.TruncateControl&& pTruncateDialog.TruncateParcelsLinesPoints && pTruncateDialog.TruncateJobs && pTruncateDialog.TruncateAdjustments) { IWorkspace2 pWS2=(IWorkspace2)pWS; IDataset TheFabricDS=(IDataset)m_pCadaFab; string sFabricName=TheFabricDS.Name; string sName = sFabricName + "_IDSequencer"; bool bExists=pWS2.get_NameExists(esriDatasetType.esriDTTable, sName); IFeatureWorkspace pFWS=(IFeatureWorkspace)pWS; ITable pSequencerTable; if (bExists) { pSequencerTable = pFWS.OpenTable(sName); IFIDSet pFIDSet= new FIDSetClass(); if (BuildFIDSetFromTable(pSequencerTable, null, ref pFIDSet)) FabricUTILS.DeleteRowsUnversioned(pWS, pSequencerTable, pFIDSet, null, null); } } Cleanup(pProgressorDialog, pMouseCursor); if (TableArray != null) { TableArray.RemoveAll(); } FabricUTILS.StopEditing(pWS); } catch (Exception ex) { FabricUTILS.AbortEditing(pWS); Cleanup(pProgressorDialog, pMouseCursor); MessageBox.Show(Convert.ToString(ex.Message)); } }
public bool DeleteRowsUnversioned(IWorkspace TheWorkSpace, ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel) { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); if (StepProgressor != null) { StepProgressor.MinRange = StepProgressor.Position; //reset the progress bar position StepProgressor.MaxRange = StepProgressor.Position + pFIDSet.Count(); if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } IQueryFilter pQF = new QueryFilterClass(); ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ICursor ipCursor = null; IRow pRow = null; //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database) int iTokenLimit = 995; int iTokenSet = 0; //the index of the set of 995 tokens string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in ("; string[] ids = { sWhereClauseLHS }; try { ITableWrite pTableWr = (ITableWrite)inTable; pFIDSet.Reset(); bool bCont = true; Int32 iID; Int32 count = pFIDSet.Count(); int j = 0; //inner count for each set of IDs for (int k = 0; k < count; k++) { if (j > iTokenLimit) { //over the limit for this Token set, time to create a new set ids[iTokenSet] += ")"; //close the previous set RedimPreserveString(ref ids, 1); //make space in the string array for the next token set iTokenSet++; //increment the index ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause j = 0; //reset the inner count back to zero } pFIDSet.Next(out iID); if (j > 0) //write a comma if this is not the first ID { ids[iTokenSet] += ","; } ids[iTokenSet] += iID.ToString(); j++; //increment the inner count } ids[iTokenSet] += ")"; if (count > 0) { for (int k = 0; k <= iTokenSet; k++) { pQF.WhereClause = ids[k]; ipCursor = pTableWr.UpdateRows(pQF, false); pRow = ipCursor.NextRow(); while (pRow != null) { ipCursor.DeleteRow(); Marshal.ReleaseComObject(pRow); if (StepProgressor != null) { //Check if the cancel button was pressed. If so, stop process if (TrackCancel != null) { bCont = TrackCancel.Continue(); } if (!bCont) { break; } if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } pRow = ipCursor.NextRow(); } if (!bCont) { AbortEditing(TheWorkSpace); if (ipCursor != null) { Marshal.ReleaseComObject(ipCursor); } if (pRow != null) { Marshal.ReleaseComObject(pRow); } if (pQF != null) { Marshal.ReleaseComObject(pQF); } if (pMouseCursor != null) { Marshal.ReleaseComObject(pMouseCursor); } return(false); } Marshal.ReleaseComObject(ipCursor); } Marshal.ReleaseComObject(pQF); } Marshal.ReleaseComObject(pMouseCursor); return(true); } catch (COMException ex) { if (ipCursor != null) { Marshal.ReleaseComObject(ipCursor); } if (pRow != null) { Marshal.ReleaseComObject(pRow); } if (pQF != null) { Marshal.ReleaseComObject(pQF); } if (pMouseCursor != null) { Marshal.ReleaseComObject(pMouseCursor); } MessageBox.Show(Convert.ToString(ex.ErrorCode)); return(false); } }
public bool DeleteRowsByFIDSet(ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel) {//this routine uses the GetRows method, avoids the need to break up the InClause. IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); try { pFIDSet.Reset(); int[] iID = { }; bool bCont = true; iID = RedimPreserveInt(ref iID, pFIDSet.Count()); for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++) { pFIDSet.Next(out iID[iCount]); } ICursor pCursor = inTable.GetRows(iID, false); IRow row = pCursor.NextRow(); if (StepProgressor != null) { StepProgressor.MinRange = StepProgressor.Position; //reset the progress bar position StepProgressor.MaxRange = StepProgressor.Position + pFIDSet.Count(); if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } while (row != null) { //Check if the cancel button was pressed. If so, stop process if (StepProgressor != null) { if (TrackCancel != null) { bCont = TrackCancel.Continue(); } if (!bCont) { break; } } row.Delete(); Marshal.ReleaseComObject(row); row = pCursor.NextRow(); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) { StepProgressor.Step(); } } } Marshal.ReleaseComObject(pCursor); inTable = null; iID = null; if (!bCont) { return(false); } return(true); } catch (COMException ex) { StepProgressor = null; MessageBox.Show(ex.Message); return(false); } }
public void EmptyGeometriesUnversioned(IWorkspace TheWorkSpace, IFeatureClass inTable, IFIDSet pFIDSet) { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); IQueryFilter pQF = new QueryFilterClass(); ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ICursor ipCursor = null; IRow pRow = null; //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database) int iTokenLimit = 995; int iTokenSet = 0; //the index of the set of 995 tokens string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in ("; string[] ids = { sWhereClauseLHS }; try { ITableWrite pTableWr = (ITableWrite)inTable; pFIDSet.Reset(); bool bCont = true; Int32 iID; Int32 count = pFIDSet.Count(); int j = 0; //inner count for each set of IDs for (int k = 0; k < count; k++) { if (j > iTokenLimit) {//over the limit for this Token set, time to create a new set ids[iTokenSet] += ")";//close the previous set RedimPreserveString(ref ids, 1);//make space in the string array for the next token set iTokenSet++;//increment the index ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause j = 0;//reset the inner count back to zero } pFIDSet.Next(out iID); if (j > 0) //write a comma if this is not the first ID ids[iTokenSet] += ","; ids[iTokenSet] += iID.ToString(); j++; //increment the inner count } ids[iTokenSet] += ")"; if (count > 0) { IFeature pFeat = null; ISet pRowSet = new SetClass(); for (int k = 0; k <= iTokenSet; k++) { pRowSet.RemoveAll(); pQF.WhereClause = ids[k]; ipCursor = pTableWr.UpdateRows(pQF, false); pRow = ipCursor.NextRow(); while (pRow != null) { pFeat = (IFeature)pRow; IGeometry pGeo = pFeat.ShapeCopy; pGeo.SetEmpty(); pFeat.Shape = pGeo; ipCursor.UpdateRow(pRow); Marshal.ReleaseComObject(pRow); pRow = ipCursor.NextRow(); } if (!bCont) { AbortEditing(TheWorkSpace); if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); return; } } Marshal.ReleaseComObject(ipCursor); //Marshal.ReleaseComObject(pQF); } return; } catch (COMException ex) { if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); MessageBox.Show(Convert.ToString(ex.ErrorCode)); return; } }
public void EmptyGeometries(IFeatureClass inFeatureClass, IFIDSet pFIDSet) { try { if (pFIDSet.Count() < 1) return; pFIDSet.Reset(); int[] iID = { }; iID = RedimPreserveInt(ref iID, pFIDSet.Count()); for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++) pFIDSet.Next(out iID[iCount]); IFeatureCursor pFeatCursor = inFeatureClass.GetFeatures(iID, false); IFeature pFeat = pFeatCursor.NextFeature(); while (pFeat != null) { IGeometry pGeo = pFeat.ShapeCopy; pGeo.SetEmpty(); pFeat.Shape = pGeo; pFeat.Store(); Marshal.ReleaseComObject(pFeat); pFeat = pFeatCursor.NextFeature(); } Marshal.ReleaseComObject(pFeatCursor); iID = null; return; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
public bool DeleteRowsUnversioned(IWorkspace TheWorkSpace, ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel) { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); Debug.WriteLine(StepProgressor.Position); Debug.WriteLine(StepProgressor.MaxRange); IQueryFilter pQF = new QueryFilterClass(); ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); ICursor ipCursor = null; IRow pRow = null; //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database) int iTokenLimit = 995; int iTokenSet = 0; //the index of the set of 995 tokens string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in ("; string[] ids = { sWhereClauseLHS }; try { ITableWrite pTableWr = (ITableWrite)inTable; pFIDSet.Reset(); bool bCont = true; Int32 iID; Int32 count = pFIDSet.Count(); int j = 0; //inner count for each set of IDs for (int k = 0; k < count; k++) { if (j > iTokenLimit) {//over the limit for this Token set, time to create a new set ids[iTokenSet] += ")";//close the previous set RedimPreserveString(ref ids, 1);//make space in the string array for the next token set iTokenSet++;//increment the index ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause j = 0;//reset the inner count back to zero } pFIDSet.Next(out iID); if (j > 0) //write a comma if this is not the first ID ids[iTokenSet] += ","; ids[iTokenSet] += iID.ToString(); j++; //increment the inner count } ids[iTokenSet] += ")"; if (count > 0) { for (int k = 0; k <= iTokenSet; k++) { pQF.WhereClause = ids[k]; ipCursor = pTableWr.UpdateRows(pQF, false); pRow = ipCursor.NextRow(); while (pRow != null) { ipCursor.DeleteRow(); Marshal.ReleaseComObject(pRow); if (StepProgressor != null) { //Check if the cancel button was pressed. If so, stop process if (TrackCancel != null) bCont = TrackCancel.Continue(); if (!bCont) break; if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } pRow = ipCursor.NextRow(); } if (!bCont) { AbortEditing(TheWorkSpace); if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); return false; } Marshal.ReleaseComObject(ipCursor); } //Marshal.ReleaseComObject(pQF); } Debug.WriteLine(StepProgressor.Position); return true; } catch (Exception ex) { if (ipCursor != null) Marshal.ReleaseComObject(ipCursor); if (pRow != null) Marshal.ReleaseComObject(pRow); //if (pQF != null) // Marshal.ReleaseComObject(pQF); MessageBox.Show(Convert.ToString(ex.Message)); return false; } }
public bool DeleteRowsByFIDSetReturnGeomCollection(ITable inTable, IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel, ref IGeometryCollection GeomCollection) { //this routine uses the GetRows method, avoids the need to break up the InClause. if (pFIDSet == null) return false; IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); try { pFIDSet.Reset(); int[] iID = { }; bool bCont = true; iID = RedimPreserveInt(ref iID, pFIDSet.Count()); for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++) pFIDSet.Next(out iID[iCount]); ICursor pCursor = inTable.GetRows(iID, false); IRow row = pCursor.NextRow(); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } while (row != null) { IFeature pFeat = row as IFeature; IGeometry pGeom = pFeat.ShapeCopy; if (pGeom != null) { if (!pGeom.IsEmpty) { object obj = Type.Missing; IEnvelope2 pEnv = (IEnvelope2)pGeom.Envelope; pEnv.Expand(0.1, 0.1, false); GeomCollection.AddGeometry(pEnv, ref obj, ref obj); } } //Check if the cancel button was pressed. If so, stop process if (StepProgressor != null) { if (TrackCancel != null) bCont = TrackCancel.Continue(); if (!bCont) break; } row.Delete(); Marshal.ReleaseComObject(row); row = pCursor.NextRow(); if (StepProgressor != null) { if (StepProgressor.Position < StepProgressor.MaxRange) StepProgressor.Step(); } } Marshal.ReleaseComObject(pCursor); inTable = null; iID = null; if (!bCont) return false; return true; } catch (COMException ex) { StepProgressor = null; if (ex.ErrorCode == -2147217400) //MessageBox.Show(ex.ErrorCode + Environment.NewLine + ex.Message + // Environment.NewLine + "This error indicates that the fabric may not have been correctly upgraded."); //TODO: need to confirm this. m_LastErrorCode = ex.ErrorCode; else MessageBox.Show(ex.Message + Environment.NewLine + ex.ErrorCode); m_LastErrorCode = ex.ErrorCode; return false; } }
public void IntersectFIDSetCommonIDs(IFIDSet InFIDSet1, IFIDSet InFIDSet2, out IFIDSet OutFIDSet) { IFIDSet OutFIDSet2 = new FIDSetClass(); Int32 pfID = -1; bool bExists = false; InFIDSet1.Reset(); for (Int32 i = 0; i <= (InFIDSet1.Count() - 1); i++) { InFIDSet1.Next(out pfID); InFIDSet2.Find(pfID, out bExists); if (bExists) OutFIDSet2.Add(pfID); } OutFIDSet = OutFIDSet2; return; }
protected override void OnClick() { m_bNoUpdates = false; m_sReport = "Direction Inverse Report:"; IEditor m_pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor"); if (m_pEd.EditState == esriEditState.esriStateNotEditing) { MessageBox.Show("Please start editing first, and try again.", "Start Editing"); return; } UID pUID = new UIDClass(); pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}"; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID); ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID); //check if there is a Manual Mode "modify" job active =========== ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan; if (pCadPacMan.PacketOpen) { MessageBox.Show("The Delete Parcels command cannot be used when there is an open job.\r\nPlease finish or discard the open job, and try again.", "Delete Selected Parcels"); return; } try { IEditProperties2 pEditorProps2 = (IEditProperties2)m_pEd; IArray LineLyrArr; IMap pMap = m_pEd.Map; ICadastralFabric pCadFabric = null; //ISpatialReference pSpatRef = m_pEd.Map.SpatialReference; //IProjectedCoordinateSystem2 pPCS = null; IActiveView pActiveView = ArcMap.Document.ActiveView; //double dMetersPerUnit = 1; //if (pSpatRef == null) // ; //else if (pSpatRef is IProjectedCoordinateSystem2) //{ // pPCS = (IProjectedCoordinateSystem2)pSpatRef; // string sUnit = pPCS.CoordinateUnit.Name; // if (sUnit.Contains("Foot") && sUnit.Contains("US")) // sUnit = "U.S. Feet"; // dMetersPerUnit = pPCS.CoordinateUnit.MetersPerUnit; //} IAngularConverter pAngConv = new AngularConverterClass(); Utilities Utils = new Utilities(); if (!Utils.GetFabricSubLayers(pMap, esriCadastralFabricTable.esriCFTLines, out LineLyrArr)) { return; } //if we're in an edit session then grab the target fabric if (m_pEd.EditState == esriEditState.esriStateEditing) { pCadFabric = pCadEd.CadastralFabric; } if (pCadFabric == null) {//find the first fabric in the map if (!Utils.GetFabricFromMap(pMap, out pCadFabric)) { MessageBox.Show ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again."); return; } } List <int> lstLineIds = new List <int>(); IFeatureClass pFabricLinesFC = (IFeatureClass)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLines); int idxParcelIDFld = pFabricLinesFC.Fields.FindField("ParcelID"); int idxCENTERPTID = pFabricLinesFC.Fields.FindField("CenterPointID"); int idxRADIUS = pFabricLinesFC.Fields.FindField("Radius"); bool bFieldsPresent = true; if (idxParcelIDFld == -1) { bFieldsPresent = false; } if (idxCENTERPTID == -1) { bFieldsPresent = false; } if (idxRADIUS == -1) { bFieldsPresent = false; } if (!bFieldsPresent) { MessageBox.Show("Fields missing."); return; } Dictionary <int, List <string> > dictLineToCurveNeighbourData = new Dictionary <int, List <string> >(); m_pFIDSetParcels = new FIDSet(); for (int i = 0; i < LineLyrArr.Count; i++) { IFeatureSelection pFeatSel = LineLyrArr.Element[i] as IFeatureSelection; ISelectionSet pSelSet = pFeatSel.SelectionSet; ICursor pCursor = null; pSelSet.Search(null, false, out pCursor); IFeature pLineFeat = pCursor.NextRow() as IFeature; while (pLineFeat != null) { if (!lstLineIds.Contains(pLineFeat.OID)) { IGeometry pGeom = pLineFeat.ShapeCopy; ISegmentCollection pSegColl = pGeom as ISegmentCollection; ISegment pSeg = null; if (pSegColl.SegmentCount == 1) { pSeg = pSegColl.get_Segment(0); } else { //todo: but for now, only deals with single segment short segments Marshal.ReleaseComObject(pLineFeat); pLineFeat = pCursor.NextRow() as IFeature; continue; } //check geometry for circular arc if (pSeg is ICircularArc) { object dVal1 = pLineFeat.get_Value(idxRADIUS); object dVal2 = pLineFeat.get_Value(idxCENTERPTID); ICircularArc pCircArc = pSeg as ICircularArc; if (dVal1 != DBNull.Value && dVal2 != DBNull.Value) { Marshal.ReleaseComObject(pLineFeat); pLineFeat = pCursor.NextRow() as IFeature; continue; } } //query near lines int iFoundTangent = 0; List <string> sCurveInfoFromNeighbours = new List <string>(); if (Utils.HasTangentCurveMatchFeatures(pFabricLinesFC, (IPolycurve)pGeom, "", 1.5, 0.033, 1, (pSeg.Length * 1.1), out iFoundTangent, ref sCurveInfoFromNeighbours)) { lstLineIds.Add(pLineFeat.OID); int j = (int)pLineFeat.get_Value(idxParcelIDFld); m_pFIDSetParcels.Add(j); dictLineToCurveNeighbourData.Add(pLineFeat.OID, sCurveInfoFromNeighbours); } if (iFoundTangent == 1) //if there's only one tangent look further afield { int iFoundLinesCount = 0; int iFoundParallel = 0; if (Utils.HasParallelCurveMatchFeatures(pFabricLinesFC, (IPolycurve)pGeom, "", 1.5, 70, out iFoundLinesCount, out iFoundParallel, ref sCurveInfoFromNeighbours)) { if (!dictLineToCurveNeighbourData.ContainsKey(pLineFeat.OID)) { dictLineToCurveNeighbourData.Add(pLineFeat.OID, sCurveInfoFromNeighbours); } } } } Marshal.ReleaseComObject(pLineFeat); pLineFeat = pCursor.NextRow() as IFeature; } Marshal.ReleaseComObject(pCursor); } #region line to curve candidate analysis if (lstLineIds.Count == 0) { return; } RefineToBestRadiusAndCenterPoint(dictLineToCurveNeighbourData); #endregion if (dictLineToCurveNeighbourData.Count == 0) { return; } bool bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedDelete = false; IWorkspace pWS = m_pEd.EditWorkspace; IProgressDialog2 pProgressorDialog = null; IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); if (!Utils.SetupEditEnvironment(pWS, pCadFabric, m_pEd, out bIsFileBasedGDB, out bIsUnVersioned, out bUseNonVersionedDelete)) { return; } #region Create Cadastral Job string sTime = ""; if (!bIsUnVersioned && !bIsFileBasedGDB) { //see if parcel locks can be obtained on the selected parcels. First create a job. DateTime localNow = DateTime.Now; sTime = Convert.ToString(localNow); ICadastralJob pJob = new CadastralJobClass(); pJob.Name = sTime; pJob.Owner = System.Windows.Forms.SystemInformation.UserName; pJob.Description = "Convert lines to curves"; try { Int32 jobId = pCadFabric.CreateJob(pJob); } catch (COMException ex) { if (ex.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_ALREADY_EXISTS) { MessageBox.Show("Job named: '" + pJob.Name + "', already exists"); } else { MessageBox.Show(ex.Message); } return; } } #endregion #region Test for Edit Locks ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric; //only need to get locks for parcels that have lines that are to be changed int[] pParcelIds = new int[m_pFIDSetParcels.Count()]; ILongArray pParcelsToLock = new LongArrayClass(); Utils.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, ref pParcelIds, m_pStepProgressor); if (!bIsUnVersioned && !bIsFileBasedGDB) { pFabLocks.LockingJob = sTime; ILongArray pLocksInConflict = null; ILongArray pSoftLcksInConflict = null; if (m_bShowProgressor && !bIsFileBasedGDB) { m_pStepProgressor.Message = "Testing for edit locks on parcels..."; } try { pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict); } catch (COMException pCOMEx) { if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS || pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED) { MessageBox.Show("Edit Locks could not be acquired on all selected parcels."); // since the operation is being aborted, release any locks that were acquired pFabLocks.UndoLastAcquiredLocks(); } else { MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode)); } return; } } #endregion if (m_pEd.EditState == esriEditState.esriStateEditing) { try { m_pEd.StartOperation(); } catch { m_pEd.AbortOperation();//abort any open edit operations and try again m_pEd.StartOperation(); } } if (bUseNonVersionedDelete) { if (!Utils.StartEditing(pWS, bIsUnVersioned)) { return; } } ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric; pSchemaEd.ReleaseReadOnlyFields((ITable)pFabricLinesFC, esriCadastralFabricTable.esriCFTLines); //release for edits m_pQF = new QueryFilter(); // m_pEd.StartOperation(); List <string> sInClauseList = Utils.InClauseFromOIDsList(lstLineIds, 995); foreach (string InClause in sInClauseList) { m_pQF.WhereClause = pFabricLinesFC.OIDFieldName + " IN (" + InClause + ")"; if (!UpdateCircularArcValues((ITable)pFabricLinesFC, m_pQF, bIsUnVersioned, dictLineToCurveNeighbourData)) { ; } } m_pEd.StopOperation("Insert missing circular arc information."); } catch (Exception ex) { MessageBox.Show(ex.Message); m_pEd.AbortOperation(); } finally { } }
protected override void OnClick() { m_pApp = (IApplication)ArcMap.Application; if (m_pApp == null) { //if the app is null then could be running from ArcCatalog m_pApp = (IApplication)ArcCatalog.Application; } if (m_pApp == null) { MessageBox.Show("Could not access the application.", "No Application found"); return; } IGxApplication pGXApp = (IGxApplication)m_pApp; stdole.IUnknown pUnk = null; try { pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open(); } catch (COMException ex) { if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE || ex.ErrorCode == -2147220944) { MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset"); } else { MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset"); } return; } if (pUnk is ICadastralFabric) { m_pCadaFab = (ICadastralFabric)pUnk; } else { MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric"); return; } IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); Utils FabricUTILS = new Utils(); ITable pTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels); IDataset pDS = (IDataset)pTable; IWorkspace pWS = pDS.Workspace; bool bIsFileBasedGDB = true; bool bIsUnVersioned = true; FabricUTILS.GetFabricPlatform(pWS, m_pCadaFab, out bIsFileBasedGDB, out bIsUnVersioned); //Do a Start and Stop editing to make sure we're not running in an edit session if (!FabricUTILS.StartEditing(pWS, true)) {//if start editing fails then bail if (pUnk != null) { Marshal.ReleaseComObject(pUnk); } Cleanup(pMouseCursor, null, pTable, null, pWS, null); FabricUTILS = null; return; } FabricUTILS.StopEditing(pWS); IFIDSet pPlansToDelete = null; try { string[] SummaryNames = new string[0]; //define as dynamic array string[] RepeatPlans = new string[0]; //define as dynamic array ITable pPlansTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans); //load all the plan names into a string array m_pProgressorDialogFact = new ProgressDialogFactoryClass(); m_pTrackCancel = new CancelTrackerClass(); m_pStepProgressor = m_pProgressorDialogFact.Create(m_pTrackCancel, m_pApp.hWnd); IProgressDialog2 pProgressorDialog = (IProgressDialog2)m_pStepProgressor; int iRowCount = pPlansTable.RowCount(null); m_pStepProgressor.MinRange = 1; m_pStepProgressor.MaxRange = iRowCount * 2; m_pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; pProgressorDialog.ShowDialog(); m_pStepProgressor.Message = "Finding same-name plans to merge..."; int iRepeatCnt = 0; if (!FindRepeatPlans(pPlansTable, out RepeatPlans, out SummaryNames, out iRepeatCnt)) { pProgressorDialog.HideDialog(); if (iRepeatCnt == 0) { MessageBox.Show("All plans in the fabric have unique names." + Environment.NewLine + "There are no plans to merge.", "Merge plans by name"); } else { MessageBox.Show("There was a problem searching for repeat plans.", "Merge plans by name"); } SummaryNames = null; RepeatPlans = null; Cleanup(pMouseCursor, null, pTable, pPlansTable, pWS, pProgressorDialog); return; } dlgMergeSameNamePlans TheSummaryDialog = new dlgMergeSameNamePlans(); FillTheSummaryList(TheSummaryDialog, SummaryNames); DialogResult dResult = TheSummaryDialog.ShowDialog(); if (dResult == DialogResult.Cancel) { pProgressorDialog.HideDialog(); SummaryNames = null; RepeatPlans = null; Cleanup(pMouseCursor, null, pTable, pPlansTable, pWS, pProgressorDialog); pPlansTable = null; return; } //get the time now m_pStartTime = new TimeClass(); m_pStartTime.SetFromCurrentLocalTime(); Dictionary <int, int> Lookup = new Dictionary <int, int>(); string[] InClause = new string[0]; //define as dynamic array m_pStepProgressor.Message = "Creating the merge query..."; FabricUTILS.BuildSearchMapAndQuery(RepeatPlans, out Lookup, out InClause, out pPlansToDelete); ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)m_pCadaFab; ITable ParcelTable = m_pCadaFab.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels); pSchemaEd.ReleaseReadOnlyFields(ParcelTable, esriCadastralFabricTable.esriCFTParcels); //release safety-catch if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) { Cleanup(pMouseCursor, pPlansToDelete, pTable, pPlansTable, pWS, pProgressorDialog); InClause = null; Lookup.Clear(); Lookup = null; return; } //setup progressor dialog for merge m_pStepProgressor.Message = "Moving parcels from source to target plans..."; if (!FabricUTILS.MergePlans(ParcelTable, Lookup, InClause, bIsUnVersioned, m_pStepProgressor, m_pTrackCancel)) { FabricUTILS.AbortEditing(pWS); pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels); Cleanup(pMouseCursor, pPlansToDelete, pTable, pPlansTable, pWS, pProgressorDialog); InClause = null; Lookup.Clear(); Lookup = null; return; } if (TheSummaryDialog.checkBox1.Checked) { //setup progressor dialog for Delete m_pStepProgressor.MaxRange = pPlansToDelete.Count(); m_pStepProgressor.Message = "Deleting source plans..."; if (bIsUnVersioned) { if (!FabricUTILS.DeleteRowsUnversioned(pWS, pPlansTable, pPlansToDelete, m_pStepProgressor, m_pTrackCancel)) { Cleanup(pMouseCursor, pPlansToDelete, pTable, pPlansTable, pWS, pProgressorDialog); } } else { if (!FabricUTILS.DeleteRowsByFIDSet(pPlansTable, pPlansToDelete, m_pStepProgressor, m_pTrackCancel)) { Cleanup(pMouseCursor, pPlansToDelete, pTable, pPlansTable, pWS, pProgressorDialog); } } } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels); m_pEndTime = new TimeClass(); m_pEndTime.SetFromCurrentLocalTime(); ITimeDuration HowLong = m_pEndTime.SubtractTime(m_pStartTime); m_pStepProgressor.Message = "[" + HowLong.Hours.ToString("00") + "h " + HowLong.Minutes.ToString("00") + "m " + HowLong.Seconds.ToString("00") + "s]" + " Saving changes...please wait."; FabricUTILS.StopEditing(pWS); Cleanup(pMouseCursor, pPlansToDelete, pTable, pPlansTable, pWS, pProgressorDialog); } catch (COMException ex) { MessageBox.Show(Convert.ToString(ex.ErrorCode)); Cleanup(pMouseCursor, pPlansToDelete, pTable, null, pWS, null); } }