public NFe(int codigo, NFeWS notas, BindingSource produtos) { InitializeComponent(); this.codigo = codigo; this.notas = notas; this.produtos = produtos; pbEnviar.BackgroundImage = Properties.Resources.BtEnv; pbInserir.BackgroundImage = Properties.Resources.btBuscar; }
//Trasnformando os JSON convertidos para NFeWS e BindingSource private async void btnWS_Click(object sender, EventArgs e) { CHNFE = Convert.ToInt32(txtURI.Text); NFeWS notas = await GetNFEById(CHNFE); BindingSource produtos = await GetProdutosById(CHNFE, bsDados); if (notas == null) { MessageBox.Show("Chave de acesso incorreta"); } else { openChildForm(new NFe(this.codigo, notas, produtos)); } }
//Obter a NFE pela chave de acesso, onde deserializa um JSON em strnig. private async Task <NFeWS> GetNFEById(int CHNFE) { using (var client = new HttpClient()) { URI = "https://localhost:44335/receitaWS/nfe/" + CHNFE.ToString(); HttpResponseMessage response = await client.GetAsync(URI); if (response.IsSuccessStatusCode || response.Content != null) { var NFeJsonString = await response.Content.ReadAsStringAsync(); NFeWS nota = JsonConvert.DeserializeObject <NFeWS>(NFeJsonString); return(nota); } else { MessageBox.Show("Falha ao obter a NFe : " + response.StatusCode); return(null); } } }