Beispiel #1
0
        private void B_Click()
        {
            switch (GlobalTool.ButtonNameZajiao)
            {
            case "ButtonSearch":
            {
                List <MyFlower> ParentL = new List <MyFlower>();
                List <MyFlower> ParentR = new List <MyFlower>();

                if (GlobalTool.BoolColorL == true)
                {        //按颜色L
                    if (GlobalTool.IndexColorL == 0)
                    {
                        GlobalTool.OpenDialogButton(this, "没有选择颜色");
                        return;
                    }
                    foreach (var everyflower in SelectedColorDicL)
                    {
                        ParentL.Add(everyflower);
                    }
                }
                if (GlobalTool.BoolColorR == true)
                {        //按颜色R
                    if (GlobalTool.IndexColorR == 0)
                    {
                        GlobalTool.OpenDialogButton(this, "没有选择颜色");
                        return;
                    }
                    foreach (var everyflower in SelectedColorDicR)
                    {
                        ParentR.Add(everyflower);
                    }
                }
                if (GlobalTool.BoolGeneL == true)
                {        //按基因型L
                    Gene     a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1L);
                    Gene     a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2L);
                    Gene     a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3L);
                    Gene     a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4L);
                    MyFlower f  = new MyFlower(SelectedFlower, a1, a2, a3, a4);
                    foreach (var i in f.GetIntArray())
                    {
                        if (i == 0)
                        {
                            GlobalTool.OpenDialogButton(this, "没有选择基因型");
                            return;
                        }
                    }
                    foreach (var a in ListColorDic)
                    {
                        if (f.GetGeneName() == a.GetGeneName())
                        {
                            ParentL.Add(a);
                        }
                    }
                }
                if (GlobalTool.BoolGeneR == true)
                {        //按基因型R
                    Gene     a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1R);
                    Gene     a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2R);
                    Gene     a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3R);
                    Gene     a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4R);
                    MyFlower f  = new MyFlower(SelectedFlower, a1, a2, a3, a4);
                    foreach (var i in f.GetIntArray())
                    {
                        if (i == 0)
                        {
                            GlobalTool.OpenDialogButton(this, "没有选择基因型");
                            return;
                        }
                    }
                    foreach (var a in ListColorDic)
                    {
                        if (f.GetGeneName() == a.GetGeneName())
                        {
                            ParentR.Add(a);
                        }
                    }
                }
                if (GlobalTool.BoolSeedL == true)
                {        //按种子L
                    int index = GlobalTool.IndexSeedL;
                    if (index == 0)
                    {
                        GlobalTool.OpenDialogButton(this, "没有选择种子");
                        return;
                    }
                    ParentL.Add(ListSeed[index - 1]);
                }
                if (GlobalTool.BoolSeedR == true)
                {        //按种子L
                    int index = GlobalTool.IndexSeedR;
                    if (index == 0)
                    {
                        GlobalTool.OpenDialogButton(this, "没有选择种子");
                        return;
                    }
                    ParentR.Add(ListSeed[index - 1]);
                }

                ObservableCollection <ChildCard> result = new ObservableCollection <ChildCard>();
                foreach (var L in ParentL)
                {
                    foreach (var R in ParentR)
                    {
                        var children = FlowerHelper.GetOurChildren(L, R);
                        foreach (var child in children)
                        {
                            var  childcard = new ChildCard(L, R, child, FlowerHelper.GetProbability(L, R, child));
                            bool isinList  = false;
                            foreach (var a in result)
                            {
                                if (
                                    (
                                        childcard.Gene == a.Gene &&
                                        childcard.GeneP1 == a.GeneP1 &&
                                        childcard.GeneP2 == a.GeneP2
                                    )
                                    ||
                                    (
                                        childcard.Gene == a.Gene &&
                                        childcard.GeneP2 == a.GeneP1 &&
                                        childcard.GeneP1 == a.GeneP2
                                    )
                                    )
                                {
                                    isinList = true;
                                }
                            }
                            if (!isinList)
                            {
                                result.Add(childcard);
                            }
                        }
                    }
                }
                Action <IEnumerable> updateAction = new Action <IEnumerable>(ShowData);
                this.Dispatcher.BeginInvoke(updateAction, result);
            }
            break;
            }
        }
