Example #1
0
        // export selected accounts to clipboard (format: description - username - password)
        void BtnExportAccountsClick(object sender, EventArgs e)
        {
            List <DataGridViewRow> selected = SelectedAccounts();
            int total = selected.Count;             // how many selected rows there are

            if (total == 0)
            {
                MessageBox.Show("Please select the account(s) you'd like to export.", "Password Storage", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <PassStoreAccount> accounts = passStore.GetAccounts();
            string data = string.Empty;

            foreach (DataGridViewRow row in selected)
            {
                int index = row.Index;
                PassStoreAccount account     = accounts[index];
                string           description = account.GetDescription();
                string           username    = account.GetUsername();
                string           password    = account.GetPassword();
                data += description + " - " + username + " - " + password;
                if (row != selected[total - 1])
                {
                    // new line if it's not the last item
                    data += Environment.NewLine;
                }
            }
            try {
                Clipboard.SetText(data);
                MessageBox.Show(total + " account(s) have been copied to your clipboard.", "Password Storage", MessageBoxButtons.OK, MessageBoxIcon.Information);
            } catch (Exception) {
                MessageBox.Show("Failed to copy information to clipboard.", "Password Storage", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        void BtnCopyUsernameClick(object sender, EventArgs e)
        {
            List <DataGridViewRow> selected = SelectedAccounts();

            if (selected.Count != 1)
            {
                MessageBox.Show("Please select one account.", "Password Storage", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PassStoreAccount account = passStore.GetAccounts()[selected[0].Index];

            try {
                Clipboard.SetText(account.GetUsername());
            } catch (Exception) {
                MessageBox.Show("Failed to copy information to clipboard.", "Password Storage", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }