/// <summary>
        /// Checks the database to see if the splice Type field has a domain; if it does load the choices, otherwise
        /// enable free text editing on the column
        /// </summary>
        /// <param name="helper">Helper class</param>
        private void LoadTypeDropdown(FiberSpliceHelper helper)
        {
            try
            {
                ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
//                ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass = helper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName);
//                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(ftClass, ConfigUtil.FiberSpliceTableName);
                ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(fiberSpliceTable.FindField(ConfigUtil.TypeFieldName));

                ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain = typeField.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain;
                if (null != domain)
                {
                    colType.Items.Clear();
                    colType.Items.Add(string.Empty); // For DBNull

                    for (int codeIdx = 0; codeIdx < domain.CodeCount; codeIdx++)
                    {
                        colType.Items.Add(domain.get_Name(codeIdx));
                    }
                }
                else
                {
                    // Change to a text column
                    System.Windows.Forms.DataGridViewTextBoxColumn colTypeText = new DataGridViewTextBoxColumn();
                    colTypeText.HeaderText = colType.HeaderText;
                    colTypeText.Name       = colType.Name;
                    grdSplices.Columns.Remove(colType);
                    grdSplices.Columns.Add(colTypeText);
                }
            }
            catch (Exception e)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Splice Connection Window (LoadTypeDropdown): ", e.Message);
            }
        }
        /// <summary>
        /// Get the existing splice ranges between two cables at an existing closure
        /// </summary>
        /// <param name="cableA">One cable</param>
        /// <param name="cableB">Other cable</param>
        /// <param name="splice">Splice Closure</param>
        /// <returns>List of FiberSplice</returns>
        /// <remarks>Currently only checks A/B as passed, does not check the reverse B/A combination</remarks>
        public static List <FiberSplice> GetSplicedRanges(FiberCableWrapper cableA, FiberCableWrapper cableB, SpliceClosureWrapper splice)
        {
            List <FiberSplice> result      = new List <FiberSplice>();
            string             spliceWhere = string.Format("{0}='{1}' AND {2}='{3}' AND {4}='{5}'",
                                                           ConfigUtil.ACableIdFieldName,
                                                           cableA.IPID,
                                                           ConfigUtil.BCableIdFieldName,
                                                           cableB.IPID,
                                                           ConfigUtil.SpliceClosureIpidFieldName,
                                                           splice.IPID);

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = TelecomWorkspaceHelper.Instance().FindTable(ConfigUtil.FiberSpliceTableName);
//                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cableA.Feature.Class, ConfigUtil.FiberSpliceTableName);
                ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                releaser.ManageLifetime(filter);

                filter.WhereClause = spliceWhere;
                ((ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition)filter).PostfixClause = string.Format("ORDER BY {0}", ConfigUtil.AFiberNumberFieldName);

                int aUnitIdx = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName);
                int bUnitIdx = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName);
                int lossIdx  = fiberSpliceTable.FindField(ConfigUtil.LossFieldName);
                int typeIdx  = fiberSpliceTable.FindField(ConfigUtil.TypeFieldName);
                ESRI.ArcGIS.Geodatabase.IField            typeField  = fiberSpliceTable.Fields.get_Field(typeIdx);
                ESRI.ArcGIS.Geodatabase.ICodedValueDomain typeDomain = typeField.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain;

                ESRI.ArcGIS.Geodatabase.ICursor splices = fiberSpliceTable.Search(filter, true);
                releaser.ManageLifetime(splices);

                ESRI.ArcGIS.Geodatabase.IRow spliceRow = splices.NextRow();

                int    lastAUnit = -1;
                int    lastBUnit = -1;
                double?lastLoss  = null;
                object lastType  = Type.Missing;

                int aLow = -1;
                int bLow = -1;

                while (null != spliceRow)
                {
                    // These are not-null columns
                    int aUnit = (int)spliceRow.get_Value(aUnitIdx);
                    int bUnit = (int)spliceRow.get_Value(bUnitIdx);

                    object lossObj = spliceRow.get_Value(lossIdx);
                    double?loss    = null;
                    if (DBNull.Value != lossObj)
                    {
                        loss = (double)lossObj;
                    }

                    object type = spliceRow.get_Value(typeIdx);

                    if (aUnit != (lastAUnit + 1) ||
                        bUnit != (lastBUnit + 1) ||
                        loss != lastLoss ||
                        !type.Equals(lastType))
                    {
                        if (-1 != lastAUnit)
                        {
                            string typeString = string.Empty;
                            if (null != typeString)
                            {
                                if (null != typeDomain)
                                {
                                    typeString = GdbUtils.GetDomainNameForValue(typeDomain, lastType);
                                }
                                else
                                {
                                    typeString = lastType.ToString(); // DBNull.Value will return string.Empty
                                }
                            }

                            result.Add(new FiberSplice(new Range(aLow, lastAUnit), new Range(bLow, lastBUnit), lastLoss, typeString));
                        }

                        aLow = aUnit;
                        bLow = bUnit;
                    }

                    lastAUnit = aUnit;
                    lastBUnit = bUnit;
                    lastLoss  = loss;
                    lastType  = type;

                    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow);
                    spliceRow = splices.NextRow();
                }

                if (-1 < aLow)
                {
                    string typeString = string.Empty;
                    if (null != typeString)
                    {
                        if (null != typeDomain)
                        {
                            typeString = GdbUtils.GetDomainNameForValue(typeDomain, lastType);
                        }
                        else
                        {
                            typeString = lastType.ToString(); // DBNull.Value will return string.Empty
                        }
                    }

                    result.Add(new FiberSplice(new Range(aLow, lastAUnit), new Range(bLow, lastBUnit), lastLoss, typeString));
                }
            }

            return(result);
        }