Exemplo n.º 1
0
        private void _selectInternal <TKey>(ServerDbs tabName, List <TKey> tuplesGen, bool changeTab)
        {
            try {
                lock (_lock) {
                    IsSelecting = true;

                    if (tabName.AdditionalTable == null)
                    {
                        TabItem item = _tab.Dispatch(() => _tab.Items.Cast <TabItem>().FirstOrDefault(p => p.Header.ToString() == tabName));

                        if (item is GDbTab)
                        {
                            GDbTab tab = (GDbTab)item;

                            var          table  = tab.To <TKey>().Table;
                            List <Tuple> tuples = tuplesGen.Select(table.TryGetTuple).Where(p => p != null).Select(p => (Tuple)p).ToList();

                            if (tuples.Count == 0)
                            {
                                if (changeTab)
                                {
                                    ErrorHandler.HandleException((tuplesGen.Count > 1 ? "Items do" : "Item does") + " not exist in [" + tabName.DisplayName + "].", ErrorLevel.NotSpecified);
                                }
                                return;
                            }

                            if (!_containsAny(tab, tuples))
                            {
                                tab.IgnoreFilterOnce();
                                tab.Filter();
                                _waitForFilter(tab);

                                if (!_containsAny(tab, tuples))
                                {
                                    if (changeTab)
                                    {
                                        ErrorHandler.HandleException((tuplesGen.Count > 1 ? "Items" : "Item") + " not found in [" + tabName.DisplayName + "]. Try clearing the search filter on the specified table.", ErrorLevel.NotSpecified);
                                    }
                                    return;
                                }
                            }

                            tab.Dispatch(p => p.IsSelected = true);
                            _waitForFilter(tab);
                            tab.Dispatch(p => p.SelectItems(tuples));
                        }
                        else
                        {
                            if (item == null)
                            {
                                return;
                            }

                            if (changeTab)
                            {
                                item.Dispatch(p => p.IsSelected = true);
                            }
                        }
                    }
                    else
                    {
                        TabItem item  = _tab.Dispatch(() => _tab.Items.Cast <TabItem>().FirstOrDefault(p => p.Header.ToString() == tabName));
                        TabItem item2 = _tab.Dispatch(() => _tab.Items.Cast <TabItem>().FirstOrDefault(p => p.Header.ToString() == tabName.AdditionalTable));

                        if (item is GDbTab && item2 is GDbTab)
                        {
                            GDbTab tab  = (GDbTab)item;
                            GDbTab tab2 = (GDbTab)item2;

                            var          table   = tab.To <TKey>().Table;
                            var          table2  = tab2.To <TKey>().Table;
                            List <Tuple> tuples  = tuplesGen.Select(table.TryGetTuple).Where(p => p != null).Select(p => (Tuple)p).ToList();
                            List <Tuple> tuples2 = tuplesGen.Select(table2.TryGetTuple).Where(p => p != null).Select(p => (Tuple)p).ToList();

                            if (tuples.Count == 0 && tuples2.Count == 0)
                            {
                                if (changeTab)
                                {
                                    ErrorHandler.HandleException((tuplesGen.Count > 1 ? "Items do" : "Item does") + " not exist in either [" + tabName.DisplayName + "] or [" + tabName.AdditionalTable.DisplayName + "].", ErrorLevel.NotSpecified);
                                }
                                return;
                            }

                            if (!_containsAny(tab, tuples))
                            {
                                tab.IgnoreFilterOnce();
                                tab.Filter();
                                _waitForFilter(tab);
                            }

                            if (!_containsAny(tab2, tuples))
                            {
                                tab2.IgnoreFilterOnce();
                                tab2.Filter();
                                _waitForFilter(tab2);
                            }

                            if (!_containsAny(tab, tuples) && !_containsAny(tab2, tuples2))
                            {
                                if (!_containsAny(tab, tuples) && !_containsAny(tab2, tuples2))
                                {
                                    if (changeTab)
                                    {
                                        ErrorHandler.HandleException((tuplesGen.Count > 1 ? "Items" : "Item") + " not found in either [" + tabName.DisplayName + "] or [" + tabName.AdditionalTable.DisplayName + "], but . Try clearing the search filter on the specified table.", ErrorLevel.NotSpecified);
                                    }
                                    return;
                                }
                            }

                            GDbTab tabToSelect = _containsAny(tab2, tuples2) ? tab2 : tab;

                            if (changeTab)
                            {
                                tabToSelect.Dispatch(p => p.IsSelected = true);
                            }

                            _waitForFilter(tabToSelect);
                            tabToSelect.Dispatch(p => p.SelectItems(tabToSelect == tab ? tuples : tuples2));
                        }
                        else
                        {
                            if (item == null)
                            {
                                return;
                            }
                            if (changeTab)
                            {
                                item.Dispatch(p => p.IsSelected = true);
                            }
                        }
                    }
                }
            }
            catch {
            }
            finally {
                IsSelecting = false;
            }
        }