本文共 1596 字,大约阅读时间需要 5 分钟。
1: static ListentitiesList = null;
2:
3: internal static void Reload()
4: {
5: entitiesList = (from pc in iDepartmentsRepository.GetDepartments()
6: orderby pc.DeptName ascending
7: select pc).ToList();
8: }
9:
10: #region 树型部门列表
11: ///
12: /// 虚拟产品类别
13: ///
14: ///虚拟产品类别列表
15: public static Entity.OA.Department GetTree()
16: {
17: Reload();
18: Entity.OA.Department root = new Entity.OA.Department();
19: try
20: {
21: root = entitiesList.Single(
22: item => item.DeptID.Equals(Entity.OA.Department.ROOTID));//获取跟节点
23: GetSubs(root);
24:
25: }
26: catch (InvalidOperationException ex)
27: {
28: ex.ToString();
29: }
30: return root;
31: }
32:
33:
34: ///
35: /// 根据父对象,找到子孙树
36: ///
37: /// 父对象
38: static public void GetSubs(Entity.OA.Department father)
39: {
40: father.SubList = entitiesList.Where(item =>
41: item.ParentID.Equals(father.DeptID)).ToList();
42: father.SubList.ForEach(item =>
43: {
44: item.Father = father;
45: GetSubs(item);
46: });
47:
48: }
49: #endregion
本文转自博客园张占岭(仓储大叔)的博客,原文链接:,如需转载请自行联系原博主。