private void GenerateJobTree(int? ID, List<ComboTreeItem> tree, string value) { var query = DepartmentService.GetALL(); if (ID.HasValue) { query = query.Where(x => x.PID == ID.Value); } else { query = query.Where(x => x.PID.Equals(null)); } var departments = query.ToList(); foreach (var depart in departments) { var treeitem = new ComboTreeItem() { id = "d_" + depart.ID, text = depart.Name, idValue = depart.ID, iconCls = "icon-depart" }; var jobTitles = JobTitleCateService.GetALL() .Include(x => x.Department) .Where(x => x.Department.Any(d => d.ID == depart.ID)).ToList(); if (jobTitles.Any()) { treeitem.state = "closed"; } foreach (var jt in jobTitles) { var treechilditem = new ComboTreeItem() { id = depart.ID.ToString() + "_" + jt.ID.ToString(), text = jt.CateName, children = null, iconCls = "icon-user", @checked = (depart.ID.ToString() + "_" + jt.ID.ToString() == value) }; treeitem.children.Add(treechilditem); } tree.Add(treeitem); if (DepartmentService.GetALL().Any(x => x.PID == depart.ID)) { GenerateJobTree(depart.ID, treeitem.children, value); } } }
public void GenerateTree(ComboTreeItem item, List<ComboTreeItem> tree, List<int> ids) { var query = DepartmentService.GetALL(); if (item != null) { query = query.Where(x => x.PID == item.idValue); } else { query = query.Where(x => x.PID.Equals(null)); } var departments = query.OrderBy(x => x.Code).ToList(); foreach (var depart in departments) { var treeitem = new ComboTreeItem() { id = depart.ID.ToString(), idValue = depart.ID, text = depart.Name, @checked = ids.Contains(depart.ID) }; tree.Add(treeitem); if (DepartmentService.GetALL().Any(x => x.PID == depart.ID)) { GenerateTree(treeitem, treeitem.children, ids); } } }