Beispiel #1
0
        /// <summary>
        /// 获取树节点基本数据
        /// </summary>
        /// <param name="view">0:基本数据;1:基本设备信息;2:基本人员信息;3:基本设备信息+基本人员信息</param>
        /// <returns></returns>
        public AreaNode GetBasicTree(int view)
        {
            var areaList = dbSet.ToList();

            if (areaList == null)
            {
                return(null);
            }
            List <Area> list2 = new List <Area>();

            for (int i = 0; i < areaList.Count; i++)
            {
                if (areaList[i].Type != AreaTypes.CAD)
                {
                    list2.Add(areaList[i]);
                }
            }
            areaList = list2;
            var list = areaList.ToTModelS();

            List <DevNode> devs = null;

            if (view == 0)
            {
            }
            else if (view == 1 || view == 4)
            {
                devs = db.DevInfos.ToList().ToTModelS();
            }
            else if (view == 2 || view == 5)
            {
                BindPerson(list);
            }
            else if (view == 3 || view == 6)
            {
                BindPerson(list);
                devs = db.DevInfos.ToList().ToTModelS();
            }

            var      roots = TreeHelper.CreateTree(list, devs);
            AreaNode root  = null;

            if (roots.Count > 0)
            {
                root = roots[0];             //根节点

                var park = root.Children[0]; //四会热电厂

                //将电厂下的人员移动到其他区域中
                var otherArea = new AreaNode();
                otherArea.Id   = 100000;
                otherArea.Name = "厂区内";
                if (park.Persons != null)
                {
                    foreach (var person in park.Persons)
                    {
                        otherArea.AddPerson(person);
                    }
                    park.Persons.Clear();
                }
                park.Children.Add(otherArea);
                root = park;//将电厂做为根节点
            }
            if (view == 4 || view == 5 || view == 6)
            {
                RemoveEmptyNodes(root);
            }

            SumNodeCount(root);

            //if (root.Children.Count == 0)
            //{
            //    root.Children = null;
            //}

            SetChildrenNull(root);

            return(root);
        }
Beispiel #2
0
        /// <summary>
        /// 获取树节点基本数据
        /// </summary>
        /// <param name="view">0:基本数据;1:基本设备信息;2:基本人员信息;3:基本设备信息+基本人员信息</param>
        /// <returns></returns>
        public AreaNode GetBasicTree(int view)
        {
            try
            {
                var areaList = dbSet.ToList();
                if (areaList == null)
                {
                    return(null);
                }
                List <Area> list2 = new List <Area>();
                for (int i = 0; i < areaList.Count; i++)
                {
                    if (areaList[i].Type != AreaTypes.CAD)
                    {
                        list2.Add(areaList[i]);
                    }
                }
                areaList = list2;
                var list = areaList.ToTModelS();

                List <DevNode> devs = null;
                if (view == 0)
                {
                }
                else if (view == 1 || view == 4)
                {
                    devs = db.DevInfos.ToList().ToTModelS();
                }
                else if (view == 2 || view == 5)
                {
                    BindPerson(list);
                }
                else if (view == 3 || view == 6)
                {
                    BindPerson(list);
                    devs = db.DevInfos.ToList().ToTModelS();
                }

                var      roots = TreeHelper.CreateTree(list, devs);
                AreaNode root  = null;
                if (roots.Count > 0)
                {
                    root = roots[0];                                       //根节点

                    if (root.Children == null || root.Children.Count == 0) //不应该,会有问题
                    {
                        Log.Error("AreaService", "获取根区域信息有问题:" + root.Name);
                        return(null);
                    }
                    var park = root.Children[0];//四会热电厂

                    //将电厂下的人员移动到其他区域中
                    var otherArea = new AreaNode();
                    otherArea.Id   = 100000;
                    otherArea.Name = "厂区内";
                    if (park.Persons != null)
                    {
                        foreach (var person in park.Persons)
                        {
                            otherArea.AddPerson(person);
                        }
                        park.Persons.Clear();
                    }
                    if (park.Children == null)
                    {
                        park.Children = new List <AreaNode>();
                    }
                    park.Children.Add(otherArea);
                    //root = park;//将电厂做为根节点
                    //考虑多种场景切换,这里还是不设置哪个为根节点了
                }
                if (view == 4 || view == 5 || view == 6)
                {
                    RemoveEmptyNodes(root);
                }

                SumNodeCount(root);

                //if (root.Children.Count == 0)
                //{
                //    root.Children = null;
                //}

                SetChildrenNull(root);

                return(root);
            }
            catch (System.Exception ex)
            {
                Log.Error(tag, "GetBasicTree", ex.ToString());
                return(null);
            }
        }