private void sortNotes(bool isDescending, ListBox listBox) { List <Note> notes; try { ListBoxNotes.Items.Clear(); switch (comboBoxSort.SelectedIndex) { case 0: notes = DbNoteHelper.getSortNotesDate(!isDescending); break; case 1: notes = DbNoteHelper.getSortNotesTitle(!isDescending); break; case 2: notes = DbNoteHelper.getSortNotesPriority(!isDescending); break; default: notes = DbNoteHelper.getSortNotesDate(true); break; } foreach (var note in notes) { listBox.Items.Add(note.Note_title); } } catch (Exception) { return; } }
private void ButtonAddNote_Click(object sender, RoutedEventArgs e) { if (textBoxNoteTitle.Text == "" || !NotePriorityUpDown.Value.HasValue) { MessageBox.Show("Ошибка при добавлении заметки.\nЗаметка должна иметь заголовок.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } using (DBContext db = new DBContext()) { if (noteId == null) { Note note = new Note(); note.Note_title = textBoxNoteTitle.Text; note.Note_text = textBoxNoteText.Text; note.Note_tag = textBoxNoteTag.Text; note.Note_priority = (int)NotePriorityUpDown.Value; try { db.Notes.Add(note); db.SaveChanges(); sortNotes((bool)IsDescending.IsChecked, ListBoxNotes); } catch (Exception) { MessageBox.Show("Произошла ошибка при добавлении. \nОбратите внимание на то, что заголовки заметок не могут быть одинаковыми.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (noteId != null) { DbNoteHelper.AlterNote(textBoxNoteTitle.Text, textBoxNoteTag.Text, (int)NotePriorityUpDown.Value, textBoxNoteText.Text, noteId); sortNotes((bool)IsDescending.IsChecked, ListBoxNotes); } } }
private void Image_PreviewMouseLeftButtonDown_3(object sender, MouseButtonEventArgs e) { ListBoxNotes.SelectedIndex = ListBoxNotes.SelectedIndex - 1; DbNoteHelper.DeleteNote(noteId); sortNotes((bool)IsDescending.IsChecked, ListBoxNotes); SetNotesTeamplate(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { ListBoxNotes.Items.Clear(); var notes = DbNoteHelper.getSortNotesDate(false); foreach (var note in notes) { ListBoxNotes.Items.Add(note.Note_title); } }