Пример #1
0
        private void TaskNewRoot()
        {
            try {

                // Create a new Task in this category
                Task new_task = new Task();
                new_task.CategoryId = (SelectedCategory == null) ? 0 : SelectedCategory.Id;

                // Edit the new task in a Task form.
                TaskForm form = new TaskForm(Lang, Settings, new_task);
                if (!this.Visible) { // From tray...
                    form.MinimizeBox = true;
                    form.ShowInTaskbar = true;
                    form.StartPosition = FormStartPosition.CenterScreen; }
                DialogResult res = form.ShowDialog();

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

                // Save pending notes
                ArrayList pending_notes = new_task.GetUnsavedNotes();
                foreach (Note note in pending_notes) { note.TaskId = new_task.Id; note.Save(); }
                if (pending_notes.Count > 0) { new_task.Reload(); new_task.ClearUnsavedNotes(); }

                // If the task is in the selected category, update the tree
                if (SelectedCategory != null) if (new_task.CategoryId != SelectedCategory.Id) return;
                Todomoo.Tasks.Add(new_task); // Add to tasks
                treeTasks.AddObject(new_task); // Add to tree (this is always a root task)
                treeTasks.RefreshItem(treeTasks.GetItem(0)); // Refresh first item. Bug?
                treeTasks.RefreshItem(treeTasks.GetItem(treeTasks.GetItemCount() - 1)); // Refresh last item. Bug?

                // Select created task
                treeTasks.SelectedObject = new_task;

            } catch {
                Utils.MsgDialog.Error(Lang.Get("task_save_error"), Lang.Get("error")); return;
            }
        }
Пример #2
0
        private void TaskNewChild()
        {
            try {

                // Create a new Task with selected parent
                Task new_task = new Task();
                Task parent_task = (Task)treeTasks.GetSelectedObject();
                new_task.CategoryId = parent_task.CategoryId;
                new_task.ParentId = parent_task.Id;

                // Edit the new task in a Task form.
                TaskForm form = new TaskForm(Lang, Settings, new_task);
                if (!this.Visible) { // From tray...
                    form.MinimizeBox = true;
                    form.ShowInTaskbar = true;
                    form.StartPosition = FormStartPosition.CenterScreen; }
                DialogResult res = form.ShowDialog();

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

                // Save pending notes
                ArrayList pending_notes = new_task.GetUnsavedNotes();
                foreach (Note note in pending_notes) { note.TaskId = new_task.Id; note.Save(); }
                if (pending_notes.Count > 0) { new_task.Reload(); new_task.ClearUnsavedNotes(); }

                // If the task is in the selected category, update the tree
                if (SelectedCategory != null) if (new_task.CategoryId != SelectedCategory.Id) return;
                Todomoo.Tasks.Add(new_task); // Add to tasks
                if (flatView) { /* Flat view? Add task and select it */
                    treeTasks.AddObject(new_task);
                    treeTasks.SelectedObject = new_task;
                } else { /* Tree view, update and expand parent */
                    treeTasks.RefreshObject(Todomoo.GetParent(new_task)); // Refresh parent task  (this will add the created child), thanks to Dege
                    treeTasks.Expand(parent_task); /* Expand parent task to view new task */ }
                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_save_error"), Lang.Get("error")); return;
            }
        }