Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Team team = db.Teams.Find(id);

                TeamForm tf = new TeamForm();
                tf.textBox1.Text = team.Name;
                tf.textBox2.Text = team.Coach;

                DialogResult result = tf.ShowDialog(this);


                if (tf.DialogResult == DialogResult.Cancel)
                {
                    return;
                }

                team.Name  = tf.textBox1.Text;
                team.Coach = tf.textBox2.Text;

                db.Entry(team).State = EntityState.Modified;
                db.SaveChanges();
                MessageBox.Show("Объект обновлен");
            }
        }
Exemple #2
0
        //add
        private void button1_Click(object sender, EventArgs e)
        {
            TeamForm     tf     = new TeamForm();
            DialogResult result = tf.ShowDialog(this);


            if (tf.DialogResult == DialogResult.Cancel)
            {
                return;
            }
            Team team = new Team();

            team.Name  = tf.textBox1.Text;
            team.Coach = tf.textBox2.Text;
            db.Teams.Add(team);
            db.SaveChanges();
            MessageBox.Show("Team addded");
        }