public ActionResult Index(int?page, int?pageSize)
        {
            var authorizedIds = m_dbAdapter.Authority.GetAuthorizedProjectIds();
            var projects      = m_dbAdapter.Project.GetProjects(page ?? 1, pageSize ?? 10, true, authorizedIds);

            var viewModel = new ProjectManagerViewModel();

            viewModel.PageInfo = Toolkit.ConvertPageInfo(projects);

            var filterDate = DateTime.Now.AddYears(10);//截止时间设定为未来十年内,仅为触发日期筛选

            foreach (var project in projects.Items)
            {
                var projectView = Toolkit.ConvertProject(project);
                if (projectView != null)
                {
                    var tasks = m_dbAdapter.Task.GetTasks(1, 1, filterDate, project.ProjectId,
                                                          new List <TaskStatus>()
                    {
                        TaskStatus.Waitting, TaskStatus.Running, TaskStatus.Finished,
                        TaskStatus.Skipped, TaskStatus.Overdue, TaskStatus.Error
                    },
                                                          new List <int> {
                        project.ProjectId
                    });
                    if (tasks.Items != null && tasks.Items.Count > 0)
                    {
                        projectView.CurrentTask = Toolkit.ConvertTask(tasks.Items.First());
                    }

                    projectView.Message = m_dbAdapter.News.CountNewsByProjectAndStatus(projectView.Id, NewsConsts.NewsStatusAll)
                                          - m_dbAdapter.News.CountNewsByProjectAndStatus(projectView.Id, NewsConsts.NewsStatusRead);
                    viewModel.Projects.Add(projectView);
                }
            }

            viewModel.HasCreateProjectAuthority = m_dbAdapter.Authority.IsAuthorized(AuthorityType.CreateProject);
            viewModel.HasEditModelAuthority     = m_dbAdapter.Authority.IsAuthorized(AuthorityType.ModifyModel);
            viewModel.HasEditProjectAuthority   = m_dbAdapter.Authority.IsAuthorized(AuthorityType.ModifyTask);
            viewModel.IsSuperUser = m_dbAdapter.SuperUser.IsSuperUser();
            return(View(viewModel));
        }
示例#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));
        }
示例#3
0
        public ActionResult Index(int?page, int?pageSize, string timeRange, string projectGuid, string paymentDay, string taskStatusList)
        {
            int projectId = -1;

            //[Check Authorization]
            var authorizedProjectIds = m_dbAdapter.Authority.GetAuthorizedProjectIds();

            var scheduleView = new ScheduleViewModel();

            var upperLimitDate = DateTime.Parse("9999-12-31");
            var lowerLimitDate = DateTime.Parse("1753-01-02");

            if (!string.IsNullOrWhiteSpace(projectGuid))
            {
                var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid);
                projectId = project.ProjectId;

                CommUtils.Assert(authorizedProjectIds.Contains(projectId), "当前用户没有读取产品[{0}]偿付期列表的权限", project.Name);
                if (paymentDay != null)
                {
                    GetLimitDates(projectGuid, paymentDay, ref upperLimitDate, ref lowerLimitDate);
                    scheduleView.PaymentDay = paymentDay;
                }
            }

            DateTime?endTime = null;

            if (timeRange != null)
            {
                var enumTime = CommUtils.ParseEnum <TaskFilterTime>(timeRange);
                scheduleView.FilterTime = timeRange;
                if (enumTime != TaskFilterTime.All)
                {
                    endTime = ParseFilterTime(enumTime);
                }
            }

            var taskStatusValues = new List <TaskStatus>();

            if (taskStatusList != null)
            {
                taskStatusValues          = CommUtils.ParseEnumList <TaskStatus>(taskStatusList);
                scheduleView.FilterStatus = CommUtils.Split(taskStatusList).ToList();
            }
            else
            {
                taskStatusValues = new List <TaskStatus>()
                {
                    TaskStatus.Waitting,
                    TaskStatus.Running,
                    TaskStatus.Finished,
                    TaskStatus.Skipped,
                    TaskStatus.Overdue,
                    TaskStatus.Error
                };
            }

            var tasks = m_dbAdapter.Task.GetTasks(page ?? 1, pageSize ?? 10, endTime, projectId,
                                                  taskStatusValues, authorizedProjectIds, Toolkit.DateToString(upperLimitDate),
                                                  Toolkit.DateToString(lowerLimitDate), paymentDay ?? "1753-01-02");

            scheduleView.PageInfo = Toolkit.ConvertPageInfo(tasks);


            //short code, name
            var taskShortCodeDict = new Dictionary <int, Tuple <string, string> >();

            foreach (var task in tasks.Items)
            {
                var taskView = Toolkit.ConvertTask(task);
                if (taskView != null)
                {
                    scheduleView.Tasks.Add(taskView);
                    taskShortCodeDict[int.Parse(taskView.Id)] = Tuple.Create(taskView.ShortCode, taskView.TaskName);
                }
            }

            var projectCache = new Dictionary <int, Project>();

            for (int i = 0; i < scheduleView.Tasks.Count; ++i)
            {
                var task         = tasks.Items[i];
                var taskView     = scheduleView.Tasks[i];
                var curProjectId = task.ProjectId;
                if (projectCache.ContainsKey(curProjectId))
                {
                    taskView.ProjectName = projectCache[curProjectId].Name;
                    taskView.ProjectGuid = projectCache[curProjectId].ProjectGuid;
                }
                else
                {
                    var project = m_dbAdapter.Project.GetProjectById(curProjectId);
                    taskView.ProjectName       = project.Name;
                    taskView.ProjectGuid       = project.ProjectGuid;
                    projectCache[curProjectId] = project;
                }

                taskView.PrevTaskShortCodeArray = new List <string>();
                taskView.PrevTaskNameArray      = new List <string>();
                if (!string.IsNullOrEmpty(taskView.PrevTasksNames) && taskView.PrevTasksNames != "-")
                {
                    string prevTaskNames = string.Empty;
                    var    prevTaskIds   = CommUtils.Split(taskView.PrevTasksNames).ToList().ConvertAll(x => int.Parse(x));
                    foreach (var prevTaskId in prevTaskIds)
                    {
                        if (!taskShortCodeDict.ContainsKey(prevTaskId))
                        {
                            var tempTask = m_dbAdapter.Task.GetTask(prevTaskId);
                            taskShortCodeDict[tempTask.TaskId] = Tuple.Create(tempTask.ShortCode, tempTask.Description);
                        }

                        if (!string.IsNullOrEmpty(prevTaskNames))
                        {
                            prevTaskNames += CommUtils.Spliter;
                        }

                        taskView.PrevTaskShortCodeArray.Add(taskShortCodeDict[prevTaskId].Item1);
                        taskView.PrevTaskNameArray.Add(taskShortCodeDict[prevTaskId].Item2);
                        prevTaskNames += taskShortCodeDict[prevTaskId].Item1;
                    }

                    taskView.PrevTasksNames = prevTaskNames;
                }
            }

            //Get projects info
            var projects = m_dbAdapter.Project.GetProjects(authorizedProjectIds);

            scheduleView.Projects = new List <ProjectViewModel>();
            foreach (var project in projects)
            {
                var projectView = Toolkit.ConvertProject(project);
                if (projectView != null)
                {
                    scheduleView.Projects.Add(projectView);
                }
            }

            return(View(scheduleView));
        }