Example #1
0
        public void AddToFave(int taskID)
        {
            if (TasksVM.IsFave(taskID))
            {
                return;
            }

            var taskNode = TasksVM.DictionaryFull[taskID];

            // Добавим всех родителей, если их нет в избранном
            List <TreeNode> toAddInFave = new List <TreeNode>();
            var             parent      = taskNode.ParentNode;

            while (parent != null && !TreeRoots.Contains(parent))
            {
                toAddInFave.Add(parent);
                parent = parent.ParentNode;
            }
            for (int i = toAddInFave.Count - 1; i >= 0; --i)
            {
                if (!TasksVM.IsFave(toAddInFave[i].Task.ID))
                {
                    TasksVM.AddFave(toAddInFave[i].Task);
                }
            }

            // Добавим себя
            TasksVM.AddFave(taskNode.Task);
            if (taskNode.Task.ParentTaskID == null)
            {
                TreeRoots.Add(taskNode);
            }
        }
Example #2
0
 private void SaveCollapse(object obj)
 {
     Mouse.SetCursor(Cursors.Wait);
     TasksVM.SaveCollapse(TreeRoots);
     Mouse.SetCursor(Cursors.Arrow);
     MessageBox.Show("Развертка сохранена", "Сохранение", MessageBoxButton.OK, MessageBoxImage.Information);
 }
Example #3
0
 private static void _initSharedStatics()
 {
     Context.Init();
     TasksVM.InitFullTree();
     TasksVM.InitFave();
     WorksVM.Init();
 }
Example #4
0
        private void DeleteTask(object obj)
        {
            FilterTaskText = "";
            FilterTree(obj);
            //Roots
            int delTaskID       = SelectedTaskNode.Task.ID;
            var curNodeToDelete = SelectedTaskNode;

            if (TasksVM.DeleteWithChildren(delTaskID) == false) //дети узла дерева удалятся внутри
            {
                return;
            }

            if (AllTreeRoots.Contains(curNodeToDelete))
            {
                AllTreeRoots.Remove(curNodeToDelete);
            }

            //if (TasksVM.Dictionary.ContainsKey(SelectedTaskNode.Task.ID))
            //    TasksVM.Dictionary.Remove(SelectedTaskNode.Task.ID);


            if (TasksVM.DictionaryFull.ContainsKey(delTaskID + 1))
            {
                ChangeSelection(TasksVM.DictionaryFull[delTaskID + 1]);
            }
            else
            {
                ChangeSelection(TasksVM.DictionaryFull.FirstOrDefault().Value);
            }
        }
Example #5
0
        public static void ReloadContext()
        {
            var refreshableObjects = _context.ChangeTracker.Entries().Where(e => e.State != EntityState.Unchanged).Select(c => c.Entity).ToList();
            var context            = ((IObjectContextAdapter)_context).ObjectContext;

            context.Refresh(RefreshMode.StoreWins, refreshableObjects);

            TasksVM.Init_Full_tracker = false;
            TasksVM.InitFullTree();
            //_init_tracker = false;
            //Init();
        }
Example #6
0
        public void Accept(object obj)
        {
            if (_favouritingTask == null)
            {
                return;
            }
            if (TasksVM.IsFave(_favouritingTask.ID))
            {
                MessageBox.Show("Данная задача уже добавлена в избранное");
                return;
            }
            //Mouse.OverrideCursor = Cursors.Wait;
            Mouse.SetCursor(Cursors.Wait);


            // Добавим всех родителей, если их нет в избранном
            List <TreeNode> toAddInFave = new List <TreeNode>();
            var             parent      = SelectedTaskNode.ParentNode;

            while (parent != null && !FaveTreeRoots.Contains(parent))
            {
                toAddInFave.Add(parent);
                parent = parent.ParentNode;
            }
            for (int i = toAddInFave.Count - 1; i >= 0; --i)
            {
                if (!TasksVM.IsFave(toAddInFave[i].Task.ID))
                {
                    TasksVM.AddFave(toAddInFave[i].Task);
                }
            }

            // Добавим себя
            TasksVM.AddFave(_favouritingTask);

            // Добавим своё поддерево
            Queue <TreeNode> nodeToFave = new Queue <TreeNode>();

            nodeToFave.Enqueue(SelectedTaskNode);
            while (nodeToFave.Count > 0)
            {
                var curNode = nodeToFave.Dequeue();
                foreach (var childNode in curNode.TreeNodes)
                {
                    TasksVM.AddFave(childNode.Task);
                    nodeToFave.Enqueue(childNode);
                }
            }
            //Mouse.OverrideCursor = Cursors.Arrow;
            Mouse.SetCursor(Cursors.Arrow);
            MessageBox.Show("Задача: " + _favouritingTask.TaskName + " добавлена в избранное", "Добавление в избранное", MessageBoxButton.OK, MessageBoxImage.Information);
            //MessengerInstance.Unregister<KeyValuePair<TaskCommandEnum, Task>>(this, _doTaskCommand);
        }
Example #7
0
        public void DoTaskCommand(KeyValuePair <FaveTaskCommandEnum, Task> pair)
        {
            FaveTaskCommandEnum command = pair.Key;
            Task task = pair.Value;

            if (!TasksVM.Dictionary.ContainsKey(task.ID))
            {
                return;
            }

            switch (command)
            {
            case FaveTaskCommandEnum.Edit:
                TreeNode oldNode = TasksVM.Dictionary[task.ID];
                int      index   = -1;

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

                //if (oldNode.ParentNode != TasksVM.DictionaryFull[task.ID].ParentNode)
                //{
                //    Context.procedureWork.RepareUserFave(task.ID);
                //    TasksVM.Init_tracker = false;
                //    TasksVM.InitFave();
                //}

                TasksVM.Edit(task, false);
                TreeNode newNode = TasksVM.Dictionary[task.ID];

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

                break;
            }
        }
Example #8
0
        private void DeleteFaveTask(object obj)
        {
            FilterTaskText = "";
            FilterTree(obj);
            TasksVM.FilterFaveTaskText = "";
            var dialogResult = System.Windows.MessageBox.Show("Вы уверены, что хотите удалить задачу из избранного?", "Подтверждение",
                                                              MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (dialogResult == MessageBoxResult.No)
            {
                return;
            }

            //Mouse.OverrideCursor = Cursors.Wait;
            Mouse.SetCursor(Cursors.Wait);

            //Roots
            int delTaskID    = SelectedTaskNode.Task.ID;
            int?parentTaskID = SelectedTaskNode.Task.ParentTaskID;

            if (TreeRoots.Contains(SelectedTaskNode))
            {
                TreeRoots.Remove(SelectedTaskNode);
            }
            //if (TasksVM.Dictionary.ContainsKey(SelectedTaskNode.Task.ID))
            //    TasksVM.Dictionary.Remove(SelectedTaskNode.Task.ID);


            TasksVM.DeleteFaveWithChildren(delTaskID);
            if (parentTaskID != null)
            {
                ChangeSelection(TasksVM.Dictionary[(int)parentTaskID]);
            }
            else
            {
                ChangeSelection(TasksVM.Dictionary.FirstOrDefault().Value);
            }
            //Mouse.OverrideCursor = Cursors.Arrow;
            Mouse.SetCursor(Cursors.Arrow);
        }
Example #9
0
        private void MoveUp(object obj)
        {
            int  curI  = (int)SelectedTaskNode.IndexNumber;
            var  task1 = SelectedTaskNode.Task;
            Task task2 = null;

            if (SelectedTaskNode.ParentNode != null)
            {
                TreeNode parentNode = SelectedTaskNode.ParentNode;
                int      index      = parentNode.TreeNodes.IndexOf(SelectedTaskNode);
                parentNode.TreeNodes[index].IndexNumber     = parentNode.TreeNodes[index - 1].IndexNumber;
                parentNode.TreeNodes[index - 1].IndexNumber = curI;
                task2 = parentNode.TreeNodes[index - 1].Task;


                DoTaskCommand(new KeyValuePair <FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, parentNode.TreeNodes[index].Task));
                DoTaskCommand(new KeyValuePair <FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, parentNode.TreeNodes[index - 1].Task));

                parentNode.TreeNodes.Move(index, index - 1);
                ChangeSelection(parentNode.TreeNodes[index - 1]);
            }
            else
            {
                int index = TreeRoots.IndexOf(SelectedTaskNode);

                TreeRoots[index].IndexNumber     = TreeRoots[index - 1].IndexNumber;
                TreeRoots[index - 1].IndexNumber = curI;
                task2 = TreeRoots[index - 1].Task;

                DoTaskCommand(new KeyValuePair <FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, TreeRoots[index].Task));
                DoTaskCommand(new KeyValuePair <FaveTaskCommandEnum, Task>(FaveTaskCommandEnum.Edit, TreeRoots[index - 1].Task));

                TreeRoots.Move(index, index - 1);
                ChangeSelection(TreeRoots[index - 1]);
            }
            TasksVM.ReplaceUserTasks(task1, task2);
        }
