private void button1_Click(object sender, EventArgs e) //Excluir
        {
            if (txtCodigo.Text == "")
            {
                MessageBox.Show("Selecione um colaborador para excluir.", "Erro",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                var result = MessageBox.Show(this, "Você tem certeza que deseja excluir este colaborador?",
                                             "Deseja excluir o colaborador?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (result == DialogResult.Yes)
                {
                    Colaborador c = GetDTO();

                    if (dao.Delete(c))
                    {
                        MessageBox.Show("Colaborador foi excluído.", "Colaborador Excluído",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    AtualizaDGV();

                    LimparTextBox();
                }
            }
        }
示例#2
0
 public void Excluir(Colaborador colaborador)
 {
     try
     {
         DAO.Delete(colaborador);
     }
     catch (DbUpdateException)
     {
         throw new Exceptions.ErroAoExcluir(colaborador);
     }
     catch
     {
         throw new Exceptions.ErroDesconhecido();
     }
 }