コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
        /// <summary>
        /// Handler for clicking "delete category"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Event arguments</param>
        public void DeleteCategoryButton_Click(object sender, RoutedEventArgs e)
        {
            // Creating new dialog
            DeleteCategoryDialog deleteCatDialog = new DeleteCategoryDialog(categoriesList);

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

            // Handlind result
            if (result == true)
            {
                Category c       = (Category)deleteCatDialog.CB_Categories.SelectedItem;
                bool     success = SafeDatabase.DeleteCategoryFromDataBase(c);
                if (success)
                {
                    categoriesList.Remove(c);
                    if (CB_Categories.SelectedItem == c)
                    {
                        CB_Categories.SelectedIndex = 0;
                    }
                    CB_Categories.Items.Remove(c);
                }
                else
                {
                    DeleteCategoryButton_Click(sender, e);
                }
            }
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
        /// <summary>
        /// Handler for clicking "new category"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Event arguments</param>
        private void AddCategoryButton_Click(object sender, RoutedEventArgs e)
        {
            // Creating new dialog
            AddCategoryDialog catDialog = new AddCategoryDialog();

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

            // Handling result
            if (result == true)
            {
                Category tempCat = new Category(-1, catDialog.Category);
                int      newId   = SafeDatabase.AddCategoryToDataBase(tempCat);
                if (newId == -1)
                {
                    return;
                }
                Category finalizedNewCategory = new Category(newId, catDialog.Category);
                categoriesList.Add(finalizedNewCategory);

                List <Category> tmpList = new List <Category>();
                tmpList.Add(finalizedNewCategory);
                AddCategoriesToCombobox(tmpList);
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
        /// <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);
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
        /// <summary>
        /// Handler for clicking "delete entry"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Event arguments</param>
        /// <param name="entry">Entry that was selected</param>
        /// <param name="sp">Stackpanel that contains the entry</param>
        private void Delete_Click(object sender, RoutedEventArgs e, Entry entry, StackPanel sp)
        {
            MessageBoxResult result = MessageBox.Show("Do you really want to delete? Deleting cannot be undone!", "Confirm delete", MessageBoxButton.OKCancel);

            switch (result)
            {
            case MessageBoxResult.OK:
                if (SafeDatabase.DeleteEntryFromDataBase(entry))
                {
                    entriesList.Remove(entry);
                    RightStack.Children.Remove(sp);
                    CheckForEmpty();
                }
                break;

            case MessageBoxResult.Cancel:
                break;
            }
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
        /// <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);
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
        /// <summary>
        /// Does initialization and diagnostics after test thread is completed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Event arguments</param>
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Result is bool)
            {
                bool testResult = (bool)e.Result;

                loadingScreen.Close();
                if (testResult)
                {
                    HandleDatabaseError(false);
                    SafeDatabase.FetchCategories(categoriesList);
                    SafeDatabase.FetchEntries(entriesList);
                    ShowEntries();
                }
                else
                {
                    HandleDatabaseError(true);
                }
                CheckForEmpty();
                AddCategoriesToCombobox(categoriesList);
                ReadApplicationProperties();
            }
        }
コード例 #7
0
ファイル: MainWindow.xaml.cs プロジェクト: Monjinn/NoteSafe
 /// <summary>
 /// Starts a new thread to run database connection test
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e">Event arguments</param>
 private void worker_DoWork(object sender, DoWorkEventArgs e)
 {
     Thread.Sleep(2000);
     e.Result = SafeDatabase.TestDatabaseConnectionAsync();
 }