using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

//using System.Data.SQLite;
using RMtrix.Class;

namespace RMtrix.Forms
{
    public partial class RMextraMainForm : Form
    {
        public string database;
        private dBHelper helper = null;
       // string database = "C:\\Users\\Tom\\Documents\\Visual Studio 2010\\Projects\\RMextra\\RMextra\\bin\\Debug\\Database\\Contact.s3db";
       // string connectionString =
       //                     @"Data Source=" + Path.GetFullPath(database); 
       // string commandText = null;
        public RMextraMainForm()
        {
            InitializeComponent();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void integrityCheckToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Database > Integrity Check";
            string commandText = "PRAGMA Integrity_Check(100);";
            helper = new dBHelper(dBFunctions.ConnectionStringSQLite2(database));
            if (helper.Load(commandText, "") == true)
            {
                dataGridViewMain.DataSource = helper.DataSet.Tables[0];
            }
        }

        private void reindexToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Database > Reindex";
            string commandText = "REINDEX; SELECT 'Completed SQLite reindex' AS Status;";
            helper = new dBHelper(dBFunctions.ConnectionStringSQLite2(database));
            if (helper.Load(commandText, "") == true)
            {
                dataGridViewMain.DataSource = helper.DataSet.Tables[0];
            }
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void databaseToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void researchToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void RMextraMainForm_Load(object sender, EventArgs e)
        {

        }

        private void dataGridViewMain_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        public void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Database > Properties";
            //toolStripStatusLabel1.Text = resultsLabel.Text;
            // string commandText = "SELECT OwnerID, Surname, Given FROM NameTable;";
            string commandText = dBQueries.dBPropertiesQuery;
            runQuery(commandText);
            // Make a new object
//            helper = new dBHelper(dBFunctions.ConnectionStringSQLite2(database));

