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); } }
private void GetSubOrganization(OrganizationTreeItemViewModel parent_organization, string ip, bool isadmin) { if (parent_organization == null) { return; } var childs = from p in _databaseComponent.GetOrganizationData(ip) where p.Parent_Guid == parent_organization.T_Organization.Guid && p.Is_Disabled == false orderby p.Sort_No select p; foreach (var child in childs) { if (child.NodeType == 0 && child.Is_Disabled == false) { T1_OrganizationPrivilege t_organization = null; if (isadmin == false) { t_organization = (from p in T_OrganizationPrivilege[ip] where p.T_Organization_Guid == child.Guid select p).FirstOrDefault(); } if (t_organization != null || isadmin == true) { OrganizationTreeItemViewModel organization = new OrganizationTreeItemViewModel(child, parent_organization); //organization.T_Organization = child; parent_organization.AddChild(organization); GetSubOrganization(organization, ip, isadmin); } } else if (child.NodeType == 1 && child.Is_Disabled == false) { T1_OrganizationPrivilege t_organization = null; if (isadmin == false) { t_organization = (from p in T_OrganizationPrivilege[ip] where p.T_Organization_Guid == child.Guid select p).FirstOrDefault(); } if (t_organization != null || isadmin == true) { DeviceTreeItemViewModel organization = new DeviceTreeItemViewModel(child, parent_organization); parent_organization.AddChild(organization); GetSubOrganization(organization, ip, isadmin); } } else if (child.NodeType == 2 && child.Is_Disabled == false) { ItemTreeItemViewModel organization = new ItemTreeItemViewModel(child, parent_organization as DeviceTreeItemViewModel); parent_organization.AddChild(organization); //测点数据 var t_item = _databaseComponent.GetItemData(ip).Where(p => p.Is_Disabled == false && p.Guid == organization.T_Organization.Guid).FirstOrDefault(); if (t_item != null) { organization.RecoverBind(t_item); t_item.ServerIP = parent_organization.ServerIP;//改为初始化时候填充,覆盖数据库的ServerIP。 //如果彻底删除此项,必须修改//服务器IP匹配20180306 } ItemTreeItems.Add(organization); GetSubOrganization(organization, ip, isadmin); } else if (child.NodeType == 3 && child.Is_Disabled == false) { DivFreTreeItemViewModel organization = new DivFreTreeItemViewModel(child, parent_organization as ItemTreeItemViewModel); //分频数据 var t_divfre = T_DivFreInfo[ip].Where(p => p.Guid == organization.T_Organization.Guid).FirstOrDefault(); if (t_divfre != null) //分频一定不为空 { parent_organization.AddChild(organization); //否则丢弃无效分频数据 organization.T_DivFreInfo = t_divfre; DivFreTreeItems.Add(organization); //GetSubOrganization(organization, ip, isadmin);//分频下无节点 } } } }