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

                Mark mark = db.Marks.Find(id);

                MarkAdd tForm = new MarkAdd();
                tForm.textBox1.Text = mark.Smark.ToString();

                List <Subject> subjects = db.Subjects.ToList();
                tForm.comboBox1.DataSource    = subjects;
                tForm.comboBox1.ValueMember   = "Id";
                tForm.comboBox1.DisplayMember = "Name";
                List <Student> students = db.Students.ToList();
                tForm.comboBox2.DataSource    = students;
                tForm.comboBox2.ValueMember   = "Id";
                tForm.comboBox2.DisplayMember = "Surname";

                if (mark.Subject != null)
                {
                    tForm.comboBox1.SelectedValue = mark.Subject.Id;
                }
                if (mark.Student != null)
                {
                    tForm.comboBox2.SelectedValue = mark.Student.Id;
                }

                DialogResult result = tForm.ShowDialog(this);

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

                mark.Smark   = Convert.ToInt32(tForm.textBox1.Text);
                mark.Subject = (Subject)tForm.comboBox1.SelectedItem;
                mark.Student = (Student)tForm.comboBox2.SelectedItem;

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

                MessageBox.Show("Оценка обновлена");
                update();
            }
        }
Пример #3
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;
                }

                Teacher teacher = db.Teachers.Find(id);

                TeachAdd tForm = new TeachAdd();
                tForm.textBox1.Text = teacher.Name;
                tForm.textBox2.Text = teacher.Surname;
                tForm.textBox3.Text = teacher.Salary.ToString();

                List <Subject> subjects = db.Subjects.ToList();
                tForm.comboBox1.DataSource    = subjects;
                tForm.comboBox1.ValueMember   = "Id";
                tForm.comboBox1.DisplayMember = "Name";

                if (teacher.Subject != null)
                {
                    tForm.comboBox1.SelectedValue = teacher.Subject.Id;
                }

                DialogResult result = tForm.ShowDialog(this);

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

                teacher.Name    = tForm.textBox1.Text;
                teacher.Surname = tForm.textBox2.Text;
                teacher.Salary  = Convert.ToInt32(tForm.textBox3.Text);
                teacher.Subject = (Subject)tForm.comboBox1.SelectedItem;

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

                MessageBox.Show("Учитель " + tForm.textBox2.Text + " обновлен");
                update();
            }
        }
Пример #4
0
 public void Update(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
 }