private void LoadAreaTree() { var tree = areaService.GetTree(1); if (tree == null) { return; } var devList = tree.GetAllDev(); var archorList = archorService.GetList(); foreach (var dev in devList) { if (archorList != null) { dev.DevDetail = archorList.FirstOrDefault(i => i.DevInfoId == dev.Id); } } var topoTree = ResourceTreeView1.TopoTree; topoTree.AreaMenu = new ContextMenu(); topoTree.AreaMenu.AddMenu("添加区域", (obj) => { var area = topoTree.SelectedObject as AreaEntity; var win = new NewAreaWindow(area); win.ShowPointEvent += (x, y) => { AreaCanvas1.ShowPoint(x, y); }; if (win.ShowDialog() == true) { var newArea = win.NewArea; area.AddChild(newArea.ToTModel()); topoTree.RefreshCurrentNode <AreaEntity, DevEntity>(area); AreaCanvas1.Refresh(); } }); topoTree.AreaMenu.AddMenu("设置区域", (tag) => { var area = topoTree.SelectedObject as AreaEntity; ShowAreaInfo(area); }); topoTree.AreaMenu.AddMenu("删除区域", (tag) => { var area = topoTree.SelectedObject as AreaEntity; RemoveArea(area); }); topoTree.AreaMenu.AddMenu("添加基站", (tag) => { var area = topoTree.SelectedObject as AreaEntity; var archor = new TArchor(); archor.X = 10; archor.Y = 10; archor.Name = "NewArchor"; archor.Code = ""; archor.Ip = ""; archor.ParentId = area.Id; var archorNew = archorService.Post(archor); archorNew.Code = "Code_" + archorNew.Id; archorService.Put(archorNew); area.AddLeaf(archorNew.DevInfo); topoTree.RefreshCurrentNode <AreaEntity, DevEntity>(area); AreaCanvas1.Refresh(); }); //topoTree.AreaMenu.AddMenu("调整子区域坐标", (tag) => //{ // var area = topoTree.SelectedObject as AreaEntity; // var bound = area.InitBound; // var x = bound.MinX; // var y = bound.MinY; // var boundList = new List<Bound>(); // foreach (var subArea in area.Children) // { // var subBound = subArea.InitBound; // if (subBound != null) // { // var points = subBound.Points; // if (points != null) // { // foreach (var point in points) // { // point.X -= x; // point.Y -= y; // } // bll.Points.EditRange(points.ToDbModel()); // } // subBound.SetMinMaxXY(); // boundList.Add(subBound); // } // } // bll.Bounds.EditRange(boundList.ToDbModel()); //}); topoTree.AreaMenu.AddMenu("复制结构", (tag) => { var area = topoTree.SelectedObject as AreaEntity; var area1 = areaService.GetEntity("240", true); area.InitBound.SetMinMaxXY(); bll.Bounds.Edit(area.InitBound.ToDbModel()); var children = area1.Children.CloneObjectList().ToList(); var newBounds = new List <Bound>(); foreach (var item in children) { if (item.InitBound.Points == null) { item.InitBound.Points = bll.Points.FindAll(i => i.BoundId == item.Id).ToTModel(); } newBounds.Add(item.InitBound); } var dbBounds = newBounds.ToDbModel(); bll.Bounds.AddRange(dbBounds); for (int i = 0; i < children.Count; i++) { AreaEntity item = children[i]; item.ParentId = area.Id; item.InitBoundId = dbBounds[i].Id; } foreach (var item in dbBounds) { var points = item.Points.CloneObjectList(); foreach (var point in points) { point.BoundId = item.Id; } bll.Points.AddRange(points); } var dbChildren = children.ToDbModel(); bll.Areas.AddRange(dbChildren); var devs = area1.LeafNodes.CloneObjectList().ToList();; foreach (var item in devs) { item.ParentId = area.Id; item.Code = ""; item.IP = ""; item.DevDetail = bll.Archors.Find(i => i.DevInfoId == item.Id).ToTModel(); } var dbDevs = devs.ToDbModel(); bll.DevInfos.AddRange(dbDevs); var archors = new List <TModel.Location.AreaAndDev.Archor>(); for (int i = 0; i < devs.Count; i++) { DevEntity dev = devs[i]; var archor = dev.DevDetail as TModel.Location.AreaAndDev.Archor; archor.Code = ""; archor.Ip = ""; archor.ParentId = area.Id; archor.DevInfoId = dbDevs[i].Id; archors.Add(archor); } bll.Archors.AddRange(archors.ToDbModel()); //var archor = new TArchor(); //archor.X = 10; //archor.Y = 10; //archor.Name = "NewArchor"; //archor.Code = ""; //archor.Ip = ""; //archor.ParentId = area.Id; //var archorNew = archorService.Post(archor); //archorNew.Code = "Code_" + archorNew.Id; //archorService.Put(archorNew); //area.AddLeaf(archorNew.DevInfo); topoTree.RefreshCurrentNode <AreaEntity, DevEntity>(area); AreaCanvas1.Refresh(); }); topoTree.DevMenu = new ContextMenu(); topoTree.DevMenu.AddMenu("设置设备", (tag) => { var dev = topoTree.SelectedObject as DevEntity; SetDevInfo(null, dev); }); topoTree.DevMenu.AddMenu("基站配置", (tag) => { //var dev = topoTree.SelectedObject as DevEntity; //SetDevInfo(null, dev); }); topoTree.DevMenu.AddMenu("删除设备", (tag) => { var dev = topoTree.SelectedObject as DevEntity; RemoveDev(dev); }); topoTree.LoadDataEx <AreaEntity, DevEntity>(tree); topoTree.Tree.SelectedItemChanged += Tree_SelectedItemChanged; topoTree.ExpandLevel(2); if (_archors != null) { List <int> ids = new List <int>(); foreach (var archor in _archors) { topoTree.SelectNode((int)archor.ParentId, archor.DevInfoId); ids.Add(archor.DevInfoId); } AreaCanvas1.SelectDevsById(ids); } else { topoTree.SelectFirst(); } }
private void LoadAreaTree() { DbAreaEntity tree1 = null; if (FilterAreaTree == null) { tree1 = bll.GetAreaTree(true, null, true); } else { tree1 = bll.GetAreaTreeEx(false, null, FilterAreaTree); } var tree = tree1.ToTModel(); if (tree == null) { return; } var devList = tree.GetAllDev(); var archorList = archorService.GetList(); foreach (var dev in devList) { if (archorList != null) { dev.DevDetail = archorList.FirstOrDefault(i => i.DevInfoId == dev.Id); } } var topoTree = ResourceTreeView1.TopoTree; var iId = topoTree.SelectedObject as IId; InitTopoTreeAreaMenu(topoTree); InitTopoTreeDevMenu(topoTree); topoTree.LoadDataEx <AreaEntity, DevEntity>(tree); topoTree.Tree.SelectedItemChanged += Tree_SelectedItemChanged; topoTree.ExpandLevel(2); if (_archors != null) { List <int> ids = new List <int>(); foreach (var archor in _archors) { topoTree.SelectNode(typeof(AreaEntity), (int)archor.ParentId, archor.DevInfoId); ids.Add(archor.DevInfoId); } AreaCanvas1.SelectDevsById(ids);// //AreaCanvas1.SelectDevsByIdEx(ids);//把其他的都删除了 } else { if (iId == null) { topoTree.SelectFirst(); } else { topoTree.SelectNodeById(iId); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { DataGrid1.ItemsSource = service.GetList(); CbKey.ItemsSource = new String[] { "Code", "Ip", "Name", "Area" }; CbKey.SelectedIndex = 0; }