Example #10
0
        public WorkBlockControlViewModel(int workID, bool IsEditingFlag = false)
        {
            WorkVM        = WorksVM.Dictionary[workID];
            WorkInBlockID = new WorkIDDependency(workID);
            _generate_path();

            SelectedWorkTypeIndex = WorkVM.Work.WorkTypeID;
            _generate_TaskTypesCb();

            _applyCommand           = new RelayCommand(ApplyChanges, CanEdit);
            _cancelCommand          = new RelayCommand(CancelChanges, CanEdit);
            _deleteCommand          = new RelayCommand(Delete, CanDelete);
            _changeTaskCommand      = new RelayCommand(ChangeTask, CanChangeTask);
            _duplicateWorkCommand   = new RelayCommand(DuplicateWork, (_) => true);
            _shareWorkTaskCommand   = new RelayCommand(ShareWork, (_) => true);
            _addWorkRangeCommand    = new RelayCommand(AddWorkTimeRange, (_) => true);
            _deleteWorkRangeCommand = new RelayCommand(param =>
            {
                if (WorkTimeRanges.Count == 1) //нельзя удалять, если диапазон один
                {
                    return;
                }
                WorkTimeRanges.Remove(param as TimeRange);
                UpdateWorkTime();
                RaisePropertyChanged("IsWorkTimeEnabled");
            }, (_) => true);

            WorkNames = TasksVM.GetAllWorksNames(WorkVM.Work.TaskID);

            //SaveHotCommand.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
            //DeleteHotCommand.InputGestures.Add(new KeyGesture(Key.Delete, ModifierKeys.Control));

            MainWindow.GlobalPropertyChanged += HandleGlobalPropertyChanged;

            MessengerInstance.Register <string>(this, ApplyAction);
            IsEditing = IsEditingFlag;
            if (IsEditing)
            {
                IsExpanded          = true;
                MainWindow.IsEnable = false;
            }
            else
            {
                IsExpanded = false;
            }
            MouseLeft = false;

            _hours        = Minutes / 60;
            _minutesShort = Minutes % 60;

            WorkTimeRanges = new ObservableCollection <TimeRange>();

            //_endTime = Work.StartTime.AddMinutes(Work.Minutes);
            timeHandler = UpdateWorkTime;
            FillTimeRanges();
            if (WorkTimeRanges.Count == 0) //Работа новая
            {
                AddWorkTimeRange(this);
            }

            WorkVM.PropertyChanged += new PropertyChangedEventHandler(SetExpended);
        }
