private void ButtonAdd_Click(object sender, EventArgs e) { if (comboBoxProvider.SelectedItem != null && comboBoxProduct.SelectedItem != null) { ProductSet productSet = new ProductSet(); productSet.IdProvider = Convert.ToInt32(comboBoxProvider.SelectedItem.ToString().Split('.')[0]); productSet.Provider = comboBoxProvider.SelectedItem.ToString().Split('.')[1]; productSet.Product = comboBoxProduct.Text; if (textBoxNumber.Text != "") { productSet.Number = Convert.ToInt32(textBoxNumber.Text); } if (textBoxPrice.Text != "") { productSet.Price = Convert.ToInt32(textBoxPrice.Text); } Program.psDb.ProductSet.Add(productSet); Program.psDb.SaveChanges(); ShowProduct(); } else { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void ListViewProduct_SelectedIndexChanged(object sender, EventArgs e) { if (listViewProduct.SelectedItems.Count == 1) { ProductSet productSet = listViewProduct.SelectedItems[0].Tag as ProductSet; comboBoxProvider.Text = productSet.IdProvider.ToString() + "." + productSet.Provider; comboBoxProduct.Text = productSet.Product; textBoxNumber.Text = productSet.Number.ToString(); textBoxPrice.Text = productSet.Price.ToString(); } else { comboBoxProvider.Text = ""; comboBoxProduct.Text = ""; textBoxNumber.Text = ""; textBoxPrice.Text = ""; } }
private void ButtonDel_Click(object sender, EventArgs e) { try { if (listViewProduct.SelectedItems.Count == 1) { ProductSet productSet = listViewProduct.SelectedItems[0].Tag as ProductSet; Program.psDb.ProductSet.Remove(productSet); Program.psDb.SaveChanges(); ShowProduct(); } comboBoxProvider.Text = ""; comboBoxProduct.Text = ""; textBoxNumber.Text = ""; textBoxPrice.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ButtonEdit_Click(object sender, EventArgs e) { if (listViewProduct.SelectedItems.Count == 1) { ProductSet productSet = listViewProduct.SelectedItems[0].Tag as ProductSet; productSet.IdProvider = Convert.ToInt32(comboBoxProvider.SelectedItem.ToString().Split('.')[0]); productSet.Provider = comboBoxProvider.SelectedItem.ToString().Split('.')[1]; productSet.Product = comboBoxProduct.Text; if (textBoxNumber.Text != "") { productSet.Number = Convert.ToInt32(textBoxNumber.Text); } if (textBoxPrice.Text != "") { productSet.Price = Convert.ToInt32(textBoxPrice.Text); } Program.psDb.SaveChanges(); ShowProduct(); } }