Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
                }
            }
        }