public int Update(ToDoNote toDoNoteForUpdate) { int index; for (index = Collections.Count - 1; index >= 0; --index) if (Collections[index].ToDoNoteId == toDoNoteForUpdate.ToDoNoteId) { Collections[index] = toDoNoteForUpdate; break; } return index; }
private void btnSaveNote_Click(object sender, EventArgs e) { // Confirm there is some text in the text box. if (txtNoteTitle.Text.Length > 0) { ShowProgressIndicator("Saving note..."); // Create a new to-do item. ToDoNote newToDoNote = new ToDoNote { NoteTitle = txtNoteTitle.Text, Category = (ToDoCategory)categoriesListPicker.SelectedItem }; // Add the item to the ViewModel. App.ViewModel.AddToDoNote(newToDoNote); HideProgressIndicator(); // Return to the main page. if (NavigationService.CanGoBack) { NavigationService.GoBack(); } } else MessageBox.Show("The title of note can not be empty."); }
//Update a to-do note from the database and collections. public void UpdateToDoNote(ToDoNote toDoForUpdate) { // Update the to-do note from the "all" observable collection. AllToDoNotes.Update(toDoForUpdate); // Update the to-do note from the appropriate category. foreach (ToDoNoteCollection collection in NoteCollectionList) if (collection.CategoryId.Equals(toDoForUpdate.Category.Id)) { collection.Update(toDoForUpdate); break; } // Save changes to the database toDoDB.SubmitChanges(); ReLoadData(); }
// Remove a to-do note from the database and collections. public void DeleteToDoNote(ToDoNote toDoForDelete) { // Remove the to-do note from the "all" observable collection. AllToDoNotes.Collections.Remove(toDoForDelete); // Remove the to-do note from the data context. toDoDB.Notes.DeleteOnSubmit(toDoForDelete); // Remove the to-do note from the appropriate category. foreach (ToDoNoteCollection collection in NoteCollectionList) if (collection.CategoryId.Equals(toDoForDelete.Category.Id)) { collection.Collections.Remove(toDoForDelete); break; } // Save changes to the database. toDoDB.SubmitChanges(); ReLoadData(); }
// Add a to-do note to the database and collections. public void AddToDoNote(ToDoNote newToDoNote) { // Add a to-do note to the data context. toDoDB.Notes.InsertOnSubmit(newToDoNote); // Save changes to the database. toDoDB.SubmitChanges(); // Add a to-do note to the "all" observable collection. AllToDoNotes.Collections.Add(newToDoNote); // Add a to-do note to the appropriate filtered collection. foreach (ToDoNoteCollection collection in NoteCollectionList) if (collection.CategoryId.Equals(newToDoNote.Category.Id)) { collection.Collections.Add(newToDoNote); break; } ReLoadData(); }
protected void LoadNote(ToDoNote note) { ShowProgressIndicator("Loading note's detail..."); if (note != null) { //title noteTitle.Text = note.NoteTitle; txtTitle.Text = note.NoteTitle; // description if (note.NoteDescription != null) txtDescription.Text = note.NoteDescription; else txtDescription.Text = ""; //tags if (note.NoteTags != null) { listTags.Visibility = System.Windows.Visibility.Visible; txtTags.Visibility = System.Windows.Visibility.Collapsed; listTags.Items.Clear(); txtTags.Text = note.NoteTags; foreach (string tag in note.NoteTags.Split(new char[] { ' ' })) { Button button = new Button(); button.Click += button_Click; button.Content = tag; button.Background = new SolidColorBrush(ColorConverter.MyColorTemplate); button.Height = 72; button.Width = 50 + tag.Length * 14; listTags.Items.Add(button); } } else { listTags.Visibility = System.Windows.Visibility.Collapsed; txtTags.Visibility = System.Windows.Visibility.Visible; txtTags.Text = ""; listTags.Items.Clear(); } //category App.ViewModel.CategorySelected = note.Category; //location mylocation = LocationXmlParser.Parse(note.NoteLocation); if (mylocation != null) txtLocation.Text = mylocation.Address; else txtLocation.Text = ""; // photos if (note.NotePhotos == null || note.NotePhotos.Length <= 0) ; else { photos = new ObservableCollection<XMLParser.MediaElement>(MediaXmlParser.Parse(note.NotePhotos)); } listphoto.ItemsSource = photos; //voices if (note.NoteVoices == null || note.NoteVoices.Length <= 0) ; else { voicespath = new ObservableCollection<XMLParser.MediaElement>(MediaXmlParser.Parse(note.NoteVoices)); } listvoice.ItemsSource = voicespath; //reminder checkboxtime.IsChecked = note.IsTimeReminder; checkboxdis.IsChecked = note.IsDistanceReminder; if (note.TimeReminder != null) { datepicker.Value = DateTime.Parse(note.TimeReminder.ToString()); timepicker.Value = DateTime.Parse(note.TimeReminder.ToString()); } txtDistance.Text = note.NoteDistanceReminder.ToString(); } HideProgressIndicator(); }
// Called during a remove operation private void detach_ToDo(ToDoNote toDo) { NotifyPropertyChanging("ToDoNote"); toDo.Category = null; }
// Called during an add operation private void attach_ToDo(ToDoNote toDo) { NotifyPropertyChanging("ToDoNote"); toDo.Category = this; }