Example #1
0
        // 搜索并更新结果。
        private async Task _SearchAndUpdateResultAsync()
        {
            Taxon  taxon   = radioButton_Root.IsChecked ?? false ? Entrance.Root : Common.CurrentTaxon;
            string keyWord = ViewModel.KeyWord;

            AsyncMethod.Start();
            await Task.Run(() =>
            {
                _SearchResult.Clear();

                IReadOnlyDictionary <MatchLevel, IReadOnlyList <Taxon> > searchResult = taxon.SearchAndGroupByMatchLevel(keyWord);
                IReadOnlyList <Taxon> perfect = searchResult[MatchLevel.Perfect];
                IReadOnlyList <Taxon> high    = searchResult[MatchLevel.High];
                IReadOnlyList <Taxon> low     = searchResult[MatchLevel.Low];

                if (perfect.Count > 0)
                {
                    List <TaxonItem> items = new List <TaxonItem>();

                    foreach (var taxon in perfect)
                    {
                        items.Add(new TaxonItem()
                        {
                            Taxon = taxon
                        });
                    }

                    _SearchResult.Add(new _SearchResultItem()
                    {
                        Title      = "最相关结果",
                        TaxonItems = items
                    });
                }

                if (high.Count > 0)
                {
                    List <TaxonItem> items = new List <TaxonItem>();

                    foreach (var taxon in high)
                    {
                        items.Add(new TaxonItem()
                        {
                            Taxon = taxon
                        });
                    }

                    _SearchResult.Add(new _SearchResultItem()
                    {
                        Title      = "较相关结果",
                        TaxonItems = items
                    });
                }

                if (low.Count > 0)
                {
                    List <TaxonItem> items = new List <TaxonItem>();

                    foreach (var taxon in low)
                    {
                        items.Add(new TaxonItem()
                        {
                            Taxon = taxon
                        });
                    }

                    _SearchResult.Add(new _SearchResultItem()
                    {
                        Title      = "次相关结果",
                        TaxonItems = items
                    });
                }
            });

            AsyncMethod.Finish();

            stackPanel_SearchResult.Children.Clear();

            if (_SearchResult.Count > 0)
            {
                foreach (var result in _SearchResult)
                {
                    CollapsibleTaxonButtonGroup taxonButtonGroup = new CollapsibleTaxonButtonGroup()
                    {
                        Title       = result.Title,
                        IsDarkTheme = Theme.IsDarkTheme,
                        Margin      = new Thickness(0, 25, 0, 0),
                    };

                    taxonButtonGroup.UpdateContent(result.TaxonItems);

                    taxonButtonGroup.MouseLeftButtonClick += (s, e) =>
                    {
                        if (e.Taxon.IsRoot)
                        {
                            MessageBox.Show("该类群已经被删除。");
                        }
                        else
                        {
                            Common.CurrentTabPage = Common.TabPage.Evo;
                            Common.CurrentTaxon   = e.Taxon;
                        }
                    };

                    result.TaxonButtonGroup = taxonButtonGroup;

                    stackPanel_SearchResult.Children.Add(taxonButtonGroup);
                }

                const int preferShowCount = 10;
                int       count           = 0;

                foreach (var result in _SearchResult)
                {
                    count += result.TaxonItems.Count;

                    if (count <= preferShowCount)
                    {
                        result.TaxonButtonGroup.Expanded = true;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            _UpdateVisibility();
        }
        // 检查并更新结果。
        private async Task _ValidateAndUpdateResultAsync()
        {
            Taxon taxon = radioButton_Root.IsChecked ?? false ? Entrance.Root : Common.CurrentTaxon;

            AsyncMethod.Start();
            await Task.Run(() =>
            {
                _ValidateResult.Clear();

                IReadOnlyDictionary <IValidator, IReadOnlyCollection <Taxon> > validateResult = taxon.ValidateChildrenAndGroupByValidator();

                foreach (var pair in validateResult)
                {
                    List <TaxonItem> items = new List <TaxonItem>();

                    foreach (var taxon in pair.Value)
                    {
                        items.Add(new TaxonItem()
                        {
                            Taxon = taxon
                        });
                    }

                    _ValidateResult.Add(new _ValidateResultItem()
                    {
                        Title      = pair.Key.ToString(),
                        TaxonItems = items
                    });
                }
            });

            AsyncMethod.Finish();

            stackPanel_ValidateResult.Children.Clear();

            if (_ValidateResult.Count > 0)
            {
                foreach (var result in _ValidateResult)
                {
                    CollapsibleTaxonButtonGroup taxonButtonGroup = new CollapsibleTaxonButtonGroup()
                    {
                        Title       = result.Title,
                        IsDarkTheme = Theme.IsDarkTheme,
                        Margin      = new Thickness(0, 25, 0, 0),
                    };

                    taxonButtonGroup.UpdateContent(result.TaxonItems);

                    taxonButtonGroup.MouseLeftButtonClick += (s, e) =>
                    {
                        if (e.Taxon.IsRoot)
                        {
                            MessageBox.Show("该类群已经被删除。");
                        }
                        else
                        {
                            Common.CurrentTabPage = Common.TabPage.Evo;
                            Common.IsEditMode     = true;
                            Common.CurrentTaxon   = e.Taxon;
                        }
                    };

                    result.TaxonButtonGroup = taxonButtonGroup;

                    stackPanel_ValidateResult.Children.Add(taxonButtonGroup);
                }
            }

            _UpdateVisibility();
        }