Пример #1
0
        public async Task <List <FipeModel> > QueryYear_modelsByFipeCode(string code)//QueryByFipeCode(Tipo t, string code)
        {
            try
            {
                int numcode = -1;
                if (code == "" || !Int32.TryParse(code.Replace("-", ""), out numcode) || numcode == 0 || numcode > 9999999)
                {
                    throw new WebException(JsonConvert.SerializeObject(new Relatório(3)));
                }

                code = numcode.ToString("000000-0");

                List <FipeModel> models = await GetModels(code);

                if (models.Count == 0)
                {
                    return(models);
                }

                List <Task <string> > requests = new List <Task <string> >();
                foreach (FipeModel model in models)
                {
                    string url = /*await*/ UrlBuilder(_queryByFipeCodeUrl, new string[] { _refTable, ((int)model.TipoVeiculo).ToString(), model.AnoModelo, model.TipoCombustivel, _vehicleTypes[(int)model.TipoVeiculo], code, _queryTypes[0] });
                    requests.Add(WebFile.HttpRequestAsync(url));
                }

                string[] responses = await TaskEx.WhenAll(requests);

                if (responses.Length == 0 || String.IsNullOrEmpty(responses[0]))
                {
                    throw new WebException(JsonConvert.SerializeObject(new Relatório(4)));
                }

                foreach (string json in responses)
                {
                    if (Array.IndexOf(responses, json) == 0)                                //insert mockup in position 0
                    {
                        FipeModel mockup = JsonConvert.DeserializeObject <FipeModel>(json); //mockup: "Selecione o ano/modelo:"
                        mockup.Label = "Selecione o ano/modelo:";
                        mockup.Value = "0";
                        mockup.Valor = null;
                        models.Insert(0, mockup);
                    }

                    FipeModel model = JsonConvert.DeserializeObject <FipeModel>(json);
                    model.Label = models.ElementAt(Array.IndexOf(responses, json) + 1).Label;
                    model.Value = models.ElementAt(Array.IndexOf(responses, json) + 1).Value;
                    models[Array.IndexOf(responses, json) + 1] = model;
                }
                return(models);
            }
            catch (Exception ex)
            {
                Relatório.ExHandler(ex);
                return(new List <FipeModel>());
            }
        }
Пример #2
0
 private void anoModeloFipe_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (anoModeloFipe.SelectedIndex >= 0)
     {
         botaobuscar.BackgroundImage = Properties.Resources.CarregandoParado;
         FipeQuery query = new FipeQuery();
         FipeModel model = query.QueryValuationByFipeModel(anoModeloFipe.SelectedItem as FipeModel);
         modelo.Text                 = model.Modelo;
         marca.Text                  = model.Marca;
         valorFipe.Text              = model.PrecoMedio.ToString("C2", CultureInfo.CurrentCulture);
         anoModeloTexto.Text         = model.Label;
         botaobuscar.BackgroundImage = Properties.Resources.Buscar;
     }
 }
Пример #3
0
 public FipeModel QueryValuationByFipeModel(FipeModel model)
 {
     return(model);
 }