Ejemplo n.º 1
0
        public bool UpdateCircularArcValues(ITable LineTable, IQueryFilter QueryFilter, bool Unversioned, Dictionary <int, List <string> > CurveLookup)
        {
            try
            {
                ITableWrite pTableWr  = (ITableWrite)LineTable;//used for unversioned table
                IRow        pLineFeat = null;
                ICursor     pLineCurs = null;

                if (Unversioned)
                {
                    pLineCurs = pTableWr.UpdateRows(QueryFilter, false);
                }
                else
                {
                    pLineCurs = LineTable.Update(QueryFilter, false);
                }

                pLineFeat = pLineCurs.NextRow();

                Int32 iCtrPointIDX = pLineCurs.Fields.FindField("CENTERPOINTID");
                Int32 iRadiusIDX   = pLineCurs.Fields.FindField("RADIUS");

                while (pLineFeat != null)
                {                                                              //loop through all of the given lines, and update centerpoint ids and the Radius values
                    List <string> CurveInfoList = CurveLookup[pLineFeat.OID];
                    string[]      sCurveInfo    = CurveInfoList[0].Split(','); //should only be one element in the list at this point
                    if (sCurveInfo.Length > 2)
                    {
                        Marshal.ReleaseComObject(pLineFeat); //garbage collection
                        pLineFeat = pLineCurs.NextRow();
                        continue;
                    }
                    double dRadius     = Convert.ToDouble(sCurveInfo[0]);
                    int    iCtrPointID = Convert.ToInt32(sCurveInfo[1]);
                    pLineFeat.set_Value(iRadiusIDX, dRadius);
                    pLineFeat.set_Value(iCtrPointIDX, iCtrPointID);

                    if (Unversioned)
                    {
                        pLineCurs.UpdateRow(pLineFeat);
                    }
                    else
                    {
                        pLineFeat.Store();
                    }

                    Marshal.ReleaseComObject(pLineFeat); //garbage collection
                    pLineFeat = pLineCurs.NextRow();
                }
                Marshal.ReleaseComObject(pLineCurs); //garbage collection
                return(true);
            }
            catch (COMException ex)
            {
                MessageBox.Show("Problem updating circular arc: " + Convert.ToString(ex.ErrorCode));
                return(false);
            }
        }
        private bool ResetPointAssociations(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned,
                                            IStepProgressor StepProgressor, ITrackCancel TrackCancel)
        {
            try
            {
                ITableWrite pTableWr   = (ITableWrite)PointTable;//used for unversioned table
                IRow        pPointFeat = null;
                ICursor     pPtCurs    = null;

                if (Unversioned)
                {
                    pPtCurs = pTableWr.UpdateRows(QueryFilter, false);
                }
                else
                {
                    pPtCurs = PointTable.Update(QueryFilter, false);
                }

                pPointFeat = pPtCurs.NextRow();

                if (StepProgressor != null)
                {
                    if (StepProgressor.Position < StepProgressor.MaxRange)
                    {
                        StepProgressor.Step();
                    }
                }

                Int32 iPointIDX = pPtCurs.Fields.FindField("NAME");
                bool  bCont     = true;
                while (pPointFeat != null)
                {//loop through all of the fabric points, and if any of the point id values are in the deleted set,
                 //then remove the control name from the point's NAME field

                    if (TrackCancel != null)
                    {
                        bCont = TrackCancel.Continue();
                    }
                    if (!bCont)
                    {
                        break;
                    }

                    pPointFeat.set_Value(iPointIDX, DBNull.Value);
                    if (Unversioned)
                    {
                        pPtCurs.UpdateRow(pPointFeat);
                    }
                    else
                    {
                        pPointFeat.Store();
                    }

                    Marshal.ReleaseComObject(pPointFeat); //garbage collection
                    pPointFeat = pPtCurs.NextRow();

                    if (StepProgressor != null)
                    {
                        if (StepProgressor.Position < StepProgressor.MaxRange)
                        {
                            StepProgressor.Step();
                        }
                    }
                }
                Marshal.ReleaseComObject(pPtCurs); //garbage collection

                if (!bCont)
                {
                    return(false);
                }
                return(true);
            }
            catch (COMException ex)
            {
                MessageBox.Show("Problem resetting point table's control association: " + Convert.ToString(ex.ErrorCode));
                return(false);
            }
        }
        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 MergePlans(ITable ParcelTable, Dictionary <int, int> Lookup, string[] sInClause, bool Unversioned,
                               IStepProgressor StepProgressor, ITrackCancel TrackCancel)
        {
            IDataset   pDS = (IDataset)ParcelTable;
            IWorkspace pWS = pDS.Workspace;

            Int32      iPlanIDX   = ParcelTable.Fields.FindField("PLANID");
            ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
            string     sPref      = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
            string     sSuff      = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

            ITableWrite pTableWr = (ITableWrite)ParcelTable;
            bool        bCont    = true;
            int         zz       = 0;
            int         iCnt     = sInClause.GetLength(0);

            try
            {
                foreach (string ss in sInClause)
                {
                    if (ss == null)
                    {
                        continue;
                    }
                    IQueryFilter pQF      = new QueryFilterClass();
                    string       InClause = ss.Replace(",", " ").Trim();
                    InClause = InClause.Replace(" ", ",");
                    string FieldName = "PLANID";
                    pQF.WhereClause = sPref + FieldName + sSuff + " IN (" + InClause + ")";
                    if (!ParcelTable.HasOID)
                    {
                        MessageBox.Show("Has no OID");
                    }

                    int     iRowCnt = ParcelTable.RowCount(pQF);
                    ICursor pCur    = null;
                    if (Unversioned)
                    {
                        pCur = pTableWr.UpdateRows(pQF, false);
                    }
                    else
                    {
                        pCur = ParcelTable.Update(pQF, false);
                    }

                    //Check if the cancel button was pressed. If so, stop process
                    if (TrackCancel != null)
                    {
                        bCont = TrackCancel.Continue();
                    }
                    if (!bCont)
                    {
                        break;
                    }

                    //now for each of these parcels, use the dictionary to re-assign the plan id value
                    IRow pParcel = pCur.NextRow();

                    if (StepProgressor != null)
                    {
                        StepProgressor.MinRange = StepProgressor.Position; //reset the progress bar position
                        StepProgressor.MaxRange = StepProgressor.Position + iRowCnt;

                        if (StepProgressor.Position < StepProgressor.MaxRange)
                        {
                            StepProgressor.Step();
                        }
                        StepProgressor.Message = "Moving parcels to target plans...step " + Convert.ToString(++zz) + " of " + Convert.ToString(iCnt);
                    }

                    if (pQF != null)
                    {
                        Marshal.ReleaseComObject(pQF);
                    }

                    while (pParcel != null)
                    {
                        //Check if the cancel button was pressed. If so, stop process
                        if (TrackCancel != null)
                        {
                            bCont = TrackCancel.Continue();
                        }
                        if (!bCont)
                        {
                            break;
                        }

                        int MergePlanID  = (int)pParcel.get_Value(iPlanIDX);
                        int TargetPlanID = -1;
                        if (Lookup.TryGetValue(MergePlanID, out TargetPlanID))
                        {
                            pParcel.set_Value(iPlanIDX, TargetPlanID);
                            pCur.UpdateRow(pParcel);
                        }
                        Marshal.ReleaseComObject(pParcel);
                        pParcel = pCur.NextRow();
                        if (StepProgressor != null)
                        {
                            if (StepProgressor.Position < StepProgressor.MaxRange)
                            {
                                StepProgressor.Step();
                            }
                        }
                    }
                    if (pCur != null)
                    {
                        Marshal.ReleaseComObject(pCur);
                    }

                    if (!bCont)
                    {
                        break;
                    }
                }

                if (pTableWr != null)
                {
                    Marshal.ReleaseComObject(pTableWr);
                }

                Marshal.ReleaseComObject(pWS);
                if (!bCont)
                {
                    return(false);
                }
                return(true);
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message + ": " + Convert.ToString(ex.ErrorCode));
                return(false);
            }
        }
