Example #1
0
        private void butSection_Add_Click(object sender, RoutedEventArgs e)
        {
            var but = sender as FrameworkElement;

            //Section
            IFreeHierarchyObject obj = but.DataContext as IFreeHierarchyObject;

            var treeItem = but.DataContext as FreeHierarchyTreeItem;

            if (treeItem == null && obj == null)
            {
                return;
            }

            if (obj == null)
            {
                obj = treeItem.Item as IFreeHierarchyObject;
            }
            if (obj != null)
            {
                SelectObject(new FreeHierarchyTree_ObjectSelectorSelectObjectEventArgs()
                {
                    ChannelType    = but.Tag.ToString(),
                    SelectedObject = obj
                });
            }
        }
        public BalanceFreeHierarchyViewModel(IFreeHierarchyObject hierarchyObject, Info_Balance_FreeHierarchy_List balance)
        {
            _hierarchyObject = hierarchyObject;
            _balance         = balance;
            Source           = new RangeObservableCollection <BalanceFreeHierarchySectionRow>();
            if (_balance == null)
            {
                //Создание нового
                byte defaultBalanceType = 0;
                _balance = new ServiceReference.ARM_20_Service.Info_Balance_FreeHierarchy_List
                {
                    HierarchyObject             = hierarchyObject,
                    BalanceFreeHierarchyType_ID = defaultBalanceType,
                    User_ID          = Manager.User.User_ID,
                    DispatchDateTime = DateTime.Now.DateTimeToWCFDateTime(),
                };

                IsNew = true;
            }
            else
            {
                BalanceFreeHierarchyTypeID = balance.BalanceFreeHierarchyType_ID;
            }

            //Подгрузка всех подразделов
            _loadSubsectionsTask = LoadSubsectionsTask();
        }
Example #3
0
        private static void ExpandParentAndSelectObjectXceedGrid(enumTypeHierarchy parentType, int parentId,
                                                                 IFreeHierarchyObject hierarchyObject, DataGridControl xamTree)
        {
            IFreeHierarchyObject parent = null;

            switch (parentType)
            {
            case enumTypeHierarchy.Dict_PS:
            case enumTypeHierarchy.USPD:
            case enumTypeHierarchy.E422:
                parent = EnumClientServiceDictionary.DetailPSList[parentId];
                break;

            case enumTypeHierarchy.Info_TP:
                var tps = EnumClientServiceDictionary.GetTps();
                if (tps != null)
                {
                    parent = tps[parentId];
                }
                break;
            }

            if (parent == null)
            {
                return;
            }

            var chain = new Stack();

#if DEBUG
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
#endif
            var source = xamTree.ItemsSource as ICollection;
            if (source == null)
            {
                return;
            }

            FinderHelper.FindFirstElement(source, parent, chain);
#if DEBUG
            sw.Stop();
            Console.WriteLine("Поиск {0} млс", sw.ElapsedMilliseconds);
#endif
            if (chain.Count <= 0)
            {
                return;
            }

            var arr = new object[chain.Count];
            chain.CopyTo(arr, 0);
            //Array.Reverse(arr);

            chain = new Stack(arr);

            xamTree.ExpandandSelectXceedGrid(chain, hierarchyObject);
        }
Example #4
0
 /// <summary>
 /// Выбор каналов или объектов из дерева FreeHierarchy
 /// </summary>
 /// <param name="selectTypesFilter">Можно выбирать только элементы заданных типов</param>
 /// <param name="selectedItem">Текущий выделенный элемент</param>
 /// <param name="channelType">Тип канала выбранного </param>
 /// <param name="channelsIsSelectable">Можно ли выбирать каналы  </param>
 public FreeHierarchyTree_ObjectSelector(List <enumTypeHierarchy> selectTypesFilter = null, IFreeHierarchyObject selectedItem = null, string channelType = null, bool channelsIsSelectable = true)
 {
     _selectTypesFilter   = selectTypesFilter;
     SelectedItem         = selectedItem;
     ChannelType          = channelType;
     ChannelsIsSelectable = channelsIsSelectable;
     this.Loaded         += OnLoaded;
     InitializeComponent();
 }
Example #5
0
        void SelectObject(FreeHierarchyTree_ObjectSelectorSelectObjectEventArgs obj)
        {
            this.ChannelType  = obj.ChannelType;
            this.SelectedItem = obj.SelectedObject;

            if (this.OnSelectObject != null)
            {
                this.OnSelectObject.Invoke(this, obj);
            }
        }
        /// <summary>
        /// Обработка глобального фильтра
        /// </summary>
        /// <param name="hierarchyObject"></param>
        /// <returns></returns>
        public static bool IsGlobalFilterHaveItem(IFreeHierarchyObject hierarchyObject)
        {
            Dictionary <int, THierarchyDbTreeObject> selectedGlobalHierDict;

            if (!_globalFilterDict.TryGetValue(hierarchyObject.Type, out selectedGlobalHierDict) || selectedGlobalHierDict == null || selectedGlobalHierDict.Count == 0)
            {
                return(true);
            }

            if (selectedGlobalHierDict.ContainsKey(hierarchyObject.Id))
            {
                return(true);
            }

            return(false);
        }
Example #7
0
        public FreeHierarchyTreeItem GetNode(IFreeHierarchyObject hierarchyObject)
        {
            var pe = Parent as FrameworkElement;

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

            if (pe is IModule && !(pe is UIManagerContainer))
            {
                return((pe as IModule).GetNode(hierarchyObject));
            }

            var m = pe.FindTrueIModule() as IModule;

            if (m != null)
            {
                return(m.GetNode(hierarchyObject));
            }

            return(null);
        }
Example #8
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null ||
                values.Length < 2)
            {
                return(null);
            }

            var dataItem = values[1] as DynamicDataItem; // vw_Alarms

            if (dataItem == null || !dataItem.IsDataAvailable)
            {
                return(null);
            }

            IFreeHierarchyObject hierarchyObject = null;
            string stringName;

            if (parameter != null)
            {
                switch (parameter.ToString())
                {
                case "Object":
                    hierarchyObject = VisualAlarmHelper.ExtractHierObjectFromDynamicDataItem(dataItem);
                    if (hierarchyObject == null)
                    {
                        dataItem.TryGetPropertyValue("ObjectName", out stringName);
                        return(stringName);
                    }
                    break;

                case "Parent":
                    hierarchyObject = VisualAlarmHelper.ExtractParentObjectFromDynamicDataItem(dataItem);
                    if (hierarchyObject == null)
                    {
                        dataItem.TryGetPropertyValue("ParentName", out stringName);
                        return(stringName);
                    }
                    break;

                case "AlarmConfirmStatusCategory":
                    return(VisualAlarmHelper.ExtractAlarmConfirmStatusCategoryFromDynamicDataItem(dataItem));
                }
            }


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

            var dt = Selector.SelectTemplate(hierarchyObject, null);

            if (dt != null)
            {
                var content = dt.LoadContent() as FrameworkElement;
                if (content != null)
                {
                    content.DataContext = hierarchyObject;
                    return(content);
                }
            }

            return(hierarchyObject.ToString());
        }
 public FreeHierarchyTreeItem GetNode(IFreeHierarchyObject hierarchyObject)
 {
     return(null);
 }
