/// <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);
            }
        }
        protected override void OnClick()
        {
            try
            {
                if (_wkspHelper.CurrentWorkspace == null)
                {
                    MessageBox.Show("You must select and open a telecom workspace before running this tool");
                    return;
                }

                DialogResult res = MessageBox.Show(null, "This test may run for a considerable time (15+ minutes) and may make modifications to the database to resolve issues. \n\nConsider taking a backup before doing this. \n\nDo you wish to proceed?", "DB Integrity Check", MessageBoxButtons.OKCancel);
                if (res != DialogResult.OK)
                {
                    return;
                }

                IFeatureClass cableFc = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName);
                if (cableFc == null)
                {
                    return;
                }

                IFeatureWorkspace fworkspace = _wkspHelper.CurrentWorkspace;
                if (fworkspace == null)
                {
                    return;
                }

                // --------------------------------------------
                // Check the integrity of the cable feature class
                // --------------------------------------------
                IRelationshipClass fiberCableToFiberRc  = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToFiberRelClassName);
                IRelationshipClass fiberCableToBufferRc = fworkspace.OpenRelationshipClass(ConfigUtil.FiberCableToBufferRelClassName);
                IFeature           feature;
                bool            badCable           = false;
                bool            badBuffers         = false;
                bool            badFibers          = false;
                bool            conversionRequired = false;
                IWorkspaceEdit2 edit        = fworkspace as IWorkspaceEdit2;
                ITransactions   transaction = edit as ITransactions;

                edit.StartEditing(true);
                edit.StartEditOperation();

                IQueryFilter qf = new QueryFilter();
                qf.AddField(ConfigUtil.NumberOfBuffersFieldName);
                qf.AddField(ConfigUtil.NumberOfFibersFieldName);
                qf.AddField(ConfigUtil.IpidFieldName);

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    IFeatureCursor fCursor = (IFeatureCursor)cableFc.Update(qf, false);
                    ICursor        pCursor = fCursor as ICursor;
                    comReleaser.ManageLifetime(fCursor);

                    int buffersFieldIdx = cableFc.FindField(ConfigUtil.NumberOfBuffersFieldName);
                    int fibersFieldIdx  = cableFc.FindField(ConfigUtil.NumberOfFibersFieldName);
                    int ipidFieldIdx    = cableFc.FindField(ConfigUtil.IpidFieldName);

                    int count = 0;
                    while ((feature = fCursor.NextFeature()) != null)
                    {
                        // Cables should have non null field values
                        if (feature.get_Value(ipidFieldIdx) == DBNull.Value)
                        {
                            badCable = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL IPID value");
                            continue;
                        }
                        if (feature.get_Value(buffersFieldIdx) == DBNull.Value)
                        {
                            badBuffers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }
                        if (feature.get_Value(fibersFieldIdx) == DBNull.Value)
                        {
                            badFibers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with NULL fiber field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }

                        int bufferCount = (int)feature.get_Value(buffersFieldIdx);
                        int fiberCount  = (int)feature.get_Value(fibersFieldIdx);

                        // Cables should have non zero values
                        if (bufferCount == 0)
                        {
                            badBuffers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 buffer field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }
                        if (fiberCount == 0)
                        {
                            badFibers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 strand field value", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }

                        // Cables should have relationships
                        int rcBufferCount = fiberCableToBufferRc.GetObjectsRelatedToObject(feature).Count;
                        if (rcBufferCount == 0)
                        {
                            badBuffers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related buffers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }
                        int rcFiberCount = fiberCableToFiberRc.GetObjectsRelatedToObject(feature).Count;
                        if (rcFiberCount == 0)
                        {
                            badFibers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with 0 related fibers", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }

                        // Buffer field count & relationships to buffers not matching
                        if (bufferCount != rcBufferCount)
                        {
                            badBuffers = true;
                            String output = "Expected: " + bufferCount + " Found: " + rcBufferCount + " Cable ID: " + feature.get_Value(ipidFieldIdx).ToString();
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Found Fiber Cable with buffer count->relationship mismatch", output);
                            continue;
                        }

                        // other checks
                        if (rcFiberCount % rcBufferCount != 0)
                        {
                            badFibers = true;
                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Fiber Cable with invalid strand count - (relationships % buffercount) is non zero", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            continue;
                        }

                        // we must be dealing with a total count (convert to per buffer tube value)
                        if (fiberCount == rcFiberCount && bufferCount > 1)
                        {
                            count++;
                            Debug.Write(count + " Strand Total to Strands Per Buffer conversion", " Cable ID: " + feature.get_Value(ipidFieldIdx).ToString() + "\n");
                            conversionRequired = true;
                            //                            _logHelper.addLogEntry(DateTime.Now.ToString(), "INTEGRITY", "Strand Total to Strands Per Buffer conversion", "Cable ID: " + feature.get_Value(ipidFieldIdx).ToString());
                            feature.set_Value(fibersFieldIdx, rcFiberCount / rcBufferCount);
                            feature.Store();
                        }
                    }
                }
                edit.StopEditOperation();
                edit.StopEditing(true);

                if (badCable)
                {
                    MessageBox.Show("Database integrity issues were detected. Found invalid Fiber Cable. Please see the log file for more details");
                }
                if (badBuffers)
                {
                    MessageBox.Show("Database integrity issues were detected. Found Fiber Cable with buffer count issues. Please see the log file for more details");
                }
                if (badFibers)
                {
                    MessageBox.Show("Database integrity issues were detected. Found Fiber Cable with strands count issues. Please see the log file for more details");
                }
                if (conversionRequired)
                {
                    MessageBox.Show("Database integrity issues were detected. Strand Total to Strands Per Buffer conversion was done.");
                }
            }
            catch (Exception e)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Integrity Check Error", e.Message);
            }

            MessageBox.Show("The results of the DB checks are listed in the tools Log window");
        }