private void GetConnectionInfoByProfile(bool isSource) { DatabaseType dbType = this.GetDatabaseType(isSource ? this.cboSourceDB.Text : this.cboTargetDB.Text); string profileName = ((isSource ? this.cboSourceProfile : this.cboTargetProfile).SelectedItem as ConnectionInfoProfile)?.Name; ConnectionInfo connectionInfo = ConnectionInfoProfileManager.GetConnectionInfo(dbType, profileName); if (connectionInfo != null) { if (isSource) { this.sourceDbConnectionInfo = connectionInfo; } else { this.targetDbConnectionInfo = connectionInfo; } } if (!isSource) { if (dbType == DatabaseType.SqlServer) { if (string.IsNullOrEmpty(this.txtTargetDbOwner.Text.Trim())) { this.txtTargetDbOwner.Text = "dbo"; } } else { this.txtTargetDbOwner.Text = ""; } } }
private void btnConfirm_Click(object sender, EventArgs e) { string profileName = this.txtProfileName.Text.Trim(); this.ConnectionInfo = this.GetConnectionInfo(); if (this.isAdd) { List <ConnectionInfoProfile> profiles = ConnectionInfoProfileManager.GetProfiles(this.DatabaseType); if (!string.IsNullOrEmpty(profileName) && profiles.Any(item => item.Name == profileName)) { DialogResult dialogResult = MessageBox.Show("The profile name is existed, are you sure to override it.", "Confirm", MessageBoxButtons.YesNo); if (dialogResult != DialogResult.Yes) { this.DialogResult = DialogResult.None; return; } } } ConnectionInfoProfile profile = new ConnectionInfoProfile() { Name = profileName, DbType = this.DatabaseType, ConnectionInfo = this.ConnectionInfo, RememberPassword = this.chkRememberPassword.Checked }; this.ProflieName = ConnectionInfoProfileManager.Save(profile); this.DialogResult = DialogResult.OK; }
private void RemoveProfile(bool isSource) { DialogResult dialogResult = MessageBox.Show("Are you sure to delete the profile?", "Confirm", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { ComboBox dbTypeCombobox = isSource ? this.cboSourceDB : this.cboTargetDB; ComboBox profileCombobox = isSource ? this.cboSourceProfile : this.cboTargetProfile; DatabaseType dbType = this.GetDatabaseType(dbTypeCombobox.Text); string profileName = (profileCombobox.SelectedItem as ConnectionInfoProfile).Name; if (ConnectionInfoProfileManager.Remove(dbType, profileName)) { this.LoadProfileNames(isSource); } } }
private void LoadProfileNames(bool isSource, string defaultValue = null) { ComboBox dbTypeControl = isSource ? this.cboSourceDB : this.cboTargetDB; ComboBox profileControl = isSource ? this.cboSourceProfile : this.cboTargetProfile; string type = dbTypeControl.Text; if (type != "") { DatabaseType dbType = this.GetDatabaseType(type); List <ConnectionInfoProfile> profiles = ConnectionInfoProfileManager.GetProfiles(dbType); List <string> names = profiles.Select(item => item.Name).ToList(); profileControl.DataSource = profiles; profileControl.DisplayMember = nameof(ConnectionInfoProfile.Description); profileControl.ValueMember = nameof(ConnectionInfoProfile.Name); if (string.IsNullOrEmpty(defaultValue)) { if (profiles.Count > 0) { profileControl.SelectedIndex = 0; } } else { if (names.Contains(defaultValue)) { profileControl.Text = profiles.FirstOrDefault(item => item.Name == defaultValue)?.Description; } } bool selected = profileControl.Text.Length > 0; if (isSource) { this.btnConfigSource.Visible = this.btnRemoveSource.Visible = selected; } else { this.btnConfigTarget.Visible = this.btnRemoveTarget.Visible = selected; } } }
private void LoadProfile() { ConnectionInfo connectionInfo = ConnectionInfoProfileManager.GetConnectionInfo(this.DatabaseType, this.ProflieName); this.txtServerName.Text = connectionInfo.Server; this.txtPort.Text = connectionInfo.Port; this.cboAuthentication.Text = connectionInfo.IntegratedSecurity ? AuthenticationType.Windows.ToString() : AuthenticationType.Password.ToString(); this.txtUserId.Text = connectionInfo.UserId; this.txtPassword.Text = connectionInfo.Password; this.cboDatabase.Text = connectionInfo.Database; if (connectionInfo.IntegratedSecurity) { this.cboAuthentication.Text = AuthenticationType.Windows.ToString(); } else { if (!string.IsNullOrEmpty(connectionInfo.Password)) { this.chkRememberPassword.Checked = true; } } }