Example #1
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            bool doClose = false;

            // If a database connection isn't defined, see if a database called 'Backsight' exists
            // on the local server. If not, ask the user to locate a database.

            string lastConn         = LastDatabase.ConnectionString;
            bool   lookedForDefault = false;

            if (String.IsNullOrEmpty(lastConn))
            {
                lastConn         = TableFactory.GetDefaultConnection();
                lookedForDefault = true;

                if (!String.IsNullOrEmpty(lastConn))
                {
                    LastDatabase.ConnectionString = lastConn;
                }
            }

            if (String.IsNullOrEmpty(lastConn) && lookedForDefault)
            {
                string msg = String.Empty;
                msg += ("The Environment Editor doesn't have a record of the database" + System.Environment.NewLine);
                msg += ("where information should be stored. Please pick an existing" + System.Environment.NewLine);
                msg += ("database, or click Cancel to exit.");

                if (MessageBox.Show(msg, "Database unknown", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    doClose = true;
                }
                else if (OpenDatabase() == null)
                {
                    doClose = true;
                }
            }
            else
            {
                if (OpenDatabase(lastConn) == null)
                {
                    string msg = String.Empty;
                    msg += (String.Format("Unable to access database '{0}'", lastConn) + System.Environment.NewLine);
                    msg += ("Please pick the database you want to access, or click Cancel to exit.");

                    if (MessageBox.Show(msg, "Cannot access database", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        doClose = true;
                    }
                    else
                    {
                        LastDatabase.ConnectionString = String.Empty;
                        if (OpenDatabase() == null)
                        {
                            doClose = true;
                        }
                    }
                }
            }

            if (doClose)
            {
                Close();
            }
            else
            {
                Application.Idle      += OnIdle;
                tabControl.SelectedTab = entityTypesPage;
                RefreshList();
            }
        }