protected override void OnClick()
        {
            if (AAState._PerformUpdates)
            {
                AAState._PerformUpdates = false;
                AAState.unInitEditing();
            }
            else
            {
                AAState._PerformUpdates = true;
                AAState.initEditing();
            }
            //if (m_Editor == null)
            //{

            //    return;
            //}
            //if (m_Editor.EditState == esriEditState.esriStateEditing)
            //{
            //    MessageBox.Show("Please stop editing before toggling the extension");
            //    return;
            //}

            //if (AAState.initTable() == false)
            //{
            //    MessageBox.Show("The required tables are missing\r\n" + "Dynamic Value Table: " + AAState._defaultsTableName + "\r\n" + "Generate ID Table: " + AAState._sequenceTableName);
            //    AAState._PerformUpdates = false;

            //    AAState.setIcon();

            //    return;
            //}
            ////Check orginal state
            //bool origState = AAState._PerformUpdates;

            ////Perform work
            //AAState._PerformUpdates = !origState;

            //AAState.setIcon();
            AAState.setIcon();
        }
Пример #2
0
        public long unversionedEdit(IQueryFilter qFilterGen, int sequenceColumnNum, int idxSeqField, int curLoop, ref ITransactions transactions)
        {
            long sequenceValue = -1;

            using (ComReleaser comReleaser = new ComReleaser())
            {
                if (AAState._gentabWorkspace.IsInEditOperation)
                {
                    // throw new Exception("Cannot use ITransactions during an edit operation.");
                }
                // Begin a transaction.
                if (transactions == null)
                {
                    transactions = (ITransactions)AAState._gentabWorkspace;
                }

                transactions.StartTransaction();
                try
                {
                    // Use ITable.Update to create an update cursor.
                    ICursor seq_updateCursor = AAState._gentab.Update(qFilterGen, true);
                    comReleaser.ManageLifetime(seq_updateCursor);

                    IRow seq_row = null;
                    seq_row = seq_updateCursor.NextRow();
                    int sequenceInt = 1;

                    if (seq_row != null)
                    {
                        if (idxSeqField > 0)
                        {
                            object seqInt = seq_row.get_Value(idxSeqField);
                            if (seqInt != null)
                            {
                                if (seqInt != DBNull.Value)
                                {
                                    try
                                    {
                                        sequenceInt = Convert.ToInt32(seqInt);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        object seqValue = seq_row.get_Value(sequenceColumnNum);

                        if (seqValue == null)
                        {
                            sequenceValue = 0;
                        }
                        else if (seqValue.ToString() == "")
                        {
                            sequenceValue = 0;
                        }
                        else
                        {
                            try
                            {
                                sequenceValue = Convert.ToInt64(seqValue);
                            }
                            catch
                            {
                                sequenceValue = 0;
                            }
                        }

                        AAState.WriteLine("                  " + sequenceValue + " is the existing value and the interval is " + sequenceInt + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                        sequenceValue = sequenceValue + sequenceInt;

                        seq_row.set_Value(sequenceColumnNum, sequenceValue);
                        AAState.WriteLine("                  " + seq_row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                        seq_updateCursor.UpdateRow(seq_row);

                        transactions.CommitTransaction();

                        seq_updateCursor = AAState._gentab.Search(qFilter, true);
                        if (seq_row != null)
                        {
                            seqValue = seq_row.get_Value(sequenceColumnNum);

                            if (seqValue == null)
                            {
                                return(sequenceValue);
                            }
                            else if (seqValue.ToString() == "")
                            {
                                return(sequenceValue);
                            }
                            else
                            {
                                try
                                {
                                    if (sequenceValue == Convert.ToInt64(seqValue))
                                    {
                                        return(sequenceValue);
                                    }
                                    else
                                    {
                                        if (curLoop > 30)
                                        {
                                            MessageBox.Show("A unique ID could not be generated after 30 attempts: " + DateTime.Now.ToString("h:mm:ss tt"));
                                        }
                                        else
                                        {
                                            return(unversionedEdit(qFilterGen, sequenceColumnNum, idxSeqField, curLoop + 1, ref transactions));
                                        }
                                    }
                                }
                                catch
                                {
                                    return(sequenceValue);
                                }
                            }
                        }
                        return(sequenceValue);
                    }
                    else
                    {
                        AAState.WriteLine("                  No records found in Generate ID table" + ": " + DateTime.Now.ToString("h:mm:ss tt"));
                        transactions.AbortTransaction();
                        return(-1);
                    }
                }
                catch (COMException comExc)
                {
                    AAState.WriteLine("                  Error saving transaction to DB" + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                    // If an error occurs during the inserts and updates, rollback the transaction.
                    transactions.AbortTransaction();
                    return(-1);
                }
            }
        }
Пример #3
0
        private string GenerateID(string valData)
        {
            string sequenceColumnName, sequenceFixedWidth, sequencePostfix = "";
            int    sequenceColumnNum;
            int    sequenceIntColumnNum;
            int    sequencePadding;
            string formatString;

            string[]   args       = null;
            string     output     = null;
            List <int> intFldIdxs = new List <int>();

            ITable _gentab = Globals.FindTable(ArcMap.Application, "GenerateId");

            try
            {
                AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorMess_14ar") + "GENERATE_ID");
                if (_gentab != null)
                {
                    sequenceColumnName = "";
                    sequenceColumnNum  = -1;

                    sequenceFixedWidth = "";
                    sequencePadding    = 0;
                    formatString       = "";
                    bool onlyWhenNull = false;

                    // Parse arguments
                    if (valData != null)
                    {
                        args = valData.Split('|');
                    }
                    switch (args.GetLength(0))
                    {
                    case 1:      // sequenceColumnName only
                        sequenceColumnName = args[0].ToString(); break;

                    case 2:      // sequenceColumnName|sequenceFixedWidth
                        sequenceColumnName = args[0].ToString();
                        sequenceFixedWidth = args[1].ToString();
                        break;

                    case 3:      // sequenceColumnName|sequenceFixedWidth|formatString
                        sequenceColumnName = args[0].ToString();
                        sequenceFixedWidth = args[1].ToString();
                        formatString       = args[2].ToString();
                        break;

                    case 4:      // sequenceColumnName|sequenceFixedWidth|formatString
                        sequenceColumnName = args[0].ToString();
                        sequenceFixedWidth = args[1].ToString();
                        formatString       = args[2].ToString();
                        onlyWhenNull       = args[3].ToString().ToUpper() == "TRUE" ? true : false;

                        break;

                    default: break;
                    }
                    //object val = inObject.get_Value(intFldIdxs[0]);
                    bool proceed = true;
                    //if (onlyWhenNull &&
                    //    (inObject.get_Value(intFldIdxs[0]) != null &&
                    //    inObject.get_Value(intFldIdxs[0]) != DBNull.Value &&
                    //    inObject.get_Value(intFldIdxs[0]).ToString().Trim() != "")
                    //    )
                    //{
                    //    proceed = false;
                    //}
                    if (proceed)
                    {
                        //Check for requested zero padding of sequence number
                        if (sequenceFixedWidth != "")
                        {
                            int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);
                        }
                        if (sequencePadding > 25)
                        {
                            AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorChain116"));
                            AAState.WriteLine("                  WARNING: " + sequencePadding + " 0's is what you have");
                        }
                        else if (sequencePadding > 50)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorChain117"));
                        }
                        qFilter             = new QueryFilterClass();
                        qFilter.WhereClause = "SEQNAME = '" + sequenceColumnName + "'";

                        sequenceColumnNum    = AAState._gentab.Fields.FindField("SEQCOUNTER");
                        sequenceIntColumnNum = AAState._gentab.Fields.FindField("SEQINTERV");
                        ITransactions pTras = null;

                        long sequenceValue = unversionedEdit(qFilter, sequenceColumnNum, sequenceIntColumnNum, 1, ref pTras);
                        //Debug.WriteLine(sequenceValue.ToString());
                        pTras = null;

                        if (sequenceValue == -1)
                        {
                            AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorError_14a") + "GENERATE_ID: " + A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorError_14ao"));
                        }

                        else
                        {
                            if (formatString == null || formatString == "" || formatString.ToLower().IndexOf("[seq]") == -1)
                            {
                                string setVal = (sequenceValue.ToString("D" + sequencePadding) + sequencePostfix).ToString();

                                output = (sequenceValue.ToString("D" + sequencePadding) + sequencePostfix).Trim();
                            }
                            else
                            {
                                int locIdx = formatString.ToUpper().IndexOf("[SEQ]");
                                if (locIdx >= 0)
                                {
                                    formatString = formatString.Remove(locIdx, 5);
                                    formatString = formatString.Insert(locIdx, sequenceValue.ToString("D" + sequencePadding));
                                }
                                //formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));



                                output = formatString.Trim();
                            }
                        }
                    }
                }
                else
                {
                    AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorError_14a") + "GENERATE_ID: " + A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorError_14ap"));
                }
            }


            catch (Exception ex)
            {
                AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorError_14a") + "GENERATE_ID: " + ex.Message);
            }
            finally
            {
                if (qFilter != null)
                {
                    Marshal.ReleaseComObject(qFilter);
                    GC.Collect(300);
                    GC.WaitForFullGCComplete();
                    qFilter = null;
                }
                AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorMess_14as") + "GENERATE_ID");
            }
            return(output);
        }
        public void RunManualRules()
        {
            ICursor cursor = null; IFeatureCursor fCursor = null;
            bool    ran = false;

            try
            {
                //Get list of editable layers
                IEditor     editor  = _editor;
                IEditLayers eLayers = (IEditLayers)editor;
                long        lastOID = -1;
                string      lastLay = "";

                if (_editor.EditState != esriEditState.esriStateEditing)
                {
                    return;
                }

                IMap        map        = editor.Map;
                IActiveView activeView = map as IActiveView;


                IStandaloneTable stTable;

                ITableSelection tableSel;

                IStandaloneTableCollection stTableColl = (IStandaloneTableCollection)map;

                long rowCount    = stTableColl.StandaloneTableCount;
                long rowSelCount = 0;
                for (int i = 0; i < stTableColl.StandaloneTableCount; i++)
                {
                    stTable  = stTableColl.get_StandaloneTable(i);
                    tableSel = (ITableSelection)stTable;
                    if (tableSel.SelectionSet != null)
                    {
                        rowSelCount = rowSelCount + tableSel.SelectionSet.Count;
                    }
                }
                long featCount  = map.SelectionCount;
                int  totalCount = (Convert.ToInt32(rowSelCount) + Convert.ToInt32(featCount));


                if (totalCount >= 1)
                {
                    editor.StartOperation();

                    if (MessageBox.Show("Are you sure you wish to apply attribute assistant manual rules for the selected " + totalCount + " rows and features?",
                                        "Confirm", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        ran = true;


                        //bool test = false;

                        //Get list of feature layers
                        UID geoFeatureLayerID = new UIDClass();
                        geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
                        IEnumLayer        enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true);
                        IFeatureLayer     fLayer;
                        IFeatureSelection fSel;
                        ILayer            layer;
                        // Step through each geofeature layer in the map
                        enumLayer.Reset();
                        // Create an edit operation enabling undo/redo
                        try
                        {
                            while ((layer = enumLayer.Next()) != null)
                            {
                                // Verify that this is a valid, visible layer and that this layer is editable
                                fLayer = (IFeatureLayer)layer;
                                if (fLayer.Valid && eLayers.IsEditable(fLayer))//fLayer.Visible &&
                                {
                                    // Verify that this layer has selected features
                                    IFeatureClass fc = fLayer.FeatureClass;
                                    fSel = (IFeatureSelection)fLayer;

                                    if ((fc != null) && (fSel.SelectionSet.Count > 0))
                                    {
                                        // test = true;

                                        fSel.SelectionSet.Search(null, false, out cursor);
                                        fCursor = cursor as IFeatureCursor;
                                        IFeature feat;
                                        while ((feat = (IFeature)fCursor.NextFeature()) != null)
                                        {
                                            lastLay = fLayer.Name;


                                            lastOID = feat.OID;
                                            IObject pObj = feat as IObject;

                                            AAState.FeatureManual(pObj);
                                            feat.Store();
                                        }
                                        if (feat != null)
                                        {
                                            Marshal.ReleaseComObject(feat);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            editor.AbortOperation();
                            ran = false;
                            MessageBox.Show("RunManualRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source);
                            return;
                        }
                        finally
                        {
                            //try
                            //{
                            //    // Stop the edit operation
                            //    editor.StopOperation("Run Manual Rules - Features");
                            //}
                            //catch (Exception ex)
                            //{ }
                        }



                        try
                        {
                            for (int i = 0; i < stTableColl.StandaloneTableCount; i++)
                            {
                                stTable  = stTableColl.get_StandaloneTable(i);
                                tableSel = (ITableSelection)stTable;
                                if (tableSel.SelectionSet != null)
                                {
                                    if (tableSel.SelectionSet.Count > 0)
                                    {
                                        tableSel.SelectionSet.Search(null, false, out cursor);
                                        IRow pRow;
                                        while ((pRow = (IRow)cursor.NextRow()) != null)
                                        {
                                            lastOID = pRow.OID;
                                            lastLay = stTable.Name;
                                            IObject pObj = pRow as IObject;
                                            AAState.FeatureManual(pObj);
                                            pRow.Store();
                                        }
                                        if (pRow != null)
                                        {
                                            Marshal.ReleaseComObject(pRow);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            editor.AbortOperation();
                            MessageBox.Show("RunManualRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source);
                            ran = false;

                            return;
                        }
                        finally
                        {
                            //try
                            //{
                            //     Stop the edit operation
                            //    editor.StopOperation("Run Manual Rules - Features");
                            //}
                            //catch (Exception ex)
                            //{ }
                        }
                        try
                        {
                            editor.StopOperation("Run Manual Rules - Features");
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select some features or rows to run this process.");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " \n" + "RunManualRules", ex.Source);
                ran = false;

                return;
            }
            finally
            {
                if (ran)
                {
                    MessageBox.Show("Process has completed successfully");
                }

                if (cursor != null)
                {
                    Marshal.ReleaseComObject(cursor);
                }
                if (fCursor != null)
                {
                    Marshal.ReleaseComObject(fCursor);
                }
            }
        }
 public AttributeAssistantToggleCommand()
 {
     m_Editor = Globals.getEditor(ArcMap.Application);
     AAState.setIcon();
 }
        protected override void OnClick()
        {
            //AAState. = false;

            AAState.promptLastValueProperrtySet();
        }