private void btOk_Click(object sender, EventArgs e) { if (this.tbMySQLHostname.Text.Trim() == "") { MessageBox.Show( "You must enter a hostname for the MySQL server!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.connection == null) { this.connection = new MySQLConnection(); } this.connection.Name = this.tbName.Text.Trim(); this.connection.MySQLHostname = this.tbMySQLHostname.Text.Trim(); this.connection.MySQLPort = (uint)this.nmMySQLPort.Value; this.connection.MySQLUsername = this.tbMySQLUsername.Text.Trim(); this.connection.MySQLPassword = (this.tbMySQLPassword.Text.Trim() != "" ? Encryption.Encrypt(this.tbMySQLPassword.Text.Trim()) : ""); this.connection.MySQLDefaultDatabase = this.tbMySQLDefaultDatabase.Text.Trim(); if (this.cbConnectOverSSH.Checked) { this.connection.SSHHostname = this.tbSSHHostname.Text.Trim(); this.connection.SSHPort = (uint)this.nmSSHPort.Value; this.connection.SSHUsername = this.tbSSHUsername.Text.Trim(); this.connection.SSHPassword = (this.tbSSHPassword.Text.Trim() != "" ? Encryption.Encrypt(this.tbSSHPassword.Text.Trim()) : ""); this.connection.LocalForwardedPort = (uint)this.nmSSHLocalForwardedPort.Value; if (this.cbAssignLocalPortDynamically.Checked) this.connection.LocalForwardedPort = 0; } else { this.connection.SSHHostname = ""; this.connection.SSHPort = 0; this.connection.SSHUsername = ""; this.connection.SSHPassword = ""; this.connection.LocalForwardedPort = 0; } this.connection.LoadTablesOnServerConnect = this.cbLoadTablesOnServerConnect.Checked; this.connection.ViewTablesOnServerConnect = this.cbViewTablesOnServerConnect.Checked; this.connection.ViewLogOnServerConnect = this.cbViewLogOnServerConnect.Checked; this.connection.AutoConnect = this.cbAutoConnect.Checked; this.connection.AutosaveQueries = this.cbAutosaveQueries.Checked; this.DialogResult = System.Windows.Forms.DialogResult.OK; }
/// <summary> /// Connect to the given server. /// </summary> private void connectToServer(MySQLConnection connection) { bool connect = true; foreach (Form form in this.MdiChildren) if (form.Text == connection.Name) connect = false; if (connect) { fmServer server = new fmServer(); server.connection = connection; server.MdiParent = this; server.WindowState = FormWindowState.Maximized; server.Show(); } }
/// <summary> /// Adds a connection to the list and save it. /// </summary> /// <param name="connection">The connection to add</param> public static void Add(MySQLConnection connection) { bool found = false; for (int i = 0; i < Connections.MySQLConnections.Count; i++) if (Connections.MySQLConnections[i].ID == connection.ID) { Connections.MySQLConnections[i] = connection; found = true; break; } if (!found) Connections.MySQLConnections.Add(connection); Connections.Save(); Connections.Load(); }
/// <summary> /// Opens the selected connection for edit. /// </summary> /// <param name="duplicate">Whether or not to duplicate the selected connection, or edit.</param> private void editSelectedConnection(bool duplicate = false) { if (this.lvConnections.SelectedItems.Count > 0) { uint id = 0; if (uint.TryParse(this.lvConnections.SelectedItems[0].Tag.ToString(), out id)) { MySQLConnection connection = Connections.MySQLConnections.SingleOrDefault(c => c.ID == id); if (connection != null) { fmConnection dialog = new fmConnection(); MySQLConnection temp = new MySQLConnection() { ID = (duplicate ? 0 : connection.ID), Name = connection.Name + (duplicate ? " (duplicate)" : ""), MySQLHostname = connection.MySQLHostname, MySQLPort = connection.MySQLPort, MySQLUsername = connection.MySQLUsername, MySQLPassword = connection.MySQLPassword, MySQLDefaultDatabase = connection.MySQLDefaultDatabase, SSHHostname = connection.SSHHostname, SSHPort = connection.SSHPort, SSHUsername = connection.SSHUsername, SSHPassword = connection.SSHPassword, LocalForwardedPort = connection.LocalForwardedPort, LoadTablesOnServerConnect = connection.LoadTablesOnServerConnect, ViewTablesOnServerConnect = connection.ViewTablesOnServerConnect, ViewLogOnServerConnect = connection.ViewLogOnServerConnect, }; dialog.connection = temp; if (dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { Connections.Add(dialog.connection); this.populateList(); } } } } }