private void button2_Click(object sender, EventArgs e) { int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value; if (typeof(T) == typeof(Product)) { Product product = _set.Find(id) as Product; if (product != null) { ProductForm productForm = new ProductForm(product); if (productForm.ShowDialog() == DialogResult.OK) { product = productForm.Product; _dbContext.SaveChanges(); dataGridView1.Update(); } } } else if (typeof(T) == typeof(Seller)) { Seller seller = _set.Find(id) as Seller; if (seller != null) { SellerForm sellerForm = new SellerForm(seller); if (sellerForm.ShowDialog() == DialogResult.OK) { seller = sellerForm.Seller; _dbContext.SaveChanges(); dataGridView1.Update(); } } } else if (typeof(T) == typeof(Customer)) { Customer customer = _set.Find(id) as Customer; if (customer != null) { CustomerForm customerForm = new CustomerForm(customer); if (customerForm.ShowDialog() == DialogResult.OK) { customer = customerForm.Customer; _dbContext.SaveChanges(); dataGridView1.Update(); } } } }
private void button2_Click(object sender, EventArgs e) { var id = dataGridView1.SelectedRows[0].Cells[0].Value; if (typeof(T) == typeof(Product)) { //по идентификатору ищем продукт var product = set.Find(id) as Product; if (product != null) { var form = new ProductForm(product); if (form.ShowDialog() == DialogResult.OK) { product = form.Product; db.SaveChanges(); dataGridView1.Update(); } } } if (typeof(T) == typeof(Seller)) { //по идентификатору ищем продукт var seller = set.Find(id) as Seller; if (seller != null) { var form = new SellerForm(seller); if (form.ShowDialog() == DialogResult.OK) { seller = form.Seller; db.SaveChanges(); dataGridView1.Update(); } } } if (typeof(T) == typeof(Customer)) { //по идентификатору ищем продукт var customer = set.Find(id) as Customer; if (customer != null) { var form = new CustomerForm(customer); if (form.ShowDialog() == DialogResult.OK) { customer = form.Customer; db.SaveChanges(); dataGridView1.Update(); } } } }
private void ChangeButton_Click(object sender, EventArgs e) { try { var id = dataGridView.SelectedRows[0].Cells[0].Value; if (typeof(T) == typeof(Product)) { var product = set.Find(id) as Product; if (product != null) { var form = new ProductForm(product); if (form.ShowDialog() == DialogResult.OK) { product = form.Product; db.SaveChanges(); } } } else if (typeof(T) == typeof(Seller)) { var seller = set.Find(id) as Seller; if (seller != null) { var form = new SellerForm(seller); if (form.ShowDialog() == DialogResult.OK) { seller = form.Seller; db.SaveChanges(); } } } else if (typeof(T) == typeof(Customer)) { var customer = set.Find(id) as Customer; if (customer != null) { var form = new CustomerForm(customer); if (form.ShowDialog() == DialogResult.OK) { customer = form.Customer; db.SaveChanges(); } } } dataGridView.Refresh(); } catch (ArgumentOutOfRangeException) { MessageBox.Show("Вы не выбрали строку!"); } }
private void btnEdit_Click(object sender, System.EventArgs e) { var id = dataGridView1.SelectedRows[0].Cells[0].Value; if (typeof(T) == typeof(Product)) { var product = set.Find(id) as Product; if (product != null) { var form = new ProductForm(product); if (form.ShowDialog() == DialogResult.OK) { product = form.Product; context.SaveChanges(); dataGridView1.Update(); } } } else if (typeof(T) == typeof(Seller)) { var seller = set.Find(id) as Seller; if (seller != null) { var form = new SellerForm(seller); if (form.ShowDialog() == DialogResult.OK) { seller = form.Seller; context.SaveChanges(); dataGridView1.Update(); } } } else if (typeof(T) == typeof(Customer)) { var customer = set.Find(id) as Customer; if (customer != null) { var form = new CustomerForm(customer); if (form.ShowDialog() == DialogResult.OK) { customer = form.Customer; context.SaveChanges(); dataGridView1.Update(); } } } }
private void button2_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count > 0) { int index = dataGridView.SelectedRows[0].Index; var id = dataGridView.SelectedRows[0].Cells[0].Value; //int id = 0; //bool converted = Int32.TryParse(dataGridView[0, index].Value.ToString(), out id); if (typeof(T) == typeof(Product)) { var product = set.Find(id) as Product; var form = new ProductForm(product); if (form.ShowDialog() == DialogResult.OK) { product = form.Product; db.SaveChanges(); dataGridView.Refresh(); } } else if (typeof(T) == typeof(Customer)) { var customer = db.Customers.Find(id); var form = new CustomerForm(customer); if (form.ShowDialog() == DialogResult.OK) { customer = form.Customer; db.SaveChanges(); dataGridView.Refresh(); } } else if (typeof(T) == typeof(Seller)) { var seller = db.Sellers.Find(id); var form = new SellerForm(seller); if (form.ShowDialog() == DialogResult.OK) { seller = form.Seller; db.SaveChanges(); dataGridView.Refresh(); } } } }
private void Button2_Click(object sender, EventArgs e) { var id = dataGridView1.SelectedRows[0].Cells[0].Value; if (typeof(T) == typeof(Product)) { var p = set.Find(id) as Product; if (p != null) { var form = new ProductForm(p); if (form.ShowDialog() == DialogResult.OK) { p = form.Product; db.SaveChanges(); dataGridView1.Update(); } } } else if (typeof(T) == typeof(Seller)) { var s = set.Find(id) as Seller; if (s != null) { var form = new SellerForm(s); if (form.ShowDialog() == DialogResult.OK) { s = form.Seller; db.SaveChanges(); dataGridView1.Update(); } } } else if (typeof(T) == typeof(Customer)) { var c = set.Find(id) as Customer; if (c != null) { var form = new CustomerForm(c); if (form.ShowDialog() == DialogResult.OK) { c = form.Customer; db.SaveChanges(); dataGridView1.Update(); } } } }