Exemplo n.º 1
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            _repositorioCliente = new RepositorioCliente();

            // var excluirCliente = new Cliente();
            try
            {
                //excluirCliente = clientedataGridView.SelectedRows[0].DataBoundItem as Cliente;
                //if (_repositorioCliente.ClienteTemContrato((Convert.ToInt32(clientedataGridView.CurrentRow.Cells[0].Value))))

                cliente = _repositorioCliente.PesquisarPorId(Convert.ToInt32(clientedataGridView.CurrentRow.Cells[0].Value));

                if (_repositorioCliente.ClienteTemContrato((Convert.ToInt32(cliente.Id))))
                {
                    MessageBox.Show("Este cliente contem contrato");
                }
                else
                {
                    HelperMensagem.confirmaExclusao("Deseja excluir?", "Exclussão", MessageBoxButtons.YesNo);
                    if (HelperMensagem.resultado == DialogResult.Yes)
                    {
                        _repositorioCliente.Excluir(cliente);
                    }
                }
                ListarCliente();
            }
            catch (Exception ex)
            {
                throw new Exception("Não foi possível reliazar a exclussão " + ex.Message);
            }

            ListarCliente();
        }