Example #10
0
        public static void ExpandandSelectXceedGrid(this DataGridControl grid, Stack chain, IFreeHierarchyObject hierarchyObject = null)
        {
            if (chain == null)
            {
                return;
            }

            Func <DataGridContext, object, bool> expand = null;

            expand = (context, obj) =>
            {
                if (chain.Count > 0)
                {
                    try
                    {
                        if (!context.AllowDetailToggle || !context.HasDetails || !context.ExpandDetails(obj))
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                    }

                    var nextObj         = chain.Pop();
                    var childrenContext = context.GetChildContexts();
                    //var container = context.GetContainerFromItem(nextObj) as DataGridContext;
                    //if (container != null) expand(container, nextObj);
                    foreach (var c in childrenContext)
                    {
                        try
                        {
                            grid.Dispatcher.BeginInvoke(expand, DispatcherPriority.ApplicationIdle, c, nextObj);
                            //if (expand(c, nextObj))  break;
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else
                {
                    if (hierarchyObject == null)
                    {
                        Keyboard.Focus(grid);
                        try
                        {
                            context.CurrentItem = obj;
                        }
                        catch { }
                        context.SelectedItems.Clear();
                        context.SelectedItems.Add(obj);
                        MoveCenter(grid, obj, context);
                    }
                    else
                    {
                        var findable = obj as IFindableItemWithPath;
                        if (findable == null)
                        {
                            return(true);
                        }

                        findable.LoadDynamicChildren();

                        try
                        {
                            if (!context.AllowDetailToggle || !context.HasDetails || !context.ExpandDetails(obj))
                            {
                                return(false);
                            }
                        }
                        catch (Exception)
                        {
                        }

                        grid.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            var children = findable.GetChildren();
                            if (children != null)
                            {
                                Keyboard.Focus(grid);
                                foreach (var item in children)
                                {
                                    var fi = item as IFindableItemWithPath;
                                    if (fi == null)
                                    {
                                        continue;
                                    }

                                    if (Equals(fi.GetItemForSearch(), hierarchyObject))
                                    {
                                        foreach (var c in context.GetChildContexts())
                                        {
                                            try
                                            {
                                                c.CurrentItem = fi;
                                                c.SelectedItems.Clear();
                                                c.SelectedItems.Add(fi);
                                            }
                                            catch (Exception)
                                            {
                                            }



                                            MoveCenter(grid, fi, c);
                                        }

                                        break;
                                    }
                                }
                            }
                        }), DispatcherPriority.Input);
                    }
                }

                return(true);
            };

            expand(DataGridControl.GetDataGridContext(grid), chain.Pop());

            //if (chain.Count == 1)
            //{
            //    var obj = chain.Pop();
            //    if (grid.Items.Groups != null)
            //    {
            //        var chainGroup = new Stack<CollectionViewGroup>();
            //        foreach (CollectionViewGroup gr in grid.Items.Groups)
            //        {
            //            chainGroup.Push(gr);
            //            if (FinderHelper.ScanGroup(chainGroup, gr.Items, obj)) break;
            //            chainGroup.Pop();
            //        }
            //        if (chainGroup.Count > 0)
            //        {
            //            var copy = chainGroup.Reverse().ToArray();
            //            foreach (var gr in copy)
            //            {
            //                grid.ExpandGroup(gr);
            //            }
            //        }
            //    }
            //    grid.CurrentItem = obj;
            //    grid.SelectedItems.Clear();
            //    grid.SelectedItems.Add(obj);
            //}
            //else expand(DataGridControl.GetDataGridContext(grid), chain.Pop());
        }
        public IFreeHierarchyObject UpdateSource(List <Info_Balance_FreeHierarchy_Description> descriptions, Dispatcher dispatcher,
                                                 Action onFieldChanged, out bool isAdded)
        {
            isAdded = false;

            //List<Info_Balance_FreeHierarchy_Description> descriptions = null;

            if (_balance != null && descriptions == null)
            {
                descriptions = ARM_Service.BL_GetFreeHierarchyBalanceDescritions(_balance.BalanceFreeHierarchy_UN);
            }

            var sections = ARM_Service.BL_GetFreeHierarchyBalanceSections(BalanceFreeHierarchyTypeID);

            if (sections == null || sections.Count == 0)
            {
                Manager.UI.ShowMessage("Не описаны разделы для данного типа баланса!");
                return(null);
            }

            var source = new List <BalanceFreeHierarchySectionRow>();
            var isExistsDescription = descriptions != null && descriptions.Count > 0;
            var tps        = EnumClientServiceDictionary.GetTps();
            var isFirst    = true;
            var isFirstRow = true;

            IFreeHierarchyObject result = null;

            foreach (var section in sections.Where(s => s.UseInTotalResult))
            {
                var row = new BalanceFreeHierarchySectionRow(section, dispatcher);
                if (isFirst)
                {
                    row.IsSelected = true;
                    isFirst        = false;
                }

                if (isExistsDescription)
                {
                    //Если есть описание данного баланса
                    foreach (var description in descriptions.Where(d => string.Equals(d.BalanceFreeHierarchySection_UN, section.BalanceFreeHierarchySection_UN)).OrderBy(d => d.SortNumber))
                    {
                        var isIntegral = false;
                        IFreeHierarchyObject hierarchyObject = null;
                        if (description.TI_ID.HasValue)
                        {
                            TInfo_TI ti;
                            if (!EnumClientServiceDictionary.TIHierarchyList.TryGetValue(description.TI_ID.Value, out ti) || ti == null)
                            {
                                continue;
                            }
                            hierarchyObject = ti;
                        }
                        if (description.IntegralTI_ID.HasValue)
                        {
                            isIntegral = true;
                            TInfo_TI ti;
                            if (!EnumClientServiceDictionary.TIHierarchyList.TryGetValue(description.IntegralTI_ID.Value, out ti) || ti == null)
                            {
                                continue;
                            }
                            hierarchyObject = ti;
                        }
                        else if (description.TP_ID.HasValue && tps != null)
                        {
                            TPoint tp;
                            if (!tps.TryGetValue(description.TP_ID.Value, out tp) || tp == null)
                            {
                                continue;
                            }
                            hierarchyObject = tp;
                        }
                        else if (!string.IsNullOrEmpty(description.Formula_UN) && EnumClientServiceDictionary.FormulasList != null)
                        {
                            var formula = EnumClientServiceDictionary.FormulasList[description.Formula_UN];
                            hierarchyObject = formula;
                        }
                        else if (!string.IsNullOrEmpty(description.OurFormula_UN))
                        {
                            TFormulaForSection formula;
                            if (!EnumClientServiceDictionary.FormulaFsk.TryGetValue(description.OurFormula_UN, out formula) || formula == null)
                            {
                                continue;
                            }
                            hierarchyObject = formula;
                        }
                        else if (!string.IsNullOrEmpty(description.ContrFormula_UN))
                        {
                            TFormulaForSection formula;
                            if (!EnumClientServiceDictionary.FormulaCA.TryGetValue(description.ContrFormula_UN, out formula) || formula == null)
                            {
                                continue;
                            }
                            hierarchyObject = formula;
                        }
                        else if (description.PTransformator_ID.HasValue)
                        {
                            var transformator = EnumClientServiceDictionary.GetOrAddTransformator(description.PTransformator_ID.Value, null);
                            hierarchyObject = transformator;
                        }
                        else if (description.PReactor_ID.HasValue)
                        {
                            var reactor = EnumClientServiceDictionary.GetOrAddReactor(description.PReactor_ID.Value, null);
                            hierarchyObject = reactor;
                        }
                        else if (description.Section_ID.HasValue)
                        {
                            var      hierarhicalSections = EnumClientServiceDictionary.GetSections();
                            TSection hierarhicalSection;
                            if (hierarhicalSections != null && hierarhicalSections.TryGetValue(description.Section_ID.Value, out hierarhicalSection))
                            {
                                hierarchyObject = hierarhicalSection;
                            }
                        }
                        else if (!string.IsNullOrEmpty(description.FormulaConstant_UN))
                        {
                            var formulaConstant = EnumClientServiceDictionary.FormulaConstantDictionary[description.FormulaConstant_UN];
                            hierarchyObject = formulaConstant;
                        }

                        if (hierarchyObject == null)
                        {
                            continue;
                        }

                        var itemRows = FindDescriptions(description, row, dispatcher);
                        if (itemRows != null)
                        {
                            itemRows.Add(new BalanceFreeHierarchyItemRow(hierarchyObject, description.ChannelType, description.Coef ?? 1, onFieldChanged,
                                                                         description.SortNumber, itemRows, isIntegral, (EnumDataSourceType?)description.DataSource_ID));
                        }

                        //Раскрываем дерево на первом объекте баланса
                        if (isFirstRow)
                        {
                            //fhTree.Dispatcher.BeginInvoke((Action)(() =>
                            //{
                            //    var freeHierTreeId = FormulaEditor_Frame.FindTreeByObjectType(hierarchyObject);
                            //    fhTree.ReloadTree(freeHierTreeId, hierarchyObject: hierarchyObject);
                            //}), DispatcherPriority.Background);

                            result = hierarchyObject;

                            isAdded    = true;
                            isFirstRow = false;
                        }
                    }
                }

                source.Add(row);
            }

            dispatcher.BeginInvoke((Action)(() => Source.AddRange(source)));

            //if (!isAdded)
            //{
            //    Task.Factory.StartNew(() =>
            //    {
            //        Thread.Sleep(100);
            //        //Раскрываем дерево на родителе баланса
            //        fhTree.Dispatcher.BeginInvoke((Action)(() =>
            //           fhTree.ExpandAndSelect(_hierarchyObject, true)), DispatcherPriority.ContextIdle);
            //    });
            //}

            return(result);
        }
Example #12
0
 public void ExpandAndSelect(IFreeHierarchyObject freeHierarchyTreeItem, bool isSelect = true)
 {
     FreeHierarchyTree.ExpandAndSelect(freeHierarchyTreeItem, false, isSelect);
 }