Exemplo n.º 1
0
        /// <summary>
        /// Check which view mode is selected and update the current view
        /// </summary>
        /// <param name="aViewMode"></param>
        private void UpdatePropertyView(ViewModes aViewMode)
        {
            // Get the view
            System.ComponentModel.ICollectionView crtView = CollectionViewSource.GetDefaultView(mProperties);
            if (crtView == null)
            {
                return;
            }

            if (aViewMode == ViewModes.Alphabetical)
            {
                // Remove the groups
                crtView.GroupDescriptions.Clear();

                // Sort options alphabetically by name
                crtView.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending));
            }
            else if (aViewMode == ViewModes.Grouped)
            {
                // Remove the sorting
                crtView.SortDescriptions.Clear();

                // Add the options groups
                crtView.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
            }

            crtView.Refresh();
        }
Exemplo n.º 2
0
        public void creatWindow(bool edit, DataGrid datagrid0)
        {
            if (!settingUp)
            {
                int    p1ID  = -1;
                string p2IDs = "-1";
                if (edit)
                {
                    p1ID  = int.Parse(((DataRowView)datagrid0.SelectedItem).Row["ID"].ToString());
                    p2IDs = ((DataRowView)datagrid0.SelectedItem).Row["对方武将ID"].ToString();
                }

                int    temp1     = p1ID;
                string tempP2IDs = p2IDs;
                //int temp2 = p2ID;
                Window win = new Window();
                win.Title = "编辑武将关系";
                if (!edit)
                {
                    win.Title = "新增武将关系";
                }
                win.Width      = 500;
                win.Height     = 250;
                win.ResizeMode = ResizeMode.NoResize;
                Grid grid = new Grid();
                win.Content = grid;
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(2, GridUnitType.Star)
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(2, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(2, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(2, GridUnitType.Star)
                });

                Person         p1      = scen.Persons.GetGameObject(p1ID) as Person;
                string         p1name  = p1 == null ? "" : p1.Name;
                string         p2names = "";
                GameObjectList list    = new GameObjectList();

                char[]   separator = new char[] { ' ', '\n', '\r', '\t' };
                string[] strArray  = p2IDs.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < strArray.Length; i++)
                {
                    Person p2 = scen.Persons.GetGameObject(int.Parse(strArray[i])) as Person;
                    if (p2 != null)
                    {
                        list.Add(p2);
                        p2names = p2names + p2.Name + " ";
                    }
                }
                string tempP1name  = p1name;
                string tempP2names = p2names;

                Label labelP1ID = new Label {
                    Content = "武将ID:   " + p1ID, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                };
                Label labelP1 = new Label {
                    Content = "武将名称:   " + p1name, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                };
                Button buttonperson = new Button()
                {
                    Width = 75, Height = 30, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = p1name, IsEnabled = !edit
                };
                Label labelP2ID = new Label {
                    Content = "对方武将ID:   " + p2IDs, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                };
                Label labelP2 = new Label {
                    Content = "对方武将名称:   " + p2names, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center
                };
                Button button2person = new Button()
                {
                    Width = 75, Height = 30, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = p2names
                };
                buttonperson.Click  += Buttonperson_Click;
                button2person.Click += Button2person_Click;
                void Buttonperson_Click(object sender, RoutedEventArgs e)
                {
                    Window window = new Window();

                    window.Title = "请选择武将--双击确认";
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    window.Width  = 800;
                    window.Height = 600;
                    Grid grid2 = new Grid();

                    window.Content = grid2;
                    grid2.Margin   = new Thickness(50);
                    ListBox   listBox   = new ListBox();
                    DataGrid  dataGrid1 = new DataGrid();
                    DataTable dt2       = new DataTable();

                    dt2.Columns.Add("ID", typeof(int));
                    dt2.Columns.Add("姓名");
                    dt2.Columns.Add("性别");
                    dt2.Columns.Add("所在");
                    dt2.Columns.Add("所属势力");
                    dt2.Columns.Add("武学");
                    dt2.Columns.Add("将略");
                    dt2.Columns.Add("谋略");
                    dt2.Columns.Add("政理");
                    dt2.Columns.Add("风度");
                    DataRow dr1 = dt2.NewRow();

                    dr1["ID"] = -1;
                    dr1["姓名"] = "无";
                    dt2.Rows.Add(dr1);
                    foreach (Person person in scen.Persons)
                    {
                        DataRow dr = dt2.NewRow();
                        dr["ID"]   = person.ID;
                        dr["姓名"]   = person.Name;
                        dr["性别"]   = person.SexString;
                        dr["所在"]   = person.Location;
                        dr["所属势力"] = person.BelongedFaction;
                        dr["武学"]   = person.Strength;
                        dr["将略"]   = person.Command;
                        dr["谋略"]   = person.Intelligence;
                        dr["政理"]   = person.Politics;
                        dr["风度"]   = person.Glamour;
                        dt2.Rows.Add(dr);
                    }
                    dataGrid1.ItemsSource       = dt2.DefaultView;
                    dataGrid1.MouseDoubleClick += dataGrid1_MouseDoubleClick;
                    void dataGrid1_MouseDoubleClick(object sender2, MouseButtonEventArgs e2)
                    {
                        if (dataGrid1.SelectedItem != null)
                        {
                            DataTable dt5 = ((DataView)dataGrid1.ItemsSource).ToTable();
                            p1ID = int.Parse(dt5.Rows[dataGrid1.SelectedIndex]["ID"].ToString());
                            window.Close();
                            p1                   = scen.Persons.GetGameObject(p1ID) as Person;
                            p1name               = p1 == null ? "" : p1.Name;
                            labelP1ID.Content    = "武将ID:   " + p1ID;
                            labelP1.Content      = "武将名称:   " + p1name;
                            buttonperson.Content = p1name;
                        }
                    }

                    dataGrid1.IsReadOnly = true;
                    grid2.Children.Add(dataGrid1);
                    dataGrid1.ColumnWidth = new DataGridLength(1, DataGridLengthUnitType.Star);
                    window.ShowDialog();
                }

                void Button2person_Click(object sender, RoutedEventArgs e)
                {
                    list     = new GameObjectList();
                    strArray = p2IDs.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        Person p2 = scen.Persons.GetGameObject(int.Parse(strArray[i])) as Person;
                        if (p2 != null)
                        {
                            list.Add(p2);
                        }
                    }
                    Window window      = new Window();
                    string titleplugin = "  注意:最多只能选一个";

                    window.Title = "请选择武将-勾选后点击确认" + titleplugin;;
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    window.Width  = 800;
                    window.Height = 600;
                    Grid grid2 = new Grid();

                    window.Content = grid2;
                    grid2.Margin   = new Thickness(50);
                    ListBox   listBox   = new ListBox();
                    DataGrid  dataGrid1 = new DataGrid();
                    DataTable dt2       = new DataTable();

                    dt2.Columns.Add("选择", typeof(bool));
                    dt2.Columns.Add("ID", typeof(int));
                    dt2.Columns.Add("姓名");
                    dt2.Columns.Add("性别");
                    dt2.Columns.Add("所在");
                    dt2.Columns.Add("所属势力");
                    dt2.Columns.Add("武学");
                    dt2.Columns.Add("将略");
                    dt2.Columns.Add("谋略");
                    dt2.Columns.Add("政理");
                    dt2.Columns.Add("风度");
                    foreach (Person person in scen.Persons)
                    {
                        DataRow dr = dt2.NewRow();
                        dr["选择"] = false;
                        if (list.HasGameObject(person))
                        {
                            dr["选择"] = true;
                        }
                        dr["ID"]   = person.ID;
                        dr["姓名"]   = person.Name;
                        dr["性别"]   = person.SexString;
                        dr["所在"]   = person.Location;
                        dr["所属势力"] = person.BelongedFaction;
                        dr["武学"]   = person.Strength;
                        dr["将略"]   = person.Command;
                        dr["谋略"]   = person.Intelligence;
                        dr["政理"]   = person.Politics;
                        dr["风度"]   = person.Glamour;
                        dt2.Rows.Add(dr);
                    }
                    dataGrid1.CanUserAddRows = false;
                    foreach (DataColumn column in dt2.Columns)
                    {
                        if (!column.ColumnName.Equals("选择"))
                        {
                            column.ReadOnly = true;
                        }
                    }
                    dataGrid1.ItemsSource        = dt2.DefaultView;
                    dataGrid1.MouseLeftButtonUp += DataGrid1_MouseLeftButtonUp;
                    void DataGrid1_MouseLeftButtonUp(object sender2, MouseButtonEventArgs e2)
                    {
                        if (!bool.Parse(((DataRowView)dataGrid1.SelectedItem).Row["选择"].ToString()))
                        {
                            ((DataRowView)dataGrid1.SelectedItem).Row["选择"] = true;
                        }
                        else if (bool.Parse(((DataRowView)dataGrid1.SelectedItem).Row["选择"].ToString()))
                        {
                            ((DataRowView)dataGrid1.SelectedItem).Row["选择"] = false;
                        }
                    }

                    Button buttonsave2 = new Button()
                    {
                        Width = 50, Height = 25, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom, Content = "确定"
                    };

                    buttonsave2.Click += Buttonsave2_Click;
                    void Buttonsave2_Click(object sender2, RoutedEventArgs e2)
                    {
                        DataTable dataTable = ((DataView)dataGrid1.ItemsSource).ToTable();
                        int       n         = 0;
                        string    idssss    = "";
                        string    namessss  = "";

                        foreach (DataRow row in dataTable.Rows)
                        {
                            if (bool.Parse(row["选择"].ToString()))
                            {
                                idssss   = idssss + row["ID"].ToString() + " ";
                                namessss = namessss + row["姓名"].ToString() + " ";
                                n++;
                            }
                        }
                        if (n > 1)
                        {
                            System.ComponentModel.ICollectionView v = CollectionViewSource.GetDefaultView(dt2);
                            v.SortDescriptions.Clear();
                            v.SortDescriptions.Add(new System.ComponentModel.SortDescription("选择", System.ComponentModel.ListSortDirection.Descending));
                            v.Refresh();
                            dataGrid1.ColumnFromDisplayIndex(0).SortDirection = System.ComponentModel.ListSortDirection.Descending;

                            //dataGrid1.Columns[dt2.Columns["选择"].Ordinal].SortDirection = System.ComponentModel.ListSortDirection.Descending;
                            //  dt2.DefaultView.Sort = ("选择 DESC");//这种方法会无法取消已点击列标题产生的排列
                            MessageBox.Show("此类关系最多只允许选择一个武将");
                        }
                        else if (n == 0)
                        {
                            p2IDs   = "-1";
                            p2names = "";
                            window.Close();
                            labelP2ID.Content     = "武将ID:   " + p2IDs;
                            labelP2.Content       = "武将名称:   " + p2names;
                            button2person.Content = p2names;
                        }
                        else
                        {
                            p2IDs   = idssss;
                            p2names = namessss;
                            window.Close();
                            labelP2ID.Content     = "武将ID:   " + p2IDs;
                            labelP2.Content       = "武将名称:   " + p2names;
                            button2person.Content = p2names;
                        }
                    }

                    Button buttonexit2 = new Button()
                    {
                        Width = 50, Height = 25, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Content = "取消"
                    };

                    buttonexit2.Click += Buttonexit2_Click;
                    void Buttonexit2_Click(object sender2, RoutedEventArgs e2)
                    {
                        window.Close();
                    }

                    dataGrid1.Margin = new Thickness(0, 0, 0, 30);
                    grid2.Children.Add(dataGrid1);
                    grid2.Children.Add(buttonsave2);
                    grid2.Children.Add(buttonexit2);
                    dataGrid1.ColumnWidth = new DataGridLength(1, DataGridLengthUnitType.Star);
                    window.ShowDialog();
                }

                Button buttonBack = new Button()
                {
                    Width = 75, Height = 30, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = "还原初始设置"
                };
                buttonBack.Click += ButtonBack_Click;
                void ButtonBack_Click(object sender, RoutedEventArgs e)
                {
                    p1ID    = temp1;
                    p1name  = tempP1name;
                    p2IDs   = tempP2IDs;
                    p2names = tempP2names;

                    labelP1ID.Content     = "武将ID:   " + p1ID;
                    labelP1.Content       = "武将名称:   " + p1name;
                    buttonperson.Content  = p1name;
                    labelP2ID.Content     = "武将ID:   " + p2IDs;
                    labelP2.Content       = "武将名称:   " + p2names;
                    button2person.Content = p2names;
                }

                Button buttonSave = new Button()
                {
                    Width = 75, Height = 30, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = "保存退出"
                };
                void dicclose1(int P1ID, int P2ID, Dictionary <int, int> dict, Window window)
                {
                    if (P1ID != -1)
                    {
                        if (dict.ContainsKey(P1ID))
                        {
                            dict[P1ID] = P2ID;
                        }
                        else
                        {
                            dict.Remove(P1ID);
                            dict.Add(P1ID, P2ID);
                        }
                    }
                    window.Close();
                }

                buttonSave.Click += ButtonSave_Click;
                void ButtonSave_Click(object sender, RoutedEventArgs e)
                {
                    Dictionary <int, int> dict = new Dictionary <int, int>();
                    int p2ID = int.Parse(p2IDs);

                    if (datagrid0.Name == "dgFatherId")
                    {
                        dict = scen.FatherIds;
                        dicclose1(p1ID, p2ID, dict, win);
                    }
                    else if (datagrid0.Name == "dgMotherId")
                    {
                        dict = scen.MotherIds;
                        dicclose1(p1ID, p2ID, dict, win);
                    }
                    else if (datagrid0.Name == "dgSpouseId")
                    {
                        dict = scen.SpouseIds;
                        dicclose1(p1ID, p2ID, dict, win);
                    }
                    initdt();
                }

                Button buttonExit = new Button()
                {
                    Width = 75, Height = 30, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = "直接退出"
                };
                buttonExit.Click += ButtonExit_Click;
                void ButtonExit_Click(object sender, RoutedEventArgs e)
                {
                    win.Close();
                }

                grid.Children.Add(labelP1ID);
                grid.Children.Add(labelP1);
                grid.Children.Add(buttonperson);
                grid.Children.Add(labelP2ID);
                grid.Children.Add(labelP2);
                grid.Children.Add(button2person);
                grid.Children.Add(buttonBack);
                grid.Children.Add(buttonSave);
                grid.Children.Add(buttonExit);
                Grid.SetColumn(labelP1ID, 0);
                Grid.SetRow(labelP1ID, 0);
                Grid.SetColumn(labelP1, 0);
                Grid.SetRow(labelP1, 1);
                Grid.SetColumn(buttonperson, 0);
                Grid.SetRow(buttonperson, 2);
                Grid.SetColumn(buttonBack, 1);
                Grid.SetRow(buttonBack, 0);
                Grid.SetColumn(buttonSave, 1);
                Grid.SetRow(buttonSave, 1);
                Grid.SetColumn(buttonExit, 1);
                Grid.SetRow(buttonExit, 2);
                Grid.SetColumn(labelP2ID, 2);
                Grid.SetRow(labelP2ID, 0);
                Grid.SetColumn(labelP2, 2);
                Grid.SetRow(labelP2, 1);
                Grid.SetColumn(button2person, 2);
                Grid.SetRow(button2person, 2);
                win.ShowDialog();
            }
        }