Esempio n. 1
0
        public bool IncludeChildrenOPCNodes(ICollection <FreeHierarchyTreeItem> children, bool isSelected = false, HashSet <long> selectedNodes = null,
                                            bool includeChildren = true)
        {
            if (HierObject == null)
            {
                return(false);
            }
            Descriptor.NeedFindUaNode = true;
            var mainNode = HierObject as TUANode;
            var result   = false;

            if (mainNode == null || mainNode.DependentNodes == null)
            {
                return(false);
            }
            IsUaNodesInitializet = true;
            var uadependentnodes = UAHierarchyDictionaries.UANodesDict.GetValues(
                new HashSet <long>(mainNode.DependentNodes
                                   .Where(c => c.UAReferenceType != EnumOpcReferenceType.HasTypeDefinition)
                                   .Select(c => c.UANodeId)), Manager.UI.ShowMessage);

            //Перебор всех зависимых OPC узлов
            foreach (var dependentNode in uadependentnodes)
            {
                UserRightsForTreeObject right;
                var isExistsRight = Manager.User.AccumulateRightsAndVerify(dependentNode, EnumObjectRightType.SeeDbObjects, HierObject.GetObjectRightType(), out right);


                var selected = isSelected || (selectedNodes != null && selectedNodes.Contains(dependentNode.UANodeId));

                var newItem = new FreeHierarchyTreeItem(Descriptor, dependentNode, selected, string.Empty, Descriptor.GetMinIdAndDecrement(), this, true,
                                                        nodeRights: right, freeHierItemType: EnumFreeHierarchyItemType.UANode);

                var isExistsChildSeeDbObjects = false;
                if (children.Any(i => i.GetKey == newItem.GetKey))
                {
                    // newItem.Dispose();
                    return(result);
                }
                if (includeChildren)
                {
                    isExistsChildSeeDbObjects = newItem.IncludeChildrenOPCNodes(newItem.Children, isSelected, selectedNodes);
                }

                //У объекта есть права на просмотр, или на дочерний объект
                if (isExistsRight || isExistsChildSeeDbObjects)
                {
                    children.Add(newItem);
                    Descriptor.Tree.TryAdd(newItem.FreeHierItem_ID, newItem);

                    result = true;
                }
                else
                {
                    newItem.Dispose();
                }
            }

            return(result);
        }
        /// <summary>
        /// Генерация дерева (списка) балансов (приложения 63) для выгрузки xml
        /// </summary>
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateBalance63Tree(FreeHierarchyTreeDescriptor descriptor)
        {
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();

            var rootNodes = DeclaratorService.Service.Get_ExportService_Balances63();

            if (rootNodes == null)
            {
                return(result);
            }

            foreach (var rootNode in rootNodes)
            {
                var newItemNode = new FreeHierarchyTreeItem(descriptor, rootNode, false, string.Empty,
                                                            descriptor.GetMinIdAndDecrement(), null, true, nodeRights: null,
                                                            freeHierItemType: EnumFreeHierarchyItemType.FiasFullAddress);
                //{
                //    StringName = rootNode.StringName,
                //};

                newItemNode.Descriptor.Tree = result;

                //newItemNode.UpdateCountParents();

                result[newItemNode.FreeHierItem_ID] = newItemNode;
            }

            return(result);
        }
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateOldTelescopeTree(FreeHierarchyTreeDescriptor descriptor)
        {
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();

            var rootNodes = EnumClientServiceDictionary.OldTelescopeTreeNodes.Values.Where(i => i.TreeLevel == 0);

            if (rootNodes == null)
            {
                return(result);
            }

            foreach (var rootNode in rootNodes)
            {
                rootNode.Parent_Absolute_Number = ""; //иначе зацикливание где нибудь будет

                var newItemNode = new FreeHierarchyTreeItem(descriptor, rootNode, false, string.Empty,
                                                            descriptor.GetMinIdAndDecrement(), null, true, nodeRights: null,
                                                            freeHierItemType: EnumFreeHierarchyItemType.OldTelescopeTreeNode);

                newItemNode.Descriptor.Tree = result;

                result[newItemNode.FreeHierItem_ID] = newItemNode;
            }

            return(result);
        }
Esempio n. 4
0
        public bool IncludeChildrenSection(int parentID, enumTypeHierarchy parentType, ICollection <FreeHierarchyTreeItem> children)
        {
            var isExistsSeeDbRights = false;

            foreach (var section in GlobalSectionsDictionary.SectionsList.Values.Where(s => s.TypeParentHierarchy == parentType && s.ParentId == parentID))
            {
                UserRightsForTreeObject right;
                if (!Manager.User.AccumulateRightsAndVerify(section, EnumObjectRightType.SeeDbObjects, HierObject.GetObjectRightType(), out right))
                {
                    continue;
                }

                isExistsSeeDbRights = true;


                var newItem = new FreeHierarchyTreeItem(Descriptor, section, false, string.Empty, Descriptor.GetMinIdAndDecrement(), this, true,
                                                        nodeRights: right, freeHierItemType: EnumFreeHierarchyItemType.Section);

                children.Add(newItem);
                Descriptor.Tree.TryAdd(newItem.FreeHierItem_ID, newItem);
                newItem.Descriptor.Tree = Descriptor.Tree;
                newItem.LoadStaticChildren(true);
            }

            return(isExistsSeeDbRights);
        }
