public void InitOrganizations(bool isadmin) { //从数据库取出,去重复 OrganizationTreeItems.Clear(); RecycledTreeItems.Clear(); //测点数据 ItemTreeItems.Clear(); foreach (var item in _databaseComponent.GetServerIPCategory()) { GetOrganizationFromDatabase(item, isadmin); } }
private void getTree() { node1 = new OrganizationTreeItemViewModel("北京航天智控测试工厂", 0, "192.168.0.210"); node1_1 = new OrganizationTreeItemViewModel("厂区1", 2, node1); node1_2 = new OrganizationTreeItemViewModel("厂区2", 1, node1); node1_3 = new OrganizationTreeItemViewModel("厂区3", 0, node1); node1_1_1 = new DeviceTreeItemViewModel("设备1", 2, node1_1); node1_1_2 = new DeviceTreeItemViewModel("设备2", 1, node1_1); node1_1_3 = new DeviceTreeItemViewModel("设备3", 0, node1_1); node1_1_1_1 = new ItemTreeItemViewModel("测点1", 2, node1_1_1); node1_1_1_2 = new ItemTreeItemViewModel("测点2", 1, node1_1_1); node1_1_1_3 = new ItemTreeItemViewModel("测点3", 0, node1_1_1); node1_1_2_1 = new ItemTreeItemViewModel("测点4", 2, node1_1_2); node1_1_2_2 = new ItemTreeItemViewModel("测点5", 1, node1_1_2); node1_1_2_3 = new ItemTreeItemViewModel("测点6", 0, node1_1_2); node1_1_3_1 = new ItemTreeItemViewModel("测点7", 2, node1_1_3); node1_1_3_2 = new ItemTreeItemViewModel("测点8", 1, node1_1_3); node1_1_3_3 = new ItemTreeItemViewModel("测点9", 0, node1_1_3); node2 = new OrganizationTreeItemViewModel("测试工厂1", 3, ""); node3 = new OrganizationTreeItemViewModel("测试工厂2", 2, ""); node4 = new OrganizationTreeItemViewModel("测试工厂3", 1, ""); OrganizationTreeItems.Clear(); List <ItemTreeItemViewModel> item1 = new List <ItemTreeItemViewModel>(); item1.Add(node1_1_1_1); item1.Add(node1_1_1_2); item1.Add(node1_1_1_3); node1_1_1.AddChildRange(from p in item1 orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <ItemTreeItemViewModel> item2 = new List <ItemTreeItemViewModel>(); item2.Add(node1_1_2_1); item2.Add(node1_1_2_2); item2.Add(node1_1_2_3); node1_1_2.AddChildRange(from p in item2 orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <ItemTreeItemViewModel> item3 = new List <ItemTreeItemViewModel>(); item3.Add(node1_1_3_1); item3.Add(node1_1_3_2); item3.Add(node1_1_3_3); node1_1_3.AddChildRange(from p in item3 orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <DeviceTreeItemViewModel> device = new List <DeviceTreeItemViewModel>(); device.Add(node1_1_1); device.Add(node1_1_2); device.Add(node1_1_3); node1_1.AddChildRange(from p in device orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <OrganizationTreeItemViewModel> organization = new List <OrganizationTreeItemViewModel>(); organization.Add(node1_1); organization.Add(node1_2); organization.Add(node1_3); node1.AddChildRange(from p in organization orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <OrganizationTreeItemViewModel> root = new List <OrganizationTreeItemViewModel>(); root.Add(node1); root.Add(node2); root.Add(node3); root.Add(node4); OrganizationTreeItems.AddRange(from p in root orderby p.T_Organization.Sort_No select p); RecycledTreeItems.Clear(); OrganizationTreeItemViewModel recyclednode = new OrganizationTreeItemViewModel("回收站", 0, "192.168.0.1"); recyclednode.IsExpanded = true; RecycledTreeItems.Add(recyclednode); //SaveOrganizationToDatabase(); //SaveItemToDatabase(); }