Пример #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;
                }

                Subject subject = db.Subjects.Find(id);

                SubjAdd tForm = new SubjAdd();
                tForm.textBox1.Text = subject.Name;

                DialogResult result = tForm.ShowDialog(this);

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

                subject.Name = tForm.textBox1.Text;


                db.Entry(subject).State = EntityState.Modified;
                db.SaveChanges();

                MessageBox.Show("Предмет обновлен");
                update();
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            SubjAdd tForm = new SubjAdd();

            DialogResult result = tForm.ShowDialog(this);

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

            subject.Name = tForm.textBox1.Text;

            db.Subjects.Add(subject);
            db.SaveChanges();

            MessageBox.Show("Предмет добавлен");
            update();
        }