Exemplo n.º 1
0
        /// <summary>
        /// Faz todas as validações necessárias dos campos da janela
        /// </summary>
        /// <returns>Retorna true se existir inconsistencias na janela</returns>
        private bool ValidaCampos()
        {
            dxErrorProvider.ClearErrors(); // Elimina todo os erros da janela

            if (responsavelDTO.Municipio.Id == 0)
            {
                dxErrorProvider.SetError(municipioTextEdit, "Município inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
            }

            if (responsavelDTO.Responsa == false &&
                responsavelDTO.Contador == false)
            {
                dxErrorProvider.SetError(responsaCheckEdit, "Responsabilidade inválida. Preenchimento obrigatório ao menos para uma das oções.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                dxErrorProvider.SetError(contadorCheckEdit, "Responsabilidade inválida. Preenchimento obrigatório ao menos para uma das oções.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
            }

            if (responsavelDTO.Contador || responsavelDTO.Responsa)
            {
                if (responsavelDTO.Nome == string.Empty)
                {
                    dxErrorProvider.SetError(nomeTextEdit, "Nome inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Endereco == string.Empty)
                {
                    dxErrorProvider.SetError(enderecoTextEdit, "Endereço inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Numero == string.Empty)
                {
                    dxErrorProvider.SetError(numeroTextEdit, "Número inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Bairro == string.Empty)
                {
                    dxErrorProvider.SetError(bairroTextEdit, "Bairro inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Cep == string.Empty)
                {
                    dxErrorProvider.SetError(cepTextEdit, "Cep inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Municipio.Codigoibge == 0)
                {
                    dxErrorProvider.SetError(codigoIBGEButtonEdit, "Cód. Município inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }
                else
                {
                    if (responsavelDTO.Municipio.Nome.Trim().Equals(string.Empty))
                    {
                        dxErrorProvider.SetError(codigoIBGEButtonEdit, "Cód. Município não localizado.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
                    }
                }

                if (responsavelDTO.Dddtelefone == string.Empty)
                {
                    dxErrorProvider.SetError(dddtelefoneTextEdit, "DDD do Telefone inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Telefone == string.Empty)
                {
                    dxErrorProvider.SetError(telefoneTextEdit, "Telefone inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (!responsavelDTO.DataNascimento.HasValue)
                {
                    dxErrorProvider.SetError(DataNascimentoDateEdit, "Data de Nascimento inválida. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Contato == string.Empty)
                {
                    dxErrorProvider.SetError(contatoTextEdit, "Contato inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                if (responsavelDTO.Cpf == string.Empty)
                {
                    dxErrorProvider.SetError(cpfTextEdit, "CPF inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }


                if (responsavelDTO.Cnpj == string.Empty && responsavelDTO.Cei == string.Empty)
                {
                    dxErrorProvider.SetError(cnpjTextEdit, "Documentação inválida. Preenchimento obrigatório ao menos para uma das opções.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                    dxErrorProvider.SetError(ceiTextEdit, "Documentação inválida. Preenchimento obrigatório ao menos para uma das opções.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }


                if (responsavelDTO.Cargo == string.Empty)
                {
                    dxErrorProvider.SetError(cargoTextEdit, "Cargo inválido. Preenchimento obrigatório.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }

                EventHandler checa; // necessário para chamar o evento dos campos

                if (responsavelDTO.Cnpj != string.Empty)
                {
                    if (Documentos.ValidarCNPJ(responsavelDTO.Cnpj) == false)
                    {
                        dxErrorProvider.SetError(cnpjTextEdit, "CNPJ inválido.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
                    }
                    else
                    {
                        checa = cnpjTextEdit_Validated;
                        if (checa != null)
                        {
                            checa(cnpjTextEdit, EventArgs.Empty);
                        }
                    }
                }

                if (responsavelDTO.Cpf != "")
                {
                    if (Documentos.ValidarCPF(responsavelDTO.Cpf) == false)
                    {
                        dxErrorProvider.SetError(cpfTextEdit, "CPF inválido.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
                    }
                    else
                    {
                        checa = cpfTextEdit_Validated;
                        if (checa != null)
                        {
                            checa(cpfTextEdit, EventArgs.Empty);
                        }
                    }
                }

                if (responsavelDTO.Cei != "")
                {
                    if (Documentos.ValidarCEI(responsavelDTO.Cei) == false)
                    {
                        dxErrorProvider.SetError(ceiTextEdit, "CEI inválido.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
                    }
                    else
                    {
                        checa = ceiTextEdit_Validated;
                        if (checa != null)
                        {
                            checa(ceiTextEdit, EventArgs.Empty);
                        }
                    }
                }

                if (responsavelDTO.Nit != "")
                {
                    checa = nitTextEdit_Validated;
                    if (checa != null)
                    {
                        checa(nitTextEdit, EventArgs.Empty);
                    }
                }

                if (responsavelDTO.Bairro.ToString().Count() > 20) //41739
                {
                    dxErrorProvider.SetError(bairroTextEdit, "O campo bairro possui mais caracteres do que o permitido nos layouts, por gentileza informe dados de modo abreviado. Tamanho máximo: 20 Caracteres.", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information);
                }
            }
            return(dxErrorProvider.HasErrors);
        }