Ejemplo n.º 5
0
        public bool DeleteByInClause(IWorkspace TheWorkSpace, ITable inTable, IField QueryIntegerField,
                                     List <string> InClauseIDs, bool IsVersioned, IStepProgressor StepProgressor, ITrackCancel TrackCancel)
        {
            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)
            //this code assumes that InClauseIDs holds an arraylist of comma separated OIDs with no more than 995 id's per list item
            string sWhereClauseLHS = sPref + QueryIntegerField.Name + sSuff + " in (";

            try
            {
                ITableWrite pTableWr = (ITableWrite)inTable;
                bool        bCont    = true;

                Int32 count = InClauseIDs.Count - 1;
                for (int k = 0; k <= count; k++)
                {
                    pQF.WhereClause = sWhereClauseLHS + InClauseIDs[k] + ")"; //left-hand side of the where clause
                    if (pQF.WhereClause.Contains("()"))
                    {
                        continue;
                    }
                    if (!IsVersioned)
                    {
                        ipCursor = pTableWr.UpdateRows(pQF, false);
                    }
                    else
                    {
                        ipCursor = inTable.Update(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);
                        }
                        return(false);
                    }
                    Marshal.ReleaseComObject(ipCursor);
                }
                return(true);
            }

            catch (Exception ex)
            {
                if (ipCursor != null)
                {
                    Marshal.ReleaseComObject(ipCursor);
                }
                if (pRow != null)
                {
                    Marshal.ReleaseComObject(pRow);
                }
                MessageBox.Show(Convert.ToString(ex.Message));
                return(false);
            }
        }
