public static void ShowDatabaseSelector(MainForm frm) { DatabaseSelectorForm dbSelectorForm = new DatabaseSelectorForm(); try { _msg.Length = 0; _msg.Append("ShowDatabaseSelector started ...\r\n"); Program._messageLog.WriteLine(_msg.ToString()); DialogResult res = dbSelectorForm.ShowDialog(); _msg.Length = 0; _msg.Append("DialogResult is "); _msg.Append(res.ToString()); Program._messageLog.WriteLine(_msg.ToString()); if (res == DialogResult.OK) { } } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { if (dbSelectorForm.Visible) { dbSelectorForm.Hide(); } dbSelectorForm = null; _msg.Length = 0; _msg.Append("\r\n... ShowDatabaseSelector finished."); Program._messageLog.WriteLine(_msg.ToString()); } }
/// <summary> /// This method adds a new database to the selected project. /// </summary> private void EditDatabase(DTNDatabase database) { // If the selected project exists if (this.SelectedProject != null) { // Create instance of Database SelectorForm DatabaseSelectorForm databaseForm = new DatabaseSelectorForm(); // Set selected project databaseForm.DatabaseSelectorControl.Setup(this.SelectedProject, database); // Show Dialog databaseForm.ShowDialog(); // if the user did not cancel if (!databaseForm.DatabaseSelectorControl.UserCancelled) { // if the selected project exists and the SelectedDatabase exists on the databaseForm if ((this.HasSelectedProject) && (databaseForm.DatabaseSelectorControl.SelectedDatabase != null)) { // Get the index of this database int index = this.SelectedProject.GetDatabaseIndex(databaseForm.DatabaseSelectorControl.SelectedDatabase.DatabaseId); // if the index was found if (index >= 0) { // remove this database this.SelectedProject.Databases.RemoveAt(index); } // Add the selected database this.SelectedProject.Databases.Add(databaseForm.DatabaseSelectorControl.SelectedDatabase); // Display Database this.DisplaySelectedProject(); } } } }