Esempio n. 5
0
        private bool IncludeForecastObjectChildren(ICollection <FreeHierarchyTreeItem> children)
        {
            bool result = false;

            //Добавлем все константы формул
            var forecastObject = HierObject as TForecastObject;

            if (forecastObject == null || forecastObject.Children == null)
            {
                return(result);
            }

            //EnumClientServiceDictionary.ForecastObjectsDictionary.Prepare(new HashSet<string>(forecastObject.Children));

            foreach (var forecastObjectUn in forecastObject.Children)
            {
                var forecastObjectChild = EnumClientServiceDictionary.ForecastObjectsDictionary[forecastObjectUn];
                if (forecastObjectChild != null)
                {
                    var newItem = new FreeHierarchyTreeItem(Descriptor, forecastObjectChild, false, string.Empty, Descriptor.GetMinIdAndDecrement(), this, true,
                                                            freeHierItemType: EnumFreeHierarchyItemType.ForecastObject);

                    children.Add(newItem);
                    Descriptor.Tree.TryAdd(newItem.FreeHierItem_ID, newItem);
                    newItem.Descriptor.Tree = Descriptor.Tree;

                    newItem.IncludeForecastObjectChildren(newItem.Children);

                    result = true;
                }
            }

            return(result);
        }
        /// <summary>
        /// Генерация стандартного дерева ПС
        /// </summary>
        /// <returns></returns>
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateStandartTreePS(FreeHierarchyTreeDescriptor descriptor, bool isHideTi)
        {
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();

            var hiers1 = EnumClientServiceDictionary.HierLev1List.Values;


            var filterStatus = descriptor.FilterStatus;

            foreach (var item in hiers1.OrderBy(v => v.Item)) //сортируем по названию
            {
                if (item == null ||
                    (filterStatus.HasValue && (item.TIStatus & filterStatus.Value) == EnumTIStatus.None) || //Используется фильтр на дереве
                    !IsGlobalFilterHaveItem(item))    //Глобальный фильтр
                {
                    continue;
                }

                var isExistsChildSeeDbObjects = Manager.User.IsAssentRight(item, EnumObjectRightType.SeeDbObjects, null);

                if (!isExistsChildSeeDbObjects && //Нет собственных прав
                    !FreeHierarchyTreePreparer.ExistsStandartChildSeeDbObjects(item, descriptor.Tree_ID ?? -101, true)   //И нет дочерних объектов с правами
                    )
                {
                    continue;
                }

                var newItem = new FreeHierarchyTreeItem(descriptor, item, false, item.Name, descriptor.GetMinIdAndDecrement(), null, true, isHideTi, item.ObjectRights,
                                                        EnumFreeHierarchyItemType.HierLev1)
                {
                    Descriptor =
                    {
                        Tree = result
                    }
                };

                if (newItem.IncludeObjectChildren)
                {
                    isExistsChildSeeDbObjects = newItem.LoadStaticChildren(isExistsChildSeeDbObjects, isHideTi);
                }

                //У объекта нет прав на просмотр, или нет дочерних объектов на которые есть такие права
                //if (isExistsRight || isExistsChildSeeDbObjects)
                //{
                result[newItem.FreeHierItem_ID] = newItem;
                //}
                //else
                //{
                //    newItem.Dispose();
                //}
            }
            //if (FreeHierarchyTreeDescriptor.Sort != null) FreeHierarchyTreeDescriptor.Sort(items);
            //foreach (var i in items) result[i.FreeHierItem_ID] = i;
            return(result);
        }
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateStandartTreeBySupplyPS(FreeHierarchyTreeDescriptor descriptor, bool isHideTi)
        {
            var items  = new List <FreeHierarchyTreeItem>();
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();

            foreach (var value in from ps in EnumClientServiceDictionary.DetailPSList
                     join ps_sup in GlobalTreeDictionary.PowerSupply_PS_List on ps.Key equals ps_sup.PS_ID into temp
                     from ps_t in temp.DefaultIfEmpty()
                     where ps_t == null
                     orderby ps.Value.Name
                     select ps.Value)
            {
                if (!IsGlobalFilterHaveItem(value))
                {
                    continue;
                }

                UserRightsForTreeObject right;
                if (!Manager.User.AccumulateRightsAndVerify(value, EnumObjectRightType.SeeDbObjects, value.GetObjectRightType(), out right))
                {
                    continue;
                }

                FreeHierarchyTreeItem newItem = new FreeHierarchyTreeItem(descriptor, value, nodeName: value.Name)
                {
                    FreeHierItem_ID       = descriptor.GetMinIdAndDecrement(),
                    IncludeObjectChildren = true,
                    IsHideTi         = isHideTi,
                    FreeHierItemType = EnumFreeHierarchyItemType.PS,
                    NodeRights       = right,
                };

                items.Add(newItem);
                newItem.Descriptor.Tree = result;
                if (newItem.IncludeObjectChildren)
                {
                    newItem.LoadStaticChildren(true, isHideTi);
                    newItem.Descriptor.NeedFindTI = true;
                }
            }
            if (FreeHierarchyTreeDescriptor.Sort != null)
            {
                FreeHierarchyTreeDescriptor.Sort(items);
            }
            foreach (var i in items)
            {
                result[i.FreeHierItem_ID] = i;
            }
            return(result);
        }
        private static FreeHierarchyTreeItem Create_FreeHierarchyTreeItem(int minID, KeyValuePair <Guid, TFIASNode> obj, FreeHierarchyTreeDescriptor descriptor)
        {
            var newItemNode = new FreeHierarchyTreeItem(descriptor, obj.Value)
            {
                FreeHierItem_ID       = minID,
                IncludeObjectChildren = true,
                FreeHierItemType      = EnumFreeHierarchyItemType.FiasFullAddress,
                NodeRights            = null,
                StringName            = obj.Value.StringName,
                FIASNode = obj.Value,
            };

            return(newItemNode);
        }
        public static ID_TypeHierarchy AsTypeHierarchy(this FreeHierarchyTreeItem item)
        {
            if (item == null)
            {
                return(null);
            }

            return(new ID_TypeHierarchy
            {
                ID = item.HierObject.Id,
                StringId = item.HierObject.StringId,
                TypeHierarchy = item.HierObject.Type,
                FreeHierItemId = item.FreeHierItem_ID < 0 ? null : (int?)item.FreeHierItem_ID
            });
        }
        /// <summary>
        /// Генерация стандартного дерева FIAS адреса, которые используются
        /// </summary>
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateStandartTree_FIAS(bool IncludeHerarchyObjects, FreeHierarchyTreeDescriptor descriptor)
        {
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();

            //добавляем корневые узлы
            IEnumerable <TFIASNode> rootNodes;

            if (!IncludeHerarchyObjects)
            {
                rootNodes = DeclaratorService.FIAS_Get_RootNodes();
            }
            else
            {
                rootNodes = DeclaratorService.FIASToHierarchy_Get_RootNodes();
            }

            if (rootNodes == null)
            {
                return(result);
            }

            foreach (var rootNode in rootNodes)
            {
                var newItemNode = new FreeHierarchyTreeItem(descriptor, rootNode, false, string.Empty, descriptor.GetMinIdAndDecrement(), null, true, nodeRights: null,
                                                            freeHierItemType: EnumFreeHierarchyItemType.FiasFullAddress)
                {
                    StringName = rootNode.StringName,
                    FIASNode   = rootNode,
                };

                newItemNode.Descriptor.Tree = result;

                //newItemNode.UpdateCountParents();

                //добавляем дочерние
                if (rootNode.IsChildrenExists)
                {
                    newItemNode.IncludeChildrenFIASNodes((rootNode.IsHierObjectExists || descriptor.Tree_ID == TreeTypeStandart_Dict_FIASToHierarchy));
                }

                result[newItemNode.FreeHierItem_ID] = newItemNode;
            }

            return(result);
        }
