private void listViewLessons_SelectedIndexChanged(object sender, EventArgs e) { if (listViewLessons.SelectedItems.Count == 1) { Lessons lessons = listViewLessons.SelectedItems[0].Tag as Lessons; comboBoxTeachers.SelectedIndex = comboBoxTeachers.FindString(lessons.IdTeachers.ToString()); textBoxName.Text = lessons.Name; } else { comboBoxTeachers.SelectedItem = null; textBoxName.Text = ""; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxTeachers.SelectedItem != null && textBoxName.Text != "") { Lessons lessons = new Lessons(); lessons.IdTeachers = Convert.ToInt32(comboBoxTeachers.SelectedItem.ToString().Split('.')[0]); lessons.Name = textBoxName.Text; Program.School.Lessons.Add(lessons); Program.School.SaveChanges(); ShowLessons(); } else { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewLessons.SelectedItems.Count == 1) { Lessons lessons = listViewLessons.SelectedItems[0].Tag as Lessons; Program.School.Lessons.Remove(lessons); Program.School.SaveChanges(); ShowLessons(); } comboBoxTeachers.SelectedItem = null; textBoxName.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }