Exemplo n.º 1
0
 private void btnDeletar_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvCliente.Rows.Count > 0)
         {
             InstanciarClienteRepositorio();
             Model.Entidades.Cliente cliente = _clienteRepositorio.GetClientePorID(GetLinhaDoGrid());
             if (OpenMdiForm.OpenForWithShowDialog(new frmCadastrarCliente(cliente, EnumTipoOperacao.Deletar)) == DialogResult.Yes)
             {
                 CarregarGrid();
             }
         }
         else
         {
             MyErro.MyCustomException("Selecione um Cliente.");
         }
     }
     catch (CustomException erro)
     {
         DialogMessage.MessageFullComButtonOkIconeDeInformacao(erro.Message, "Aviso");
     }
     catch (Exception erro)
     {
         SaveErroInTxt.RecordInTxt(erro, this.GetType().Name);
         DialogMessage.MessageComButtonOkIconeErro(erro.Message, "Erro");
     }
 }
        public int Salvar(Cliente cliente)
        {

            try
            {
                InstanciarClienteBO();
                int retorno = Insucesso;
                if (_clienteBO.VerificarSeJaExisteNoSalvamento(cliente) == NaoExiste)
                {
                    _banco.Entry(cliente).State = EntityState.Added;
                    retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Insucesso.ErroCustomForTernary("Não foi possível salvar o cliente");
                }
                return retorno;
            }
            catch (CustomException erro)
            {
                throw new CustomException(erro.Message);
            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }


        }
Exemplo n.º 3
0
 public bool VerificarSeJaExisteNoSalvamento(Cliente cliente)
 {
     try
     {
         InstanciarBanco();
         return _banco.Cliente.FirstOrDefault(c => c.CPF == cliente.CPF) != null ? Existe.RetornaErro("CPF já existe.") : NaoExiste;
     }
     catch (CustomException erro)
     {
         throw new CustomException(erro.Message);
     }
     catch (Exception erro)
     {
         throw new Exception(erro.Message);
     }
 }
        public int Deletar(Cliente cliente)
        {
            try
            {
                _banco.Entry(cliente).State = EntityState.Deleted;
                return _banco.SaveChanges() == Sucesso ? Sucesso : Sucesso;

            }
            catch (CustomException erro)
            {
                throw new CustomException(erro.Message);
            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }
        }
Exemplo n.º 5
0
        public bool VerificarSeJaExisteNaAlteracao(Cliente cliente)
        {
            try
            {
                bool retorno = NaoExiste;
                InstanciarBanco();
                if (_banco.Cliente.Find(cliente.ID).CPF !=  cliente.CPF)
                {
                    if (_banco.Cliente.Any(c => c.CPF == cliente.CPF))
                        retorno = Existe.RetornaErro("CPF já existe.");
                }
                return retorno;
            }
            catch (CustomException erro)
            {
                throw new CustomException(erro.Message);
            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }

        }
        public int Alterar(Cliente cliente)
        {
            try
            {
                InstanciarClienteBO();
                int retorno = Insucesso;
                if (_clienteBO.VerificarSeJaExisteNaAlteracao(cliente) == NaoExiste)
                {
                    _banco.Entry(cliente).State = EntityState.Modified;
                    retorno = _banco.SaveChanges() == Sucesso ? Sucesso : Sucesso;
                }
                return retorno;

            }
            catch (CustomException erro)
            {
                throw new CustomException(erro.Message);
            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }
        }
 private void dgvCliente_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         InstanciarClienteRepositorio();
         if (dgvCliente.Rows.Count > 0 && e.RowIndex >= 0 && _clienteRepositorio.GetQuantidade() > 0)
         {
             InstanciarClienteRepositorio();
             Model.Entidades.Cliente cliente = _clienteRepositorio.GetClientePorID(GetLinhaDoGrid());
             OpenMdiForm.OpenForWithShowDialog(new frmCadastrarCliente(cliente, EnumTipoOperacao.Detalhes));
             LimparTxt();
             FocarNoTxt();
         }
     }
     catch (CustomException erro)
     {
         DialogMessage.MessageFullComButtonOkIconeDeInformacao(erro.Message, "Aviso");
     }
     catch (Exception erro)
     {
         DialogMessage.MessageComButtonOkIconeErro(erro.Message, "Erro");
     }
 }
 private void CarregaClienteTipoOperacao(Model.Entidades.Cliente cliente, EnumTipoOperacao tipoOpercacao)
 {
     _cliente = cliente;
     _tipoOperacao = tipoOpercacao;
 }
 public frmCadastrarCliente(Cliente cliente, EnumTipoOperacao tipoOpercacao)
 {
     InitializeComponent();
     CarregaClienteTipoOperacao(cliente, tipoOpercacao);
 }
Exemplo n.º 10
0
 private void CarregaClienteTipoOperacao(Model.Entidades.Cliente cliente, EnumTipoOperacao tipoOpercacao)
 {
     _cliente      = cliente;
     _tipoOperacao = tipoOpercacao;
 }