private void buttonEdit_Click(object sender, EventArgs e)
 {
     if ((textBoxName.Text != "") &&
         (textBoxTeacher.Text != "") &&
         (textBoxSemester.Text != "") &&
         (textBoxYear.Text != ""))
     {
         if (listViewLesson.SelectedItems.Count == 1)
         {
             LessonsSet lessonset = listViewLesson.SelectedItems[0].Tag as LessonsSet;
             if (textBoxName.Text != "")
             {
                 lessonset.Lesson = textBoxName.Text;
             }
             if (textBoxTeacher.Text != "")
             {
                 lessonset.Teacher = textBoxTeacher.Text;
             }
             if (textBoxSemester.Text != "")
             {
                 lessonset.Semester = Convert.ToInt32(textBoxSemester.Text);
             }
             if (textBoxYear.Text != "")
             {
                 lessonset.Year = Convert.ToInt32(textBoxYear.Text);
             }
             Program.EduDb.SaveChanges();
             ShowLessons();
         }
     }
     else
     {
         MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     try
     {
         LessonsSet lessonset = new LessonsSet();
         if (textBoxName.Text != "")
         {
             lessonset.Lesson = textBoxName.Text;
         }
         if (textBoxTeacher.Text != "")
         {
             lessonset.Teacher = textBoxTeacher.Text;
         }
         if (textBoxSemester.Text != "")
         {
             lessonset.Semester = Convert.ToInt32(textBoxSemester.Text);
         }
         if (textBoxYear.Text != "")
         {
             lessonset.Year = Convert.ToInt32(textBoxYear.Text);
         }
         Program.EduDb.LessonsSet.Add(lessonset);
         Program.EduDb.SaveChanges();
     }
     catch
     {
         { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); }
     }
     ShowLessons();
 }
 private void listViewLesson_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewLesson.SelectedItems.Count == 1)
     {
         LessonsSet lessonset = listViewLesson.SelectedItems[0].Tag as LessonsSet;
         textBoxName.Text     = lessonset.Lesson;
         textBoxTeacher.Text  = lessonset.Teacher;
         textBoxSemester.Text = lessonset.Semester.ToString();
         textBoxYear.Text     = lessonset.Year.ToString();
     }
     else
     {
         textBoxName.Text     = "";
         textBoxTeacher.Text  = "";
         textBoxSemester.Text = "";
         textBoxYear.Text     = "";
     }
 }
 private void buttonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewLesson.SelectedItems.Count == 1)
         {
             LessonsSet lessonset = listViewLesson.SelectedItems[0].Tag as LessonsSet;
             Program.EduDb.LessonsSet.Remove(lessonset);
             Program.EduDb.SaveChanges();
             ShowLessons();
         }
         textBoxName.Text     = "";
         textBoxTeacher.Text  = "";
         textBoxSemester.Text = "";
         textBoxYear.Text     = "";
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }