private void listViewProfessions_SelectedIndexChanged(object sender, EventArgs e) { if (listViewProfessions.SelectedItems.Count == 1) { Professions professionsSet = listViewProfessions.SelectedItems[0].Tag as Professions; textBoxProfession.Text = professionsSet.Profession; } else { textBoxProfession.Text = ""; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (textBoxProfession.Text != "") { Professions professionsSet = new Professions(); professionsSet.Profession = textBoxProfession.Text; Program.csr.Professions.Add(professionsSet); Program.csr.SaveChanges(); ShowProfessions(); } else { MessageBox.Show("Заполните все поля", "Невозможно внести данные!", MessageBoxButtons.OK); } }
private void buttonEdit_Click(object sender, EventArgs e) { if (textBoxProfession.Text != "") { if (listViewProfessions.SelectedItems.Count == 1) { Professions professionsSet = listViewProfessions.SelectedItems[0].Tag as Professions; professionsSet.Profession = textBoxProfession.Text; Program.csr.SaveChanges(); ShowProfessions(); } } else { MessageBox.Show("Заполните все поля", "Невозможно внести данные!", MessageBoxButtons.OK); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewProfessions.SelectedItems.Count == 1) { Professions professionsSet = listViewProfessions.SelectedItems[0].Tag as Professions; Program.csr.Professions.Remove(professionsSet); Program.csr.SaveChanges(); ShowProfessions(); } textBoxProfession.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }