private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewFirm.SelectedItems.Count == 1) { FirmsSet firmsSet = listViewFirm.SelectedItems[0].Tag as FirmsSet; if (textBoxNameFirm.Text == "" || textBoxAddress.Text == "" || textBoxCity.Text == "" || textBoxTelephone.Text == "") { throw new Exception("Обязательные поля не заполнены!"); } else { firmsSet.NameFirm = textBoxNameFirm.Text; firmsSet.Address = textBoxAddress.Text; firmsSet.City = textBoxCity.Text; firmsSet.Telephone = textBoxTelephone.Text; } Program.cGG.SaveChanges(); ShowFirms(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void listViewFirm_SelectedIndexChanged(object sender, EventArgs e) { if (listViewFirm.SelectedItems.Count == 1) { FirmsSet firmsSet = listViewFirm.SelectedItems[0].Tag as FirmsSet; textBoxNameFirm.Text = firmsSet.NameFirm; textBoxAddress.Text = firmsSet.Address; textBoxCity.Text = firmsSet.City; textBoxTelephone.Text = firmsSet.Telephone; } else { textBoxNameFirm.Text = ""; textBoxAddress.Text = ""; textBoxCity.Text = ""; textBoxTelephone.Text = ""; } }
private void buttonAdd_Click(object sender, EventArgs e) { try { FirmsSet firmsSet = new FirmsSet(); firmsSet.NameFirm = textBoxNameFirm.Text; firmsSet.Address = textBoxAddress.Text; firmsSet.City = textBoxCity.Text; firmsSet.Telephone = textBoxTelephone.Text; if (firmsSet.NameFirm == "" || firmsSet.Address == "" || firmsSet.City == "" || firmsSet.Telephone == "") { throw new Exception("Обязательные поля не заполнены!"); } Program.cGG.FirmsSet.Add(firmsSet); Program.cGG.SaveChanges(); ShowFirms(); } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewFirm.SelectedItems.Count == 1) { FirmsSet firmsSet = listViewFirm.SelectedItems[0].Tag as FirmsSet; Program.cGG.FirmsSet.Remove(firmsSet); Program.cGG.SaveChanges(); ShowFirms(); } textBoxNameFirm.Text = ""; textBoxAddress.Text = ""; textBoxCity.Text = ""; textBoxTelephone.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);; } }