Ejemplo n.º 1
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;
            }
        }