Пример #1
0
        private void InitVisual()
        {
            var nodeContext = DataContext as XamDataTreeNodeDataContext;

            if (nodeContext == null)
            {
                return;
            }

            var item = nodeContext.Data as FreeHierarchyTreeItem;

            if (_parentTree == null)
            {
                _parentTree = nodeContext.Node.NodeLayout.Tree.TryFindResource("treeModule") as FreeHierarchyTree; //.FindParent<FreeHierarchyTree>();
            }

            #region Определяемся нужно ли пересоздавать контрол

            var isRecreateControl = _freeHierarchyTreeItem == null ||
                                    item == null;

            if (!isRecreateControl)
            {
                var oldTypeFound = false;
                var newTypeFound = false;

                isRecreateControl = true;

                foreach (var notRecreatableType in _notRecreatableTypes)
                {
                    if (!oldTypeFound && notRecreatableType == _freeHierarchyTreeItem.FreeHierItemType)
                    {
                        oldTypeFound = true;
                    }

                    if (!newTypeFound && notRecreatableType == item.FreeHierItemType)
                    {
                        newTypeFound = true;
                    }

                    if (oldTypeFound && newTypeFound)
                    {
                        isRecreateControl = false;
                        break;
                    }
                }
            }

            #endregion

            _freeHierarchyTreeItem = item;

            if (_freeHierarchyTreeItem == null || _freeHierarchyTreeItem.Descriptor == null)
            {
                return;
            }

            //MainLayout.DataContext = _freeHierarchyTreeItem;

            if (_outerSelector == null && _parentTree != null && _parentTree.OuterSelector != null)
            {
                _outerSelector = _parentTree.OuterSelector;
            }

            //if (_freeHierarchyTreeItem.UpdateItemContent == null)
            //{
            //    _freeHierarchyTreeItem.UpdateItemContent = UpdateItemContent;
            //}

            if (_parentTree == null)
            {
                return;
            }

            _treeDescriptor = _parentTree.GetDescriptor();
            if (_treeDescriptor == null)
            {
                return;
            }

            bool isHideStandartIcon = false;


            //если указана пользовательская иконка то скрываем стандартные
            if (item != null && item.NodeIcon_ID != null)
            {
                isHideStandartIcon = true;

                DictNodeIcon imgBytes;
                GlobalTreeDictionary.DictNodeIconList.TryGetValue(item.NodeIcon_ID ?? 0, out imgBytes);


                if (imgBytes != null)
                {
                    UserImage.Source = imgBytes.DataImage;
                }
                UserImage.Visibility = Visibility.Visible;
            }
            else if (UserImage.Visibility == Visibility.Visible)
            {
                UserImage.Visibility = Visibility.Collapsed;
                //TODO
            }


            //if (ccLayout.Content != null) DisposeControlContent();
            UpdateItemContent(_freeHierarchyTreeItem, isRecreateControl, isHideStandartIcon);

            //ccLayout.Content = _freeHierarchyTreeItem.Name;
        }
