protected override void OnClick()
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();
              pMouseCursor.SetCursor(2);

              //get the plans
              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);

              IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");
              dlgEmptyPlansList pPlansListDialog = new dlgEmptyPlansList();

              IActiveView pActiveView = ArcMap.Document.ActiveView;
              IMap pMap = pActiveView.FocusMap;
              ICadastralFabric pCadFabric = null;
              clsFabricUtils FabricUTILS = new clsFabricUtils();

              //if we're in an edit session then grab the target fabric
              if (pEd.EditState == esriEditState.esriStateEditing)
              {
            pCadFabric = pCadEd.CadastralFabric;
              }
              if(pCadFabric==null)
              {
              //find the first fabric in the map
            if (!FabricUTILS.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;
            }
              }
              ITable pPlansTable =null;
              if (pCadFabric != null)
            pPlansTable = pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans);
              else
            return;
              IDataset pDS = (IDataset)pPlansTable;
              IWorkspace pWS = pDS.Workspace;

              bool bIsFileBasedGDB;
              bool bIsUnVersioned;
              bool bUseNonVersionedEdit;
              if (!(FabricUTILS.SetupEditEnvironment(pWS, pCadFabric, pEd,
            out bIsFileBasedGDB, out bIsUnVersioned, out bUseNonVersionedEdit)))
            return;

              IFIDSet pEmptyPlans = null;
              if (!FindEmptyPlans(pCadFabric, null, null, out pEmptyPlans))
            return;

              //Fill the list on the dialog
              AddEmptyPlansToList(pCadFabric, pEmptyPlans, pPlansListDialog);

              //Display the dialog
              DialogResult pDialogResult = pPlansListDialog.ShowDialog();
              if (pDialogResult != DialogResult.OK)
            return;
              IArray array = (IArray)pPlansListDialog.checkedListBox1.Tag;

              IFIDSet pPlansToDelete = new FIDSetClass();

              foreach (int checkedItemIndex in pPlansListDialog.checkedListBox1.CheckedIndices)
              {
            Int32 iPlansID = (Int32)array.get_Element(checkedItemIndex);
            if (iPlansID>-1)
              pPlansToDelete.Add(iPlansID);
              }

              if (bUseNonVersionedEdit)
              {
            FabricUTILS.DeleteRowsUnversioned(pWS, pPlansTable, pPlansToDelete, null, null);
              }
              else
              {
            try
            {
              try
              {
            pEd.StartOperation();
              }
              catch
              {
            pEd.AbortOperation();//abort any open edit operations and try again
            pEd.StartOperation();
              }
              FabricUTILS.DeleteRowsByFIDSet(pPlansTable, pPlansToDelete, null, null);
              pEd.StopOperation("Delete Empty Plans");
            }
            catch (COMException ex)
            {
              MessageBox.Show(Convert.ToString(ex.ErrorCode));
              pEd.AbortOperation();
            }
              }
        }
Exemple #2
0
        protected override void OnClick()
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();

            pMouseCursor.SetCursor(2);

            //get the plans
            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);

            IEditor           pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");
            dlgEmptyPlansList pPlansListDialog = new dlgEmptyPlansList();

            IActiveView      pActiveView = ArcMap.Document.ActiveView;
            IMap             pMap        = pActiveView.FocusMap;
            ICadastralFabric pCadFabric  = null;
            clsFabricUtils   FabricUTILS = new clsFabricUtils();

            //if we're in an edit session then grab the target fabric
            if (pEd.EditState == esriEditState.esriStateEditing)
            {
                pCadFabric = pCadEd.CadastralFabric;
            }
            if (pCadFabric == null)
            {
                //find the first fabric in the map
                if (!FabricUTILS.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;
                }
            }
            ITable pPlansTable = null;

            if (pCadFabric != null)
            {
                pPlansTable = pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans);
            }
            else
            {
                return;
            }
            IDataset   pDS = (IDataset)pPlansTable;
            IWorkspace pWS = pDS.Workspace;

            bool bIsFileBasedGDB;
            bool bIsUnVersioned;
            bool bUseNonVersionedEdit;

            if (!(FabricUTILS.SetupEditEnvironment(pWS, pCadFabric, pEd,
                                                   out bIsFileBasedGDB, out bIsUnVersioned, out bUseNonVersionedEdit)))
            {
                return;
            }

            IFIDSet pEmptyPlans = null;

            if (!FindEmptyPlans(pCadFabric, null, null, out pEmptyPlans))
            {
                return;
            }

            //Fill the list on the dialog
            AddEmptyPlansToList(pCadFabric, pEmptyPlans, pPlansListDialog);

            //Display the dialog
            DialogResult pDialogResult = pPlansListDialog.ShowDialog();

            if (pDialogResult != DialogResult.OK)
            {
                return;
            }
            IArray array = (IArray)pPlansListDialog.checkedListBox1.Tag;

            IFIDSet pPlansToDelete = new FIDSetClass();

            foreach (int checkedItemIndex in pPlansListDialog.checkedListBox1.CheckedIndices)
            {
                Int32 iPlansID = (Int32)array.get_Element(checkedItemIndex);
                if (iPlansID > -1)
                {
                    pPlansToDelete.Add(iPlansID);
                }
            }

            if (bUseNonVersionedEdit)
            {
                FabricUTILS.DeleteRowsUnversioned(pWS, pPlansTable, pPlansToDelete, null, null);
            }
            else
            {
                try
                {
                    try
                    {
                        pEd.StartOperation();
                    }
                    catch
                    {
                        pEd.AbortOperation();//abort any open edit operations and try again
                        pEd.StartOperation();
                    }
                    FabricUTILS.DeleteRowsByFIDSet(pPlansTable, pPlansToDelete, null, null);
                    pEd.StopOperation("Delete Empty Plans");
                }
                catch (COMException ex)
                {
                    MessageBox.Show(Convert.ToString(ex.ErrorCode));
                    pEd.AbortOperation();
                }
            }
        }