private void buttonEdit_Click(object sender, EventArgs e) { if (listViewBookPlace.SelectedItems.Count == 1) { BookPlaceSet bookPlace = listViewBookPlace.SelectedItems[0].Tag as BookPlaceSet; bookPlace.IDBook = Convert.ToInt32(comboBoxBook.SelectedItem.ToString().Split('.')[0]); bookPlace.IDReader = Convert.ToInt32(comboBoxReader.SelectedItem.ToString().Split('.')[0]); bookPlace.IDLibrarian = Convert.ToInt32(comboBoxLibrarian.SelectedItem.ToString().Split('.')[0]); Program.qwer.SaveChanges(); ShowBookPlace(); } }
private void listViewBookPlace_SelectedIndexChanged(object sender, EventArgs e) { if (listViewBookPlace.SelectedItems.Count == 1) { BookPlaceSet bookPlace = listViewBookPlace.SelectedItems[0].Tag as BookPlaceSet; comboBoxBook.SelectedIndex = comboBoxBook.FindString(bookPlace.IDBook.ToString()); comboBoxReader.SelectedIndex = comboBoxReader.FindString(bookPlace.IDReader.ToString()); comboBoxLibrarian.SelectedIndex = comboBoxLibrarian.FindString(bookPlace.IDLibrarian.ToString()); } else { comboBoxBook.SelectedItem = null; comboBoxReader.SelectedItem = null; comboBoxLibrarian.SelectedItem = null; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxBook.SelectedItem != null && comboBoxReader.SelectedItem != null && comboBoxLibrarian.SelectedItem != null) { BookPlaceSet bookPlace = new BookPlaceSet(); bookPlace.IDBook = Convert.ToInt32(comboBoxBook.SelectedItem.ToString().Split('.')[0]); bookPlace.IDReader = Convert.ToInt32(comboBoxReader.SelectedItem.ToString().Split('.')[0]); bookPlace.IDLibrarian = Convert.ToInt32(comboBoxLibrarian.SelectedItem.ToString().Split('.')[0]); Program.qwer.BookPlaceSet.Add(bookPlace); Program.qwer.SaveChanges(); ShowBookPlace(); } else { MessageBox.Show("Данные не выбраны", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewBookPlace.SelectedItems.Count == 1) { BookPlaceSet bookPlace = listViewBookPlace.SelectedItems[0].Tag as BookPlaceSet; Program.qwer.BookPlaceSet.Remove(bookPlace); Program.qwer.SaveChanges(); ShowBookPlace(); } comboBoxBook.SelectedItem = null; comboBoxReader.SelectedItem = null; comboBoxLibrarian.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }