private async void GetEmitente() { try { dataGridEmitente.DataSource = await EmitenteBLL.GetEmitenteBLL(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async void LoadEmitente() { if (UtilClass.IsInDesignMode) { Emitentes.Add(new Emitente { RazaoSocial = "Eficaz Contabilidae", Logradouro = "Rua Sete de setembro" }); Emitentes.Add(new Emitente { RazaoSocial = "Eficaz Contabilidae 2", Logradouro = "Rua Sete de setembro" }); } else { List <Emitente> emitenteList = new List <Emitente>(); emitenteList = await EmitenteBLL.GetEmitenteBLL(); foreach (var item in emitenteList) { Emitentes.Add(new Emitente { RazaoSocial = item.RazaoSocial, Logradouro = item.Logradouro }); } } }
private async void SetEmitente(Enuns.TipoCrud tipoCrud) { Emitente emitente = new Emitente(); string mensagemException = Utilidade.GetMensagemParaException(tipoCrud); string mensagemCrud = Utilidade.GetMensagemParaCrud(tipoCrud); try { #region set parameters emitente.RazaoSocial = txtNomeRazao.Text; emitente.CNPJ = txtCNPJ.Text.Replace(".", "").Replace("/", "").Replace("-", ""); emitente.NomeFantasia = txtNomeFantasia.Text; emitente.Bairro = txtBairro.Text; emitente.CEP = txtCEP.Text.Replace("-", string.Empty); emitente.Cidade = txtCidade.Text; emitente.CNAE = txtCNAE.Text; emitente.CidadeCodigo = int.Parse(txtCodigoCidade.Text); emitente.Complemento = txtComplemento.Text; emitente.Fone = txtTelefone.Text; emitente.InscricaoEstadual = txtInscricaoEstatudal.Text; emitente.IM = txtIM.Text; emitente.Logradouro = txtEndereco.Text; emitente.NumeroCasa = txtNumero.Text; emitente.UF = txtEstado.Text; emitente.Cliente = MyGlobals.Cliente; #endregion HttpResponseMessage response = new HttpResponseMessage(); if (tipoCrud.Equals(Enuns.TipoCrud.novo)) { response = await EmitenteBLL.AdicionarEmitenteBLL(emitente); if (response.IsSuccessStatusCode) { MessageBox.Show("Emitente " + mensagemCrud + " com sucesso!", "Emitente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Ocorreu um erro ao " + mensagemException + " o emitente! \nErro: " + response.RequestMessage, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (tipoCrud.Equals(Enuns.TipoCrud.update)) { emitente.Id = int.Parse(txtIdEmitente.Text); response = await EmitenteBLL.AtualizarEmitenteBLL(emitente); if (response.IsSuccessStatusCode) { MessageBox.Show("Emitente " + mensagemCrud + " com sucesso!", "Emitente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Ocorreu um erro ao " + mensagemException + " o emitente! \nErro: " + response.RequestMessage, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (tipoCrud.Equals(Enuns.TipoCrud.delete)) { emitente.Id = int.Parse(txtIdEmitente.Text); response = await EmitenteBLL.DeletarEmitenteBLL(emitente.Id); if (response.IsSuccessStatusCode) { MessageBox.Show("Emitente " + mensagemCrud + " com sucesso!", "Emitente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Ocorreu um erro ao " + mensagemException + " o emitente! \nErro: " + response.RequestMessage, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Erro ao fazer operação no Emitente"); } LimpaCampos(); GetEmitente(); btnSalvar.Enabled = false; } catch (Exception ex) { MessageBox.Show("Ocorreu um erro ao " + mensagemException + " o emitente! \nErro: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }