/// <summary>
    /// 设置选择节点
    /// </summary>
    /// <param name="dep"></param>
    public void SetSelectNode(DepNode lastDep, DepNode currentDep)
    {
        TreeNode <TreeViewItem> lastNode    = null;
        TreeNode <TreeViewItem> currentNode = null;

        for (int i = 0; i < AreaList.Count; i++)
        {
            PhysicalTopology topoTemp = AreaList[i].Item.Tag as PhysicalTopology;
            if (topoTemp.Id == currentDep.NodeID)
            {
                currentNode = AreaList[i];
            }
            if (lastDep != null)
            {
                if (topoTemp.Id == lastDep.NodeID)
                {
                    lastNode = AreaList[i];
                }
            }
            if (currentNode != null && lastNode != null)
            {
                break;
            }
        }

        if (lastDep != currentDep)
        {
            if (lastNode != null)
            {
                NarrowLastNode(lastNode);
            }
            if (currentNode != null)
            {
                Tree.FindSelectNode(currentNode, false);
            }
        }
    }
Пример #2
0
    public void RefreshPersonnelTree()
    {
        TreeNode <TreeViewItem> node = Tree.SelectedNode;

        foreach (var person in PersonList)
        {
            if (personDic.ContainsKey(person.Id))                       //若该人员存在树里面
            {
                TreeNode <TreeViewItem> personP = personDic[person.Id]; //取出该人员在人员树里面的节点
                PersonNode personNode           = (PersonNode)personP.Item.Tag;
                if (person.ParentId != personNode.ParentId)             //如果该人员现在所在的区域和在之前的区域不相等
                {
                    if (person.ParentId == FactoryNodeNum)
                    {
                        person.ParentId = InFactoryNodeNum;
                    }
                    if (AreaDic.ContainsKey((int)person.ParentId))
                    {
                        SetMinusParentNodepersonnelNum(personP.Parent);
                        personP.Parent      = AreaDic[(int)person.ParentId];//把该人员移到现在所在的区域中
                        personNode.ParentId = person.ParentId;
                        UpdatePersonnelNumOfText(personP.Parent, 1);
                    }
                }
            }
            else
            {
                Log.Info("RefreshPersonnelTree", "AddPerson:" + person.Name);

                TreeNode <TreeViewItem> newperson = CreatePersonnalNode(person); //添加人物节点
                if (newperson != null)
                {
                    //if (AreaDic[(int)person.ParentId] != null)
                    int CurrentParentID = (int)person.ParentId;
                    if (AreaDic.ContainsKey(CurrentParentID) || CurrentParentID == FactoryNodeNum)//上面的写法有问题
                    {
                        if (CurrentParentID == FactoryNodeNum)
                        {
                            CurrentParentID = (int)InFactoryNodeNum;
                        }
                        TreeNode <TreeViewItem> ParentPersonnel = AreaDic[CurrentParentID];
                        newperson.Parent = AreaDic[CurrentParentID];
                        //ParentPersonnel.Nodes.Add(newperson);//这个和上面一句重复了,会导致增加两个相同的节点
                        Log.Info("RefreshPersonnelTree", "SetAddParentNodepersonnelNum:" + person.Name);
                        UpdatePersonnelNumOfText(newperson.Parent, 1);
                    }
                }
            }
        }

        RomvePersonnelNode(personDic, PersonList);
        if (node != null && node.Item.Tag is PersonNode)
        {
            PersonNode     per = node.Item.Tag as PersonNode;
            LocationObject currentLocationFocusObj = LocationManager.Instance.currentLocationFocusObj;
            if (currentLocationFocusObj != null && currentLocationFocusObj.personnel.Id != per.Id)
            {
                Tree.FindSelectNode(node);
            }
        }
    }