Example #1
0
        /// <summary>
        /// Handler for clicking "new entry"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Event arguments</param>
        private void NewEntry_Click(object sender, RoutedEventArgs e)
        {
            NewEntryWindow newEntryWindow = new NewEntryWindow(new object[] { categoriesList, CB_Categories.SelectedItem });

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

            if (result == false)
            {
                return;
            }

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

            long newId = -1;

            using (Entry newEntry = new Entry(-1, newEntryName, newEntryUsername, newEntryPassword, newEntryCat))
            {
                newId = SafeDatabase.AddEntryToDataBase(newEntry);
                if (newId == -1)
                {
                    return;
                }
            }
            Entry newEntry_Finalized = new Entry(newId, newEntryName, newEntryUsername, newEntryPassword, newEntryCat);

            ShowEntry(newEntry_Finalized);
            entriesList.Add(newEntry_Finalized);
        }
Example #2
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);
        }