protected async void FetchPokemonAsync() { if (!string.IsNullOrEmpty(pokemonName)) { pokemon = await pokemonService.GetPokemonAsync(pokemonName); this.StateHasChanged(); } }
//PROCURAR POKÉMON private async void btnProcurarPokemon_Click(object sender, EventArgs e) { if (!FieldErrorCheck("searchPokemon")) { return; } timerUpdateGrid.Enabled = false; timerUpdateGrid.Stop(); gridPokemons.Rows.Clear(); btnProcurarPokemon.Enabled = false; txtProcuraPoke.Enabled = false; btnProcurarPokemon.Text = "PROCURANDO"; PokemonAttributes pokemonList = null; try { if (cbIv100.Checked) { pokemonList = await PesquisaPokemon.SearchPokemon(true, (int)Enum.Parse(typeof(PokemonId), txtProcuraPoke.Text)); } else { pokemonList = await PesquisaPokemon.SearchPokemon(false, (int)Enum.Parse(typeof(PokemonId), txtProcuraPoke.Text)); } if (pokemonList == null) { timerUpdateGrid.Enabled = true; timerUpdateGrid.Start(); btnProcurarPokemon.Enabled = true; txtProcuraPoke.Enabled = true; btnProcurarPokemon.Text = "PROCURAR"; return; } } catch (Exception exception) { SayLog.Error(exception.Message + exception.StackTrace); return; } var countryImage = new DataGridViewImageColumn(); countryImage.Description = "image"; countryImage.ImageLayout = DataGridViewImageCellLayout.Normal; var pokemonIcon = new DataGridViewImageColumn(); pokemonIcon.Description = "image"; pokemonIcon.ImageLayout = DataGridViewImageCellLayout.Stretch; foreach (var pokemon in pokemonList.PokemonAtribbutes) { if (pokemon == null) { continue; } if (!string.IsNullOrEmpty(pokemon.Country)) { try { var imagePathCountry = @"Images\flags\" + pokemon.Country + ".gif"; var imagePathIcon = @"Images\pokemons\" + pokemon.Number + ".png"; countryImage.Image = Image.FromFile(imagePathCountry); pokemonIcon.Image = Image.FromFile(imagePathIcon); gridPokemons.Rows.Add(pokemonIcon.Image, pokemon.Number, pokemon.Name, countryImage.Image, pokemon.Iv, pokemon.Cp, pokemon.TimeLeft, pokemon.Latitude, pokemon.Longitude, PesquisaPokemon.CalculateTimeLeft(PogoGlobalSettings.PlayerLatitude, PogoGlobalSettings.PlayerLongitude, pokemon.Latitude, pokemon.Longitude).ToString()); } catch (Exception exception) { Console.WriteLine(exception); SayLog.Error(exception.Message + "\t" + exception.StackTrace); } } else { var imagePathCountry = @"Images\flags\bra.gif"; var imagePathIcon = @"Images\pokemons\" + pokemon.Number + ".png"; countryImage.Image = Image.FromFile(imagePathCountry); pokemonIcon.Image = Image.FromFile(imagePathIcon); gridPokemons.Rows.Add(pokemonIcon.Image, pokemon.Number, pokemon.Name, countryImage.Image, pokemon.Iv, pokemon.Cp, pokemon.TimeLeft, pokemon.Latitude, pokemon.Longitude, PesquisaPokemon.CalculateTimeLeft(PogoGlobalSettings.PlayerLatitude, PogoGlobalSettings.PlayerLongitude, pokemon.Latitude, pokemon.Longitude).ToString()); } } timerUpdateGrid.Enabled = true; timerUpdateGrid.Start(); btnProcurarPokemon.Enabled = true; txtProcuraPoke.Enabled = true; btnProcurarPokemon.Text = "PROCURAR"; }