private void buttonAdd_Click(object sender, EventArgs e) { ProviderSet providerSet = new ProviderSet(); providerSet.idProduct = Convert.ToInt32(comboBoxNameProduct.SelectedItem.ToString().Split('.')[0]); providerSet.NameProduct = comboBoxNameProduct.Text; providerSet.Company = textBoxCompany.Text; providerSet.Phone = textBoxPhone.Text; providerSet.Email = textBoxEmail.Text; Program.master.ProviderSet.Add(providerSet); Program.master.SaveChanges(); ShowProviderSet(); }
private void buttonEdit_Click(object sender, EventArgs e) { if (listViewProvider.SelectedItems.Count == 1) { ProviderSet providerSet = listViewProvider.SelectedItems[0].Tag as ProviderSet; providerSet.idProduct = Convert.ToInt32(comboBoxNameProduct.SelectedItem.ToString().Split('.')[0]); providerSet.NameProduct = comboBoxNameProduct.Text; providerSet.Company = textBoxCompany.Text; providerSet.Phone = textBoxPhone.Text; providerSet.Email = textBoxEmail.Text; Program.master.SaveChanges(); ShowProviderSet(); } }
private void listViewProvider_SelectedIndexChanged(object sender, EventArgs e) { if (listViewProvider.SelectedItems.Count == 1) { ProviderSet providerSet = listViewProvider.SelectedItems[0].Tag as ProviderSet; textBoxCompany.Text = providerSet.Company; textBoxPhone.Text = providerSet.Phone; textBoxEmail.Text = providerSet.Email; comboBoxNameProduct.Text = providerSet.NameProduct; } else { textBoxCompany.Text = ""; textBoxPhone.Text = ""; textBoxEmail.Text = ""; comboBoxNameProduct.Text = ""; } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewProvider.SelectedItems.Count == 1) { ProviderSet providerSet = listViewProvider.SelectedItems[0].Tag as ProviderSet; Program.master.ProviderSet.Remove(providerSet); Program.master.SaveChanges(); ShowProviderSet(); } textBoxCompany.Text = ""; textBoxPhone.Text = ""; textBoxEmail.Text = ""; comboBoxNameProduct.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }