Ejemplo n.º 1
0
        /// <summary>
        /// event is fired when the 'EditNoteButton' is clicked.
        /// </summary>
        private void EditNoteButton_Click(object sender, EventArgs e)
        {
            // if the value for HasSelectedNote is true
            if (HasSelectedNote)
            {
                // Create a new instance of a 'NoteEditorForm' object.
                NoteEditorForm noteEditorForm = new NoteEditorForm();

                // Create a new note
                noteEditorForm.Note = this.SelectedNote;

                // show the form to the user
                noteEditorForm.ShowDialog();

                // if the user 'Saved'
                if (!noteEditorForm.UserCancelled)
                {
                    // Save this note to our Xml File
                    if (noteEditorForm.HasNote)
                    {
                        // update an existing note

                        // first we must find the note
                        Note note = this.Notes.FirstOrDefault(x => x.Id == noteEditorForm.Note.Id);

                        // If the note object exists
                        if (NullHelper.Exists(note))
                        {
                            // Find the Id of this note
                            int noteIndex = FindNoteIndex(note.Id);

                            // if the noteIndex was found
                            if (noteIndex >= 0)
                            {
                                // Update the note
                                Notes[noteIndex] = noteEditorForm.Note;
                            }
                        }

                        // Save the Notes
                        Save();

                        // Display the current notes
                        DisplayNotes();

                        // Erase any selections
                        SelectedNoteControl = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// event is fired when the 'AddNoteButton' is clicked.
        /// </summary>
        private void AddNoteButton_Click(object sender, EventArgs e)
        {
            // Create a new instance of a 'NoteEditorForm' object.
            NoteEditorForm noteEditorForm = new NoteEditorForm();

            // Create a new instance of a 'Note' object.
            Note note = new Note();

            // Set the NoteId
            note.Id = this.Notes.Max(x => x.Id) + 1;

            // Set the note so the Id is displayed
            noteEditorForm.Note = note;

            // show the form to the user
            noteEditorForm.ShowDialog();

            // if the user 'Saved'
            if (!noteEditorForm.UserCancelled)
            {
                // Save this note to our Xml File
                if (noteEditorForm.HasNote)
                {
                    // get the updated note
                    note = noteEditorForm.Note;

                    // Add this note
                    this.Notes.Add(noteEditorForm.Note);

                    // Save the Notes
                    Save();

                    // Display the current notes
                    DisplayNotes();
                }
            }
        }