Пример #2
0
        private void ContextMenuOnLoaded(object sender, RoutedEventArgs e)
        {
            if (_parentTree == null)
            {
                InitParentTree();
            }

            if (_parentTree == null)
            {
                return;
            }

            var cm = sender as XamContextMenu;

            if (cm == null)
            {
                return;
            }

            var descriptor = _parentTree.GetDescriptor();

            if (descriptor.Tree_ID != GlobalFreeHierarchyDictionary.TreeTypeStandartGroupTP &&
                descriptor.Tree_ID != GlobalFreeHierarchyDictionary.TreeTypeStandartSections &&
                descriptor.Tree_ID != GlobalFreeHierarchyDictionary.TreeTypeStandartSectionsNSI &&
                descriptor.Tree_ID < 0)
            {
                miSelectEpu.Visibility = Visibility.Collapsed;

                if (descriptor.Tree_ID <= -GlobalFreeHierarchyDictionary.TreeTypeStandart)
                {
                    miSelectSections.Visibility = Visibility.Collapsed;
                    if (descriptor.Tree_ID != GlobalFreeHierarchyDictionary.TreeTypeStandartJuridicalPerson)
                    {
                        miSelectTps.Visibility = Visibility.Collapsed;
                    }
                }
            }

            var item = cm.DataContext as FreeHierarchyTreeItem;

            if (item == null)
            {
                //Свободная иерархия
                var xndc = cm.DataContext as XamDataTreeNodeDataContext;
                if (xndc != null)
                {
                    item = xndc.Data as FreeHierarchyTreeItem;
                }
            }

            if (item != null)
            {
                switch (item.FreeHierItemType)
                {
                case EnumFreeHierarchyItemType.Section:
                    miSelectSections.Visibility = Visibility.Collapsed;
                    break;

                case EnumFreeHierarchyItemType.TP:
                case EnumFreeHierarchyItemType.TI:
                    miSelectContracts.Visibility                        =
                        miSelectLev3.Visibility                         =
                            miSelectPs.Visibility                       =
                                miSelectEpu.Visibility                  =
                                    miSelectTps.Visibility              =
                                        miSelectTi.Visibility           =
                                            miSelectSections.Visibility =
                                                Visibility.Collapsed;
                    break;

                case EnumFreeHierarchyItemType.FiasFullAddress:
                    miSelectAll.Visibility = miExpand3.Visibility = miExpand2.Visibility
                                                                        = Visibility.Collapsed;
                    break;
                }

                //Свободная иерархия
            }

            var tm = TreeMode;

            if (tm.HasValue && tm.Value == enumTreeMode.PSMultiMode)
            {
                miSelectTi.Visibility           =
                    miSelectChildren.Visibility =
                        miSelectLev3.Visibility =
                            Visibility.Collapsed;
            }
            else
            {
                var parentFrame = _parentTree.PermissibleForSelectObjects;

                if (_parentTree.IsHideTp)
                {
                    miSelectTps.Visibility = Visibility.Collapsed;
                }

                if (_parentTree.IsHideTi)
                {
                    miSelectTi.Visibility = Visibility.Collapsed;

                    if (parentFrame != null && parentFrame.PermissibleForSelectObjects != null)
                    {
                        if (parentFrame.PermissibleForSelectObjects.Contains(EnumFreeHierarchyItemType.PS))
                        {
                            StandartTreeOnLoaded(miSelectPs, e);
                        }
                        else
                        {
                            miSelectPs.Visibility = Visibility.Collapsed;
                        }

                        if (parentFrame.PermissibleForSelectObjects.Contains(EnumFreeHierarchyItemType.HierLev3))
                        {
                            StandartTreeOnLoaded(miSelectLev3, e);
                        }
                        else
                        {
                            miSelectLev3.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        StandartTreeOnLoaded(miSelectPs, e);
                        StandartTreeOnLoaded(miSelectLev3, e);
                    }
                }
                else
                {
                    if (descriptor != null && descriptor.Tree_ID != GlobalFreeHierarchyDictionary.TreeTypeStandartTIFormula && descriptor.Tree_ID <= -102)
                    {
                        miSelectTi.Visibility = Visibility.Collapsed;
                    }

                    miSelectLev3.Visibility = miSelectPs.Visibility = Visibility.Collapsed;
                }

                if (parentFrame != null && parentFrame.PermissibleForSelectObjects != null && parentFrame.PermissibleForSelectObjects.Contains(EnumFreeHierarchyItemType.USPD))
                {
                    StandartTreeOnLoaded(miSelectUSPDs, e);
                }
                else
                {
                    miSelectUSPDs.Visibility = Visibility.Collapsed;
                }

                if (descriptor != null && !_parentTree.IsSelectSingle)
                {
                    miSelectChildren.Visibility = Visibility.Visible;
                }
                else
                {
                    miSelectChildren.Visibility = Visibility.Collapsed;
                }
            }

            //if (descriptor != null && descriptor.NeedFindUaNode) miSelectAll.Visibility = Visibility.Collapsed;
            //else
            {
                miSelectAll.Visibility = Visibility.Visible;
                miSelectAll.IsEnabled  = !_parentTree.IsSelectSingle;
            }

            if (descriptor.Tree_ID != GlobalFreeHierarchyDictionary.TreeTypeStandartGroupTP)
            {
                miSelectContracts.Visibility = Visibility.Collapsed;
            }

            SeparatorSection.Visibility = miSelectSections.Visibility;
        }