private void BtnExcluir_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Deseja realmente deletar o cadastro selecionado?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ProdutoNegocio produtoNegocio = new ProdutoNegocio(); string aviso = produtoNegocio.Excluir(Convert.ToInt32(DgvProduto.Rows[DgvProduto.CurrentRow.Index].Cells[0].Value)); if (aviso != "0") { MessageBox.Show("Não foi possível excluir pois já foi feito a venda desse mesmo produto!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Excluido com Sucesso!", "Exclusão", MessageBoxButtons.OK, MessageBoxIcon.Information); CarregaQtdeProduto(); CarregaTodosProdutos(); } } } catch (Exception ex) { MessageBox.Show("Não foi possível excluir o produto/serviço selecionado!" + ex.Message, "Exclusão", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public JsonResult Excluir(int id) { try { ProdutoNegocio produtoNegocio = new ProdutoNegocio(); Produto p = produtoNegocio.Consulta(id); produtoNegocio.Excluir(p); return(Json("")); } catch (Exception) { throw; } }