private void buttonEdit_Click(object sender, EventArgs e) { if (listViewChekProduct.SelectedItems.Count == 1) { ProductTraking product = listViewChekProduct.SelectedItems[0].Tag as ProductTraking; product.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); product.IdProduct = Convert.ToInt32(comboBoxProduct.SelectedItem.ToString().Split('.')[0]); product.IdWorker = Convert.ToInt32(comboBoxWorker.SelectedItem.ToString().Split('.')[0]); Program.mpgc.SaveChanges(); ShowProductTraking(); } }
private void listViewChekProduct_SelectedIndexChanged(object sender, EventArgs e) { if (listViewChekProduct.SelectedItems.Count == 1) { ProductTraking product = listViewChekProduct.SelectedItems[0].Tag as ProductTraking; comboBoxClient.SelectedIndex = comboBoxClient.FindString(product.IdClient.ToString()); comboBoxWorker.SelectedIndex = comboBoxWorker.FindString(product.IdWorker.ToString()); comboBoxProduct.SelectedIndex = comboBoxProduct.FindString(product.IdProduct.ToString()); } else { comboBoxClient.SelectedItem = null; comboBoxProduct.SelectedItem = null; comboBoxWorker.SelectedItem = null; } }
private void buttonAdd_Click(object sender, EventArgs e) { if (comboBoxClient.SelectedItem != null && comboBoxProduct.SelectedItem != null && comboBoxWorker.SelectedItem != null) { ProductTraking product = new ProductTraking(); product.IdClient = Convert.ToInt32(comboBoxClient.SelectedItem.ToString().Split('.')[0]); product.IdProduct = Convert.ToInt32(comboBoxProduct.SelectedItem.ToString().Split('.')[0]); product.IdWorker = Convert.ToInt32(comboBoxWorker.SelectedItem.ToString().Split('.')[0]); Program.mpgc.ProductTraking.Add(product); Program.mpgc.SaveChanges(); ShowProductTraking(); } else { MessageBox.Show("Данные не выбраны", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewChekProduct.SelectedItems.Count == 1) { ProductTraking product = listViewChekProduct.SelectedItems[0].Tag as ProductTraking; Program.mpgc.ProductTraking.Remove(product); Program.mpgc.SaveChanges(); ShowProductTraking(); } comboBoxClient.SelectedItem = null; comboBoxProduct.SelectedItem = null; comboBoxWorker.SelectedItem = null; } catch { MessageBox.Show("Невозможно удалить, эта запись используется", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }