/// <summary>
        /// 添加新任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewTask_OnClick(object sender, RoutedEventArgs e)
        {
            NewTaskWindow newTaskWindow = new NewTaskWindow();

            newTaskWindow.ShowDialog();
            UpdateView();
        }
    // Some method that will be called when you want to open another window
    public void OpenTheWindow()
    {
        var modalViewModel = new NewTaskViewModel(Model);
        // Create an instance of your new Window and show it.
        var win = new NewTaskWindow(modalViewModel);

        win.ShowDialog();
    }
Ejemplo n.º 3
0
        private void AddNewTask()
        {
            //By setting Owner it maintains the UI Automation tree, normally this would be done by a service so the VM doesnt reference the view
            var dialog = new NewTaskWindow {
                Owner = Owner
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            _repo.Add(dialog.Task);
            Refresh();
        }
        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ModifyTasks(object sender, RoutedEventArgs e)
        {
            TaskItem selectedTaskItem = AllTasksListView.SelectedItem as TaskItem;

            if (selectedTaskItem == null)
            {
                MessageBox.Show("没有选中任务");
                return;
            }

            NewTaskWindow newTaskWindow = new NewTaskWindow(TransferTaskInfoFromTaskItem(selectedTaskItem));

            newTaskWindow.ShowDialog();
            UpdateView();
        }
Ejemplo n.º 5
0
 private void openNewTaskWindow()
 {
     newTaskWindow = new NewTaskWindow(new NewTaskVM());
     newTaskWindow.ShowDialog();
 }
Ejemplo n.º 6
0
        public Main()
        {
            errorScroller = new ErrorScroller();
            errorScroller.RaiseErrorChanged += () => RaisePropertyChanged(nameof(CurrentError));
            // Работа с SQL
            currentTasks     = new CurrentTasks(errorScroller);
            checkForNewTasks = new AsutpServer(errorScroller);

            TaskList = new ObservableCollection <ProductionTask>(currentTasks.TaskList);
            ((INotifyCollectionChanged)currentTasks.TaskList).CollectionChanged += (s, a) =>
            {
                if (a.NewItems?.Count >= 1)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        foreach (ProductionTask task in a.NewItems)
                        {
                            TaskList.Add(task);
                        }
                    }));
                }
                if (a.OldItems?.Count >= 1)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        foreach (ProductionTask task in a.OldItems)
                        {
                            TaskList.Remove(task);
                        }
                    }));
                }
            };

            FinishedTaskList = new ObservableCollection <ProductionTask>(currentTasks.FinishedTaskList);
            ((INotifyCollectionChanged)currentTasks.FinishedTaskList).CollectionChanged += (s, a) =>
            {
                if (a.NewItems?.Count >= 1)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        foreach (ProductionTask task in a.NewItems)
                        {
                            FinishedTaskList.Add(task);
                        }
                    }));
                }
                if (a.OldItems?.Count >= 1)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        foreach (ProductionTask task in a.OldItems)
                        {
                            FinishedTaskList.Remove(task);
                        }
                    }));
                }
            };


            //Работа с ПЛК
            plc = new Plc();
            OpenNewTaskWindow = new DelegateCommand(() =>
            {
                NewTaskWindow newTaskWindow = new NewTaskWindow(new NewTask(currentTasks));
                newTaskWindow.ShowDialog();
            });

            StartTask = new DelegateCommand(() =>
            {
                try
                {
                    plc.SendTask(new ProductionTaskExtended(SelectedTask));
                    currentTasks.UpdateStartDate(SelectedTask.ID);
                }
                catch (Exception e)
                {
                    Log.logThis(e.Message);
                    MessageBox.Show("Нет подключения к ПЛК");
                }
                //RaisePropertyChanged(nameof(SelectedTask));
            });
            FinishTask = new DelegateCommand(() =>
            {
                try
                {
                    ProductionTask taskResult = plc.GetCurrentTaskResult();
                    taskResult.FinishDate     = DateTime.Now;
                    try
                    {
                        currentTasks.LoadTaskResult(taskResult);
                    }
                    catch (TaskNotCreatedException)
                    {
                        MessageBox.Show("Задание не найдено. Введите параметры");
                        NewTaskWindow newTaskWindow = new NewTaskWindow(new NewTask(currentTasks, taskResult));
                        newTaskWindow.ShowDialog();
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            });
            ShowCurrentTask  = new DelegateCommand(() => { VisibleCurrentTask = true; VisibleFinishedTask = false; });
            ShowFinishedTask = new DelegateCommand(() => { VisibleCurrentTask = false; VisibleFinishedTask = true; });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Редактировать выбранную задачу
        /// </summary>
        /// <param name="editedTask"></param>
        private void EditTask(TaskEntity editedTask)
        {
            CurrentlyEditedTask = editedTask;
            if (CurrentlyEditedTask.ParentTask == null)
            {
                CurrentlyEditedTask.ParentTask = _nullTask;
            }
            NewTaskWindow taskWindow = new NewTaskWindow();

            taskWindow.Assignee.Visibility       = Visibility.Collapsed;
            taskWindow.AssigneeSingle.Visibility = Visibility.Visible;
            List <ProcessProxy> oldProcesses = new List <ProcessProxy>(CurrentlyEditedTask.Processes);

            AddedTaskAssigneeFIO = CurrentlyEditedTask.Assignee.Name;
            AddedTaskReporterFIO = CurrentlyEditedTask.Reporter?.Name;
            RaisePropertyChanged(nameof(AddedTaskAssigneeFIO));
            RaisePropertyChanged(nameof(AddedTaskReporterFIO));
            taskWindow.Reporter.IgnoreTextChange       = false;
            taskWindow.AssigneeSingle.IgnoreTextChange = false;

            taskWindow.Processes.SelectedItemsOverride.Clear();
            foreach (ProcessProxy process in CurrentlyEditedTask.Processes)
            {
                AddFormSelectedProcesses.Add(AllProcesses.FirstOrDefault(proc => proc.id == process.ProcessId));
            }
            if (taskWindow.ShowDialog() == true)
            {
                if (CurrentlyEditedTask.ParentTask == _nullTask)
                {
                    CurrentlyEditedTask.ParentTask = null;
                }
                else if (_nullTask.ChildTasks.Contains(CurrentlyEditedTask))
                {
                    _nullTask.ChildTasks.Remove(CurrentlyEditedTask);
                    RaisePropertyChanged(nameof(CurrentlyEditedTask.ParentTask));
                }

                if (_taskContext.Employees.Any(i => i.Name.Equals(AddedTaskAssigneeFIO)))
                {
                    CurrentlyEditedTask.Assignee = _taskContext.Employees.FirstOrDefault(i => i.Name.Equals(AddedTaskAssigneeFIO));
                }
                else
                {
                    CurrentlyEditedTask.Assignee = GetEmployee(AddedTaskAssigneeFIO);
                }

                if (_taskContext.Employees.Any(i => i.Name.Equals(AddedTaskReporterFIO)))
                {
                    CurrentlyEditedTask.Reporter = _taskContext.Employees.FirstOrDefault(i => i.Name.Equals(AddedTaskReporterFIO));
                }
                else
                {
                    CurrentlyEditedTask.Reporter = GetEmployee(AddedTaskReporterFIO);
                }

                foreach (ProcessProxy process in oldProcesses)
                {
                    _taskContext.Processes.Remove(process);
                }
                CurrentlyEditedTask.Processes = AddFormSelectedProcesses.Select(proc => new ProcessProxy {
                    ProcessId = proc.id
                }).ToList();
                _taskContext.SaveChanges();
            }
            RaisePropertyChanged(nameof(SelectedTask));
            taskWindow.Assignee.Visibility       = Visibility.Visible;
            taskWindow.AssigneeSingle.Visibility = Visibility.Collapsed;
            AddFormSelectedProcesses.Clear();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Метод вызывает окно создания новой задачи, где родительской задачей будет являться parentTask
        /// </summary>
        /// <param name="parentTask"></param>
        private void AddTask(TaskEntity parentTask)
        {
            #region инициализация новой задачи
            CurrentlyEditedTask = new TaskEntity
            {
                Owner        = _currentEmployee,
                Reporter     = _currentEmployee,
                CreationDate = DateTime.Now,
                DueDate      = DateTime.Now,
                ParentTask   = parentTask,
                Weight       = 100
            };
            #endregion


            AddedTaskReporterFIO = CurrentlyEditedTask.Reporter.Name;
            #region Настройка формы добавления
            NewTaskWindow newTaskWindow = new NewTaskWindow();
            newTaskWindow.Reporter.IgnoreTextChange = false;

            if (newTaskWindow.ShowDialog() == true)
            {
                #region Добавление новой задачи
                if (_taskContext.Employees.Any(i => i.Name.Equals(AddedTaskReporterFIO)))
                {
                    CurrentlyEditedTask.Reporter = _taskContext.Employees.FirstOrDefault(i => i.Name.Equals(AddedTaskReporterFIO));
                }
                else
                {
                    CurrentlyEditedTask.Reporter = GetEmployee(AddedTaskReporterFIO);
                }

                //Основная задача
                TaskEntity newHeadTask = new TaskEntity
                {
                    Name          = CurrentlyEditedTask.Name,
                    Comment       = CurrentlyEditedTask.Comment,
                    Assignee      = CurrentlyEditedTask.Reporter,
                    ParentTask    = CurrentlyEditedTask.ParentTask,
                    AwaitedResult = CurrentlyEditedTask.AwaitedResult,
                    CreationDate  = CurrentlyEditedTask.CreationDate,
                    DueDate       = CurrentlyEditedTask.DueDate,
                    Meter         = CurrentlyEditedTask.Meter,
                    Owner         = CurrentlyEditedTask.Reporter,
                    Processes     = AddFormSelectedProcesses.
                                    Select(process => new ProcessProxy {
                        ProcessId = process.id
                    }).
                                    ToList(),
                    Reporter   = CurrentlyEditedTask.Reporter,
                    Weight     = CurrentlyEditedTask.Weight,
                    ChildTasks = new ObservableCollection <TaskEntity>()
                };
                if (newHeadTask.ParentTask == _nullTask)
                {
                    newHeadTask.ParentTask = null;
                }
                if (AddFormSelectedAnalytics.Count > 1)
                {
                    //Для каждого выбранного ответственного создается новая подзадача
                    foreach (Employee employee in AddFormSelectedAnalytics)
                    {
                        newHeadTask.ChildTasks.Add(new TaskEntity
                        {
                            Name          = CurrentlyEditedTask.Name,
                            Comment       = CurrentlyEditedTask.Comment,
                            Assignee      = employee,
                            ParentTask    = newHeadTask,
                            AwaitedResult = CurrentlyEditedTask.AwaitedResult,
                            CreationDate  = CurrentlyEditedTask.CreationDate,
                            DueDate       = CurrentlyEditedTask.DueDate,
                            Meter         = CurrentlyEditedTask.Meter,
                            Owner         = CurrentlyEditedTask.Owner,
                            Processes     = AddFormSelectedProcesses.
                                            Select(process => new ProcessProxy {
                                ProcessId = process.id
                            }).
                                            ToList(),
                            Reporter = CurrentlyEditedTask.Reporter,
                            Weight   = CurrentlyEditedTask.Weight,
                        });
                    }
                }
                else
                {
                    newHeadTask.Assignee = AddFormSelectedAnalytics[0];
                }

                _taskContext.Tasks.Add(newHeadTask);
                _taskContext.SaveChanges();
                RaisePropertyChanged(nameof(CurrentlyShownTask));
                if (newHeadTask.ParentTask.Name.Equals(_nullTask.Name))
                {
                    CurrentlyShownTask.ChildTasks.Add(newHeadTask);
                }
                AddFormSelectedAnalytics.Clear();
                AddFormSelectedProcesses.Clear();

                #endregion
            }
            #endregion
        }