Exemple #1
0
        private async void Pesquisa(object obj)
        {
            if (string.IsNullOrEmpty(TermoPesquisa) || EstadoSelecionado == null)
            {
                return;
            }
            ResultadoPesquisa.Clear();
            IsOcupado = true;
            if (TermoPesquisa.Length == 14)
            {
                var e = GetEmpresa(TermoPesquisa);
                if (e != null)
                {
                    ResultadoPesquisa.Add(e);
                    IsOcupado = false;
                    return;
                }
            }
            IProgress <string> reportEmpresa = new Progress <string>(AddEmpresa);
            string             uf            = EstadoSelecionado.UF;
            List <string>      termos        = new List <string>(TermoPesquisa.Split(' '));

            termos.RemoveAll(t => t.Length <= 2);
            using (cts = new CancellationTokenSource())
            {
                await Task.Run(() =>
                {
                    var estado = GetEstado(uf);
                    foreach (var municipio in estado.Municipios)
                    {
                        foreach (var empresa in municipio.Empresas)
                        {
                            if (empresa.Contato == null || empresa.Contato.Numeros.Count == 0 && string.IsNullOrEmpty(empresa.Contato.Email))
                            {
                                continue;
                            }
                            //Verifica se todos os termos da pesquisa foram encontrados
                            bool isTermoCompleto = false;
                            foreach (var t in termos)
                            {
                                if (empresa.CNAE_Fiscal.Descricao.Contains(t, StringComparison.CurrentCultureIgnoreCase) ||
                                    empresa.RazaoSocial.Contains(t, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    isTermoCompleto = true;
                                    continue;
                                }
                                isTermoCompleto = false;
                            }
                            if (isTermoCompleto)
                            {
                                reportEmpresa.Report(empresa.CNPJ);
                            }
                            if (cts.IsCancellationRequested)
                            {
                                return;
                            }
                        }
                    }
                });

                IsOcupado = false;
            }
        }
Exemple #2
0
 private void AddEmpresa(string obj)
 {
     ResultadoPesquisa.Add(GetEmpresa(obj));
 }