Esempio n. 11
0
        // добавление ТП
        private static void addTP(FreeHierarchyTreeItem parent, TPoint tp, ref int minID,
                                  FreeHierarchyTreeDescriptor descriptor, ConcurrentDictionary <int, FreeHierarchyTreeItem> result, List <int> removedTp)
        {
            minID--;
            var newTP = new FreeHierarchyTreeItem(descriptor, tp)
            {
                FreeHierItem_ID       = minID,
                FreeHierItemType      = EnumFreeHierarchyItemType.TP,
                Parent                = parent,
                NodeRights            = parent.HierObject.GetObjectRightType(),
                IsChildrenInitializet = true,
            };

            parent.Children.Add(newTP);
            result.TryAdd(minID, newTP);
            removedTp.Add(minID);
            newTP.Descriptor.Tree = result;
        }
Esempio n. 12
0
        private void IncludeChildrenBalances(ICollection <FreeHierarchyTreeItem> chidren)
        {
            //var objectIds = new HashSet<ID_TypeHierarchy>(chidren.Where(o=>o.HierObject!=null).Select(o => new ID_TypeHierarchy
            //{
            //    TypeHierarchy = o.HierObject.Type,
            //    ID = o.HierObject.Id,
            //    StringId = o.HierObject.StringId,
            //}), new ID_TypeHierarchy_EqualityComparer());

            //EnumClientServiceDictionary.FreeHierarchyBalances.Prepare(objectIds, Manager.UI.ShowMessage);

            if (HierObject == null)
            {
                return;
            }

            List <ServiceReference.ARM_20_Service.Info_Balance_FreeHierarchy_List> objectBalances;

            if (!EnumClientServiceDictionary.FreeHierarchyBalancesByParent.TryGetValue(new ID_TypeHierarchy
            {
                TypeHierarchy = HierObject.Type,
                ID = HierObject.Id,
                StringId = HierObject.StringId,
            }, out objectBalances, false) || objectBalances == null || objectBalances.Count == 0)
            {
                return;
            }

            foreach (var balance in objectBalances)
            {
                if (balance.BalanceFreeHierarchyType_ID > 1)
                {
                    continue;                                          //Допустимы только балансы ЭЭ
                }
                var newItem = new FreeHierarchyTreeItem(Descriptor, balance, false, string.Empty,
                                                        Descriptor.GetMinIdAndDecrement(), this, true,
                                                        freeHierItemType: EnumFreeHierarchyItemType.UniversalBalance, isChildrenInitializet: true);

                chidren.Add(newItem);
                Descriptor.Tree.TryAdd(newItem.FreeHierItem_ID, newItem);
                newItem.Descriptor.Tree = Descriptor.Tree;
            }
        }
Esempio n. 13
0
 public void RemoveAddSelected(bool isAdd, FreeHierarchyTreeItem item)
 {
     if (_treeItemsSyncLock.TryEnterWriteLock(TimeSpan.FromSeconds(5)))
     {
         try
         {
             if (isAdd)
             {
                 SelectedItems[item.FreeHierItem_ID] = item;
             }
             else
             {
                 SelectedItems.Remove(item.FreeHierItem_ID);
             }
         }
         finally
         {
             _treeItemsSyncLock.ExitWriteLock();
         }
     }
 }
Esempio n. 14
0
        private void IncludeChildrenFormulaConstant(ICollection <FreeHierarchyTreeItem> chidren)
        {
            //Добавлем все константы формул
            var withChildrenObject = HierObject as IFreeHierarchyObjectWithChildren;

            if (withChildrenObject == null || withChildrenObject.FormulaConstants == null)
            {
                return;
            }

            var isSelected = IsSelectedChildren;

            foreach (var constant in withChildrenObject.FormulaConstants)
            {
                var newItem = new FreeHierarchyTreeItem(Descriptor, constant, isSelected, string.Empty,
                                                        Descriptor.GetMinIdAndDecrement(), this, true,
                                                        freeHierItemType: EnumFreeHierarchyItemType.FormulaConstant, isChildrenInitializet: true);

                chidren.Add(newItem);
                Descriptor.Tree.TryAdd(newItem.FreeHierItem_ID, newItem);
                newItem.Descriptor.Tree = Descriptor.Tree;
            }
        }
Esempio n. 15
0
        public bool IncludeChildrenFormulas(long parentID, enumTypeHierarchy parentType, ICollection <FreeHierarchyTreeItem> children)
        {
            if (EnumClientServiceDictionary.FormulasList == null)
            {
                return(false);
            }
            bool result = false;

            var isSelected = IsSelectedChildren;

            foreach (var f in EnumClientServiceDictionary.FormulasList.Where(i => i.Value.ParentId == parentID && i.Value.ParentType == parentType))
            {
                var newItem = new FreeHierarchyTreeItem(Descriptor, f.Value, isSelected, string.Empty, Descriptor.GetMinIdAndDecrement(), this, true,
                                                        freeHierItemType: EnumFreeHierarchyItemType.Formula, isChildrenInitializet: true);

                children.Add(newItem);
                Descriptor.Tree.TryAdd(newItem.FreeHierItem_ID, newItem);
                newItem.Descriptor.Tree = Descriptor.Tree;
                result = true;
            }

            return(result);
        }
Esempio n. 16
0
        public void Dispose()
        {
            try
            {
                FreeHierarchyTree = null;

                SelectedChanged = null;

                SelectedItems = null;

                //ContextMenu = null;
                //if (Tree != null && Tree.Count > 0)
                //{
                //    foreach (var t in Tree.Values.ToList())
                //    {
                //        if (t == null) continue;

                //        t.Dispose();
                //    }
                //    Tree = null;
                //}

                if (PreviousSelected != null)
                {
                    PreviousSelected.Dispose();
                    PreviousSelected = null;
                }

                if (Tree != null)
                {
                    Tree = null;
                }
            }
            catch
            {
            }
        }
Esempio n. 17
0
        private static bool buildParents(FreeHierarchyTreeItem item, bool isFactPowerTree, bool isExistsContractRight, bool isExistsChildSeeDbObjects, ref int minID, out UserRightsForTreeObject parentRights)
        {
            parentRights          = null;
            isExistsContractRight = isExistsContractRight | Manager.User.IsAssentRight(item.NodeRights, EnumObjectRightType.SeeDbObjects);

            int parentID = -1;
            enumTypeHierarchy parentType = enumTypeHierarchy.Unknown;

            var juridicalPerson = item.HierObject as TJuridicalPerson;

            if (juridicalPerson != null && juridicalPerson.ParrentID != null)
            {
                //Не строим юр. лица у которых отсутствует родитель
                parentID   = juridicalPerson.ParrentID.ID;
                parentType = juridicalPerson.ParrentID.TypeHierarchy;
            }
            else
            {
                var section = item.HierObject as TSection;
                if (section != null)
                {
                    parentID   = section.ParentId;
                    parentType = section.TypeParentHierarchy;
                }
            }

            bool isNew = true, isNewNext = false;
            var  saveItem        = item;
            var  isParrentExists = true;

            //Права уровня ПС
            UserRightsForTreeObject hietLevPsRights = null;

            //Права уровня 3
            UserRightsForTreeObject hietLev3Rights = null;

            //Права уровня 2
            UserRightsForTreeObject hietLev2Rights = null;

            var removedFreeItems = new Stack <Tuple <FreeHierarchyTreeItem, bool> >();

            while (isParrentExists && parentType != enumTypeHierarchy.Dict_HierLev0)
            {
                switch (parentType)
                {
                case enumTypeHierarchy.Dict_PS:
                    TPSHierarchy ps;
                    if (!EnumClientServiceDictionary.DetailPSList.TryGetValue(parentID, out ps) || ps == null)
                    {
                        isParrentExists = false;
                        break;
                    }

                    if (isFactPowerTree)
                    {
                        Manager.User.AccumulateRightsAndVerify(ps, EnumObjectRightType.SeeDbObjects, null, out hietLevPsRights);
                        FreeHierarchyTreeItem psFreeHierarchyTreeItem =
                            item.Descriptor.Tree.Select(i => i.Value)
                            .FirstOrDefault(i => i.FreeHierItemType == EnumFreeHierarchyItemType.PS && i.HierObject != null && i.HierObject.Id == parentID);
                        if (psFreeHierarchyTreeItem == null)
                        {
                            minID--;
                            psFreeHierarchyTreeItem = new FreeHierarchyTreeItem(item.Descriptor, ps)
                            {
                                FreeHierItem_ID       = minID,
                                FreeHierItemType      = EnumFreeHierarchyItemType.PS,
                                IsChildrenInitializet = true,
                            };
                            item.Descriptor.Tree.TryAdd(minID, psFreeHierarchyTreeItem);
                            isNewNext = true;
                        }
                        else
                        {
                            isNewNext = false;
                        }
                        if (isNew)
                        {
                            psFreeHierarchyTreeItem.Children.Add(item);
                        }
                        removedFreeItems.Push(new Tuple <FreeHierarchyTreeItem, bool>(psFreeHierarchyTreeItem, isNew));
                        isNew       = isNewNext;
                        item.Parent = psFreeHierarchyTreeItem;
                        item        = psFreeHierarchyTreeItem;
                    }

                    parentID   = ps.ParentId;
                    parentType = enumTypeHierarchy.Dict_HierLev3;
                    break;

                case enumTypeHierarchy.Dict_HierLev3:
                    THierarchyDbTreeObject hier3Hierarchy;
                    if (!EnumClientServiceDictionary.HierLev3List.TryGetValue(parentID, out hier3Hierarchy) || hier3Hierarchy == null)
                    {
                        isParrentExists = false;
                        break;
                    }

                    if (isFactPowerTree)
                    {
                        Manager.User.AccumulateRightsAndVerify(hier3Hierarchy, EnumObjectRightType.SeeDbObjects, null, out hietLev3Rights);
                        FreeHierarchyTreeItem hierLev3FreeHierarchyTreeItem =
                            item.Descriptor.Tree.Values
                            .FirstOrDefault(i => i.FreeHierItemType == EnumFreeHierarchyItemType.HierLev3 && i.HierObject != null && i.HierObject.Id == parentID);
                        if (hierLev3FreeHierarchyTreeItem == null)
                        {
                            minID--;
                            hierLev3FreeHierarchyTreeItem = new FreeHierarchyTreeItem(item.Descriptor, hier3Hierarchy)
                            {
                                FreeHierItem_ID       = minID,
                                FreeHierItemType      = EnumFreeHierarchyItemType.HierLev3,
                                IsChildrenInitializet = true,
                            };
                            item.Descriptor.Tree.TryAdd(minID, hierLev3FreeHierarchyTreeItem);
                            isNewNext = true;
                        }
                        else
                        {
                            isNewNext = false;
                        }
                        if (isNew)
                        {
                            hierLev3FreeHierarchyTreeItem.Children.Add(item);
                        }
                        removedFreeItems.Push(new Tuple <FreeHierarchyTreeItem, bool>(hierLev3FreeHierarchyTreeItem, isNew));
                        isNew       = isNewNext;
                        item.Parent = hierLev3FreeHierarchyTreeItem;
                        item        = hierLev3FreeHierarchyTreeItem;
                    }
                    parentID   = hier3Hierarchy.ParentId;
                    parentType = enumTypeHierarchy.Dict_HierLev2;
                    break;

                case enumTypeHierarchy.Dict_HierLev2:
                    THierarchyDbTreeObject hier2Hierarchy;
                    if (!EnumClientServiceDictionary.HierLev2List.TryGetValue(parentID, out hier2Hierarchy) || hier2Hierarchy == null)
                    {
                        isParrentExists = false;
                        break;
                    }

                    Manager.User.AccumulateRightsAndVerify(hier2Hierarchy, EnumObjectRightType.SeeDbObjects, null, out hietLev2Rights);

                    FreeHierarchyTreeItem hierLev2 = item.Descriptor.Tree.Select(i => i.Value)
                                                     .FirstOrDefault(i => i.FreeHierItemType == EnumFreeHierarchyItemType.HierLev2 && i.HierObject != null && i.HierObject.Id == parentID);
                    if (hierLev2 == null)
                    {
                        minID--;
                        hierLev2 = new FreeHierarchyTreeItem(item.Descriptor, EnumClientServiceDictionary.HierLev2List[parentID])
                        {
                            FreeHierItem_ID       = minID,
                            FreeHierItemType      = EnumFreeHierarchyItemType.HierLev2,
                            IsChildrenInitializet = true,
                        };
                        item.Descriptor.Tree.TryAdd(minID, hierLev2);
                        isNewNext = true;
                    }
                    else
                    {
                        isNewNext = false;
                    }
                    if (isNew)
                    {
                        hierLev2.Children.Add(item);
                    }
                    removedFreeItems.Push(new Tuple <FreeHierarchyTreeItem, bool>(hierLev2, isNew));
                    isNew       = isNewNext;
                    item.Parent = hierLev2;
                    item        = hierLev2;
                    parentID    = item.HierObject.ParentId;
                    parentType  = enumTypeHierarchy.Dict_HierLev1;
                    break;

                case enumTypeHierarchy.Dict_HierLev1:
                    THierarchyDbTreeObject hier1Hierarchy;
                    if (!EnumClientServiceDictionary.HierLev1List.TryGetValue(parentID, out hier1Hierarchy) || hier1Hierarchy == null)
                    {
                        isParrentExists = false;
                        break;
                    }

                    UserRightsForTreeObject hietLev1Rights = null;
                    isExistsContractRight = Manager.User.AccumulateRightsAndVerify(hier1Hierarchy, EnumObjectRightType.SeeDbObjects, null, out hietLev1Rights) | isExistsChildSeeDbObjects;

                    UserRightsForTreeObject rights = hietLev1Rights;
                    //while (removedFreeItems.Count > 0)
                    var ri = new Stack <Tuple <FreeHierarchyTreeItem, bool> >();
                    while (removedFreeItems.Count > 0)
                    {
                        var removedFreeItem = removedFreeItems.Pop();
                        ri.Push(removedFreeItem);
                        isExistsContractRight = Manager.User.AccumulateRightsAndVerify(removedFreeItem.Item1.HierObject, EnumObjectRightType.SeeDbObjects, rights, out rights) |
                                                isExistsContractRight;
                        removedFreeItem.Item1.NodeRights = rights;
                    }

                    //Проверкак прав, убираем если нет прав
                    if (!isExistsContractRight && !isExistsChildSeeDbObjects)
                    {
                        isParrentExists = false;
                        var removedChild = saveItem;
                        while (ri.Count > 0)
                        {
                            //removedChild.Parent = null;
                            var removedFreeItem = ri.Pop();
                            if (removedFreeItem.Item2)
                            {
                                FreeHierarchyTreeItem removed;
                                removedChild.Descriptor.Tree.TryRemove(removedFreeItem.Item1.FreeHierItem_ID, out removed);
                            }
                            removedFreeItem.Item1.Children.Remove(removedChild);
                            removedChild = removedFreeItem.Item1;
                        }
                        break;
                    }

                    parentRights = rights;

                    FreeHierarchyTreeItem hierLev1 =
                        item.Descriptor.Tree.Select(i => i.Value)
                        .FirstOrDefault(i => i.FreeHierItemType == EnumFreeHierarchyItemType.HierLev1 && i.HierObject != null && i.HierObject.Id == parentID);
                    if (hierLev1 == null)
                    {
                        minID--;
                        hierLev1 = new FreeHierarchyTreeItem(item.Descriptor, EnumClientServiceDictionary.HierLev1List[parentID])
                        {
                            FreeHierItem_ID       = minID,
                            FreeHierItemType      = EnumFreeHierarchyItemType.HierLev1,
                            IsChildrenInitializet = true,
                        };
                        item.Descriptor.Tree.TryAdd(minID, hierLev1);
                        isNewNext = true;
                    }
                    else
                    {
                        isNewNext = false;
                    }
                    if (isNew)
                    {
                        hierLev1.Children.Add(item);
                    }
                    isNew       = isNewNext;
                    item.Parent = hierLev1;
                    item        = hierLev1;
                    parentID    = item.HierObject.ParentId;
                    parentType  = enumTypeHierarchy.Dict_HierLev0;
                    break;

                case enumTypeHierarchy.Unknown:
                    isParrentExists = false;
                    break;
                }
            }

            return(isParrentExists);
        }
Esempio n. 18
0
        public static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateJuridicalPersonTree(FreeHierarchyTreeDescriptor descriptor, bool isFactPowerTree, bool isAddVoidJuridicalPerson)
        {
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();
            int minID  = -1;

            var directConsumerDictionary   = new Dictionary <int, Dictionary <int, FreeHierarchyTreeItem> >();
            var juridicalPersonsDictionary = new Dictionary <int, FreeHierarchyTreeItem>();

            var sectionsWithContracts = new HashSet <int>();

            // Построение договоров
            foreach (var contract in EnumClientServiceDictionary.ContractDict.Values)
            {
                List <int> sectionIds;
                if (EnumClientServiceDictionary.SectionByContract == null || !EnumClientServiceDictionary.SectionByContract.TryGetValue(contract.JuridicalPersonContract_ID, out sectionIds) || sectionIds == null)
                {
                    continue;
                }

                if (isFactPowerTree)
                {
                    sectionsWithContracts.UnionWith(sectionIds);
                }

                UserRightsForTreeObject juridicalPersonRight         = null;
                FreeHierarchyTreeItem   juridicalPersonHierarchyItem = null;
                TJuridicalPerson        juridicalPerson;
                var  isExistsJuridicalPersonRight = false;
                int? rId         = null;
                bool isNewPerson = false;
                // построение Юридических лиц
                if (EnumClientServiceDictionary.JuridicalPersonByContract.TryGetValue(contract.JuridicalPersonContract_ID, out juridicalPerson))
                {
                    isExistsJuridicalPersonRight = Manager.User.AccumulateRightsAndVerify(juridicalPerson, EnumObjectRightType.SeeDbObjects, null, out juridicalPersonRight);
                    isNewPerson = !juridicalPersonsDictionary.TryGetValue(juridicalPerson.Item.JuridicalPerson_ID, out juridicalPersonHierarchyItem);
                    if (isNewPerson || juridicalPersonHierarchyItem == null)
                    {
                        minID--;
                        juridicalPersonHierarchyItem = new FreeHierarchyTreeItem(descriptor, juridicalPerson)
                        {
                            FreeHierItem_ID       = minID,
                            FreeHierItemType      = EnumFreeHierarchyItemType.JuridicalPerson,
                            NodeRights            = juridicalPersonRight,
                            IsChildrenInitializet = true,
                        };

                        // построение родителей иерархической структуры
                        rId = minID;
                        juridicalPersonsDictionary[juridicalPerson.Item.JuridicalPerson_ID] = juridicalPersonHierarchyItem;
                    }
                }

                UserRightsForTreeObject contractRight;
                var isExistsContractRight = Manager.User.AccumulateRightsAndVerify(contract, EnumObjectRightType.SeeDbObjects, juridicalPersonRight, out contractRight);

                minID--;
                var contractTreeId = minID;
                var newContract    = new FreeHierarchyTreeItem(descriptor, contract)
                {
                    FreeHierItem_ID       = minID,
                    FreeHierItemType      = EnumFreeHierarchyItemType.Contract,
                    NodeRights            = contractRight,
                    Parent                = juridicalPersonHierarchyItem,
                    IsChildrenInitializet = true,
                };

                var isExistsChildSeeDbObjects = false;
                var absentSections            = new Dictionary <int, FreeHierarchyTreeItem>();
                var removedItems = new List <int>();
                // построение сечений
                foreach (var section in sectionIds.Select(s => GlobalSectionsDictionary.SectionsList[s]))
                {
                    if (section == null)
                    {
                        continue;
                    }

                    UserRightsForTreeObject sectionRight;
                    var isExistsSectionRight = Manager.User.AccumulateRightsAndVerify(section, EnumObjectRightType.SeeDbObjects, contractRight, out sectionRight);
                    if (sectionRight.IsDeniedRight(EnumObjectRightType.SeeDbObjects))
                    {
                        continue;
                    }

                    minID--;
                    var newSection = new FreeHierarchyTreeItem(descriptor, section)
                    {
                        FreeHierItem_ID       = minID,
                        FreeHierItemType      = EnumFreeHierarchyItemType.Section,
                        Parent                = newContract,
                        NodeRights            = sectionRight,
                        IsChildrenInitializet = true,
                    };
                    var sectionTreeId = minID;
                    var isExistsSectionChildrenRight = false;
                    var removedTp = new List <int>();
                    Dictionary <int, FreeHierarchyTreeItem> dirConsumers;
                    directConsumerDictionary.TryGetValue(section.Section_ID, out dirConsumers);

                    if (section.TP != null)
                    {
                        foreach (var tp in section.TP.OrderBy(s => s.Item.StringName))
                        {
                            if (tp.DirectConsumer_ID != null)
                            {
                                if (dirConsumers == null)
                                {
                                    dirConsumers = new Dictionary <int, FreeHierarchyTreeItem>();
                                    directConsumerDictionary.Add(section.Section_ID, dirConsumers);
                                }

                                FreeHierarchyTreeItem dirCon = null;
                                if (!dirConsumers.TryGetValue(tp.DirectConsumer_ID.Value, out dirCon) || dirCon == null)
                                {
                                    var dc = EnumClientServiceDictionary.DirectConsumers[tp.DirectConsumer_ID.Value];
                                    UserRightsForTreeObject directConsumerRight;
                                    if (!Manager.User.AccumulateRightsAndVerify(dc, EnumObjectRightType.SeeDbObjects, sectionRight, out directConsumerRight))
                                    {
                                        continue;
                                    }
                                    isExistsSectionChildrenRight = true;
                                    minID--;
                                    dirCon = new FreeHierarchyTreeItem(descriptor, dc)
                                    {
                                        FreeHierItem_ID       = minID,
                                        FreeHierItemType      = EnumFreeHierarchyItemType.DirectConsumer,
                                        Parent                = newSection,
                                        NodeRights            = directConsumerRight,
                                        IsChildrenInitializet = true,
                                    };
                                    newSection.Children.Add(dirCon);
                                    result.TryAdd(minID, dirCon);
                                    removedTp.Add(minID);
                                    dirCon.Descriptor.Tree             = result;
                                    dirConsumers[dc.DirectConsumer_ID] = dirCon;
                                }

                                // добавление ТП в объект ЭПУ
                                addTP(dirCon, tp, ref minID, descriptor, result, removedTp);
                            }
                            // добавление ТП в сечение (в случае, если ТП не связано с прямым потребителем)
                            else
                            {
                                addTP(newSection, tp, ref minID, descriptor, result, removedTp);
                            }
                        }
                    }

                    if (isExistsSectionRight || isExistsSectionChildrenRight)
                    {
                        isExistsChildSeeDbObjects = true;
                        newContract.Children.Add(newSection);
                        result.TryAdd(sectionTreeId, newSection);
                        newSection.Descriptor.Tree = result;
                    }
                    else
                    {
                        removedItems.AddRange(removedTp);
                        absentSections.Add(sectionTreeId, newSection);
                    }
                }

                if (juridicalPersonHierarchyItem != null)
                {
                    if (isNewPerson)
                    {
                        UserRightsForTreeObject parentRights;
                        buildParents(juridicalPersonHierarchyItem, isFactPowerTree, isExistsJuridicalPersonRight | isExistsContractRight, isExistsChildSeeDbObjects,
                                     ref minID,
                                     out parentRights);

                        juridicalPersonHierarchyItem.NodeRights = parentRights.AccamulateRights(juridicalPersonRight);
                    }

                    isExistsContractRight = isExistsContractRight |
                                            Manager.User.IsAssentRight(juridicalPersonHierarchyItem.HierObject.GetObjectRightType(), EnumObjectRightType.SeeDbObjects);

                    if (isExistsContractRight || isExistsChildSeeDbObjects)
                    {
                        newContract.NodeRights = newContract.NodeRights.AccamulateRights(juridicalPersonHierarchyItem.NodeRights);
                        //Добавляем пропущенные сечения
                        foreach (var freeHierarchyTreeItem in absentSections)
                        {
                            freeHierarchyTreeItem.Value.NodeRights = freeHierarchyTreeItem.Value.NodeRights.AccamulateRights(juridicalPersonHierarchyItem.NodeRights);
                            newContract.Children.Add(freeHierarchyTreeItem.Value);
                            result.TryAdd(freeHierarchyTreeItem.Key, freeHierarchyTreeItem.Value);
                            freeHierarchyTreeItem.Value.Descriptor.Tree = result;
                            removedItems.Add(freeHierarchyTreeItem.Key);
                            foreach (var sectionChildren in freeHierarchyTreeItem.Value.Children)
                            {
                                sectionChildren.NodeRights = sectionChildren.NodeRights.AccamulateRights(juridicalPersonHierarchyItem.NodeRights);
                            }
                        }

                        if (isNewPerson && rId.HasValue)
                        {
                            juridicalPersonHierarchyItem.Descriptor.Tree = result;
                            result.TryAdd(rId.Value, juridicalPersonHierarchyItem);
                            removedItems.Add(rId.Value);
                        }

                        juridicalPersonHierarchyItem.Children.Add(newContract);
                    }
                }

                if (isExistsContractRight || isExistsChildSeeDbObjects)
                {
                    newContract.Descriptor.Tree = result;
                    result.TryAdd(contractTreeId, newContract);
                }
                else
                {
                    //Удаление т.к. нет прав
                    foreach (var removedItemId in removedItems)
                    {
                        FreeHierarchyTreeItem removed;
                        result.TryRemove(removedItemId, out removed);
                    }
                }
            }


            //Добавляем пропущенные юр. лица (у которых нет привязки к контракту)
            if (isAddVoidJuridicalPerson)
            {
                var contractByPersonDict = EnumClientServiceDictionary.ContractByPersonDict;
                //contractByPersonDict.Prepare(new HashSet<int>(EnumClientServiceDictionary.JuridicalPersonsDict.Values.Select(jp=>jp.Item.JuridicalPerson_ID)));
                foreach (var juridicalPerson in EnumClientServiceDictionary.JuridicalPersonsDict.Values)
                {
                    var id = juridicalPerson.Item.JuridicalPerson_ID;
                    //пропускаем уже добавленные или те на которые нехватает прав
                    if (juridicalPersonsDictionary.ContainsKey(id))
                    {
                        continue;
                    }

                    UserRightsForTreeObject juridicalPersonRight;
                    var isExistsJuridicalPersonRight = Manager.User.AccumulateRightsAndVerify(juridicalPerson, EnumObjectRightType.SeeDbObjects, null, out juridicalPersonRight);

                    var rId = --minID;
                    var juridicalPersonHierarchyItem = new FreeHierarchyTreeItem(descriptor, juridicalPerson)
                    {
                        FreeHierItem_ID  = rId,
                        FreeHierItemType = EnumFreeHierarchyItemType.JuridicalPerson,
                        NodeRights       = juridicalPerson.GetObjectRightType(),
                    };

                    var isExistsContractRight = false;

                    UserRightsForTreeObject parentRights;
                    buildParents(juridicalPersonHierarchyItem, isFactPowerTree, isExistsJuridicalPersonRight, isExistsContractRight,
                                 ref minID,
                                 out parentRights);
                    juridicalPersonHierarchyItem.NodeRights = parentRights.AccamulateRights(juridicalPersonRight);

                    List <Dict_JuridicalPersons_Contract> contracts;
                    if (contractByPersonDict != null && contractByPersonDict.TryGetValue(id, out contracts) && contracts.Count > 0)
                    {
                        //Перебирам контракты для этого юр. лица
                        foreach (var contract in contracts)
                        {
                            UserRightsForTreeObject contractRight;
                            if (!Manager.User.AccumulateRightsAndVerify(contract, EnumObjectRightType.SeeDbObjects, juridicalPersonHierarchyItem.NodeRights, out contractRight))
                            {
                                continue;
                            }

                            isExistsContractRight = true;

                            FreeHierarchyTreeItem newContract = new FreeHierarchyTreeItem(descriptor, contract)
                            {
                                FreeHierItem_ID  = --minID,
                                FreeHierItemType = EnumFreeHierarchyItemType.Contract,
                                NodeRights       = contractRight,
                                Parent           = juridicalPersonHierarchyItem,
                            };

                            newContract.NodeRights      = newContract.NodeRights.AccamulateRights(juridicalPersonHierarchyItem.NodeRights);
                            newContract.Descriptor.Tree = result;
                            juridicalPersonHierarchyItem.Children.Add(newContract);
                            result.TryAdd(minID, newContract);
                        }
                    }

                    if (Manager.User.IsAssentRight(juridicalPersonHierarchyItem.NodeRights, EnumObjectRightType.SeeDbObjects) || isExistsContractRight)
                    {
                        juridicalPersonHierarchyItem.Descriptor.Tree = result;
                        result.TryAdd(rId, juridicalPersonHierarchyItem);
                    }
                }
            }

            if (isFactPowerTree)
            {
                // добавление оставшихся сечений (те, что не привязаны к юр.лицам и договорам)
                foreach (var section in GlobalSectionsDictionary.SectionsList.Values)
                {
                    if (section.Section_ID <= 0 || sectionsWithContracts.Contains(section.Section_ID))
                    {
                        continue;
                    }

                    minID--;
                    UserRightsForTreeObject sectionRight;
                    var isExistsSectionRight = Manager.User.AccumulateRightsAndVerify(section, EnumObjectRightType.SeeDbObjects, null, out sectionRight);

                    var newSection = new FreeHierarchyTreeItem(descriptor, section)
                    {
                        FreeHierItem_ID  = minID,
                        FreeHierItemType = EnumFreeHierarchyItemType.Section,
                    };

                    var rId = minID;
                    newSection.Descriptor.Tree = result;
                    // построение родителей иерархической структуры
                    UserRightsForTreeObject parentRights = null;
                    buildParents(newSection, true, isExistsSectionRight, isExistsSectionRight, ref minID, out parentRights);
                    newSection.NodeRights = parentRights;

                    if (section.TP != null)
                    {
                        result[rId] = newSection;
                        var removedTp = new List <int>();
                        foreach (var tp in section.TP)
                        {
                            addTP(newSection, tp, ref minID, descriptor, result, removedTp);
                        }
                    }
                }
            }

            // просчет кол-ва элементов всех узлов и сортировка
            countElements(result.Where(i => i.Value.Parent == null).Select(i => i.Value));

            return(result);
        }
        /// <summary>
        /// Генерация стандартного дерева Список OPCUA серверов
        /// </summary>
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateStandartTree_Dict_OPCUAServers(FreeHierarchyTreeDescriptor descriptor)
        {
            var items     = new List <FreeHierarchyTreeItem>();
            var result    = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();
            var uaServers = UAHierarchyDictionaries.UaServers(Manager.UI.ShowMessage);

            if (uaServers == null)
            {
                return(null);
            }

            descriptor.NeedFindUaNode = true;

            foreach (var item in uaServers.Values)
            {
                UserRightsForTreeObject right;
                if (!Manager.User.AccumulateRightsAndVerify(item, EnumObjectRightType.SeeDbObjects, null, out right))
                {
                    continue;
                }

                var newItem = new FreeHierarchyTreeItem(descriptor, item)
                {
                    FreeHierItem_ID       = descriptor.GetMinIdAndDecrement(),
                    IncludeObjectChildren = true,
                    IsHideTi         = false,
                    FreeHierItemType = EnumFreeHierarchyItemType.UAServer,
                    NodeRights       = null,
                };

                newItem.Descriptor.Tree = result;

                items.Add(newItem);

                //дабавляем корневые узлы вручную
                //дальше будут подгружаться при раскрытии?
                List <TUANode> rootNodes = UAService.Service.UA_Get_RootNodes(item.UAServer_ID);
                foreach (var rootNode in rootNodes)
                {
                    TUANode node = null;
                    UAHierarchyDictionaries.UANodesDict.TryGetValue(rootNode.UANodeId, out node);
                    if (node == null)
                    {
                        continue;
                    }

                    FreeHierarchyTreeItem newItemNode = new FreeHierarchyTreeItem(newItem.Descriptor, node)
                    {
                        FreeHierItem_ID       = descriptor.GetMinIdAndDecrement(),
                        Parent                = newItem,
                        IncludeObjectChildren = true,
                        FreeHierItemType      = EnumFreeHierarchyItemType.UANode,
                        NodeRights            = right,
                    };

                    newItem.Children.Add(newItemNode);
                    newItem.Descriptor.Tree.TryAdd(newItemNode.FreeHierItem_ID, newItemNode);

                    //добавляем дочерние
                    //newItemNode.IncludeChildrenOPCNodes(newItemNode.Children, false);
                }
            }
            if (FreeHierarchyTreeDescriptor.Sort != null)
            {
                FreeHierarchyTreeDescriptor.Sort(items);
            }
            foreach (var i in items)
            {
                result[i.FreeHierItem_ID] = i;
            }
            return(result);
        }
        private static ConcurrentDictionary <int, FreeHierarchyTreeItem> GenerateStandartTreeSections(FreeHierarchyTreeDescriptor descriptor)
        {
            var result = new ConcurrentDictionary <int, FreeHierarchyTreeItem>();
            var items  = new List <FreeHierarchyTreeItem>();

            HashSet <ID_TypeHierarchy> objectsHasRightDbSee = null;
            var hiers1 = EnumClientServiceDictionary.HierLev1List.Values;

            if (Manager.User != null && !Manager.User.IsAdmin)
            {
                try
                {
                    //Запрашиваем права на список объектов
                    objectsHasRightDbSee = Manager.User.UserHasRightDbSee(hiers1.Select(h1 => new ID_TypeHierarchy
                    {
                        ID            = h1.Id,
                        TypeHierarchy = enumTypeHierarchy.Dict_HierLev1,
                    }).ToList());
                }
                catch (Exception ex)
                {
                    Manager.UI.ShowMessage("Ошибка запроса прав: " + ex.Message);
                }
            }

            foreach (var item in hiers1.OrderBy(v => v.Item))
            {
                //Глобальный фильтр
                if (!IsGlobalFilterHaveItem(item))
                {
                    continue;
                }

                var minID = descriptor.GetMinIdAndDecrement();
                UserRightsForTreeObject hier1Right;
                var isExistsRight = Manager.User.AccumulateRightsAndVerify(item, EnumObjectRightType.SeeDbObjects, null, out hier1Right);
                if (!isExistsRight && Manager.User != null && !Manager.User.IsAdmin && objectsHasRightDbSee != null)
                {
                    //Проверяем через дочерних объектов
                    isExistsRight = objectsHasRightDbSee.Any(o => o.ID == item.Id && o.TypeHierarchy == item.GetTypeHierarchy());
                }

                var newItem = new FreeHierarchyTreeItem(descriptor, item, nodeName: item.Name)
                {
                    FreeHierItem_ID       = minID,
                    IncludeObjectChildren = true,
                    FreeHierItemType      = EnumFreeHierarchyItemType.HierLev1,
                    NodeRights            = hier1Right
                };

                newItem.Descriptor.Tree = result;
                bool isExistsChildSeeDbObjects = false;
                if (newItem.IncludeObjectChildren)
                {
                    isExistsChildSeeDbObjects = newItem.LoadStaticChildren(isExistsRight, isLoadStatic: true);
                }

                isExistsChildSeeDbObjects = newItem.IncludeChildrenSection(item.Id, item.Type, newItem.Children) || isExistsChildSeeDbObjects ||
                                            item.TIStatus.HasFlag(EnumTIStatus.Is_Section_Enabled);

                //У объекта нет прав на просмотр, или нет дочерних объектов на которые есть такие права
                if (isExistsChildSeeDbObjects) //Включаем только если есть сечения
                {
                    items.Add(newItem);
                }
                else
                {
                    newItem.Dispose();
                }
            }

            //Сечения которые не привязаны ни к чему
            foreach (var section in EnumClientServiceDictionary.GetSections().Values.Where(s => s.ParentId <= 0 && s.Section_ID > 0).OrderBy(s => s.Item))
            {
                UserRightsForTreeObject right;
                if (!Manager.User.AccumulateRightsAndVerify(section, EnumObjectRightType.SeeDbObjects, null, out right))
                {
                    continue;
                }

                var minID = descriptor.GetMinIdAndDecrement();
                FreeHierarchyTreeItem newItem = new FreeHierarchyTreeItem(descriptor, section)
                {
                    FreeHierItem_ID       = minID,
                    IncludeObjectChildren = true,
                    NodeRights            = right,
                    FreeHierItemType      = EnumFreeHierarchyItemType.Section,
                };

                newItem.Descriptor.Tree = result;
                newItem.LoadStaticChildren(true);

                items.Add(newItem);
            }

            if (FreeHierarchyTreeDescriptor.Sort != null)
            {
                FreeHierarchyTreeDescriptor.Sort(items);
            }
            foreach (var i in items)
            {
                result[i.FreeHierItem_ID] = i;
            }
            return(result);
        }
