private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewSuppliers.SelectedItems.Count == 1) { SuppliersSet suppliersSet = listViewSuppliers.SelectedItems[0].Tag as SuppliersSet; if (textBoxNameSupplier.Text == "" || textBoxINN.Text == "" || textBoxAddress.Text == "" || textBoxTelephone.Text == "") { throw new Exception("Обязательные данные не заполнены"); } else { suppliersSet.NameSupplier = textBoxNameSupplier.Text; suppliersSet.INN = textBoxINN.Text; suppliersSet.Address = textBoxAddress.Text; suppliersSet.Telephone = textBoxTelephone.Text; } Program.varr.SaveChanges(); ShowSuppliers(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewSuppliers_SelectedIndexChanged(object sender, EventArgs e) { if (listViewSuppliers.SelectedItems.Count == 1) { SuppliersSet suppliersSet = listViewSuppliers.SelectedItems[0].Tag as SuppliersSet; textBoxNameSupplier.Text = suppliersSet.NameSupplier; textBoxINN.Text = suppliersSet.INN; textBoxAddress.Text = suppliersSet.Address; textBoxTelephone.Text = suppliersSet.Telephone; } else { textBoxNameSupplier.Text = ""; textBoxINN.Text = ""; textBoxAddress.Text = ""; textBoxTelephone.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewSuppliers.SelectedItems.Count == 1) { SuppliersSet suppliersSet = listViewSuppliers.SelectedItems[0].Tag as SuppliersSet; Program.varr.SuppliersSet.Remove(suppliersSet); Program.varr.SaveChanges(); ShowSuppliers(); } textBoxNameSupplier.Text = ""; textBoxINN.Text = ""; textBoxAddress.Text = ""; textBoxTelephone.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);; } }