Esempio n. 1
0
        /// <summary>
        /// 获取……孩子们
        /// </summary>
        /// <param name="f1">爸比</param>
        /// <param name="f2">妈咪</param>
        /// <returns>孩子们</returns>
        public static List <MyFlower> GetOurChildren(MyFlower f1, MyFlower f2)
        {
            List <MyFlower> result = new List <MyFlower>();

            if (f1.Type != f2.Type)
            {
                return(result);
            }

            var AllFlowers = GetFlowerPart(f1.GetFlowerType());

            List <MyFlower> f1children = f1.GetChildren();
            List <MyFlower> f2children = f2.GetChildren();

            foreach (var f1child in f1children)
            {
                int[] aa = f1child.GetIntArray();
                foreach (var f2child in f2children)
                {
                    int[] bb = f2child.GetIntArray();
                    int[] cc = new int[aa.Length];
                    for (int i = 0; i < aa.Length; i++)
                    {
                        cc[i] = aa[i] + bb[i];
                    }
                    foreach (var f in AllFlowers)
                    {
                        int eq = 0;
                        var fi = f.GetIntArray();
                        for (int i = 0; i < fi.Length; i++)
                        {
                            if (cc[i] == fi[i])
                            {
                                eq++;
                            }
                        }
                        if (eq == fi.Length)
                        {
                            bool inresult = false;
                            foreach (var r in result)
                            {
                                if (r.GetGeneName() == f.GetGeneName())
                                {
                                    inresult = true;
                                }
                            }
                            if (!inresult)
                            {
                                result.Add(f);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取概率
        /// </summary>
        /// <param name="p1">父本1</param>
        /// <param name="p2">父本2</param>
        /// <param name="c">儿子</param>
        /// <returns>概率</returns>
        public static float GetProbability(MyFlower f1, MyFlower f2, MyFlower c)
        {
            if (f1.Type != f2.Type || f1.Type != c.Type)
            {
                return(0);
            }
            int[] f1ca = f1.GetIntArray();
            int[] f2ca = f2.GetIntArray();

            float        zongshu = 1;
            List <int[]> f1c     = new List <int[]>();
            List <int[]> f2c     = new List <int[]>();

            int[] linshi = new int[f1ca.Length];
            Permutation(ref f1c, ref zongshu, linshi, f1ca, 0);
            Permutation(ref f2c, ref zongshu, linshi, f2ca, 0);

            int count = 0;

            for (int i = 0; i < f1c.Count; i++)
            {
                for (int j = 0; j < f2c.Count; j++)
                {
                    int[] ca = c.GetIntArray();
                    if (c.GetFlowerType() == FlowerType.Roses)
                    {
                        if (
                            ca[0] == f1c[i][0] + f2c[j][0] &&
                            ca[1] == f1c[i][1] + f2c[j][1] &&
                            ca[2] == f1c[i][2] + f2c[j][2] &&
                            ca[3] == f1c[i][3] + f2c[j][3]
                            )
                        {
                            count++;
                        }
                    }
                    else
                    {
                        if (ca[0] == f1c[i][0] + f2c[j][0] &&
                            ca[1] == f1c[i][1] + f2c[j][1] &&
                            ca[2] == f1c[i][2] + f2c[j][2]
                            )
                        {
                            count++;
                        }
                    }
                }
            }
            float r = count / zongshu;

            return(r);
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
0
        private void GroupChanged(object sender, SelectionChangedEventArgs e)
        {
            GlobalTool.ChangeZajiaoComboBox(sender);

            ComboBox cb = sender as ComboBox;

            string senderName = cb.Name;

            switch (senderName)
            {
            case "ComboBoxChoose":
            {
                SelectedFlower = (FlowerType)cb.SelectedIndex + 1;

                TextBlockTypeL.Text = FlowerHelper.FlowerNameShow[SelectedFlower];
                TextBlockTypeR.Text = TextBlockTypeL.Text;

                ListColorDic = new List <MyFlower>();
                ListColorDic = FlowerHelper.GetFlowerPart(SelectedFlower);

                ListColor     = new List <string>();
                ListColorName = new List <string>();
                ListColor.Add("");
                ListColorName.Add("无");
                foreach (var a in ListColorDic)
                {
                    if (!ListColor.Contains(a.Color) && a.Color != "Unknown")
                    {
                        ListColor.Add(a.Color);
                        MyColor mc = (MyColor)Enum.Parse(typeof(MyColor), a.Color);
                        ListColorName.Add(FlowerHelper.ColorNameShow[mc]);
                    }
                }

                ComboBoxColorL.SelectionChanged -= GroupChanged;
                ComboBoxColorR.SelectionChanged -= GroupChanged;
                ComboBoxColorL.ItemsSource       = ListColorName;
                ComboBoxColorR.ItemsSource       = ListColorName;
                ComboBoxColorL.SelectedIndex     = 0;
                ComboBoxColorR.SelectedIndex     = 0;
                ComboBoxColorL.SelectionChanged += GroupChanged;
                ComboBoxColorR.SelectionChanged += GroupChanged;
                ComboBoxColorL.SelectedIndex     = 1;
                ComboBoxColorR.SelectedIndex     = 1;

                CheckBoxColorL.IsChecked = true;
                CheckBoxColorR.IsChecked = true;

                //需要在选定花朵之后绑定种子
                BindSeed();
            }
            break;

            case "ComboBoxColorL":
            {
                if (cb.SelectedIndex == 0)
                {
                    return;
                }

                SelectedColorL = (MyColor)Enum.Parse(typeof(MyColor), ListColor[cb.SelectedIndex]);

                TextBlockColorL.Text       = FlowerHelper.ColorNameShow[SelectedColorL];
                TextBlockColorL.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[SelectedColorL]);
                ImageFlowerL.Source        = new BitmapImage(new Uri("/Assets/" + SelectedFlower.ToString() + SelectedColorL.ToString() + ".png", UriKind.Relative));

                string s = "";
                SelectedColorDicL = new List <MyFlower>();
                foreach (var a in ListColorDic)
                {
                    if (a.Color == ListColor[cb.SelectedIndex])
                    {
                        SelectedColorDicL.Add(a);
                        string n = a.GetGeneName();
                        if (!s.Contains(n))
                        {
                            s += n + " ";
                        }
                    }
                }
                TextBlockGeneL.Text = s;
            }
            break;

            case "ComboBoxColorR":
            {
                if (cb.SelectedIndex == 0)
                {
                    return;
                }

                SelectedColorR = (MyColor)Enum.Parse(typeof(MyColor), ListColor[cb.SelectedIndex]);

                TextBlockColorR.Text       = FlowerHelper.ColorNameShow[SelectedColorR];
                TextBlockColorR.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[SelectedColorR]);
                ImageFlowerR.Source        = new BitmapImage(new Uri("/Assets/" + SelectedFlower.ToString() + SelectedColorR.ToString() + ".png", UriKind.Relative));

                string s = "";
                SelectedColorDicR = new List <MyFlower>();
                foreach (var a in ListColorDic)
                {
                    if (a.Color == ListColor[cb.SelectedIndex])
                    {
                        SelectedColorDicR.Add(a);
                        string n = a.GetGeneName();
                        if (!s.Contains(n))
                        {
                            s += n + " ";
                        }
                    }
                }
                TextBlockGeneR.Text = s;
            }
            break;

            case "ComboBoxA1L":
            case "ComboBoxA2L":
            case "ComboBoxA3L":
            case "ComboBoxA4L":
            {
                if (CheckBoxGeneL.IsChecked == false)
                {
                    return;
                }

                int a1  = ComboBoxA1L.SelectedIndex;
                int a2  = ComboBoxA2L.SelectedIndex;
                int a3  = ComboBoxA3L.SelectedIndex;
                int a4  = ComboBoxA4L.SelectedIndex;
                int aa1 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA1L.SelectedItem.ToString());
                int aa2 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA2L.SelectedItem.ToString());
                int aa3 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA3L.SelectedItem.ToString());
                int aa4 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA4L.SelectedItem.ToString());

                if (
                    (a1 > 0 && a2 > 0 && a3 > 0 && SelectedFlower != FlowerType.Roses)
                    ||
                    (a1 > 0 && a2 > 0 && a3 > 0 && a4 > 0)
                    )
                {
                    MyFlower cd = new MyFlower();
                    foreach (var a in ListColorDic)
                    {
                        if (SelectedFlower == FlowerType.Roses)
                        {
                            if (a.A1 == aa1.ToString() && a.A2 == aa2.ToString() && a.A3 == aa3.ToString() && a.A4 == aa4.ToString())
                            {
                                cd = a;
                                break;
                            }
                        }
                        else
                        {
                            if (a.A1 == aa1.ToString() && a.A2 == aa2.ToString() && a.A3 == aa3.ToString())
                            {
                                cd = a;
                                break;
                            }
                        }
                    }
                    TextBlockGeneL.Text        = cd.GetGeneName();
                    TextBlockColorL.Text       = FlowerHelper.ColorNameShow[cd.GetColor()];
                    TextBlockColorL.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[cd.GetColor()]);

                    string path = cd.GetImagePath();
                    ImageFlowerL.Source = new BitmapImage(new Uri(path, UriKind.Relative));
                }
            }
            break;

            case "ComboBoxA1R":
            case "ComboBoxA2R":
            case "ComboBoxA3R":
            case "ComboBoxA4R":
            {
                if (CheckBoxGeneR.IsChecked == false)
                {
                    return;
                }

                int a1  = ComboBoxA1R.SelectedIndex;
                int a2  = ComboBoxA2R.SelectedIndex;
                int a3  = ComboBoxA3R.SelectedIndex;
                int a4  = ComboBoxA4R.SelectedIndex;
                int aa1 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA1R.SelectedItem.ToString());
                int aa2 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA2R.SelectedItem.ToString());
                int aa3 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA3R.SelectedItem.ToString());
                int aa4 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA4R.SelectedItem.ToString());

                if (
                    (a1 > 0 && a2 > 0 && a3 > 0 && SelectedFlower != FlowerType.Roses)
                    ||
                    (a1 > 0 && a2 > 0 && a3 > 0 && a4 > 0)
                    )
                {
                    MyFlower cd = new MyFlower();
                    foreach (var a in ListColorDic)
                    {
                        if (SelectedFlower == FlowerType.Roses)
                        {
                            if (a.A1 == aa1.ToString() && a.A2 == aa2.ToString() && a.A3 == aa3.ToString() && a.A4 == aa4.ToString())
                            {
                                cd = a;
                                break;
                            }
                        }
                        else
                        {
                            if (a.A1 == aa1.ToString() && a.A2 == aa2.ToString() && a.A3 == aa3.ToString())
                            {
                                cd = a;
                                break;
                            }
                        }
                    }
                    TextBlockGeneR.Text        = cd.GetGeneName();
                    TextBlockColorR.Text       = FlowerHelper.ColorNameShow[cd.GetColor()];
                    TextBlockColorR.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[cd.GetColor()]);

                    string path = cd.GetImagePath();
                    ImageFlowerR.Source = new BitmapImage(new Uri(path, UriKind.Relative));
                }
            }
            break;

            case "ComboBoxSeedL":
            {
                if (cb.SelectedIndex == 0)
                {
                    return;
                }
                int index = cb.SelectedIndex - 1;
                TextBlockGeneL.Text        = ListSeed[index].GetGeneName();
                TextBlockColorL.Text       = FlowerHelper.ColorNameShow[ListSeed[index].GetColor()];
                TextBlockColorL.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[ListSeed[index].GetColor()]);
                string path = ListSeed[index].GetImagePath();
                ImageFlowerL.Source = new BitmapImage(new Uri(path, UriKind.Relative));
            }
            break;

            case "ComboBoxSeedR":
            {
                if (cb.SelectedIndex == 0)
                {
                    return;
                }
                int index = cb.SelectedIndex - 1;
                TextBlockGeneR.Text        = ListSeed[index].GetGeneName();
                TextBlockColorR.Text       = FlowerHelper.ColorNameShow[ListSeed[index].GetColor()];
                TextBlockColorR.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[ListSeed[index].GetColor()]);
                string path = ListSeed[index].GetImagePath();
                ImageFlowerR.Source = new BitmapImage(new Uri(path, UriKind.Relative));
            }
            break;
            }
        }
Esempio n. 5
0
        private void B_Click()
        {
            switch (GlobalTool.ButtonNameParent)
            {
            case "ButtonSearch":
            {
                ObservableCollection <ParentCard> reCard = new ObservableCollection <ParentCard>();

                if (GlobalTool.BoolColor == true)
                {        //按颜色查父本
                    if (GlobalTool.IndexColor == 0)
                    {
                        GlobalTool.OpenDialogButton(_syncContextTaskScheduler, "没有选择颜色");
                        return;
                    }
                    if (SelectedColorDic == null || SelectedColorDic.Count == 0)
                    {
                        return;
                    }

                    foreach (var everyflower in SelectedColorDic)
                    {
                        var parent = FlowerHelper.GetMyParent(everyflower);
                        foreach (var a in parent)
                        {
                            var  aa       = new ParentCard(a);
                            bool inResult = false;
                            foreach (var b in reCard)
                            {
                                if (b.TextGeneLeft == aa.TextGeneLeft && b.TextGeneRight == aa.TextGeneRight)
                                {
                                    inResult = true;
                                }
                            }
                            if (!inResult)
                            {
                                reCard.Add(aa);
                            }
                        }
                    }
                }
                if (GlobalTool.BoolGene == true)
                {        //按基因型查父本
                    Gene     a1 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1);
                    Gene     a2 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2);
                    Gene     a3 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3);
                    Gene     a4 = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4);
                    MyFlower f  = new MyFlower(SelectedFlower, a1, a2, a3, a4);
                    var      re = FlowerHelper.GetMyParent(f);

                    foreach (var a in re)
                    {
                        reCard.Add(new ParentCard(a));
                    }
                }

                Task.Factory.StartNew(() => ShowData(reCard),
                                      new CancellationTokenSource().Token, TaskCreationOptions.None, _syncContextTaskScheduler).Wait();
            }
            break;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 获取父本对列表
        /// </summary>
        /// <param name="flower">要获取父本的花朵</param>
        /// <returns>父本对列表</returns>
        public static List <MyFlower[]> GetMyParent(MyFlower flower)
        {
            int[] ig = flower.GetIntArray();

            if (ig.Length > 3)
            {
                if (ig == new int[] { 0, 0, 0, 0 })
                {
                    return(new List <MyFlower[]>());
                }
                if ((ig[0] > 0 && ig[0] < 4) || (ig[1] > 0 && ig[1] < 4) || (ig[2] > 0 && ig[2] < 4) || (ig[3] > 0 && ig[3] < 4))
                {
                    return(new List <MyFlower[]>());
                }
            }
            else
            {
                if (ig == new int[] { 0, 0, 0 })
                {
                    return(new List <MyFlower[]>());
                }
                if ((ig[0] > 0 && ig[0] < 4) || (ig[1] > 0 && ig[1] < 4) || (ig[2] > 0 && ig[2] < 4))
                {
                    return(new List <MyFlower[]>());
                }
                ig = new int[] { ig[0], ig[1], ig[2] };
            }

            List <List <int[]> > lli = new List <List <int[]> >();

            for (int i = 0; i < ig.Length; i++)
            {
                List <int[]> li = new List <int[]>();
                switch (ig[i])
                {
                case 4:
                    li.Add(new int[] { 4, 4 });
                    li.Add(new int[] { 4, 5 });
                    li.Add(new int[] { 5, 5 });
                    break;

                case 5:
                    li.Add(new int[] { 5, 5 });
                    li.Add(new int[] { 4, 6 });
                    li.Add(new int[] { 5, 6 });
                    break;

                case 6:
                    li.Add(new int[] { 5, 5 });
                    li.Add(new int[] { 5, 6 });
                    li.Add(new int[] { 6, 6 });
                    break;

                default:
                    li.Add(new int[] { 4, 4 });
                    li.Add(new int[] { 4, 5 });
                    li.Add(new int[] { 5, 5 });
                    li.Add(new int[] { 5, 6 });
                    li.Add(new int[] { 6, 6 });
                    li.Add(new int[] { 4, 6 });
                    break;
                }
                lli.Add(li);
            }

            List <MyFlower[]> result = new List <MyFlower[]>();

            int[] left, right;

            for (int i = 0; i < lli[0].Count; i++)
            {
                left     = new int[lli.Count];
                right    = new int[lli.Count];
                left[0]  = lli[0][i][0];
                right[0] = lli[0][i][1];
                for (int j = 0; j < lli[1].Count; j++)
                {
                    left[1]  = lli[1][j][0];
                    right[1] = lli[1][j][1];
                    for (int k = 0; k < lli[2].Count; k++)
                    {
                        left[2]  = lli[2][k][0];
                        right[2] = lli[2][k][1];
                        if (lli.Count == 4)
                        {
                            for (int h = 0; h < lli[3].Count; h++)
                            {
                                left[3]  = lli[3][h][0];
                                right[3] = lli[3][h][1];
                                MyFlower mfLeft = new MyFlower(
                                    flower.GetFlowerType(),
                                    (Gene)left[0],
                                    (Gene)left[1],
                                    (Gene)left[2],
                                    (Gene)left[3]);
                                MyFlower mfRight = new MyFlower(
                                    flower.GetFlowerType(),
                                    (Gene)right[0],
                                    (Gene)right[1],
                                    (Gene)right[2],
                                    (Gene)right[3]);
                                MyFlower[] ff = new MyFlower[] { mfLeft, mfRight };
                                if (!result.Contains(ff) || !result.Contains(ff.Reverse()))
                                {
                                    result.Add(ff);
                                }
                            }
                        }
                        else
                        {
                            MyFlower mfLeft = new MyFlower(
                                flower.GetFlowerType(),
                                (Gene)left[0],
                                (Gene)left[1],
                                (Gene)left[2]);
                            MyFlower mfRight = new MyFlower(
                                flower.GetFlowerType(),
                                (Gene)right[0],
                                (Gene)right[1],
                                (Gene)right[2]);
                            MyFlower[] ff = new MyFlower[] { mfLeft, mfRight };
                            if (!result.Contains(ff) || !result.Contains(ff.Reverse()))
                            {
                                result.Add(ff);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 7
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);
            });
        }
Esempio n. 8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (GlobalTool.NaviViewMain.SelectedItem != GlobalTool.NaviItemParent)
            {
                return;
            }

            ObservableCollection <ParentCard> reCard = new ObservableCollection <ParentCard>();

            GlobalTool.ShowProgress();
            Task.Factory.StartNew(() =>
            {
                if (GlobalTool.BoolColor == true)
                {//按颜色查父本
                    if (GlobalTool.IndexColor == 0)
                    {
                        GlobalTool.TipSearch.IsOpen = true;
                        return;
                    }
                    if (SelectedColorDic == null || SelectedColorDic.Count == 0)
                    {
                        return;
                    }

                    foreach (var everyflower in SelectedColorDic)
                    {
                        var parent = FlowerHelper.GetMyParent(everyflower);
                        foreach (var a in parent)
                        {
                            var aa        = new ParentCard(a);
                            bool inResult = false;
                            foreach (var b in reCard)
                            {
                                if (b.TextGeneLeft == aa.TextGeneLeft && b.TextGeneRight == aa.TextGeneRight)
                                {
                                    inResult = true;
                                }
                            }
                            if (!inResult)
                            {
                                reCard.Add(aa);
                            }
                        }
                    }
                }
                if (GlobalTool.BoolGene == true)
                {//按基因型查父本
                    Gene a1    = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA1);
                    Gene a2    = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA2);
                    Gene a3    = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA3);
                    Gene a4    = (Gene)Enum.Parse(typeof(Gene), GlobalTool.ItemA4);
                    MyFlower f = new MyFlower(GlobalTool.SelectedFlower, a1, a2, a3, a4);
                    var re     = FlowerHelper.GetMyParent(f);

                    foreach (var a in re)
                    {
                        reCard.Add(new ParentCard(a));
                    }
                }

                Sync.Post((o) =>
                {
                    GlobalTool.CloseProgress();
                    var r = o as ObservableCollection <ParentCard>;
                    ListViewParent.ItemsSource = r;
                }, reCard);
            });
        }