Example #11
0
        public void Accept(object obj)
        {
            if (ALLVM == null) //мы запустили на просмотр задачу
            {
                if (dialog != null)
                {
                    dialog.Close();
                    dialog = null;
                    return;
                }
            }

            ////Значения доп. полей почистить
            //FilterPropValues();

            if (_command == TaskCommandEnum.Edit)
            {
                if (_editingTask.ID == _editingTask.ParentTaskID || TasksVM.CheckIsChild(_editingTask.ID, _editingTask.ParentTaskID)) // todo по моему параметры неверно передаются в функцию CheckIsChild
                {
                    MessageBox.Show("Нельзя назначить новым родителем потомка или самого себя");
                    return;
                }
                if (TasksVM.IsExist(_editingTask.ID, _editingTask.TaskName, _editingTask.ParentTaskID))
                {
                    MessageBox.Show("Задача с таким именем на данном уровне уже существует!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                if (_task.ResponsibleID != _editingTask.ResponsibleID)
                {
                    var dialogResult = System.Windows.MessageBox.Show("Обновить ответственного у ВСЕХ дочерних задач на текущего?", "Подтверждение",
                                                                      MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        TasksVM.SetResponsibleForTaskChildren(_editingTask.ID, _editingTask.ResponsibleID);
                    }
                }
            }
            else if (_command == TaskCommandEnum.Add)
            {
                //if (SelectedTaskNode != null)
                //{
                //    var parentNode = SelectedTaskNode.ParentNode;
                //    if (parentNode != null)
                //    {
                //        foreach (var currentNodeNeighbour in parentNode.TreeNodes)
                //        {
                //            if (currentNodeNeighbour.Task.TaskName.ToLower() == _editingTask.TaskName.ToLower())
                //            {
                //                MessageBox.Show("Задача с таким именем уже существует!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                //                return;
                //            }
                //        }
                //    }
                //    else
                //    {
                //        int aa = 1;
                //    }
                //int parentTaskID = _editingTask.ParentTaskID == null ? 0 : (int)_editingTask.ParentTaskID;
                if (TasksVM.IsExist(_editingTask.ID, _editingTask.TaskName, _editingTask.ParentTaskID))
                {
                    MessageBox.Show("Задача с таким именем на данном уровне уже существует!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                Context.procedureWork.UpdateTasksIndexNumbers((int)_editingTask.IndexNumber); // обновим индексы с текущего
                //}
            }

            //Значения доп. полей почистить
            FilterPropValues();
            ALLVM.DoTaskCommand(new KeyValuePair <TaskCommandEnum, Task>(_command, _editingTask));


            //Обновить в БД значения родительских списков
            var pvLists = PropValuesCollection.Where(pvi => pvi.propVal.Property.DataType == 5 && pvi.propVal.Property.ListType == true).ToList();

            foreach (var pvi in pvLists)
            {
                var list         = pvi.listsValues;
                var listID       = pvi.propVal.Property.ListID;
                var parentTaskID = pvi.parentListTaskID;
                Context.listWork.UpdateListValues(list, parentTaskID, (int)listID);
            }
            //Обновить в БД значения своих списков
            TaskLists.Select(tl => tl.TaskID = _editingTask.ID);
            TaskLists.ForEach(delegate(ListInfo lInfo)
            {
                lInfo.listsValues.ForEach(delegate(ListsValue listVal)
                {
                    listVal.TaskID = _editingTask.ID;
                });
            });
            var taskLists = TaskLists.Select(tl => tl.list).ToList();

            Context.listWork.UpdateLists(taskLists);

            foreach (var listInfo in TaskLists)
            {
                var list   = listInfo.listsValues;
                var listID = listInfo.list.ID;
                var taskID = listInfo.TaskID > 0 ? listInfo.TaskID : _editingTask.ID;
                Context.listWork.UpdateListValues(list, taskID, (int)listID);
            }



            //         MessengerInstance.Send<KeyValuePair<TaskCommandEnum, Task>>(
            //new KeyValuePair<TaskCommandEnum, Task>(_command, _editingTask));

            if (dialog != null)
            {
                dialog.Close();
                dialog = null;
            }
        }
Example #12
0
 private void ExpandAll(object obj)
 {
     TasksVM.ExpandAll();
 }
Example #13
0
 private void CollapseAll(object obj)
 {
     TasksVM.CollapseAll();
 }
Example #14
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;
            }
        }