Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
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));
        }