Esempio n. 9
0
        private void GroupChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;

            GlobalTool.ChangeParentComboBox(sender);

            string senderName = cb.Name;

            switch (senderName)
            {
            case "ComboBoxChoose":
            {
                if (cb.SelectedIndex < 0)
                {
                    return;
                }
                TextBlockType.Text = FlowerHelper.FlowerNameShow[GlobalTool.SelectedFlower];

                ComboBoxColor.SelectionChanged -= GroupChanged;
                ComboBoxColor.ItemsSource       = GlobalTool.ListColorName;
                ComboBoxColor.SelectedIndex     = 0;
                ComboBoxColor.SelectionChanged += GroupChanged;
                ComboBoxColor.SelectedIndex     = 1;

                CheckBoxColor.IsChecked = true;
            }
            break;

            case "ComboBoxColor":
            {
                if (cb.SelectedIndex == 0)
                {
                    return;
                }

                SelectedColor = (MyColor)Enum.Parse(typeof(MyColor), GlobalTool.ListColor[cb.SelectedIndex]);

                TextBlockColor.Text       = FlowerHelper.ColorNameShow[SelectedColor];
                TextBlockColor.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[SelectedColor]);
                ImageFlower.Source        = new BitmapImage(new Uri("ms-appx:///Assets/" + GlobalTool.SelectedFlower.ToString() + SelectedColor.ToString() + ".png"));

                string s = "";
                SelectedColorDic = new List <MyFlower>();
                foreach (var a in GlobalTool.ListColorDic)
                {
                    if (a.Color == GlobalTool.ListColor[cb.SelectedIndex])
                    {
                        SelectedColorDic.Add(a);
                        string n = a.GetGeneName();
                        if (!s.Contains(n))
                        {
                            s += n + " ";
                        }
                    }
                }
                TextBlockGene.Text = s;
            }
            break;

            case "ComboBoxA1":
            case "ComboBoxA2":
            case "ComboBoxA3":
            case "ComboBoxA4":
            {
                if (CheckBoxGene.IsChecked == false)
                {
                    return;
                }

                int a1  = ComboBoxA1.SelectedIndex;
                int a2  = ComboBoxA2.SelectedIndex;
                int a3  = ComboBoxA3.SelectedIndex;
                int a4  = ComboBoxA4.SelectedIndex;
                int aa1 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA1.SelectedItem.ToString());
                int aa2 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA2.SelectedItem.ToString());
                int aa3 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA3.SelectedItem.ToString());
                int aa4 = (int)(Gene)Enum.Parse(typeof(Gene), ComboBoxA4.SelectedItem.ToString());

                if (
                    (a1 > 0 && a2 > 0 && a3 > 0 && GlobalTool.SelectedFlower != FlowerType.Roses)
                    ||
                    (a1 > 0 && a2 > 0 && a3 > 0 && a4 > 0)
                    )
                {
                    MyFlower cd = new MyFlower();
                    foreach (var a in GlobalTool.ListColorDic)
                    {
                        if (GlobalTool.SelectedFlower == FlowerType.Roses)
                        {
                            if (a.A1 == aa1.ToString() && a.A2 == aa2.ToString() && a.A3 == aa3.ToString() && a.A4 == aa4.ToString())
                            {
                                cd = a;
                                break;
                            }
                        }
                        else
                        {
                            if (a.A1 == aa1.ToString() && a.A2 == aa2.ToString() && a.A3 == aa3.ToString())
                            {
                                cd = a;
                                break;
                            }
                        }
                    }
                    TextBlockGene.Text        = cd.GetGeneName();
                    TextBlockColor.Text       = FlowerHelper.ColorNameShow[cd.GetColor()];
                    TextBlockColor.Foreground = new SolidColorBrush(FlowerHelper.ColorShow[cd.GetColor()]);

                    ImageFlower.Source = new BitmapImage(new Uri(cd.GetImagePath()));
                }
            }
            break;
            }
        }