コード例 #1
0
ファイル: Form2.cs プロジェクト: t0is/fantastic-spork
        public Form2(string b, string p_id = "")
        {
            InitializeComponent();

            if (b == "add")
            {
                //add
                Player_add_edit.Visible  = true;
                label2.Visible           = false;
                button2.Visible          = true;
                button1.Visible          = false;
                textBox3.Visible         = false;
                button3.Visible          = false;
                TransferButton.Visible   = false;
                comboBoxTransfer.Visible = false;

                foreach (var r in role)
                {
                    comboBoxRole.Items.Add(r);
                }
                comboBoxRole.SelectedIndex = -1;


                var games = GameTable.Select();
                foreach (Game g in games)
                {
                    comboBoxGame.Items.Add(g.Name);
                }
                comboBoxGame.SelectedIndex = -1;


                var teams = TeamTable.Select();
                foreach (Team t in teams)
                {
                    comboBoxTeam.Items.Add(t.Name);
                    comboBoxTransfer.Items.Add(t.Name);
                }
                comboBoxTeam.SelectedIndex     = -1;
                comboBoxTransfer.SelectedIndex = -1;
            }
            if (b == "detail")
            {
                //detail
                Player_add_edit.Visible = false;
                label2.Visible          = true;
                button1.Visible         = true;
                button2.Visible         = false;

                Person p = new Person();
                p = PersonTable.SelectOne(Int32.Parse(p_id));

                textBox1.Text = p.First_Name;
                textBox5.Text = p.Last_Name;
                textBox4.Text = p.Birth_Date.ToString();

                textBox3.Text    = p_id.ToString();
                textBox3.Visible = false;
                setReadonly(true);
                label2.Text              = "Player detail";
                button2.Visible          = false;
                button1.Visible          = false;
                TransferButton.Visible   = false;
                comboBoxTransfer.Visible = false;

                button3.Visible = true;

                int idx = 0;

                foreach (var r in role)
                {
                    comboBoxRole.Items.Add(r);
                    if (p.Role == r)
                    {
                        comboBoxRole.SelectedIndex = idx;
                    }
                    idx++;
                }

                var games = GameTable.Select();
                foreach (Game g in games)
                {
                    comboBoxGame.Items.Add(g.Name);
                }
                comboBoxGame.SelectedIndex = p.Game_Id.Id - 1;


                var teams = TeamTable.Select();
                foreach (Team t in teams)
                {
                    comboBoxTeam.Items.Add(t.Name);
                    comboBoxTransfer.Items.Add(t.Name);
                }
                comboBoxTeam.SelectedIndex = p.Team_Id.Id - 1;
            }
            if (b == "edit")
            {
                Player_add_edit.Visible = false;
                label2.Visible          = true;
                button1.Visible         = true;
                button2.Visible         = false;

                Person p = new Person();
                p = PersonTable.SelectOne(Int32.Parse(p_id));

                textBox1.Text = p.First_Name;
                textBox5.Text = p.Last_Name;
                textBox4.Text = p.Birth_Date.ToString();

                textBox3.Text    = p_id.ToString();
                textBox3.Visible = false;
                button3.Visible  = true;

                setReadonly(false);
                label2.Text              = "Edit player";
                button2.Visible          = false;
                button1.Visible          = true;
                TransferButton.Visible   = true;
                comboBoxTransfer.Visible = true;

                int idx = 0;
                foreach (var r in role)
                {
                    comboBoxRole.Items.Add(r);
                    if (p.Role == r)
                    {
                        comboBoxRole.SelectedIndex = idx;
                    }
                    idx++;
                }

                var games = GameTable.Select();
                foreach (Game g in games)
                {
                    comboBoxGame.Items.Add(g.Name);
                }
                comboBoxGame.SelectedIndex = p.Game_Id.Id - 1;


                var teams = TeamTable.Select();
                foreach (Team t in teams)
                {
                    comboBoxTeam.Items.Add(t.Name);
                    comboBoxTransfer.Items.Add(t.Name);
                }
                comboBoxTeam.SelectedIndex = p.Team_Id.Id - 1;
            }
        }