Ejemplo n.º 6
0
        protected override void OnClick()
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();

            pMouseCursor.SetCursor(2);

            //first get the selected parcel features
            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);

            Marshal.ReleaseComObject(pUID);

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

            IFeatureLayer CFPointLayer = null; IFeatureLayer CFLineLayer = null;
            IFeatureLayer CFControlLayer   = null;
            IFeatureLayer CFLinePointLayer = null;

            IActiveView      pActiveView       = ArcMap.Document.ActiveView;
            IMap             pMap              = pActiveView.FocusMap;
            ICadastralFabric pCadFabric        = null;
            IProgressDialog2 pProgressorDialog = null;

            clsFabricUtils UTILS = 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 (!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;
                }
            }

            IArray CFParcelLayers = new ArrayClass();

            if (!(UTILS.GetFabricSubLayersFromFabric(pMap, pCadFabric, out CFPointLayer, out CFLineLayer,
                                                     out CFParcelLayers, out CFControlLayer, out CFLinePointLayer)))
            {
                return; //no fabric sublayers available for the targeted fabric
            }
            bool       bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersioned = false;
            IWorkspace pWS = null;

            try
            {
                //Get the selection of parcels
                IFeatureLayer pFL = (IFeatureLayer)CFParcelLayers.get_Element(0);
                IDataset      pDS = (IDataset)pFL.FeatureClass;
                pWS = pDS.Workspace;

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

                if (bUseNonVersioned)
                {
                    ICadastralFabricLayer pCFLayer = new CadastralFabricLayerClass();
                    pCFLayer.CadastralFabric    = pCadFabric;
                    pCadEd.CadastralFabricLayer = pCFLayer;//NOTE: Need to set this back to NULL when done.
                }

                Hashtable   FabLyrToFieldMap   = new Hashtable();
                DateChanger pDateChangerDialog = new DateChanger();
                pDateChangerDialog.cboBoxFabricClasses.Items.Clear();
                string[] FieldStrArr = new string[CFParcelLayers.Count];
                for (int i = 0; i < CFParcelLayers.Count; i++)
                {
                    FieldStrArr[i] = "";
                    IFeatureLayer lyr = (IFeatureLayer)CFParcelLayers.get_Element(i);
                    //   ICadastralFabricLayer cflyr = CFParcelLayers.get_Element(i);

                    pDateChangerDialog.cboBoxFabricClasses.Items.Add(lyr.Name);
                    IFields pFlds = lyr.FeatureClass.Fields;
                    for (int j = 0; j < lyr.FeatureClass.Fields.FieldCount; j++)
                    {
                        IField pFld = lyr.FeatureClass.Fields.get_Field(j);
                        if (pFld.Type == esriFieldType.esriFieldTypeDate)
                        {
                            if (FieldStrArr[i].Trim() == "")
                            {
                                FieldStrArr[i] = pFld.Name;
                            }
                            else
                            {
                                FieldStrArr[i] += "," + pFld.Name;
                            }
                        }
                    }
                    FabLyrToFieldMap.Add(i, FieldStrArr[i]);
                }
                pDateChangerDialog.FieldMap = FabLyrToFieldMap;
                pDateChangerDialog.cboBoxFabricClasses.SelectedIndex = 0;



                // ********  Display the dialog  *********
                DialogResult pDialogResult = pDateChangerDialog.ShowDialog();
                if (pDialogResult != DialogResult.OK)
                {
                    return;
                }
                //************************

                //*** get the choices from the dialog
                IFeatureLayer flyr     = (IFeatureLayer)CFParcelLayers.get_Element(pDateChangerDialog.cboBoxFabricClasses.SelectedIndex);
                int           iDateFld = flyr.FeatureClass.Fields.FindField(pDateChangerDialog.cboBoxFields.Text);

                if (pDateChangerDialog.radioButton2.Checked)
                {
                    IField pFld = flyr.FeatureClass.Fields.get_Field(iDateFld);
                    if (!pFld.IsNullable)
                    {
                        MessageBox.Show("The field you selected does not allow NULL values, and must have a date." + Environment.NewLine +
                                        "Please try again using the date option, or using a different date field.", "Field does not Allow Null", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                ICadastralFabricSubLayer pSubLyr = (ICadastralFabricSubLayer)flyr;
                bool bLines   = false;
                bool bParcels = false;
                if (pSubLyr.CadastralTableType == esriCadastralFabricTable.esriCFTLines)
                {
                    bLines = true;
                }
                if (pSubLyr.CadastralTableType == esriCadastralFabricTable.esriCFTParcels)
                {
                    bParcels = true;
                }

                //find out if there is a selection for the chosen layer
                bool ChosenLayerHasSelection = false;

                IFeatureSelection   pFeatSel       = null;
                ISelectionSet2      pSelSet        = null;
                ICadastralSelection pCadaSel       = null;
                IEnumGSParcels      pEnumGSParcels = null;

                int iFeatureCnt = 0;
                pFeatSel = (IFeatureSelection)flyr;
                if (pFeatSel != null)
                {
                    pSelSet = (ISelectionSet2)pFeatSel.SelectionSet;
                    ChosenLayerHasSelection = (pSelSet.Count > 0);
                    iFeatureCnt             = pSelSet.Count;
                }
                //****

                if (iFeatureCnt == 0)
                {
                    if (MessageBox.Show("There are no features selected in the " + flyr.Name + " layer." + Environment.NewLine + "Click OK to Change dates for ALL features in the layer.", "No Selection",
                                        MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }
                }
                else
                {
                    pCadaSel = (ICadastralSelection)pCadEd;
                    //** TODO: this enum should be based on the selected points, lines, or line-points
                    pEnumGSParcels = pCadaSel.SelectedParcels;// need to get the parcels before trying to get the parcel count: BUG workaround
                    //***
                }

                if (iFeatureCnt == 0)
                {
                    m_pCursor = (ICursor)flyr.FeatureClass.Search(null, false);
                    ITable pTable = (ITable)flyr.FeatureClass;
                    iFeatureCnt = pTable.RowCount(null);
                }

                m_bShowProgressor = (iFeatureCnt > 10);
                if (m_bShowProgressor)
                {
                    m_pProgressorDialogFact     = new ProgressDialogFactoryClass();
                    m_pTrackCancel              = new CancelTrackerClass();
                    m_pStepProgressor           = m_pProgressorDialogFact.Create(m_pTrackCancel, ArcMap.Application.hWnd);
                    pProgressorDialog           = (IProgressDialog2)m_pStepProgressor;
                    m_pStepProgressor.MinRange  = 1;
                    m_pStepProgressor.MaxRange  = iFeatureCnt;
                    m_pStepProgressor.StepValue = 1;
                    pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                }
                m_pQF = new QueryFilterClass();
                string sPref; string sSuff;

                ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
                sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
                sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

                //====== need to do this for all the parcel sublayers in the map that are part of the target fabric
                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Collecting data...";
                }

                bool bCont = true;
                m_pFIDSetParcels = new FIDSetClass();

                if (ChosenLayerHasSelection && bParcels && !bIsUnVersioned)
                {
                    //if there is a selection add the OIDs of all the selected parcels into a new feature IDSet
                    pEnumGSParcels.Reset();
                    IGSParcel pGSParcel = pEnumGSParcels.Next();

                    while (pGSParcel != null)
                    {
                        //Check if the cancel button was pressed. If so, stop process
                        if (m_bShowProgressor)
                        {
                            bCont = m_pTrackCancel.Continue();
                            if (!bCont)
                            {
                                break;
                            }
                        }
                        m_pFIDSetParcels.Add(pGSParcel.DatabaseId);
                        Marshal.ReleaseComObject(pGSParcel); //garbage collection
                        pGSParcel = pEnumGSParcels.Next();
                        //}
                        if (m_bShowProgressor)
                        {
                            if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
                            {
                                m_pStepProgressor.Step();
                            }
                        }
                    }
                }

                if ((!ChosenLayerHasSelection && bParcels && !bIsUnVersioned) ||
                    (!ChosenLayerHasSelection && bLines && !bIsUnVersioned))
                {
                    IRow pRow = m_pCursor.NextRow();
                    while (pRow != null)
                    {
                        m_pFIDSetParcels.Add(pRow.OID);
                        Marshal.ReleaseComObject(pRow);
                        pRow = m_pCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(m_pCursor);
                }

                if (bLines && ChosenLayerHasSelection && !bIsUnVersioned)
                {
                    pSelSet.Search(null, false, out m_pCursor);
                    IRow pRow = m_pCursor.NextRow();
                    int  iFld = m_pCursor.FindField("PARCELID");
                    while (pRow != null)
                    {
                        m_pFIDSetParcels.Add((int)pRow.get_Value(iFld));
                        Marshal.ReleaseComObject(pRow);
                        pRow = m_pCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(m_pCursor);
                }

                //=========================================================
                if (!bCont)
                {
                    //Since I'm using update cursor need to clear the cadastral selection
                    pCadaSel.SelectedParcels = null;
                    //clear selection, to make sure the parcel explorer is updated and refreshed properly
                    return;
                }

                string sTime = "";
                if (!bIsUnVersioned)
                {
                    //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 = "Change Date on selected parcels";
                    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);
                        }
                        m_pStepProgressor = null;
                        if (!(pProgressorDialog == null))
                        {
                            pProgressorDialog.HideDialog();
                        }
                        pProgressorDialog = null;
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //if we're in an enterprise then test for edit locks
                ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric;
                if (!bIsUnVersioned)
                {
                    pFabLocks.LockingJob = sTime;
                    ILongArray pLocksInConflict    = null;
                    ILongArray pSoftLcksInConflict = null;

                    ILongArray pParcelsToLock = new LongArrayClass();

                    UTILS.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, m_pStepProgressor);
                    if (m_pStepProgressor != null && !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)
                        {
                            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();
                            //clear selection, to make sure the parcel explorer is updated and refreshed properly
                            RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);
                        }
                        else
                        {
                            MessageBox.Show(Convert.ToString(pCOMEx.ErrorCode));
                        }

                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //Now... start the edit. Start an edit operation.
                if (pEd.EditState == esriEditState.esriStateEditing)
                {
                    pEd.StartOperation();
                }

                if (bUseNonVersioned)
                {
                    if (!UTILS.StartEditing(pWS, bUseNonVersioned))
                    {
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //Change all the date records
                if (m_pStepProgressor != null)
                {
                    m_pStepProgressor.Message = "Changing dates...";
                }

                bool bSuccess = true;

                ITable      Table2Edit = (ITable)flyr.FeatureClass;
                ITableWrite pTableWr   = (ITableWrite)Table2Edit;

                if (ChosenLayerHasSelection)
                {
                    //TODO: Selection based update does not work on unversioned tables
                    //need to change this code to create an update cursor from the selection,
                    //including code for tokens > 995
                    pSelSet.Update(null, false, out m_pCursor);
                }
                else
                {
                    if (bUseNonVersioned)
                    {
                        m_pCursor = pTableWr.UpdateRows(null, false);
                    }
                    else
                    {
                        m_pCursor = Table2Edit.Update(null, false);
                    }
                }
                ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                if (bLines)
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTLines); //release safety-catch
                }
                else if (bParcels)
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTParcels); //release safety-catch
                }
                else
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTPoints);     //release safety-catch
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTControl);    //release safety-catch
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTLinePoints); //release safety-catch
                }

                if (pDateChangerDialog.radioButton2.Checked)
                {
                    bSuccess = UTILS.ChangeDatesOnTable(m_pCursor, pDateChangerDialog.cboBoxFields.Text, "",
                                                        bUseNonVersioned, m_pStepProgressor, m_pTrackCancel);
                }
                else
                {
                    bSuccess = UTILS.ChangeDatesOnTable(m_pCursor, pDateChangerDialog.cboBoxFields.Text,
                                                        pDateChangerDialog.dateTimePicker1.Text, bUseNonVersioned, m_pStepProgressor, m_pTrackCancel);
                }

                if (!bSuccess)
                {
                    if (!bIsUnVersioned)
                    {
                        pFabLocks.UndoLastAcquiredLocks();
                    }
                    if (bUseNonVersioned)
                    {
                        UTILS.AbortEditing(pWS);
                    }
                    else
                    {
                        pEd.AbortOperation();
                    }
                    //clear selection, to make sure the parcel explorer is updated and refreshed properly

                    return;
                }

                if (pEd.EditState == esriEditState.esriStateEditing)
                {
                    pEd.StopOperation("Change Date");
                }

                if (bUseNonVersioned)
                {
                    UTILS.StopEditing(pWS);
                }

                if (bParcels)
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels);
                }
                else if (bLines)
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLines);
                }
                else
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints);     //release safety-catch
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);    //release safety-catch
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLinePoints); //release safety-catch
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + ex.Message);
                if (bUseNonVersioned)
                {
                    UTILS.AbortEditing(pWS);
                }
                else
                {
                    pEd.AbortOperation();
                }
            }
            finally
            {
                RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);

                if (bUseNonVersioned)
                {
                    pCadEd.CadastralFabricLayer = null;
                    CFParcelLayers   = null;
                    CFPointLayer     = null;
                    CFLineLayer      = null;
                    CFControlLayer   = null;
                    CFLinePointLayer = null;
                }

                m_pStepProgressor = null;
                if (!(pProgressorDialog == null))
                {
                    pProgressorDialog.HideDialog();
                }
                pProgressorDialog = null;
            }
        }
        private bool UpdatePointXYFromGeometry(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned, double UpdateIfMoreThanTolerance, out int ChangedPointCount)
        {
            IApplication pApp = (IApplication)ArcMap.Application;

            if (pApp == null)
            {
                //if the app is null then must be running from ArcCatalog...based on equivalent test in calling function.
                pApp = (IApplication)ArcCatalog.Application;
            }

            IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass();
            ITrackCancel           pTrackCancel          = new CancelTrackerClass();
            IStepProgressor        pStepProgressor       = pProgressorDialogFact.Create(pTrackCancel, pApp.hWnd);
            IProgressDialog2       pProgressorDialog     = (IProgressDialog2)pStepProgressor;

            try
            {
                pStepProgressor.MinRange    = 0;
                pStepProgressor.MaxRange    = PointTable.RowCount(null);
                pStepProgressor.StepValue   = 1;
                pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                bool bCont = true;

                IRow    pPointFeat = null;
                ICursor pPtCurs    = null;
                ChangedPointCount = 0;
                if (Unversioned)
                {
                    ITableWrite pTableWr = (ITableWrite)PointTable;//used for unversioned table
                    pPtCurs = pTableWr.UpdateRows(QueryFilter, false);
                }
                else
                {
                    pPtCurs = PointTable.Update(QueryFilter, false);
                }

                pPointFeat = pPtCurs.NextRow();

                int iPointIdx_X = pPtCurs.Fields.FindField("X");
                int iPointIdx_Y = pPtCurs.Fields.FindField("Y");

                pProgressorDialog.ShowDialog();
                pStepProgressor.Message = "Updating point data...";

                while (pPointFeat != null)
                {//loop through all of the fabric points, and if any of the point id values are in the deleted set,
                 //then remove the control name from the point's NAME field

                    bCont = pTrackCancel.Continue();
                    if (!bCont)
                    {
                        break;
                    }

                    IFeature pFeat     = (IFeature)pPointFeat;
                    IPoint   pPtSource = (IPoint)pFeat.ShapeCopy;

                    if (pPtSource == null)
                    {
                        Marshal.ReleaseComObject(pPointFeat); //garbage collection
                        pPointFeat = pPtCurs.NextRow();
                        continue;
                    }

                    if (pPtSource.IsEmpty)
                    {
                        Marshal.ReleaseComObject(pPointFeat); //garbage collection
                        pPointFeat = pPtCurs.NextRow();
                        continue;
                    }
                    IPoint pPtTarget = new ESRI.ArcGIS.Geometry.PointClass();
                    pPtTarget.X = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_X));
                    pPtTarget.Y = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_Y));

                    ILine pLine = new ESRI.ArcGIS.Geometry.LineClass();
                    pLine.PutCoords(pPtSource, pPtTarget);

                    if (pLine.Length > UpdateIfMoreThanTolerance)
                    {
                        pPointFeat.set_Value(iPointIdx_X, pPtSource.X);
                        pPointFeat.set_Value(iPointIdx_Y, pPtSource.Y);

                        //if (Unversioned)
                        pPtCurs.UpdateRow(pPointFeat);
                        //else
                        //  pPointFeat.Store();
                        ChangedPointCount++;
                        string sCnt = ChangedPointCount.ToString() + " of " + pStepProgressor.MaxRange.ToString();
                        pStepProgressor.Message = "Updating point data..." + sCnt;
                    }

                    Marshal.ReleaseComObject(pPointFeat); //garbage collection
                    pPointFeat = pPtCurs.NextRow();

                    if (pStepProgressor.Position < pStepProgressor.MaxRange)
                    {
                        pStepProgressor.Step();
                    }
                }
                Marshal.ReleaseComObject(pPtCurs); //garbage collection
                return(bCont);
            }
            catch (COMException ex)
            {
                MessageBox.Show("Problem updating point XY from shape: " + Convert.ToString(ex.ErrorCode));
                ChangedPointCount = 0;
                return(false);
            }
            finally
            {
                pStepProgressor = null;
                if (!(pProgressorDialog == null))
                {
                    pProgressorDialog.HideDialog();
                }
                pProgressorDialog = null;
            }
        }
        protected override void OnClick()
        {
            IEditor          m_pEd  = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");
            ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");

            if (m_pEd.EditState == esriEditState.esriStateNotEditing)
            {
                MessageBox.Show("Please start editing first, and try again.", "Start Editing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            IArray           PolygonLyrArr;
            IMap             pMap       = m_pEd.Map;
            ICadastralFabric pCadFabric = null;

            //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
                MessageBox.Show
                    ("No Parcel Fabric found in the workspace you're editing.\r\nPlease re-start editing on a workspace with a fabric, and try again.",
                    "No Fabric found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Utilities Utils = new Utilities();

            if (!Utils.GetFabricSubLayers(pMap, esriCadastralFabricTable.esriCFTParcels, out PolygonLyrArr))
            {
                return;
            }
            //check if there is a Manual Mode "modify" job active ===========
            ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadEd;

            if (pCadPacMan.PacketOpen)
            {
                MessageBox.Show("The Area Calculation does not work when the parcel is open.\r\nPlease close the parcel and try again.",
                                "Calculate Stated Area", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            IActiveView pActiveView = ArcMap.Document.ActiveView;

            CalcStatedAreaDLG CalcStatedArea = new CalcStatedAreaDLG();
            bool             bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedEdit = false;
            IWorkspace       pWS               = null;
            ITable           pParcelsTable     = null;
            IProgressDialog2 pProgressorDialog = null;
            IMouseCursor     pMouseCursor      = new MouseCursorClass();

            pMouseCursor.SetCursor(2);
            var pTool = ArcMap.Application.CurrentTool;

            try
            {
                IFeatureLayer pFL = (IFeatureLayer)PolygonLyrArr.get_Element(0);
                IDataset      pDS = (IDataset)pFL.FeatureClass;
                pWS = pDS.Workspace;

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

                ICadastralSelection pCadaSel       = (ICadastralSelection)pCadEd;
                IEnumGSParcels      pEnumGSParcels = pCadaSel.SelectedParcels;// need to get the parcels before trying to get the parcel count: BUG workaround
                IFeatureSelection   pFeatSel       = (IFeatureSelection)pFL;
                ISelectionSet2      pSelSet        = (ISelectionSet2)pFeatSel.SelectionSet;

                if (pCadaSel.SelectedParcelCount == 0 && pSelSet.Count == 0)
                {
                    MessageBox.Show("Please select some fabric parcels and try again.", "No Selection",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ArcMap.Application.CurrentTool = null;

                //Display the dialog
                DialogResult pDialogResult = CalcStatedArea.ShowDialog();
                if (pDialogResult != DialogResult.OK)
                {
                    return;
                }

                m_bShowProgressor = (pSelSet.Count > 10) || pCadaSel.SelectedParcelCount > 10;
                if (m_bShowProgressor)
                {
                    m_pProgressorDialogFact     = new ProgressDialogFactoryClass();
                    m_pTrackCancel              = new CancelTrackerClass();
                    m_pStepProgressor           = m_pProgressorDialogFact.Create(m_pTrackCancel, ArcMap.Application.hWnd);
                    pProgressorDialog           = (IProgressDialog2)m_pStepProgressor;
                    m_pStepProgressor.MinRange  = 1;
                    m_pStepProgressor.MaxRange  = pCadaSel.SelectedParcelCount * 3; //(3 runs through the selection)
                    m_pStepProgressor.StepValue = 1;
                    pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                }

                m_pQF = new QueryFilterClass();
                string sPref; string sSuff;

                ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
                sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
                sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

                //====== need to do this for all the parcel sublayers in the map that are part of the target fabric
                //pEnumGSParcels should take care of this automatically
                //but need to do this for line sublayer

                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Collecting parcel data...";
                }

                //Add the OIDs of all the selected parcels into a new feature IDSet
                int        tokenLimit = 995;
                List <int> oidList    = new List <int>();
                Dictionary <int, string> dict_ParcelSelection2CalculatedArea = new Dictionary <int, string>();

                pParcelsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);

                pEnumGSParcels.Reset();
                IGSParcel pGSParcel = pEnumGSParcels.Next();
                while (pGSParcel != null)
                {
                    //Check if the cancel button was pressed. If so, stop process
                    if (m_bShowProgressor)
                    {
                        if (!m_pTrackCancel.Continue())
                        {
                            break;
                        }
                    }
                    int iDBId = pGSParcel.DatabaseId;
                    if (!oidList.Contains(iDBId))
                    {
                        oidList.Add(iDBId);
                    }

                    Marshal.ReleaseComObject(pGSParcel); //garbage collection
                    pGSParcel = pEnumGSParcels.Next();
                    if (m_bShowProgressor)
                    {
                        if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
                        {
                            m_pStepProgressor.Step();
                        }
                    }
                }
                Marshal.ReleaseComObject(pEnumGSParcels); //garbage collection

                if (m_bShowProgressor)
                {
                    if (!m_pTrackCancel.Continue())
                    {
                        return;
                    }
                }


                string sSuffixUnit = CalcStatedArea.txtSuffix.Text;
                int    iAreaPrec   = (int)CalcStatedArea.numDecPlaces.Value;

                double dSqMPerUnit = 1;
                if (CalcStatedArea.cboAreaUnit.FindStringExact("Acres") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 4046.86;
                }

                if (CalcStatedArea.cboAreaUnit.FindStringExact("Hectares") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 10000;
                }

                if (CalcStatedArea.cboAreaUnit.FindStringExact("Square Feet") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 0.09290304;
                }

                if (CalcStatedArea.cboAreaUnit.FindStringExact("Square Feet US") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 0.09290341;
                }

                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Computing areas...";
                }
                List <string> sInClauseList0 = null;
                m_pQF = new QueryFilterClass();
                if (oidList.Count() > 0)
                {
                    sInClauseList0 = Utils.InClauseFromOIDsList(oidList, tokenLimit);
                    foreach (string sInClause in sInClauseList0)
                    {
                        m_pQF.WhereClause = pParcelsTable.OIDFieldName + " IN (" + sInClause + ")";
                        CalculateStatedArea(m_pQF, pParcelsTable, pCadEd, m_pEd.Map.SpatialReference, dSqMPerUnit, sSuffixUnit,
                                            iAreaPrec, ref dict_ParcelSelection2CalculatedArea, m_pTrackCancel);

                        if (m_bShowProgressor)
                        {
                            if (!m_pTrackCancel.Continue())
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    return;
                }


                if (m_bShowProgressor)
                {
                    if (!m_pTrackCancel.Continue())
                    {
                        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 = "Interpolate Z values on selected features";
                //  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

                //ILongArray pTempParcelsLongArray = new LongArrayClass();
                //List<int> lstParcelChanges = Utils.FIDsetToLongArray(m_pFIDSetParcels, ref pTempParcelsLongArray, ref pParcelIds, m_pStepProgressor);

                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 (bUseNonVersionedEdit)
                {
                    if (!Utils.StartEditing(pWS, bIsUnVersioned))
                    {
                        return;
                    }
                }

                //ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                //pSchemaEd.ReleaseReadOnlyFields(pParcelsTable, esriCadastralFabricTable.esriCFTParcels);
                int    idxParcelStatedArea       = pParcelsTable.FindField("STATEDAREA");
                string ParcelStatedAreaFieldName = pParcelsTable.Fields.get_Field(idxParcelStatedArea).Name;
                if (m_bShowProgressor)
                {
                    //  pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Updating parcel areas...";
                }

                IRow    pTheFeatRow   = null;
                ICursor pUpdateCursor = null;
                foreach (string sInClause in sInClauseList0)
                {
                    m_pQF.WhereClause = pParcelsTable.OIDFieldName + " IN (" + sInClause + ")";

                    if (bUseNonVersionedEdit)
                    {
                        ITableWrite pTableWr = (ITableWrite)pParcelsTable; //used for unversioned table
                        pUpdateCursor = pTableWr.UpdateRows(m_pQF, false);
                    }
                    else
                    {
                        pUpdateCursor = pParcelsTable.Update(m_pQF, false);
                    }

                    pTheFeatRow = pUpdateCursor.NextRow();
                    while (pTheFeatRow != null)
                    {
                        string sAreaString = dict_ParcelSelection2CalculatedArea[pTheFeatRow.OID];
                        pTheFeatRow.set_Value(idxParcelStatedArea, sAreaString);
                        pTheFeatRow.Store();
                        Marshal.ReleaseComObject(pTheFeatRow); //garbage collection
                        if (m_bShowProgressor)
                        {
                            if (!m_pTrackCancel.Continue())
                            {
                                break;
                            }
                        }
                        pTheFeatRow = pUpdateCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(pUpdateCursor); //garbage collection
                    if (m_bShowProgressor)
                    {
                        if (!m_pTrackCancel.Continue())
                        {
                            break;
                        }
                    }
                }
                m_pEd.StopOperation("Calculate Stated Area");
                //pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels);//set fields back to read-only
            }
            catch (Exception ex)
            {
                if (m_pEd != null)
                {
                    AbortEdits(bIsUnVersioned, m_pEd, pWS);
                }
                MessageBox.Show(ex.Message);
            }
            finally
            {
                ArcMap.Application.CurrentTool = pTool;
                m_pStepProgressor = null;
                m_pTrackCancel    = null;
                if (pProgressorDialog != null)
                {
                    pProgressorDialog.HideDialog();
                }

                RefreshMap(pActiveView, PolygonLyrArr);
                ICadastralExtensionManager pCExMan = (ICadastralExtensionManager)pCadEd;
                IParcelPropertiesWindow2   pPropW  = (IParcelPropertiesWindow2)pCExMan.ParcelPropertiesWindow;
                pPropW.RefreshAll();
                //update the TOC
                IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)(ArcMap.Application.Document);
                for (int i = 0; i < mxDocument.ContentsViewCount; i++)
                {
                    IContentsView pCV = (IContentsView)mxDocument.get_ContentsView(i);
                    pCV.Refresh(null);
                }

                // refresh the attributes dialog
                ISelectionEvents pSelEvents = (ISelectionEvents)m_pEd.Map;
                pSelEvents.SelectionChanged();

                if (bUseNonVersionedEdit)
                {
                    pCadEd.CadastralFabricLayer = null;
                    PolygonLyrArr = null;
                }

                if (pMouseCursor != null)
                {
                    pMouseCursor.SetCursor(0);
                }
            }
        }