コード例 #1
0
ファイル: PasswordManager.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Add an item.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            UI.Input input = new UI.Input();
            input.ShowDialog(this);

            // If ok then add.
            if (input.InputType == InputType.OK)
            {
                // A value must exist.
                if (!String.IsNullOrEmpty(input.InputValue))
                {
                    // Does the name already exist.
                    int count = _items.Count(u => u.name == input.InputValue);

                    // If already exists.
                    if (count > 0)
                    {
                        MessageBox.Show("The item '" + input.InputValue + "' already exists!", "Input");
                    }
                    else
                    {
                        try
                        {
                            listBoxPasswordName.Items.Add(input.InputValue);

                            // Add a new item.
                            Data.passwordManagerItem newItem = new Data.passwordManagerItem();
                            newItem.name = input.InputValue;
                            _items.Add(newItem);

                            // Assign the current item user.
                            _currentItem = newItem;

                            // If no items exist.
                            if (listBoxPasswordName.Items.Count > 0)
                            {
                                btnRemoveItem.Enabled = true;
                            }
                        }
                        catch { }
                    }
                }
            }
        }
コード例 #2
0
ファイル: PasswordManager.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Change account name
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void changeAccountNameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // If a real item has been selected.
            if (listBoxPasswordName.SelectedIndex > -1)
            {
                UI.Input input = new UI.Input();
                input.ShowDialog(this);

                // If ok then add.
                if (input.InputType == InputType.OK)
                {
                    // A value must exist.
                    if (!String.IsNullOrEmpty(input.InputValue))
                    {
                        // Does the name already exist.
                        int count = _items.Count(u => u.name == input.InputValue);

                        // If already exists.
                        if (count > 0)
                        {
                            MessageBox.Show("The item '" + input.InputValue + "' already exists!", "Input");
                        }
                        else
                        {
                            try
                            {
                                // Get the current item name.
                                // Remove the current item.
                                string itemName = listBoxPasswordName.SelectedItem.ToString();
                                listBoxPasswordName.Items.Remove(itemName);

                                // Add the new item.
                                listBoxPasswordName.Items.Add(input.InputValue);
                                _currentItem.name = input.InputValue;
                                groupBoxItem.Text = input.InputValue;
                            }
                            catch { }
                        }
                    }
                }
            }
        }