Example #1
0
        /// <summary>
        /// Добавление курсовой работы
        /// </summary>
        private void btnCWAdd_Click(object sender, EventArgs e)
        {
            if (tbCWTitle.Text.Trim(' ') == "" || cbCWCourse.SelectedIndex == -1 || cbCWMark.SelectedIndex == -1 ||
                cbCWStudent.SelectedIndex == -1 || cbCWTeacher.SelectedIndex == -1)
            {
                MessageBox.Show("Заполните все поля.", "Ошибка!");
                return;
            }

            CourseWork cw = new CourseWork()
            {
                Title   = tbCWTitle.Text.Trim(' '),
                Mark    = cbCWMark.Text,
                Course  = byte.Parse(cbCWCourse.Text),
                Student = _cont.StudentSet.Find(((Student)cbCWStudent.SelectedValue).Id),
                Teacher = _cont.TeacherSet.Find(((Teacher)cbCWTeacher.SelectedValue).Id)
            };

            _cont.CourseWorkSet.Add(cw);
            _cont.SaveChanges();

            tbCWTitle.Text            = "";
            cbCWMark.SelectedIndex    = -1;
            cbCWCourse.SelectedIndex  = -1;
            cbCWStudent.SelectedIndex = -1;
            cbCWTeacher.SelectedIndex = -1;

            RefreshDgvCW();
        }
Example #2
0
        /// <summary>
        /// Удаление курсовой работы
        /// </summary>
        private void btnCWDelete_Click(object sender, EventArgs e)
        {
            CourseWork cw = _cont.CourseWorkSet.Find(dgvCW.SelectedRows[0].Cells[0].Value);

            if (cw != null)
            {
                _cont.CourseWorkSet.Remove(cw);
            }
            _cont.SaveChanges();

            RefreshDgvCW();
        }