Beispiel #2
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (GlobalTool.NaviViewMain.SelectedItem != GlobalTool.NaviItemZajiao)
            {
                return;
            }

            List <MyFlower> ParentL = new List <MyFlower>();
            List <MyFlower> ParentR = new List <MyFlower>();

            if (GlobalTool.BoolColorL == true)
            {//按颜色L
                if (GlobalTool.IndexColorL == 0)
                {
                    GlobalTool.TipSearch.IsOpen = true;
                    return;
                }
                foreach (var everyflower in SelectedColorDicL)
                {
                    ParentL.Add(everyflower);
                }
            }
            if (GlobalTool.BoolColorR == true)
            {//按颜色R
                if (GlobalTool.IndexColorR == 0)
                {
                    GlobalTool.TipSearch.IsOpen = true;
                    return;
                }
                foreach (var everyflower in SelectedColorDicR)
                {
                    ParentR.Add(everyflower);
                }
            }
            if (GlobalTool.BoolGeneL == true)
            {//按基因型L
                Gene     a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1L);
                Gene     a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2L);
                Gene     a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3L);
                Gene     a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4L);
                MyFlower f  = new MyFlower(GlobalTool.SelectedFlower, a1, a2, a3, a4);
                foreach (var i in f.GetIntArray())
                {
                    if (i == 0)
                    {
                        GlobalTool.TipSearch.IsOpen = true;
                        return;
                    }
                }
                foreach (var a in GlobalTool.ListColorDic)
                {
                    if (f.GetGeneName() == a.GetGeneName())
                    {
                        ParentL.Add(a);
                    }
                }
            }
            if (GlobalTool.BoolGeneR == true)
            {//按基因型R
                Gene     a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1R);
                Gene     a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2R);
                Gene     a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3R);
                Gene     a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4R);
                MyFlower f  = new MyFlower(GlobalTool.SelectedFlower, a1, a2, a3, a4);
                foreach (var i in f.GetIntArray())
                {
                    if (i == 0)
                    {
                        GlobalTool.TipSearch.IsOpen = true;
                        return;
                    }
                }
                foreach (var a in GlobalTool.ListColorDic)
                {
                    if (f.GetGeneName() == a.GetGeneName())
                    {
                        ParentR.Add(a);
                    }
                }
            }
            if (GlobalTool.BoolSeedL == true)
            {//按种子L
                int index = GlobalTool.IndexSeedL;
                if (index == 0)
                {
                    GlobalTool.TipSearch.IsOpen = true;
                    return;
                }
                ParentL.Add(ListSeed[index - 1]);
            }
            if (GlobalTool.BoolSeedR == true)
            {//按种子R
                int index = GlobalTool.IndexSeedR;
                if (index == 0)
                {
                    GlobalTool.TipSearch.IsOpen = true;
                    return;
                }
                ParentR.Add(ListSeed[index - 1]);
            }

            GlobalTool.ShowProgress();
            await Task.Factory.StartNew(() =>
            {
                ObservableCollection <ChildCard> result = new ObservableCollection <ChildCard>();
                foreach (var L in ParentL)
                {
                    foreach (var R in ParentR)
                    {
                        var children = FlowerHelper.GetOurChildren(L, R);
                        foreach (var child in children)
                        {
                            var childcard = new ChildCard(L, R, child, FlowerHelper.GetProbability(L, R, child));
                            bool isinList = false;
                            foreach (var a in result)
                            {
                                if (
                                    (
                                        childcard.Gene == a.Gene &&
                                        childcard.GeneP1 == a.GeneP1 &&
                                        childcard.GeneP2 == a.GeneP2
                                    )
                                    ||
                                    (
                                        childcard.Gene == a.Gene &&
                                        childcard.GeneP2 == a.GeneP1 &&
                                        childcard.GeneP1 == a.GeneP2
                                    )
                                    )
                                {
                                    isinList = true;
                                }
                            }
                            if (!isinList)
                            {
                                result.Add(childcard);
                            }
                        }
                    }
                }
                Sync.Post((o) =>
                {
                    GlobalTool.CloseProgress();
                    var r = o as ObservableCollection <ChildCard>;
                    ListViewChildren.ItemsSource = r;
                }, result);
            });
        }