Beispiel #1
0
        //pesquisa a quantidade de registros em uma data
        public async Task GetRegisterByDate()
        {
            try
            {
                DateTime date = await new DateSelectionConsole().RunConsoleDateSelection();

                WriteConsole.WriteInLine("Pesquisando ", Console.CursorTop + 1, 1);
                List <Registro> aps = await WebApi.GetListRegistroByDate(date);

                if (aps == null)
                {
                    return;
                }

                Console.Clear();

                //escreve o resultado da pesquisa na tela
                aps.ForEach(x =>
                {
                    Console.Write(x.Cliente.Nome + x.Aparelho.Modelo + " " + (x.DiagnosticGD.consul != 1 ? "N" : "Y"));

                    WriteConsole.Separator('/');
                });

                //await aps.ForEachAsync(x =>
                //{
                //    try
                //    {
                //        x.ToString();

                //        //var ap = await WebApi.GetRegistroById(x.Id);

                //        //Console.Write(ap.ToString());

                //        WriteConsole.Separator('/', 1, 1);
                //    }
                //    catch (Exception e)
                //    {
                //        Console.WriteLine(e.Message);
                //    }
                //});
                var aa = aps.Select(x => x.DiagnosticGD.consul != 0);

                Console.WriteLine("\n" + (aps == null ? 0 : aps.Count()) + " registros e "
                                  + (aps.Where(x => x.DiagnosticGD.consul == 1).ToList().Count() == 0 ? 0 : aps.Where(x => x.DiagnosticGD.consul == 1).ToList().Count())
                                  + " diagnosticos no dia " + date.Date.ToString("dd/MM/yyyy"));
            }
            catch (Exception e)
            {
            }
        }
Beispiel #2
0
        public async Task SetRegister()
        {
            Console.Clear();
            try
            {
                diagnosticos = await GalaxyDiagnosticService.LoadDiagnostics();

                registros = GSPNDataService.LoadDataRegistros();
                pendentes = await GSPNDataService.LoadDataPendentes();

                //Diagnostico[] diagnosticos = JsonConvert.DeserializeObject<Diagnostico[]>(FileHelper.OpenFile("diagnosticosPendentes.txt"));

                WriteConsole.Separator('-');

                List <Registro> pendenteForEach = (List <Registro>)pendentes.Select(b => b).ToList();


                await pendenteForEach.ForEachAsync(async x =>
                {
                    try
                    {
                        Cliente c = await WebApi.GetClienteByCPF(x.Cliente.Cpf, x.Cliente);
                        if (c == null)
                        {
                            c = await WebApi.RegisterNewCliente(x.Cliente);
                        }
                        if (c == null)
                        {
                            Console.WriteLine("Usuario não encontrado"); return;
                        }

                        x.Aparelho = await WebApi.GetModelData(x.Aparelho);
                        x.Cliente  = c;

                        if (x.Cliente == null || x.Aparelho == null)
                        {
                            Console.WriteLine("Erro em construir formulario"); return;
                        }

                        if (x.Reason == null)
                        {
                            x = RegistroData.SD.ContainsKey(x.Type.ToString()) ? GetDiagnosticoByType(x) : GetDiagnosticoByConsole(x);
                        }

                        x.DiagnosticGD = await GetDiagnosticoGD(x.Aparelho);

                        x.Data = DateTime.Now.Date.ToString("MM-dd-yyyy");
                        Console.Write(x.ToString());

                        if (registros == null)
                        {
                            registros = new List <Registro>();
                        }

                        //se o aparelho ja foi registrado no dia ele fica em espera
                        if (registros.Any(y => x.Data == y.Data && x.Aparelho.RN == y.Aparelho.RN))
                        {
                            Console.WriteLine("/nNOVO REGISTRO PENDENTE");
                            return;
                        }
                        ;

                        Registro r = await WebApi.NewRegister(x);
                        if (r == null)
                        {
                            return;
                        }

                        registros.Add(r);
                        pendentes.RemoveAll(a => a.Aparelho.Imei == x.Aparelho.Imei);

                        //salva o registro setado em registrados.txt
                        GSPNDataService.SaveData(registros, pendentes);
                        Console.WriteLine("Salvo com Sucesso");
                    }
                    catch (Exception e)
                    {
                        Console.Write(e.Message);
                    }
                });

                Console.WriteLine("\nFim - Registros setados\n");
            }
            catch (Exception e)
            {
                throw e;
            }
        }