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