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);
                }
            }
        }
        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);
        }