/// <summary> /// Lấy danh sách nội dụng task của đề tài /// </summary> /// <param name="masterID">ID của đề tài</param> /// <returns>Danh sách nội dung của đề tài</returns> /// Create by: dvthang:06.02.2018 public List <ProjectTaskTree> GetTaskTree(Guid?masterID) { List <ProjectTask> projectTasks = this.ExecuteReader <ProjectTask>("[dbo].[Proc_GetListProjectTaskByMasterID]", masterID); List <ProjectTaskTree> trees = new List <ProjectTaskTree>(); if (projectTasks != null) { foreach (ProjectTask task in projectTasks) { ProjectTaskTree tree = new ProjectTaskTree { ProjectTaskID = task.ProjectTaskID, StartDate = task.StartDate, EndDate = task.EndDate, Contents = task.Contents, ProjectID = task.ProjectID, Inactive = task.Inactive, Expanded = true }; if (task.ParentID.HasValue) { tree.ParentID = task.ParentID.Value; } List <ProjectTask> taskChild = projectTasks.Where(m => m.ParentID.HasValue && m.ParentID == task.ProjectTaskID).ToList(); if (taskChild != null && taskChild.Count > 0) { tree.Leaf = false; CreateTreeTask(taskChild, task, tree); } else { tree.Expanded = false; tree.Leaf = true; } trees.Add(tree); } } return(trees); }
/// <summary> /// Tạo cây nội dung đề tài /// </summary> /// Create by: dvthang:06.02.2018 private void CreateTreeTask(List <ProjectTask> tasks, ProjectTask task, ProjectTaskTree tree) { List <ProjectTaskTree> treeChild = new List <ProjectTaskTree>(); foreach (ProjectTask item in tasks) { ProjectTaskTree child = new ProjectTaskTree { ProjectTaskID = item.ProjectTaskID, StartDate = item.StartDate, EndDate = item.EndDate, Contents = item.Contents, ProjectID = item.ProjectID, Inactive = item.Inactive, ParentID = item.ParentID ?? task.ParentID.Value, Expanded = true }; if (item.ParentID.HasValue) { child.ParentID = item.ParentID.Value; } List <ProjectTask> taskChild = tasks.Where(m => m.ParentID.HasValue && m.ParentID == item.ProjectTaskID).ToList(); if (taskChild != null && taskChild.Count > 0) { child.Leaf = false; CreateTreeTask(taskChild, item, child); } else { child.Expanded = false; child.Leaf = true; } treeChild.Add(child); } tree.Data = treeChild; }