Exemplo n.º 1
0
        //Edit
        private void button2_Click(object sender, EventArgs e)
        {
            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 tmForm = new TeamForm();

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

            DialogResult result = tmForm.ShowDialog(this);

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

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

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

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

            Team team = new Team();

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

            db.Teams.Add(team);
            db.SaveChanges();
            MessageBox.Show("Объект добавлен");
        }