            // Load the data
//            if (helper.Load(commandText, "") == true)
//            {
//                // Show the data in the datagridview
//                dataGridViewMain.DataSource = helper.DataSet.Tables[0];
//            }

        }
        /// <summary>
        /// Needs revision is this still required ?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridViewMain_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            // Do something on double click, except when on the header.
            if (e.RowIndex == -1)
            {
                return;
            }
            // Have aquired a valided row
            UpdateSidePannel();
        }
        private void UpdateSidePannel()
        {
            Int32 i = Convert.ToInt32(dataGridViewMain.CurrentRow.Cells[0].Value);
            DataRow dataRow = helper.DataSet.Tables[0].Rows[i - 1];
            MessageBox.Show(dataRow[1].ToString() + ' ' + dataRow[2].ToString());
        }

        private void identifyBlankNamesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Addresses > Identify Blank Names";
            string commandText = dBQueries.dBAddressBlankNameQuery ;
            runQuery(commandText);
        }

        private void addressHowUsedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Addresses > How Used";
            string commandText = dBQueries.dBAddressHowUsedQuery;
            runQuery(commandText);
        }

        private void resultsLabel_Click(object sender, EventArgs e)
        {

        }

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void sharedEventsWithMissingWitnessesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Shared events with missing witnesses";
            string commandText = dBQueries.dBEventsSharedMissingWitnesses;
            runQuery(commandText);
        }

        private void multipleSpousesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Multiple spouses";
            string commandText = dBQueries.dBPeopleMultipleSpouses;
            runQuery(commandText);
        }

        private void unusedPlacesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Places > Unused places";
            string commandText = dBQueries.dBPlacesUnusedPlaces;
            runQuery(commandText);
        }

        private void placesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Places > having Place Details";
            string commandText = dBQueries.dBPlaceshavingPlaceDetails;
            runQuery(commandText);
        }

        private void duplicateNameSearchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Duplicate Name Search";
            string commandText = dBQueries.dBPeopleDuplicateNameSearch;
            runQuery(commandText);
        }

        private void vacuumToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Database > Vacuum";
            string commandText = "VACUUM; SELECT 'Completed SQLite vacuuming of wasted space' AS Status";
            runQuery(commandText);
        }

        private void filesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Media > File Links";
            string commandText = "SELECT CASE FileExists(MediaPath || MediaFile) WHEN 0 THEN 'X' END AS Broken, MediaFile, MediaPath FROM MultiMediaTable;";
            runQuery(commandText);
        }

        public string rmdbVersion;
        public void selectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openRmFileDialog.ShowDialog() == DialogResult.OK)
            {
                database = openRmFileDialog.FileName;
                fileLabel.Text = System.IO.Path.GetFileName(database);
                this.Text = "RMtrix: " + System.IO.Path.GetFullPath(database); //Tryng to get Filename onto top of form
                menuStrip1.Enabled = true;
                
                // load fake RMNOCASE collation from unifuzz.dll
                //int sqlite3_enable_load_extension(sqlite3 *db, 1);
                resultsLabel.Text = "Loading outboard extension";
                string commandText1 = "SELECT load_extension('unifuzz.dll','auto_load') AS Result";
                runQuery(commandText1);
                MessageBox.Show("Pause to see if unifuzz.dll was loaded");
                 
                // get RM database version and store for conditional switches
                resultsLabel.Text = "RootsMagic Database Version";
                string commandText = "SELECT CAST(substr(datarec,58,4) AS TEXT) AS Version FROM ConfigTable WHERE RecType=1";
                runQuery(commandText);
                // how do I get the result out of the dataGridViewMain?
                rmdbVersion = dataGridViewMain.Rows[0].Cells[0].Value.ToString();
                toolStripStatusLabel1.Text = "RM database ver: " + rmdbVersion;
                // commandText = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='zFactTypeTable';";
               // Boolean snapshotExists = nongridQuery(commandText);
                Boolean snapshotExists = isTableExists("zFactTypeTable");
                deleteSnapshotToolStripMenuItem.Enabled = snapshotExists;
                restoreFromSnapshotToolStripMenuItem.Enabled = snapshotExists;
                viewSnapshotoutputsToolStripMenuItem.Enabled = snapshotExists;
            }

        }

        private void runQuery(string commandText)
        {
            Cursor.Current = Cursors.WaitCursor;
            helper = new dBHelper(dBFunctions.ConnectionStringSQLite2(database));
            if (helper.Load(commandText, "") == true)
            {
                dataGridViewMain.DataSource = helper.DataSet.Tables[0];
            }
            Cursor.Current = Cursors.Default;
        }

        private Boolean isTopCellNot0(string commandText)
        {
            // Cursor.Current = Cursors.WaitCursor;
            helper = new dBHelper(dBFunctions.ConnectionStringSQLite2(database));
            if (helper.Load(commandText, "") == true)
            {
                short count = (short)(long)helper.DataSet.Tables[0].Rows[0][0];
                MessageBox.Show("Got this far testing for existence of FactTypes snapshot: " + count);
                return count != 0;
            }
            return false;
            // Cursor.Current = Cursors.Default;
        }

        Boolean isTableExists(String tableName)
        {
            // Cursor.Current = Cursors.WaitCursor;
            helper = new dBHelper(dBFunctions.ConnectionStringSQLite2(database));
            string commandText = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='" + tableName + "';";
            if (helper.Load(commandText, "") == true)
            {
                short count = (short)(long)helper.DataSet.Tables[0].Rows[0][0];
               // MessageBox.Show("isTableExists " + tableName + ": " + count);
                return count > 0;
            }
            // Cursor.Current = Cursors.Default;
            return false;
        }

        private void sourceListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Sources > Source List";
            string commandText = dBQueries.dBSourcesSourceList;
            runQuery(commandText);
        }

        private void masterSourcesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Sources > Master Sources";
            string commandText = dBQueries.dBSourcesMasterSources;
            runQuery(commandText);
        }

        private void toDoListToolStripMenuItem_Click(object sender, EventArgs e)
        {

            resultsLabel.Text = "To-Do > To-Do List";
            string commandText = dBQueries.dBToDoToDoList;
            runQuery(commandText);
        }

        private void setSameDateSortOrderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Set same date sort order";
            string commandText = dBQueries.dBEventsSameDateSort;
            runQuery(commandText);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {

            
        }

        private void paragraphingStripToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Reports > Paragraphing - Strip";
            string commandText = dBQueries.dBReportsParagraphStrip;
            runQuery(commandText);
        }

        private void paragraphingAddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Reports > Paragraphing - Add";
            string commandText = dBQueries.dBReportsParagraphAdd;
            runQuery(commandText);
        }

        private void dummyFamilyAddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Reports > Dummy Family - Add";
            string commandText = dBQueries.dBReportsDummyFamilyAdd;
            runQuery(commandText);
        }

        private void dummyFamilyDeleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Reports > Dummy Family - Delete";
            string commandText = dBQueries.dBReportsDummyFamilyDelete;
            runQuery(commandText);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AboutBox().ShowDialog(this);
        }

        private void namelessPeopleDELETEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Nameless People - DELETE";
            string commandText = dBQueries.dBPeopleNamelessPeopleDelete;
            runQuery(commandText);

        }

        private void resolvedDuplicateNamesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Resolved Duplicate Names";
            string commandText = dBQueries.dBPeopleResolvedDuplicateNames;
            runQuery(commandText);

        }

        private void alternateNamesListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Alternate Names > List";
            string commandText = dBQueries.dBPeopleAltNamesList;
            runQuery(commandText);

        }

        private void alternateNamesDELETEOrphansToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Alternate Names > DELETE Orphans";
            string commandText = dBQueries.dBPeopleAltNamesDeleteOrphans;
            runQuery(commandText);
        }

        private void alternateNamesListToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Alternate Names > List";
            string commandText = dBQueries.dBPeopleAltNamesList;
            runQuery(commandText);
        }

        private void alternateNamesDELETEOrphansToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Alternate Names > DELETE Orphans";
            string commandText = dBQueries.dBPeopleAltNamesDeleteOrphans;
            runQuery(commandText);
        }

        private void listToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Places > Orphaned Place Details > List";
            string commandText = dBQueries.dBPlacesOrphanedPlaceDetailsList;
            runQuery(commandText);

        }

        private void orphanedPlaceDetailsDeleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Places > Orphaned Place Details > Delete Unused";
            string commandText = dBQueries.dBPlacesOrphanedPlaceDetailsDeleteUnused;
            runQuery(commandText);

        }

        private void mediaListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Media > Media List";
            if (rmdbVersion.StartsWith("4"))
            {
                runQuery(dBQueries.dBMediaListRM4);
            }
            else
                {
                    runQuery(dBQueries.dBMediaListRM5);
                }
        }

        private void deAnalyzeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Database > De-Analyze";
            string commandText = 
                "DROP TABLE IF EXISTS sqlite_stat1;"
                + "DROP TABLE IF EXISTS sqlite_stat2;"
                + "DROP TABLE IF EXISTS sqlite_stat3;"
                + "SELECT 'De-Analyze completed';"
                ;
            runQuery(commandText);

        }

        private void analyzeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Database > Analyze";
            string commandText = 
                "ANALYZE;"
                + "SELECT 'Analyze completed';"
                ;
            runQuery(commandText);

        }

        private void errorsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Places > Errors";
            string commandText = dBQueries.dBPlacesErrors;
            runQuery(commandText);

        }

        private void reviewCurrentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Fact Type settings > View current output settings";
            string commandText = dBQueries.dBEventsFactTypeOutputsView;
            runQuery(commandText);

        }

        private void snapshotCurrentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Fact Type settings > Snapshot current";
            string commandText = dBQueries.dBEventsFactTypeSettingsSnapshot;
            runQuery(commandText);
            deleteSnapshotToolStripMenuItem.Enabled = true;
            restoreFromSnapshotToolStripMenuItem.Enabled = true;
            viewSnapshotoutputsToolStripMenuItem.Enabled = true;
        }

        private void setAllToGEDCOMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("You should have a snapshot of the current settings if you intend to set all to GEDCOM just temporarily. Are you sure you want to set all to GEDCOM now?",
                "Confirm Action", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            if (result == DialogResult.Yes)
            {
                resultsLabel.Text = "Events > Fact Type settings > Set all to output GEDCOM";
                string commandText = dBQueries.dBEventsFactTypeSettingsAllGEDCOM;
                runQuery(commandText);
            }

        }

        private void restoreFromSnapshotToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Fact Type settings > Restore from Snapshot";
            string commandText = dBQueries.dBEventsFactTypeSettingsRestore;
            runQuery(commandText);

        }

        private void deleteSnapshotToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Fact Type settings > Delete Snapshot";
            string commandText = dBQueries.dBEventsFactTypeSettingsDeleteSnapshot;
            runQuery(commandText);
            deleteSnapshotToolStripMenuItem.Enabled = false;
            restoreFromSnapshotToolStripMenuItem.Enabled = false;
            viewSnapshotoutputsToolStripMenuItem.Enabled = false;
        }


        private void viewSnapshotoutputsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Fact Type settings > View Snapshot output settings";
            string commandText = dBQueries.dBEventsFactTypeSnapOutputsView;
            runQuery(commandText);

        }

        private void lifeLinesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Reports > LifeLines";
            string commandText = dBQueries.dBReportsLifeLines;
            runQuery(commandText);

        }

        private void sharableEventsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Sharable events";
            string commandText = dBQueries.dBEventsSharableFacts;
            runQuery(commandText);

        }

        private void invisibleNameCitationsListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Sources > Invisible Name Citations - List";
            string commandText = dBQueries.dBSourceInvisibleNameCitationsList;
            runQuery(commandText);
        }

        private void invisibleNameCitationsConvertToPersonalCitationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Sources > Invisible Name Citations - Convert to Personal citations";
            string commandText = dBQueries.dBSourceInvisibleNameCitationsConvert;
            commandText = commandText + "SELECT 'Conversion completed' AS [Status];";
            runQuery(commandText);

        }

        private void peopleDeleteManyColorREDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > DELETE Many > Color RED";
            string commandText = dBQueries.dBPeopleDeleteManyColorRED;
            commandText = commandText + "SELECT 'Deletions completed. Follow with Tools > Delete Phantoms.' AS [Status];";
            runQuery(commandText);

        }

        private void peopleDeleteManyGroupNamedDELETEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > DELETE Many > Groups named #DELETE#...";
            string commandText = dBQueries.dBPeopleDeleteManyGroupNamedDELETE;
            commandText = commandText + "SELECT 'Deletions completed. Follow with Tools > Delete Phantoms.' AS [Status];";
            runQuery(commandText);

        }

        private void toolsDeletePhantomsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Tools > Delete Phantoms";
            string commandText = dBQueries.dBToolsDeletePhantoms;
            commandText = commandText + "SELECT 'Deletions completed. Follow with RM Rebuild Indexes and Compact Database!' AS [Status];";
            runQuery(commandText);

        }

        private void mediaDeleteUnusedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Media > Delete Unused";
            string commandText = dBQueries.dBMediaDeleteUnused;
            commandText = commandText + "SELECT 'Deletions completed. Follow with RM Rebuild Indexes and Compact Database!' AS [Status];";
            runQuery(commandText);

        }

        private void placesDeleteUnusedToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Places > DELETE Unused";
            string commandText = dBQueries.dBPlacesDeleteUnused;
            commandText = commandText + "SELECT 'Deletions completed. Follow with RM Rebuild Indexes and Compact Database!' AS [Status];";
            runQuery(commandText);

        }

        private void eventsBirthYearMismatchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Birth Year Mismatch List";
            string commandText = dBQueries.dBEventsBirthYearMismatchList;
            runQuery(commandText);

        }

        private void eventsDeathYearMismatchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Death Year Mismatch List";
            string commandText = dBQueries.dBEventsDeathYearMismatchList;
            runQuery(commandText);

        }

        private void updateBirthDeathYearsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > UPDATE Birth and Death Years";
            string commandText = dBQueries.dBUpdateBirthDeathYears;
            commandText = commandText + "SELECT 'Updates completed. Follow with RM Rebuild Indexes!' AS [Status];";
            runQuery(commandText);

        }

        private void namesADDMarriedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Alternate Names > ADD Married";
            string commandText = dBQueries.dBPeopleNamesADDMarried;
            commandText = commandText + "SELECT 'Additions completed. Follow with RM Rebuild Indexes!' AS [Status];";
            runQuery(commandText);

        }

        private void altNamesSETTypeMarriedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "People > Alternate Names > SET Type = Married";
            string commandText = dBQueries.dBPeopleNamesSETMarried;
            commandText = commandText + "SELECT 'Updates completed. Follow with RM Rebuild Indexes!' AS [Status];";
            runQuery(commandText);

        }

        private void rESETMediaTypeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Media > RESET Media Type";
            string commandText = dBQueries.dBMediaResetType;
            commandText = commandText + "SELECT 'Updates completed.' AS [Status];";
            runQuery(commandText);

        }

        private void mediaTagsCopyFromSharedEventsToPersonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Media > Media Tags > COPY from Shared Events to Personals";
            string commandText = dBQueries.dBMediaTagsCopyShared2Personal;
            commandText = commandText + "SELECT 'Copying completed.' AS [Status];";
            runQuery(commandText);

        }

        private void mediaTagsDELETEPersonalsDuplicatingEventsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Media > Media Tags > DELETE Personals duplicating Events";
            string commandText = dBQueries.dBMediaTagsDeletePersonalsDuplicatingEvents;
            commandText = commandText + "SELECT 'Deletions completed.' AS [Status];";
            runQuery(commandText);

        }

        private void eventsConvertSplitSharedToIndividualToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Convert Shared to Individual > SPLIT Shared Events to Individuals";
            string commandText = dBQueries.dBEventsSplitShared2Individual;
            commandText = commandText + "SELECT 'Splitting shared events completed.' AS [Status];";
            runQuery(commandText);

        }

        private void eventsConvertSharedUNSHAREToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Convert Shared to Individual > UNSHARE";
            string commandText = dBQueries.dBEventsUNSHARE;
            commandText = commandText + "SELECT 'UNSHARE of shared events completed.' AS [Status];";
            runQuery(commandText);

        }

        private void eventsConvertSharedUNDOSplitsAndRESHAREToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Convert Shared to Individual > UNDO Splits and RESHARE";
            string commandText = dBQueries.dBEventsUNDOsplitsRESHARE;
            commandText = commandText + "SELECT 'UNDO Splits and RESHARE events completed.' AS [Status];";
            runQuery(commandText);

        }

        private void eventsConvertSharedHIDETracksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "Events > Convert Shared to Individual > HIDE Tracks";
            string commandText = dBQueries.dBEventsConvertSharedHideTracks;
            commandText = commandText + "SELECT 'HIDE Tracks completed. No going back!' AS [Status];";
            runQuery(commandText);

        }

        private void webTagsMAKEFromCitationCommentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "WebTags > MAKE WebTags from citation Comments";
            string commandText = dBQueries.dBWebTagsMAKEfromcitationComments;
            commandText = commandText + "SELECT 'MAKE WebTags completed.' AS [Status];";
            runQuery(commandText);

        }

        private void webTagsCopyFromCitationsToPersonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "WebTags > COPY from Citations to Person";
            string commandText = dBQueries.dBWebTagsCOPYcitationtoPerson;
            commandText = commandText + "SELECT 'COPY WebTags completed.' AS [Status];";
            runQuery(commandText);

        }

        private void webTagsDELETEDuplicatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            resultsLabel.Text = "WebTags > DELETE Duplicates";
            string commandText = dBQueries.dBWebTagsDELETEduplicates;
            commandText = commandText + "SELECT 'Duplicate WebTags deleted.' AS [Status];";
            runQuery(commandText);

        }



    }
}
