コード例 #1
0
        public void GetOrganizationFromDatabase(string ip, bool isadmin)
        {
            var roots = from p in _databaseComponent.GetOrganizationData(ip) where p.Level == 0 && p.Is_Disabled == false orderby p.Sort_No select p;

            foreach (var root in roots.Distinct())//去重复
            {
                if (root.NodeType == 0 && root.Is_Disabled == false)
                {
                    T1_OrganizationPrivilege t_organization = null;
                    if (isadmin == false)
                    {
                        t_organization = (from p in T_OrganizationPrivilege[ip] where p.T_Organization_Guid == root.Guid select p).FirstOrDefault();
                    }
                    if (t_organization != null || isadmin == true)
                    {
                        OrganizationTreeItemViewModel organization = new OrganizationTreeItemViewModel(root, ip);
                        OrganizationTreeItems.Add(organization);
                        GetSubOrganization(organization, ip, isadmin);
                    }
                }
            }

            //新建回收站
            OrganizationTreeItemViewModel recyclednode = new OrganizationTreeItemViewModel("回收站", 0, ip);

            recyclednode.IsExpanded = true;
            RecycledTreeItems.Add(recyclednode);

            //回收站,有问题,htzk123,忘记是否修复了没有
            var recycles = from p in _databaseComponent.GetItemData(ip) where p.Is_Disabled == true orderby p.Modify_Time select p;

            foreach (var recycle in recycles.Distinct())//去重复
            {
                ItemTreeItemViewModel organization = new ItemTreeItemViewModel(recycle);
                recyclednode.AddChild(organization);

                ItemTreeItems.Add(organization);
            }
        }
コード例 #2
0
        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();
        }