Esempio n. 21
0
        public bool LoadStaticChildren(bool isExistsParentRight, bool isHideTi = false, HashSet <long> selectedNodes = null,
                                       int recursionNumber = 0, bool isLoadStatic = false)
        {
            //if (!IncludeObjectChildren)
            //{
            //    // Эти объекты автоматически не подгружают дочерние объекты
            //    IsChildrenInitializet = true;
            //    return false;
            //}

            bool isExistsChildSeeDbObjects = false; //Наличие дочерних объектов которые явно имеют признак отображения

            if (isExistsParentRight && HierObject != null && Descriptor.Tree_ID == GlobalFreeHierarchyDictionary.TreeTypeStandartSectionsNSI)
            {
                //Добавление констант
                var hierarchyWithChildren = HierObject as IFreeHierarchyObjectWithChildren;
                if (hierarchyWithChildren != null && hierarchyWithChildren.FormulaConstants != null && hierarchyWithChildren.FormulaConstants.Count > 0)
                {
                    isExistsChildSeeDbObjects = true;

                    foreach (var formulaConstant in hierarchyWithChildren.FormulaConstants)
                    {
                        var formula = new FreeHierarchyTreeItem(Descriptor, formulaConstant, false, string.Empty, Descriptor.GetMinIdAndDecrement(), this, false,
                                                                freeHierItemType: EnumFreeHierarchyItemType.FormulaConstant, isChildrenInitializet: true);
                        //lock (_syncLock)
                        {
                            _children.Add(formula);
                        }

                        Descriptor.Tree.TryAdd(formula.FreeHierItem_ID, formula);
                    }
                }

                //if (Descriptor.TreeID == GlobalFreeHierarchyDictionary.TreeTypeStandartTIFormula)
                //{
                //    if (IncludeChildrenFormulas(HierObject.Id, HierObject.Type, children)) isExistsChildSeeDbObjects = true;

                //    IncludeChildrenFormulaConstant();
                //}
            }

            if (FreeHierItemType == EnumFreeHierarchyItemType.Error ||
                FreeHierItemType == EnumFreeHierarchyItemType.Formula)
            {
                return(false);
            }

            if (_hierObject != null)
            {
                // Эти объекты автоматически не подгружают дочерние объекты
                IsChildrenInitializet = IsChildrenInitializet ||
                                        _hierObject.Type == enumTypeHierarchy.Dict_HierLev0
                                        //|| _hierObject.Type == enumTypeHierarchy.Dict_HierLev1
                                        //|| _hierObject.Type == enumTypeHierarchy.Dict_HierLev2
                                        //|| _hierObject.Type == enumTypeHierarchy.Dict_HierLev3 //Перевел в динамическую подгрузку
                                        //|| _hierObject.Type == enumTypeHierarchy.Info_TI
                                        || _hierObject.Type == enumTypeHierarchy.Formula ||
                                        _hierObject.Type == enumTypeHierarchy.Formula_TP_OurSide ||
                                        _hierObject.Type == enumTypeHierarchy.FormulaConstant;
            }

            return(isExistsChildSeeDbObjects);
        }