Пример #1
0
    internal override void OnStarting(BaseWizardForm wizard)
    {
      _wiz = (BaseWizardForm)wizard;

      ConnectionString = _wiz.ConnectionString;
      if (!string.IsNullOrEmpty(_wiz.ConnectionString))
      {
        var cnn = new MySqlConnection(_wiz.ConnectionString);
        try
        {
          cnn.Open();
        }
        catch (Exception)
        {
          var infoProps = InfoDialogProperties.GetInfoDialogProperties(InfoDialog.InfoType.Error, CommandAreaProperties.ButtonsLayoutType.Generic2Buttons, Resources.ErrorTitle, Resources.ErrorOnConnection);
          infoProps.CommandAreaProperties.Button1Text = "Retry";
          infoProps.CommandAreaProperties.Button1DialogResult = DialogResult.Retry;
          infoProps.CommandAreaProperties.Button2Text = "Cancel";
          infoProps.CommandAreaProperties.Button2DialogResult = DialogResult.Cancel;
          var infoResult = InfoDialog.ShowDialog(infoProps);
          if (infoResult.DialogResult == DialogResult.Cancel)
          {
            listTables.Enabled = false;
          }
        }

        FillTables(_wiz.ConnectionString);
      }
    }
Пример #2
0
        /// <summary>
        /// Event delegate method fired when the <see cref="ConnectDialog"/> is being closed.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void ConnectDialogNew_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.Cancel)
            {
                return;
            }

            if (GetConnection(true, true) == null)
            {
                e.Cancel = true;
                return;
            }

            if (!AddToServerExplorerCheckBox.Checked)
            {
                return;
            }

            // Check if the Server Explorer connection name is not empty, and if so prompt the user to use a suggested connection name
            var validateConnectionName       = true;
            var serverExplorerConnectionName = ConnectionNameTextBox.Text.Trim();

            if (string.IsNullOrEmpty(serverExplorerConnectionName))
            {
                serverExplorerConnectionName = GetProposedServerExplorerConnectionName(null);
                var infoResult = InfoDialog.ShowDialog(InfoDialogProperties.GetYesNoDialogProperties(InfoDialog.InfoType.Warning,
                                                                                                     Resources.ConnectDialog_EmptyConnectionNameTitle,
                                                                                                     Resources.ConnectDialog_EmptyConnectionNameDetail,
                                                                                                     string.Format(Resources.ConnectDialog_EmptyConnectionNameSubDetail, serverExplorerConnectionName)));
                if (infoResult.DialogResult == DialogResult.No)
                {
                    e.Cancel = true;
                    return;
                }

                validateConnectionName = false;
            }

            // Validate if there is an existing connection in the Server Explorer with the same name, if so prompt the user for an action.
            IVsDataExplorerConnection existingConnection = null;

            if (validateConnectionName)
            {
                existingConnection = MySqlDataProviderPackage.Instance.GetServerExplorerConnection(serverExplorerConnectionName);
                if (existingConnection != null)
                {
                    var newConnectionName = GetProposedServerExplorerConnectionName(serverExplorerConnectionName);
                    var infoProperties    = InfoDialogProperties.GetInfoDialogProperties(InfoDialog.InfoType.Warning,
                                                                                         CommandAreaProperties.ButtonsLayoutType.Generic3Buttons,
                                                                                         Resources.ConnectDialog_ConnectionAlreadyExistsTitle,
                                                                                         string.Format(Resources.ConnectDialog_ConnectionAlreadyExistsDetail, serverExplorerConnectionName),
                                                                                         string.Format(Resources.ConnectDialog_ConnectionAlreadyExistsSubDetail, newConnectionName),
                                                                                         string.Format(Resources.ConnectDialog_ConnectionAlreadyExistsMoreInfo, newConnectionName, serverExplorerConnectionName));
                    infoProperties.FitTextStrategy  = InfoDialog.FitTextsAction.IncreaseDialogWidth;
                    infoProperties.WordWrapMoreInfo = false;
                    infoProperties.CommandAreaProperties.Button1Text         = Resources.ConnectDialog_Rename;
                    infoProperties.CommandAreaProperties.Button1DialogResult = DialogResult.Yes;
                    infoProperties.CommandAreaProperties.Button2Text         = Resources.ConnectDialog_Replace;
                    infoProperties.CommandAreaProperties.Button1DialogResult = DialogResult.No;
                    infoProperties.CommandAreaProperties.Button3Text         = Resources.ConnectDialog_Cancel;
                    infoProperties.CommandAreaProperties.Button3DialogResult = DialogResult.Cancel;
                    var infoResult = InfoDialog.ShowDialog(infoProperties);
                    switch (infoResult.DialogResult)
                    {
                    case DialogResult.Yes:
                        // Set values needed to Rename the connection.
                        serverExplorerConnectionName = newConnectionName;
                        existingConnection           = null;
                        break;

                    case DialogResult.No:
                        // Do nothing, the serverExplorerConnectionName and existingConnection variables have the values needed to Replace.
                        break;

                    case DialogResult.Cancel:
                        // Abort the closing of the dialog.
                        e.Cancel = true;
                        return;
                    }
                }
            }

            // Create the Server Explorer connection
            MySqlDataProviderPackage.Instance.AddServerExplorerConnection(serverExplorerConnectionName, ConnectionString, existingConnection);
        }