Ejemplo n.º 1
0
        private void TaskNoteAdd()
        {
            try {

                // Edit the selected task in a Task form, showing notes.
                Task edit_task = (Task)treeTasks.GetSelectedObject();
                TaskForm form = new TaskForm(Lang, Settings, edit_task, TaskForm.StartingTab.Notes);
                form.AddNewNoteAccordionItem(); // Add a new note
                form.giveFocusToNewNote = true;
                DialogResult res = form.ShowDialog();

                // If the task has been modified, save it to the DB.
                if (res != DialogResult.OK) return;
                edit_task.Update(); // Save task in DB

                // Save pending notes
                ArrayList current_notes = edit_task.GetNotes();
                ArrayList pending_notes = edit_task.GetUnsavedNotes();
                foreach (Note note in current_notes) { bool d = true; foreach (Note p in pending_notes) if (note.Id == p.Id) d = false; if (d) Todomoo.RemoveNote(note); }
                foreach (Note note in pending_notes) { note.TaskId = edit_task.Id; note.Save(); }
                if ((pending_notes.Count > 0) || (current_notes.Count > 0)) { edit_task.Reload(); edit_task.ClearUnsavedNotes(); }

                // If the task is in the selected category, update the tree
                if (SelectedCategory != null) if (edit_task.CategoryId != SelectedCategory.Id) return;
                if (flatView) treeTasks.RefreshObject(edit_task);
                else treeTasks.RefreshObject(Todomoo.GetRoot(edit_task)); // Refresh root task (whis will refresh the editid child or itself)
                treeTasks.RefreshItem(treeTasks.GetItem(0)); // Refresh first item. Bug?
                treeTasks.RefreshItem(treeTasks.GetItem(treeTasks.GetItemCount() - 1)); // Refresh last item. Bug?

            } catch {
                Utils.MsgDialog.Error(Lang.Get("task_edit_error"), Lang.Get("error")); return;
            }
        }