private void btnUpdateProduct_Click(object sender, EventArgs e) { if (dgvProducts.SelectedRows.Count > 0) { int idSelectedProduct = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[0].Value); IRepositoryGeneric <Product> repositoryProduct = new RepositoryProduct(); Product productToBeChanged = repositoryProduct.SelectById(idSelectedProduct); FrmProduct frmProduct = new FrmProduct(productToBeChanged); frmProduct.ShowDialog(); FillDataGridViewProducsAsync(); } else { MessageBox.Show("Please select one product first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnRemoveProduct_Click(object sender, EventArgs e) { DialogResult myResult; myResult = MessageBox.Show("Are you sure that you want to exclude this product", "Caution", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (myResult == DialogResult.OK) { if (dgvProducts.SelectedRows.Count == 0) { MessageBox.Show("Please select one product to be excluded", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { int idSelectedProduct = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[0].Value); IRepositoryGeneric <Product> repositoryProduct = new RepositoryProduct(); Product productToBeExcluded = repositoryProduct.SelectById(idSelectedProduct); repositoryProduct.Remove(productToBeExcluded); FillDataGridViewBrandsAsync(); FillDataGridViewProducsAsync(); } } }