private void buttonEdit_Click(object sender, EventArgs e) { if (listViewMarks.SelectedItems.Count == 1) { if (comboBoxStudent.SelectedItem != null && comboBoxSubject.SelectedItem != null && textBoxMark.Text != "") { int temp; bool mark = int.TryParse(textBoxMark.Text, out temp); if (!mark) { MessageBox.Show("Оценка - это число", "Неверный формат оценки", MessageBoxButtons.OK); } else { MarksSet marksSet = listViewMarks.SelectedItems[0].Tag as MarksSet; marksSet.id_Student = Convert.ToInt32(comboBoxStudent.SelectedItem.ToString().Split('.')[0]); marksSet.id_Subject = Convert.ToInt32(comboBoxSubject.SelectedItem.ToString().Split('.')[0]); marksSet.Mark = Convert.ToInt32(textBoxMark.Text); Program.abc.SaveChanges(); ShowMarks(); } } else { MessageBox.Show("Заполните все поля", "Невозможно внести данные!", MessageBoxButtons.OK); } } }
private void listViewMarks_SelectedIndexChanged(object sender, EventArgs e) { if (listViewMarks.SelectedItems.Count == 1) { MarksSet marksSet = listViewMarks.SelectedItems[0].Tag as MarksSet; comboBoxStudent.SelectedIndex = comboBoxStudent.FindString(marksSet.id_Student.ToString()); comboBoxSubject.SelectedIndex = comboBoxSubject.FindString(marksSet.id_Subject.ToString()); textBoxMark.Text = marksSet.Mark.ToString(); } else { comboBoxStudent.SelectedItem = null; comboBoxSubject.SelectedItem = null; textBoxMark.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewMarks.SelectedItems.Count == 1) { MarksSet marksSet = listViewMarks.SelectedItems[0].Tag as MarksSet; Program.abc.MarksSet.Remove(marksSet); Program.abc.SaveChanges(); ShowMarks(); } comboBoxStudent.SelectedItem = null; comboBoxSubject.SelectedItem = null; textBoxMark.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }