Пример #1
0
        private TaskExBase CheckChangeTaskStatus(Task task, TaskStatus newStatus)
        {
            //新状态是否和现有状态相同
            CommUtils.Assert(task.TaskStatus != newStatus, "无法将任务状态从[{0}]修改为[{1}]",
                             TranslateUtils.ToCnString(task.TaskStatus), TranslateUtils.ToCnString(newStatus));

            //前置工作是否完成
            if (newStatus == TaskStatus.Running || newStatus == TaskStatus.Finished)
            {
                foreach (var prevTaskId in task.PrevTaskIdArray)
                {
                    var prevTask = m_dbAdapter.Task.GetTask(prevTaskId);
                    CommUtils.Assert(prevTask.TaskStatus == TaskStatus.Finished || prevTask.TaskStatus == TaskStatus.Skipped,
                                     "前置工作[{0}][{1}]未完成", prevTask.ShortCode, prevTask.Description);
                }
            }

            //扩展工作未完成,不能完成工作
            TaskExBase taskEx = null;

            if (task.TaskExtensionId.HasValue)
            {
                var taskExtension = m_dbAdapter.Task.GetTaskExtension(task.TaskExtensionId.Value);
                taskEx = TaskExFactory.CreateInstance(taskExtension.TaskExtensionType, task.ShortCode, CurrentUserName);
                if (taskEx != null)
                {
                    var eventResult = taskEx.InvokeStatusChanging(task.TaskStatus, newStatus);
                    CommUtils.Assert(eventResult.EventResult != EventResult.Cancel, eventResult.Message);
                }
            }

            return(taskEx);
        }
Пример #2
0
        public ActionResult Index(string shortCode)
        {
            if (string.IsNullOrEmpty(shortCode))
            {
                return(RedirectToAction("Index", "Schedule"));
            }

            var task    = m_dbAdapter.Task.GetTask(shortCode);
            var project = m_dbAdapter.Project.GetProjectById(task.ProjectId);

            task.ProjectName = project.Name;

            var taskViewModel = Toolkit.ConvertTask(task);

            GetPrevAndNextTaskShortCode(taskViewModel, task);
            taskViewModel.ProjectGuid = project.ProjectGuid;
            taskViewModel.TaskHandler = Platform.UserProfile.GetDisplayRealNameAndUserName(taskViewModel.TaskHandler);

            taskViewModel.PrevTaskNameArray      = new List <string>();
            taskViewModel.PrevTaskShortCodeArray = new List <string>();
            foreach (var prevTaskId in task.PrevTaskIdArray)
            {
                var prevTask = m_dbAdapter.Task.GetTask(prevTaskId);
                taskViewModel.PrevTaskShortCodeArray.Add(prevTask.ShortCode);
                taskViewModel.PrevTaskNameArray.Add(prevTask.Description);
            }

            //Get task extension info.
            if (task.TaskExtensionId.HasValue)
            {
                var taskExtension = m_dbAdapter.Task.GetTaskExtension(task.TaskExtensionId.Value);
                taskExtension.TaskExtensionHandler = Platform.UserProfile.GetDisplayRealNameAndUserName(taskExtension.TaskExtensionHandler);
                taskViewModel.TaskExtension        = Toolkit.ConvertTaskExtension(taskExtension);

                var instance = TaskExFactory.CreateInstance(taskViewModel.TaskExtension.Type, shortCode, CurrentUserName);
                if (instance != null)
                {
                    //扩展工作页面初始化时的异常返回错误信息
                    object entity;
                    try
                    {
                        entity = instance.GetEntity();
                    }
                    catch (ApplicationException e)
                    {
                        entity = e.Message;
                    }
                    taskViewModel.TaskExtension.Info = entity;
                }
            }

            //Get task status history info.
            var taskStatusHitory = m_dbAdapter.Task.GetTaskStatusHistory(task.TaskId);

            if (taskStatusHitory != null)
            {
                var usernameCache = new Dictionary <string, string>();

                taskViewModel.TaskStatusHistory = new List <TaskStatusHistoryViewModel>();
                foreach (var item in taskStatusHitory)
                {
                    var viewModel = Toolkit.ConvertTaskStatusHistory(item);

                    string name = string.Empty;
                    if (usernameCache.ContainsKey(viewModel.TimeStampUserName))
                    {
                        name = usernameCache[viewModel.TimeStampUserName];
                    }
                    else
                    {
                        name = m_dbAdapter.Authority.GetNameByUserName(viewModel.TimeStampUserName);
                        usernameCache[viewModel.TimeStampUserName] = name;
                    }

                    name = string.IsNullOrEmpty(name) ? viewModel.TimeStampUserName
                        : (name + "(" + viewModel.TimeStampUserName + ")");
                    viewModel.TimeStampUserName = name;

                    taskViewModel.TaskStatusHistory.Add(viewModel);
                }
            }

            taskViewModel.ProjectSeriesStage = ProjectSeriesStage.存续期;
            if (project.ProjectSeriesId.HasValue && project.TypeId.HasValue && project.TypeId.Value == 1)
            {
                taskViewModel.ProjectSeriesStage = ProjectSeriesStage.发行;

                var projectSeries = m_dbAdapter.ProjectSeries.GetById(project.ProjectSeriesId.Value);
                taskViewModel.ProjectSeriesGuid = projectSeries.Guid;
            }

            return(View(taskViewModel));
        }