Ejemplo n.º 1
0
        public TaskDialogViewModel(TasksAllViewModel allVM, Task task, TaskCommandEnum command, TreeNode editNodeParent = null, bool _isEnabled = true)
        {
            ALLVM = allVM;
            _generate_TaskTypesCb();

            IsEditEnabled         = _isEnabled;
            _task                 = task;
            EditingTreeNodeParent = editNodeParent;
            EditingTask           = new Task(task);

            SelectedTaskTypeIndex = task.TaskTypeID;

            if (command == TaskCommandEnum.Add)
            {
                var taskTypeObj = TaskTypesCb.FirstOrDefault(tp => tp.TypeName.ToLower() == "задача");
                if (taskTypeObj != null)
                {
                    SelectedTaskTypeIndex = TaskTypesCb.IndexOf(taskTypeObj);
                }
            }

            levels   = Context.levelWork.Read_AllLevelsLowerMe();
            SelLevel = levels[0];

            users           = Context.usersWork.Read_AllUsers();
            ResponsibleUser = GlobalInfo.CurrentUser;
            OwnerUser       = GlobalInfo.CurrentUser;

            if (command == TaskCommandEnum.Edit)
            {
                var treeNode = TasksVM.DictionaryFull[EditingTask.ID];
                _generate_Tree(treeNode);
                Message         = "Выбрать задачу-родителя";
                SelLevel        = levels.FirstOrDefault(l => l.LevelID == task.LevelID);
                ResponsibleUser = users.FirstOrDefault(u => u.ID == task.ResponsibleID);
                OwnerUser       = users.FirstOrDefault(u => u.ID == task.OwnerID);
            }
            _command = command;
            Command  = (int)_command;


            AcceptCommand      = new RelayCommand(Accept, CanAccept); // todo чем чётче мы показываем намерения, тем легче программа
            CancelCommand      = new RelayCommand(Cancel, CanCancel); // в данном случае у нас return true всегда, наглядней было бы CancelCommand = new RelayCommand(Cancel, (_) => true);
            _filterTaskCommand = new RelayCommand(FilterTree, (_) => true);
        }
Ejemplo n.º 2
0
        //private void _doTaskCommand(KeyValuePair<TaskCommandEnum, Task> pair)
        public void DoTaskCommand(KeyValuePair <TaskCommandEnum, Task> pair)
        {
            TaskCommandEnum command = pair.Key;
            Task            task    = pair.Value;

            switch (command)
            {
            case TaskCommandEnum.Add:
                TasksVM.Add(task);
                TreeNode newNode = TasksVM.DictionaryFull[task.ID];

                if (newNode.ParentNode == null)
                {
                    AddRootNode(newNode);
                }

                ChangeSelection(newNode);
                if (newNode.ParentNode != null)
                {
                    newNode.ParentNode.IsExpanded = true;
                }

                break;

            case TaskCommandEnum.Edit:
                TreeNode oldNode = TasksVM.DictionaryFull[task.ID];
                int      index   = -1;

                if (oldNode.ParentNode == null)
                {
                    index = AllTreeRoots.IndexOf(oldNode);
                }

                TasksVM.Edit(task, true);
                newNode = TasksVM.DictionaryFull[task.ID];

                if (index != -1 && newNode.ParentNode == null)
                {
                    UpdateRootNode(index, newNode);
                }
                else if (newNode.ParentNode == null)
                {
                    AddRootNode(newNode);
                }
                else
                {
                    DeleteRootNode(oldNode);
                }

                if (oldNode.ParentNode != newNode.ParentNode)
                {
                    Context.procedureWork.RepareUserFave(task.ID);
                    TasksVM.Init_tracker = false;
                    TasksVM.InitFave();
                }
                TaskFaveVM.DoTaskCommand(new KeyValuePair <FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, task));
                //    MessengerInstance.Send<KeyValuePair<FaveTaskCommandEnum, Task>>(
                //new KeyValuePair<FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, task)); //todo Настя сделать ссылки на task из общего словаря, чтобы не пришлось пробрасывать изменения в избранное
                break;
            }
        }