Ejemplo n.º 1
0
        private void cboDbProfile_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox combobox = sender as ComboBox;

            if (combobox.DroppedDown)
            {
                e.DrawBackground();
            }

            e.DrawFocusRectangle();

            var items = combobox.Items;

            if (e.Index < 0)
            {
                e.Graphics.DrawString(combobox.Text, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Y);
            }
            else
            {
                if (items.Count > 0 && e.Index < items.Count)
                {
                    ConnectionProfileInfo model = items[e.Index] as ConnectionProfileInfo;
                    e.Graphics.DrawString(model.Description, e.Font, new SolidBrush(combobox.DroppedDown ? e.ForeColor : Color.Black), e.Bounds.Left, e.Bounds.Y);
                }
            }
        }
        /// <summary>
        /// Scans for APs and sets NetworkList with scan result.
        /// </summary>
        private void SetNetworkListAsync()
        {
            try
            {
                ConnectionProfileInfo info = new ConnectionProfileInfo();

                var profileList = info.GetProfileList();

                ProfileList.Clear();
                foreach (var n in profileList)
                {
                    ProfileList.Add(n.Name);
                }
            }
            catch (NotSupportedException e)
            {
                Toast.DisplayText("Not supported");
                Logger.Log(e.Message);
            }
            catch (Exception e)
            {
                Toast.DisplayText("Retrieving list failed!");
                Logger.Log(e.Message);
            }
        }
Ejemplo n.º 3
0
        public void ConfigConnection(bool requriePassword = false)
        {
            string type                   = this.cboDbType.Text;
            object selectedItem           = this.cboDbProfile.SelectedItem;
            ConnectionProfileInfo profile = selectedItem as ConnectionProfileInfo;
            string profileName            = selectedItem == null ? string.Empty : profile?.Name;

            if (string.IsNullOrEmpty(type))
            {
                MessageBox.Show("Please select database type.");
                return;
            }

            if (string.IsNullOrEmpty(profileName))
            {
                MessageBox.Show("Please select a profile.");
                return;
            }

            DatabaseType dbType = this.DatabaseType;
            frmDbConnect from   = new frmDbConnect(dbType, profileName, requriePassword);

            from.ConnectionInfo = profile?.ConnectionInfo;

            this.SetConnectionInfo(from);

            if (profileName != from.ProflieName)
            {
                this.LoadProfileNames(from.ProflieName);
            }

            if (this.cboDbProfile.SelectedItem != null)
            {
                (this.cboDbProfile.SelectedItem as ConnectionProfileInfo).ConnectionInfo = from.ConnectionInfo;
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (!this.ucDbAccountInfo.ValidateInfo())
            {
                return;
            }

            if (string.IsNullOrEmpty(this.cboDatabase.Text))
            {
                MessageBox.Show("Please select a database.");
                return;
            }

            string profileName = this.txtProfileName.Text.Trim();
            string database    = this.cboDatabase.Text;

            this.ConnectionInfo = this.GetConnectionInfo();

            if (!this.NotUseProfile)
            {
                IEnumerable <ConnectionProfileInfo> profiles = ConnectionProfileManager.GetProfiles(this.DatabaseType.ToString());

                Guid?oldAccountProfileId = null;

                if (!string.IsNullOrEmpty(profileName) && profiles.Any(item => item.Name == profileName))
                {
                    string msg = $"The profile name \"{profileName}\" has been existed";

                    if (this.isAdd)
                    {
                        DialogResult dialogResult = MessageBox.Show(msg + ", are you sure to override it.", "Confirm", MessageBoxButtons.YesNo);

                        if (dialogResult != DialogResult.Yes)
                        {
                            this.DialogResult = DialogResult.None;
                            return;
                        }
                    }
                    else if (!this.isAdd && this.ProflieName != profileName)
                    {
                        MessageBox.Show(msg + ", please edit that.");
                        return;
                    }
                    else //edit
                    {
                        oldAccountProfileId = profiles.FirstOrDefault(item => item.Name == profileName).AccountProfileId;
                    }
                }

                ConnectionProfileInfo profile = new ConnectionProfileInfo()
                {
                    ConnectionInfo = this.ConnectionInfo
                };

                if (oldAccountProfileId.HasValue)
                {
                    profile.AccountProfileId = oldAccountProfileId.Value;
                }

                profile.Name         = profileName;
                profile.DatabaseType = this.DatabaseType.ToString();

                this.ProflieName = ConnectionProfileManager.Save(profile, this.ucDbAccountInfo.RememberPassword);
            }

            this.DialogResult = DialogResult.OK;
        }