示例#1
0
        private void mnuAddAccount_Click(object sender, EventArgs e)
        {
            using (frmAddAccount form = new frmAddAccount())
            {
                DialogResult result = form.ShowDialog(this);

                if (result == DialogResult.OK)
                {
                    string password    = Regex.Replace(form.Key, "\\s", "");
                    string accountName = form.AccountName;

                    settings.Accounts[accountName] = password;
                    settings.SaveAccounts();

                    InitAccount(accountName, password);
                }
            }
        }
示例#2
0
        private void mnuAccount_Click(object sender, EventArgs e)
        {
            ToolStripItem accountMenuItem = sender as ToolStripItem;
            string        oldAccountName  = accountMenuItem.Text;
            ToolStripItem timeoutMenuItem = accountMenuItem.Tag as ToolStripItem;
            string        oldPassword     = timeoutMenuItem.Tag as string;

            using (frmAddAccount form = new frmAddAccount())
            {
                form.ShowRemove(true);
                form.AccountName = oldAccountName;
                form.SetKey(oldPassword);
                form.RenderQRCode(oldAccountName, oldPassword);
                DialogResult result = form.ShowDialog(this);

                if (result == DialogResult.OK)
                {
                    settings.Accounts.Remove(oldAccountName);

                    string password    = form.Key;
                    string accountName = form.AccountName;

                    if (String.IsNullOrEmpty(accountName) == false &&
                        String.IsNullOrEmpty(password) == false)
                    {
                        settings.Accounts[accountName] = password;

                        accountMenuItem.Text = accountName;
                        timeoutMenuItem.Tag  = password;
                    }
                    else
                    {
                        var ix = contextMenu.Items.IndexOf(accountMenuItem);
                        contextMenu.Items.RemoveAt(ix + 2); // remove separator
                        contextMenu.Items.RemoveAt(ix + 1); // remove timeout password
                        contextMenu.Items.RemoveAt(ix);     // remove account name
                    }

                    settings.SaveAccounts();
                }
            }
        }