Exemple #1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            var dialog = new AccountView();
            var result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var config = new ClientConfig();

            config.ServerId = Convert.ToInt32(dialog.ServerId);
            config.Username = dialog.Username;
            config.Password = dialog.Password;

            AddConfig(config);
        }
Exemple #2
0
        private void changeButton_Click(object sender, EventArgs e)
        {
            var selectedIndices = FindSelectedIndices();

            if (selectedIndices.Count == 0)
            {
                return;
            }

            const string MultipleValues = "<Nhiều giá trị>";
            var          serverIds      = new HashSet <int>();
            var          usernames      = new HashSet <string>();
            var          passwords      = new HashSet <string>();

            foreach (var index in selectedIndices)
            {
                var config = ConfigManager.Instance.Configs[index];
                serverIds.Add(config.ServerId);
                usernames.Add(config.Username);
                passwords.Add(config.Password);
            }

            var serverId = (serverIds.Count == 1 ? serverIds.First().ToString() : MultipleValues);
            var username = (usernames.Count == 1 ? usernames.First() : MultipleValues);
            var password = (passwords.Count == 1 ? passwords.First() : MultipleValues);

            var dialog = new AccountView();

            dialog.ServerId = serverId;
            dialog.Username = username;
            dialog.Password = password;
            var result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var newServerId = dialog.ServerId;
            var newUsername = dialog.Username;
            var newPassword = dialog.Password;

            bool changed = false;

            foreach (var index in selectedIndices)
            {
                var config       = ConfigManager.Instance.Configs[index];
                var clientConfig = ClientManager.Instance.Clients[index].Config;
                if (!newServerId.Equals(serverId))
                {
                    config.ServerId = clientConfig.ServerId = Convert.ToInt32(newServerId);
                    changed         = true;
                }
                if (!newUsername.Equals(username))
                {
                    config.Username = clientConfig.Username = newUsername;
                    changed         = true;
                }
                if (!newPassword.Equals(password))
                {
                    config.Password = clientConfig.Password = newPassword;
                    changed         = true;
                }
            }
            if (changed)
            {
                ConfigManager.Instance.Flush();
            }
        }