public SelectorToolConfig()
        {
            // Open xml
            myFileFuncs = new FileFunctions();
            string strAppDLL = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string strFolder = myFileFuncs.GetDirectoryName(strAppDLL);
            // Get the XML file
            string strXMLFile = strFolder + @"\AODataSelector.xml";
            
            // Read the file.
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(strXMLFile);

            XmlNode currNode = xmlConfig.DocumentElement.FirstChild; // This gets us the DataSelector.
            xmlDataSelector = (XmlElement)currNode;

            // Get all of the detail into the object
            FileDSN = xmlDataSelector["FileDSN"].InnerText;
            ConnectionString = xmlDataSelector["ConnectionString"].InnerText;
            LogFilePath = xmlDataSelector["LogFilePath"].InnerText;
            DefaultExtractPath = xmlDataSelector["DefaultExtractPath"].InnerText;
            DefaultQueryPath = xmlDataSelector["DefaultQueryPath"].InnerText;
            DefaultFormat = xmlDataSelector["DefaultFormat"].InnerText;
            DatabaseSchema = xmlDataSelector["DatabaseSchema"].InnerText;
            IncludeWildcard = xmlDataSelector["IncludeWildcard"].InnerText;
            ExcludeWildcard = xmlDataSelector["ExcludeWildcard"].InnerText;
            RecMax = xmlDataSelector["RecMax"].InnerText;
            DefaultSetSymbology = xmlDataSelector["DefaultSetSymbology"].InnerText;
            LayerLocation = xmlDataSelector["LayerLocation"].InnerText;
            EnableSpatialPlotting = xmlDataSelector["EnableSpatialPlotting"].InnerText;
        }
 // Class constructor.
 public ArcMapFunctions(IApplication theApplication)
 {
     // Set the application for the class to work with.
     // Note the application can be got at from a command / tool by using
     // IApplication pApp = ArcMap.Application - then pass pApp as an argument.
     this.thisApplication = theApplication;
     myFileFuncs = new FileFunctions();
 }
        public SelectorToolConfig()
        {
            // Open xml
            myFileFuncs = new FileFunctions();
            string strAppDLL = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string strFolder = myFileFuncs.GetDirectoryName(strAppDLL);
            // Get the XML file path
            //string strXMLFile = strFolder + @"\AODataSelector.xml";
            string strXMLFile = Settings.Default.XMLFile;

            // If the XML file path is blank or doesn't exist
            if (String.IsNullOrEmpty(strXMLFile) || (!myFileFuncs.FileExists(strXMLFile)))
                {
                // Prompt the user for the correct file path
                string strFolder2 = GetConfigFilePath();
                if (!String.IsNullOrEmpty(strFolder2))
                    strXMLFile = strFolder2 + @"\DataSelector.xml";

                // Check the new file path exists
                if (myFileFuncs.FileExists(strXMLFile))
                {
                    Settings.Default.XMLFile = strXMLFile;
                    Settings.Default.Save();
                }
                else
                {
                    MessageBox.Show("XML File not found.");
                }
            }

            // Read the file.
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(strXMLFile);

            XmlNode currNode = xmlConfig.DocumentElement.FirstChild; // This gets us the DataSelector.
            xmlDataSelector = (XmlElement)currNode;

            // Get all of the detail into the object
            FileDSN = xmlDataSelector["FileDSN"].InnerText;
            ConnectionString = xmlDataSelector["ConnectionString"].InnerText;
            LogFilePath = xmlDataSelector["LogFilePath"].InnerText;
            DefaultExtractPath = xmlDataSelector["DefaultExtractPath"].InnerText;
            DefaultQueryPath = xmlDataSelector["DefaultQueryPath"].InnerText;
            DefaultFormat = xmlDataSelector["DefaultFormat"].InnerText;
            DatabaseSchema = xmlDataSelector["DatabaseSchema"].InnerText;
            IncludeWildcard = xmlDataSelector["IncludeWildcard"].InnerText;
            ExcludeWildcard = xmlDataSelector["ExcludeWildcard"].InnerText;
            RecMax = xmlDataSelector["RecMax"].InnerText;
            DefaultSetSymbology = xmlDataSelector["DefaultSetSymbology"].InnerText;
            LayerLocation = xmlDataSelector["LayerLocation"].InnerText;
            EnableSpatialPlotting = xmlDataSelector["EnableSpatialPlotting"].InnerText;
        }
 public frmDataSelector()
 {
     InitializeComponent();
     // Fill with the relevant.
     myConfig = new SelectorToolConfig(); // Should find the config file automatically.
     myArcSDEFuncs = new ESRISQLServerFunctions();
     myADOFuncs = new ADOSQLServerFunctions();
     myFileFuncs = new FileFunctions();
     // fill the list box with SQL tables
     string strSDE = myConfig.GetSDEName();
     string strIncludeWildcard = myConfig.GetIncludeWildcard();
     string strExcludeWildcard = myConfig.GetExcludeWildcard();
     //MessageBox.Show(strSDE);
     IWorkspace wsSQLWorkspace = myArcSDEFuncs.OpenArcSDEConnection(strSDE);
     List<string> strTableList = myArcSDEFuncs.GetTableNames(wsSQLWorkspace, strIncludeWildcard, strExcludeWildcard);
     foreach (string strItem in strTableList)
     {
         lstTables.Items.Add(strItem);
     }
     // Close the SQL connection
     wsSQLWorkspace = null;
     // However keep the Config and SQLFuncs objects alive for use later in the form.
     
 }
        public SelectorToolConfig()
        {
            // Open xml
            myFileFuncs = new FileFunctions();
            string strXMLFile = null;
            bool blFoundXML = false;
            LoadedXML = true;
            try
            {
                // Get the XML file
                strXMLFile = Settings.Default.XMLFile;

                // If the XML file path is blank or doesn't exist
                if (String.IsNullOrEmpty(strXMLFile) || (!myFileFuncs.FileExists(strXMLFile)))
                {
                    // Prompt the user for the correct file path
                    string strFolder = GetConfigFilePath();
                    if (!String.IsNullOrEmpty(strFolder))
                        strXMLFile = strFolder + @"\DataSelector.xml";
                }

                // Check the xml file path exists
                if (myFileFuncs.FileExists(strXMLFile))
                {
                    Settings.Default.XMLFile = strXMLFile;
                    Settings.Default.Save();
                    blFoundXML = true;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error " + ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
            // Read the file.
            if (blFoundXML)
            {
                FoundXML = true;
                XmlDocument xmlConfig = new XmlDocument();
                xmlConfig.Load(strXMLFile);

                XmlNode currNode = xmlConfig.DocumentElement.FirstChild; // This gets us the DataSelector.
                xmlDataSelector = (XmlElement)currNode;

                // Get all of the detail into the object
                try
                {
                    LogFilePath = xmlDataSelector["LogFilePath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LogFilePath' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    FileDSN = xmlDataSelector["FileDSN"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'FileDSN' in the XML file");
                    LoadedXML = false;
                    return;
                }

                try
                {
                    ConnectionString = xmlDataSelector["ConnectionString"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'ConnectionString' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    DefaultExtractPath = xmlDataSelector["DefaultExtractPath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultExtractPath' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    DefaultQueryPath = xmlDataSelector["DefaultQueryPath"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultQueryPath' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    DefaultFormat = xmlDataSelector["DefaultFormat"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultFormat' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    DatabaseSchema = xmlDataSelector["DatabaseSchema"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DatabaseSchema' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    IncludeWildcard = xmlDataSelector["IncludeWildcard"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'IncludeWildcard' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    ExcludeWildcard = xmlDataSelector["ExcludeWildcard"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'ExcludeWildcard' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    RecMax = xmlDataSelector["RecMax"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'RecMax' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    DefaultSetSymbology = xmlDataSelector["DefaultSetSymbology"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'DefaultSetSymbology' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    LayerLocation = xmlDataSelector["LayerLocation"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'LayerLocation' in the XML file");
                    LoadedXML = false;
                    return;
                }
                try
                {
                    EnableSpatialPlotting = xmlDataSelector["EnableSpatialPlotting"].InnerText;
                }
                catch
                {
                    MessageBox.Show("Could not locate the item 'EnableSpatialPlotting' in the XML file");
                    LoadedXML = false;
                }
            }
            else
            {
                FoundXML = false; // this has to be checked first; all other properties are empty.
            }

        }
        bool blOpenForm; // This tracks all the way through whether the form is initialising correctly.
        public frmDataSelector()
        {
            InitializeComponent();
            blOpenForm = true;
            // Fill with the relevant.
            myConfig = new SelectorToolConfig(); // Should find the config file automatically.
            if (myConfig.GetFoundXML() == false)
            {
                MessageBox.Show("XML file not found; form cannot load.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                blOpenForm = false;
            }
            else if (myConfig.GetLoadedXML() == false)
            {
                MessageBox.Show("Error loading XML File; form cannot load.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                blOpenForm = false;
            }

            myArcSDEFuncs = new ArcSDEFunctions();
            mySQLServerFuncs = new SQLServerFunctions();
            myFileFuncs = new FileFunctions();
            // fill the list box with SQL tables
            string strSDE = myConfig.GetSDEName();

            if (!myFileFuncs.FileExists(strSDE) && blOpenForm)
            {
                MessageBox.Show("ArcSDE connection file " + strSDE + " not found. Cannot load Data Selector", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                blOpenForm = false;
            }

            IWorkspace wsSQLWorkspace = null;

            if (blOpenForm)
            {
                try
                {
                    wsSQLWorkspace = myArcSDEFuncs.OpenArcSDEConnection(strSDE);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Cannot open ArcSDE connection " + strSDE + ". Error is " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    blOpenForm = false;
                }
            }
            if (blOpenForm)
            {

                string strIncludeWildcard = myConfig.GetIncludeWildcard();
                string strExcludeWildcard = myConfig.GetExcludeWildcard();
                string strDefaultFormat = myConfig.GetDefaultFormat();

                cmbOutFormat.Text = strDefaultFormat;
                
                List<string> strTableList = myArcSDEFuncs.GetTableNames(wsSQLWorkspace, strIncludeWildcard, strExcludeWildcard);
                foreach (string strItem in strTableList)
                {
                    lstTables.Items.Add(strItem);
                }
                // Close the SQL connection
                wsSQLWorkspace = null;
                // However keep the Config and SQLFuncs objects alive for use later in the form.
            }
            else // Something has gone wrong during initialisation; don't load form.
            {
                    Load += (s, e) => Close();
                    return;
            }
            
        }