示例#1
0
        /// <summary>
        /// Handles editing of the entry. Clears old entry and adds new controls and handlers
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        /// <param name="entry">Entry to be edited</param>
        /// <param name="sp">Stackpanel for entry label</param>
        /// <param name="dp">Dockpanel for entry controls</param>
        private void Edit_Click(object sender, RoutedEventArgs e, Entry entry, StackPanel sp)
        {
            NewEntryWindow editEntryWindow = new NewEntryWindow(new object[] { categoriesList, CB_Categories.SelectedItem, entry });

            editEntryWindow.Owner = this;
            bool?result = editEntryWindow.ShowDialog();

            if (result == false)
            {
                return;
            }

            String   newEntryName     = editEntryWindow.EntryName;
            String   newEntryPassword = editEntryWindow.EntryPassword;
            String   newEntryUsername = editEntryWindow.EntryUsername;
            Category newEntryCat      = editEntryWindow.EntryCategory;

            Entry editedEntry = new Entry(entry.ID, newEntryName, newEntryUsername, newEntryPassword, newEntryCat);

            entry.Dispose();
            SafeDatabase.UpdateEntryInDataBase(editedEntry);

            // Updating the lists
            entriesList.Remove(entry);
            entriesList.Add(editedEntry);

            // Clearing all controls for old entry
            sp.Children.Clear();

            if (CB_Categories.SelectedItem is Category)
            {
                Category c = (Category)CB_Categories.SelectedItem;
                if (c.ID != editedEntry.Category.ID)
                {
                    RightStack.Children.Remove(sp);
                    CheckForEmpty();
                    return;
                }
            }

            GenerateEntryControls(editedEntry, sp);
        }