private async void MostrarCliente(string cpf) { PF.Clear(); ListaPJ.Clear(); var pf = Task.Run(() => mdata.ExistPessoaFisica(cpf)); await pf; if (pf.IsCompleted) { PF.Add(new mCliente() { Inscricao = pf.Result.CPF, NomeRazao = pf.Result.Nome, Telefones = pf.Result.Telefones, Email = pf.Result.Email }); } List <Task <mPJ_Ext> > l_pj = new List <Task <mPJ_Ext> >(); foreach (mVinculos v in pf.Result.ColecaoVinculos) { l_pj.Add(Task.Run(() => mdata.ExistPessoaJuridica(v.CNPJ))); } foreach (Task <mPJ_Ext> pj in l_pj) { await pj; //if (pj.Result.SituacaoCadastral != "BAIXADO") if (pj.IsCompleted) { if (pf.Result.ColecaoVinculos.Count > 1) { ListaPJ.Add(new mCliente() { Inscricao = pj.Result.CNPJ, NomeRazao = pj.Result.RazaoSocial, Telefones = pj.Result.Telefones, Email = pj.Result.Email }); ViewListaPJ = Visibility.Visible; } else { PJ.Add(new mCliente() { Inscricao = pj.Result.CNPJ, NomeRazao = pj.Result.RazaoSocial, Telefones = pj.Result.Telefones, Email = pj.Result.Email }); } } } }
private void AsyncMostrarCliente(string cpf) { Task <mPF_Ext> .Factory.StartNew(() => mdata.ExistPessoaFisica(cpf)) .ContinueWith(task => { if (task.IsCompleted) { PF.Clear(); PF.Add(new mCliente() { Inscricao = task.Result.CPF, NomeRazao = task.Result.Nome, Telefones = task.Result.Telefones, Email = task.Result.Email }); ListaPJ.Clear(); foreach (mVinculos v in task.Result.ColecaoVinculos) { Task <mPJ_Ext> .Factory.StartNew(() => mdata.ExistPessoaJuridica(v.CNPJ)).ContinueWith(task_two => { if (task_two.IsCompleted) { if (task.Result.ColecaoVinculos.Count > 1) { ListaPJ.Add(new mCliente() { Inscricao = task_two.Result.CNPJ, NomeRazao = task_two.Result.RazaoSocial, Telefones = task_two.Result.Telefones, Email = task_two.Result.Email }); ViewListaPJ = Visibility.Visible; } else { PJ.Add(new mCliente() { Inscricao = task_two.Result.CNPJ, NomeRazao = task_two.Result.RazaoSocial, Telefones = task_two.Result.Telefones, Email = task_two.Result.Email }); } } }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } } }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); }
private void AsyncPessoa(string cpf) { try { Task <mPF_Ext> .Factory.StartNew(() => mdata.ExistPessoaFisica(cpf)) .ContinueWith(task => { if (task.IsCompleted) { PF = new ObservableCollection <mCliente>(); PF.Add(new mCliente() { Inscricao = task.Result.CPF, NomeRazao = task.Result.Nome, Telefones = task.Result.Telefones, Email = task.Result.Email }); ListaPJ.Clear(); PJ.Clear(); if (task.Result.ColecaoVinculos.Count < 1) { SomentePF = true; TemEmpresa = Visibility.Visible; } else { SomentePF = false; TemEmpresa = Visibility.Collapsed; } foreach (mVinculos v in task.Result.ColecaoVinculos) { Task <mPJ_Ext> .Factory.StartNew(() => mdata.ExistPessoaJuridica(v.CNPJ)).ContinueWith(task_two => { if (task_two.IsCompleted) { if (task.Result.ColecaoVinculos.Count > 1) { ListaPJ.Add(new mCliente() { Inscricao = task_two.Result.CNPJ, NomeRazao = task_two.Result.RazaoSocial, Telefones = task_two.Result.Telefones, Email = task_two.Result.Email }); ViewListaPJ = Visibility.Visible; } else { PJ = new ObservableCollection <mCliente>(); PJ.Add(new mCliente() { Inscricao = task_two.Result.CNPJ, NomeRazao = task_two.Result.RazaoSocial, Telefones = task_two.Result.Telefones, Email = task_two.Result.Email }); } } }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } } }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }