private void buttonAdd_Click(object sender, EventArgs e) { Drivers factorySet = new Drivers(); factorySet.Surname = textBoxSurname.Text; factorySet.Name = textBoxName.Text; factorySet.Patronymic = textBoxPatronymic.Text; Program.wftDb.Drivers.Add(factorySet); Program.wftDb.SaveChanges(); ShowDrivers(); }
private void buttonEdit_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 1) { Drivers factory = listView1.SelectedItems[0].Tag as Drivers; factory.Surname = textBoxSurname.Text; factory.Name = textBoxName.Text; factory.Patronymic = textBoxPatronymic.Text; Program.wftDb.SaveChanges(); ShowDrivers(); } }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 1) { Drivers factory = listView1.SelectedItems[0].Tag as Drivers; textBoxSurname.Text = factory.Surname; textBoxName.Text = factory.Name; textBoxPatronymic.Text = factory.Patronymic; } else { textBoxSurname.Text = ""; textBoxName.Text = ""; textBoxPatronymic.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listView1.SelectedItems.Count == 1) { Drivers factory = listView1.SelectedItems[0].Tag as Drivers; Program.wftDb.Drivers.Remove(factory); Program.wftDb.SaveChanges(); ShowDrivers(); } textBoxSurname.Text = ""; textBoxName.Text = ""; textBoxPatronymic.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }