private void ListViewShops_SelectedIndexChanged(object sender, EventArgs e) { if (listViewShops.SelectedItems.Count == 1) { Shops shop = listViewShops.SelectedItems[0].Tag as Shops; textBoxShop.Text = shop.NameShop; textBoxAddress.Text = shop.Address; comboBoxAutopart.Text = shop.IdAutopart.ToString() + "." + shop.AutopartSet.NameAutopart + " " + shop.AutopartSet.CarSet.CarBrand; } else { textBoxShop.Text = ""; textBoxAddress.Text = ""; comboBoxAutopart.SelectedItem = null; } }
private void ButtonDel_Click(object sender, EventArgs e) { try { if (listViewShops.SelectedItems.Count == 1) { Shops shop = listViewShops.SelectedItems[0].Tag as Shops; Program.catalog.Shops.Remove(shop); Program.catalog.SaveChanges(); ShowShop(); } } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ButtonAdd_Click(object sender, EventArgs e) { try { Shops shop = new Shops(); if (textBoxShop.Text == "" || textBoxAddress.Text == "" || comboBoxAutopart.SelectedItem == null) { throw new Exception("Обязательные данные не заполнены"); } else { shop.NameShop = textBoxShop.Text; shop.Address = textBoxAddress.Text; shop.IdAutopart = Convert.ToInt32(comboBoxAutopart.SelectedItem.ToString().Split('.')[0]); } Program.catalog.Shops.Add(shop); Program.catalog.SaveChanges(); ShowShop(); } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }