Ejemplo n.º 1
0
        private void updToolStripMenuItem_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;
                }

                Country  team   = db.Countries.Find(id);
                TeamForm tmForm = new TeamForm();
                tmForm.textBox1.Text = team.Name;
                DialogResult result = tmForm.ShowDialog(this);
                if (result == DialogResult.Cancel)
                {
                    return;
                }

                team.Name            = tmForm.textBox1.Text;
                db.Entry(team).State = EntityState.Modified;
                db.SaveChanges();
                MessageBox.Show("Объект обновлен");
                db.Countries.Load();
                dataGridView1.DataSource = db.Countries.Local.ToBindingList();
            }
        }
Ejemplo n.º 2
0
        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TeamForm     tmForm = new TeamForm();//
            DialogResult result = tmForm.ShowDialog(this);

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

            Country country = new Country();

            country.Name     = tmForm.textBox1.Text;
            country.Treaties = new List <Treaty>();
            db.Countries.Add(country);
            db.SaveChanges();
            db.Countries.Load();
            dataGridView1.DataSource = db.Countries.Local.ToList();
        }