protected void GridFornecedores_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { int idFornecedor = Convert.ToInt32(GridFornecedores.Rows[Convert.ToInt32(e.CommandArgument)].Cells[1].Text.Trim()); if (e.CommandName.Equals("Editar")) { Usuario usuario = (Usuario)Session["UsuarioLogado"]; Fornecedor fornecedor = new Fornecedor(idFornecedor); Fornecedor rtnFornecedor = FornecedorFacade.RecuperarFornecedor(fornecedor); lblCodigoFornecedor.Text = rtnFornecedor.Id.ToString(); txtLogradouro.Text = rtnFornecedor.Logradouro.Descricao; txtBairro.Text = rtnFornecedor.Logradouro.Descricao_Bairro; txtCep.Text = rtnFornecedor.Logradouro.Cep; txtCidade.Text = rtnFornecedor.Logradouro.Cidade; txtEstado.Text = rtnFornecedor.Logradouro.Uf; MultiViewNota.ActiveViewIndex = 1; } if (e.CommandName.Equals("Excluir")) { lblCodigoFornecedorExclusao.Text = idFornecedor.ToString(); lblNomeForcedorExluir.Text = GridFornecedores.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text.Trim(); lblCpf_CnpjExcluir.Text = GridFornecedores.Rows[Convert.ToInt32(e.CommandArgument)].Cells[3].Text.Trim(); MultiViewNota.ActiveViewIndex = 3; } }
protected void btnPesquisar_Click(object sender, EventArgs e) { if (!txtFornecedorPesquisa.Text.Equals("")) { Usuario usuario = (Usuario)Session["UsuarioLogado"]; Fornecedor fornecedor = new Fornecedor(); ValueObjectLayer.Empresa empresa = new ValueObjectLayer.Empresa(); empresa.Nome = txtFornecedorPesquisa.Text; IList <Fornecedor> fornecedores = FornecedorFacade.RecuperarFornecedores(fornecedor); if (fornecedores.Count > 0) { GridFornecedores.DataSource = fornecedores; GridFornecedores.DataBind(); } else { string alerta1 = "Nenhum Fornecedor encontrado para este critério de pesquisa! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } } else { string alerta1 = "Digite o nome do Fornecedor para pesquisar! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } }
protected void PreencheComboFornecedor() { Usuario usuario = (Usuario)Session["UsuarioLogado"]; Fornecedor fornece = new Fornecedor(); IList <Fornecedor> lstFornecedores = FornecedorFacade.RecuperarFornecedores(fornece); Fornecedor objFornecedor = new Fornecedor(); objFornecedor.Id = 0; objFornecedor.Nome = "Selecione"; lstFornecedores.Add(objFornecedor); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (this.Master.GetType().BaseType.Name != "PopUp") { Resultado resultado = new Resultado(); int FornecedorID = Convert.ToInt32(Request.QueryString["id"]); HarunaNet.Entities.Fornecedor oFornecedor = new FornecedorFacade().Obter(ref resultado, FornecedorID); if (oFornecedor.FornecedorID >= 0) { ObterDados(oFornecedor); } } } }
protected void btnConfirmarExclusaoFornecedor_Click(object sender, EventArgs e) { Fornecedor fornecedor = new Fornecedor(Convert.ToInt32(lblCodigoFornecedorExclusao.Text)); string alerta1 = string.Empty; if (FornecedorFacade.ExcluiFornecedor(fornecedor)) { alerta1 = "Fornecedor Excluído com Sucesso! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); MultiViewNota.ActiveViewIndex = 0; } else { alerta1 = "Falha ao tentar Excluir o Fornecedor " + lblNomeForcedorExluir.Text; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } }
protected void InserirFornecedor_Click(object sender, EventArgs e) { string alerta1 = string.Empty; Usuario usuario = (Usuario)Session["UsuarioLogado"]; Fornecedor fornecedor = new Fornecedor(); ValueObjectLayer.Empresa empresa = new ValueObjectLayer.Empresa(); empresa.Nome = txtNomeInsere.Text; empresa.Cpf_Cnpj = ttxtCpf_CnpjInsere.Text; empresa.PessoaFisicaJuridica = ddlPessoaFisicaJuridaInsere.SelectedValue; empresa.Email = txtEmailInsere.Text; empresa.Fone = txtTelefoneInsere.Text; Logradouro logradouro = new Logradouro(); logradouro.Descricao = txtLogradouroInsere.Text; logradouro.Descricao_Bairro = txtBairroInsere.Text; logradouro.Cep = txtCepInsere.Text; logradouro.Cidade = txtCidadeInsere.Text; logradouro.Uf = txtEstadoInsere.Text; fornecedor.Logradouro = logradouro; if (FornecedorFacade.RecuperarFornecedor(fornecedor) == null) { if (FornecedorFacade.CriarFornecedor(fornecedor) > 0) { alerta1 = "Fornecedor criado com sucesso! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); InserirFornecedor.Enabled = false; } else { alerta1 = "Falha ao tentar criar um Fornecedor! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } } else { alerta1 = "Já existe um Fornecedor com este Cpf/Cnpj! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } }
protected void PreencheComboFornecedor() { Usuario usuario = (Usuario)Session["UsuarioLogado"]; Fornecedor fornece = new Fornecedor(); //fornece.Empresa = new Empresa(usuario.Empresa.Id); IList<Fornecedor> lstFornecedores = FornecedorFacade.RecuperarFornecedores(fornece); Fornecedor objFornecedor = new Fornecedor(); objFornecedor.Id = 0; //objFornecedor.Empresa = new Empresa(); objFornecedor.Nome = "Selecione"; lstFornecedores.Add(objFornecedor); ddlFornecedor.DataSource = lstFornecedores; ddlFornecedor.DataTextField = "Nome"; ddlFornecedor.DataValueField = "Id"; ddlFornecedor.DataBind(); ddlFornecedor.SelectedValue = "0"; }
protected void btnSalvar_Click(object sender, EventArgs e) { HarunaNet.Entities.Fornecedor oFornecedor = new HarunaNet.Entities.Fornecedor(); Resultado resultado = new Resultado(); try { oFornecedor.FornecedorID = FornecedorID.Value.Trim() != String.Empty ? Convert.ToInt32(FornecedorID.Value) : 0; oFornecedor.NomeFantasia = txtNomeFantasia.Text; oFornecedor.RazaoSocial = txtRazaoSocial.Text; oFornecedor.CNPJ = txtCNPJ.Text; oFornecedor.InscricaoEstadual = txtInscEstadual.Text; oFornecedor.InscricaoMunicipal = txtInscMunicipal.Text; oFornecedor.Logradouro = txtEndereco.Text; oFornecedor.Bairro = txtBairro.Text; oFornecedor.CEP = txtCEP.Text; oFornecedor.Cidade = txtCidade.Text; oFornecedor.UF = txtUF.Text; oFornecedor.Telefone_1 = txtTelefone1.Text; oFornecedor.Ramal_1 = txtRamal1.Text; oFornecedor.Telefone_2 = txtTelefone2.Text; oFornecedor.Ramal_2 = txtRamal2.Text; oFornecedor.Celular = txtCelular.Text; oFornecedor.Email = txtEmail.Text; oFornecedor.Observacao = txtObservacoes.Text.Trim(); oFornecedor.Status = 1; resultado = new FornecedorFacade().Salvar(oFornecedor); if (resultado.Sucesso) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alerta", Consts.JavaScript.Alert(Consts.Funcoes.Replacer4js(resultado.Mensagens[0].Descricoes[0].ToString()), false), true); btnCancelar.Text = "Voltar"; } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "alerta", Consts.JavaScript.Alert(Consts.Funcoes.Replacer4js(resultado.Mensagens[0].Descricoes[0].ToString()), false), true); } } catch (Exception) { //Fechar(); } }
protected void btnSalvarFornecedor_Click(object sender, EventArgs e) { string alerta1 = string.Empty; if (ValidaFornecedor()) { Usuario usuario = (Usuario)Session["UsuarioLogado"]; Fornecedor fornecedor = new Fornecedor(Convert.ToInt32(lblCodigoFornecedor.Text)); ValueObjectLayer.Empresa empresa = new ValueObjectLayer.Empresa(); empresa.Nome = txtNome.Text; empresa.Cpf_Cnpj = txtCpf_Cnpj.Text; empresa.PessoaFisicaJuridica = ddlPessoaFisicaJurida.SelectedValue; empresa.Email = txtEmail.Text; empresa.Fone = txtTelefone.Text; Logradouro logradouro = new Logradouro(); logradouro.Descricao = txtLogradouro.Text; logradouro.Descricao_Bairro = txtBairro.Text; logradouro.Cep = txtCep.Text; logradouro.Cidade = txtCidade.Text; logradouro.Uf = txtEstado.Text; fornecedor.Logradouro = logradouro; if (FornecedorFacade.AlterarFornecedor(fornecedor)) { alerta1 = "Registro alterado com sucesso! "; } else { alerta1 = "Falha ao tentar alterar o registro! "; } this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } else { alerta1 = "Todos Os Campos São De Preenchimento Obrigatório! "; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alerta", "<script type='text/javascript'>alert('" + alerta1 + "')</script>"); } }
public async Task <ActionResult <Fornecedor> > Update([FromBody] Fornecedor fornecedor) { Fornecedor fornecedorToUpdate = await _context.Fornecedores.FindAsync(fornecedor.ID); fornecedorToUpdate.Empresa = await _context.Empresas.FindAsync(fornecedor.EmpresaID) ?? fornecedorToUpdate.Empresa; fornecedorToUpdate.Nome = fornecedor.Nome ?? fornecedorToUpdate.Nome; fornecedorToUpdate.NumeroRegistro = fornecedor.NumeroRegistro ?? fornecedorToUpdate.NumeroRegistro; ///if (FornecedorFacade.IsPessoaFisica(fornecedorToUpdate)) ///{ fornecedorToUpdate.DataNascimento = fornecedor.DataNascimento ?? fornecedorToUpdate.DataNascimento; fornecedorToUpdate.RG = fornecedor.RG ?? fornecedorToUpdate.RG; //} FornecedorFacade.CadastroIsValid(fornecedorToUpdate); Telefone currTel = new Telefone(); if (fornecedor.Telefone != null) { foreach (var item in fornecedor.Telefone) { currTel = await _context.Telefones.FindAsync(item.ID); if (currTel != null) { currTel.NumeroTelefone = item.NumeroTelefone; } else { item.FornecedorID = fornecedorToUpdate.ID; await _context.Telefones.AddAsync(item); } } } await _context.SaveChangesAsync(); return(Ok(fornecedorToUpdate)); }
public async Task <ActionResult <Fornecedor> > Insert(Fornecedor fornecedor) { fornecedor.Empresa = await _context.Empresas.FindAsync(fornecedor.EmpresaID); FornecedorFacade.CadastroIsValid(fornecedor); await _context.AddAsync(fornecedor); await _context.SaveChangesAsync(); if (fornecedor.Telefone != null) { foreach (var item in fornecedor.Telefone) { item.FornecedorID = fornecedor.ID; await _context.Telefones.AddAsync(item); } await _context.SaveChangesAsync(); } return(Ok(fornecedor)); }