protected void btnCadastrar_Click(object sender, EventArgs e) { string descricao = txtdescricaotipo.Text; TIPO tip = new TIPO() { descricao = descricao }; Aula5Entities contextAula5 = new Aula5Entities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextAula5.TIPO.Add(tip); lblmsg.Text = "Registro Inserido!"; } else { int id = Convert.ToInt32(valor); TIPO tipo = contextAula5.TIPO.First(c => c.id == id); tipo.descricao = tip.descricao; lblmsg.Text = "Registro Alterado!"; }; contextAula5.SaveChanges(); LoadGrid(); }
protected void btnCadastrar_Click(object sender, EventArgs e) { int fornecedor = int.Parse(ddlFornecedor.SelectedValue.ToString()); int tipo = int.Parse(ddlTipo.SelectedValue.ToString()); DateTime dataentrada = Convert.ToDateTime(txtdataentrada.Text); string descricao = txtdescricao.Text; decimal valor = Convert.ToDecimal(txtvalor.Text); MATERIAL m = new MATERIAL() { id_fornecedor = fornecedor, id_tipo = tipo, dataentrada = dataentrada, descricao = descricao, valor = valor }; Aula5Entities contextAula5 = new Aula5Entities(); string value = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(value)) { contextAula5.MATERIAL.Add(m); lblmsg.Text = "Registro Inserido!"; } else { int id = Convert.ToInt32(value); MATERIAL material = contextAula5.MATERIAL.First(c => c.id == id); material.id_fornecedor = m.id_fornecedor; material.id_tipo = m.id_tipo; material.dataentrada = m.dataentrada; material.valor = m.valor; material.descricao = m.descricao; lblmsg.Text = "Registro Alterado!"; }; contextAula5.SaveChanges(); LoadGrid(); }
protected void btnCadastrar_Click(object sender, EventArgs e) { int fornecedor = int.Parse(ddlFornecedor.SelectedValue.ToString()); int cliente = int.Parse(ddlCliente.SelectedValue.ToString()); int material = int.Parse(ddlMaterial.SelectedValue.ToString()); DateTime datavenda = Convert.ToDateTime(txtdatavenda.Text); COMPRA com = new COMPRA() { id_fornecedor = fornecedor, id_cliente = cliente, id_material = material, datavenda = datavenda }; Aula5Entities contextAula5 = new Aula5Entities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextAula5.COMPRA.Add(com); lblmsg.Text = "Registro Inserido!"; } else { int id = Convert.ToInt32(valor); COMPRA compra = contextAula5.COMPRA.First(c => c.id == id); compra.id_cliente = com.id_cliente; compra.id_fornecedor = com.id_fornecedor; compra.id_material = com.id_material; compra.datavenda = com.datavenda; lblmsg.Text = "Registro Alterado!"; }; contextAula5.SaveChanges(); LoadGrid(); }
private void CarregarListaTipo() { Aula5Entities context = new Aula5Entities(); List <TIPO> lsttipo = context.TIPO.ToList <TIPO>(); GVTipo.DataSource = lsttipo; GVTipo.DataBind(); }
private void CarregarListaFornecedor() { Aula5Entities context = new Aula5Entities(); List <FORNECEDOR> lstfornecedor = context.FORNECEDOR.ToList <FORNECEDOR>(); GVFornecedor.DataSource = lstfornecedor; GVFornecedor.DataBind(); }
private void CarregarListaCliente() { Aula5Entities context = new Aula5Entities(); List <CLIENTE> lstcliente = context.CLIENTE.ToList <CLIENTE>(); GVCliente.DataSource = lstcliente; GVCliente.DataBind(); }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; TIPO tipo = new TIPO(); Aula5Entities contextTipo = new Aula5Entities(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); tipo = contextTipo.TIPO.First(c => c.id == idItem); txtdescricaotipo.Text = tipo.descricao; } }
private void LoadGrid() { Aula5Entities context = new Aula5Entities(); List <FORNECEDOR> lstfornecedor = context.FORNECEDOR.ToList <FORNECEDOR>(); foreach (var item in lstfornecedor) { string cnpj = Convert.ToString(item.cnpj.Value); cnpj = cnpj + "0001"; string digito = IsCnpj(cnpj); item.cnpj = Convert.ToInt64(cnpj + digito); } GVFornecedor.DataSource = lstfornecedor; GVFornecedor.DataBind(); }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; COMPRA compra = new COMPRA(); Aula5Entities contextCompra = new Aula5Entities(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); compra = contextCompra.COMPRA.First(c => c.id == idItem); ddlCliente.Equals(compra.id_cliente); ddlFornecedor.Equals(compra.id_fornecedor); ddlMaterial.Equals(compra.id_material); txtdatavenda.Text = compra.datavenda.ToString(); } }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; FORNECEDOR fornecedor = new FORNECEDOR(); Aula5Entities contextFor = new Aula5Entities(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); fornecedor = contextFor.FORNECEDOR.First(c => c.id == idItem); txtnome.Text = fornecedor.nome; txttelefone.Text = fornecedor.telefone; txtcidade.Text = fornecedor.cidade; txtendereco.Text = fornecedor.endereco; txtCNPJ.Text = Convert.ToString(fornecedor.cnpj); } }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; MATERIAL material = new MATERIAL(); Aula5Entities contextMaterial = new Aula5Entities(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); material = contextMaterial.MATERIAL.First(c => c.id == idItem);; ddlFornecedor.Equals(material.id_fornecedor); ddlTipo.Equals(material.id_tipo); txtdataentrada.Text = material.dataentrada.ToString(); txtdescricao.Text = material.descricao; txtvalor.Text = material.valor.ToString(); } }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; CLIENTE cliente = new CLIENTE(); Aula5Entities contextCli = new Aula5Entities(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); cliente = contextCli.CLIENTE.First(c => c.id == idItem); txtnome.Text = cliente.nome; txttelefone.Text = cliente.telefone; txtcidade.Text = cliente.cidade; txtendereco.Text = cliente.endereco; txtCPF.Text = Convert.ToString(cliente.cpf); } }
protected void btnCadastrar_Click(object sender, EventArgs e) { if (txtcidade.Text == "" || txtnome.Text == "" || txttelefone.Text == "" || txtcidade.Text == "" || txtCNPJ.Text == "" || txtendereco.Text == "") { lblmsg.Text = "Preencha todos os campos!"; } else { string nome = txtnome.Text; string telefone = txttelefone.Text; string cidade = txtcidade.Text; string endereco = txtendereco.Text; long cnpj = Convert.ToInt64(txtCNPJ.Text.ToString().Substring(0, 8)); FORNECEDOR f = new FORNECEDOR() { nome = nome, telefone = telefone, cidade = cidade, endereco = endereco, cnpj = cnpj }; Aula5Entities contextAula5 = new Aula5Entities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextAula5.FORNECEDOR.Add(f); lblmsg.Text = "Registro Inserido!"; } else { int id = Convert.ToInt32(valor); FORNECEDOR fornecedor = contextAula5.FORNECEDOR.First(c => c.id == id); fornecedor.id = f.id; fornecedor.nome = f.nome; fornecedor.telefone = f.telefone; fornecedor.endereco = f.endereco; fornecedor.cidade = f.cidade; fornecedor.cnpj = f.cnpj; lblmsg.Text = "Registro Alterado!"; }; contextAula5.SaveChanges(); LoadGrid(); } }
protected void btnCadastrar_Click(object sender, EventArgs e) { if (txtcidade.Text == "" || txtnome.Text == "" || txttelefone.Text == "" || txtcidade.Text == "" || txtCPF.Text == "" || txtendereco.Text == "") { lblmsg.Text = "Preencha todos os campos!"; } else { string nome = txtnome.Text; string telefone = txttelefone.Text; string cidade = txtcidade.Text; string endereco = txtendereco.Text; long cpf = Convert.ToInt64(txtCPF.Text.ToString().Substring(0, 9)); CLIENTE cli = new CLIENTE() { nome = nome, telefone = telefone, cidade = cidade, endereco = endereco, cpf = cpf }; Aula5Entities contextAula5 = new Aula5Entities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextAula5.CLIENTE.Add(cli); lblmsg.Text = "Registro Inserido!"; } else { int id = Convert.ToInt32(valor); CLIENTE cliente = contextAula5.CLIENTE.First(c => c.id == id); cliente.id = cli.id; cliente.nome = cli.nome; cliente.telefone = cli.telefone; cliente.endereco = cli.endereco; cliente.cidade = cli.cidade; cliente.cpf = cli.cpf; lblmsg.Text = "Registro Alterado!"; }; contextAula5.SaveChanges(); LoadGrid(); } }
private void CarregarListaMaterial() { Aula5Entities context = new Aula5Entities(); var dados = ( from m in context.MATERIAL from f in context.FORNECEDOR.Where(x => x.id == m.id_fornecedor) from t in context.TIPO.Where(x => x.id == m.id_tipo) select new { Id = m.id, Descricao = m.descricao, Dataentrada = m.dataentrada, Id_tipo = t.descricao, Id_fornecedor = f.nome, Valor = m.valor }).ToList(); GVMaterial.DataSource = dados; GVMaterial.DataBind(); }
private void CarregarListaCompra() { Aula5Entities context = new Aula5Entities(); var dados = ( from compra in context.COMPRA from m in context.MATERIAL.Where(x => x.id == compra.id_material) from f in context.FORNECEDOR.Where(x => x.id == compra.id_fornecedor) from cliente in context.CLIENTE.Where(x => x.id == compra.id_cliente) select new { Id = compra.id, Id_fornecedor = f.nome, Id_cliente = cliente.nome, Id_material = m.descricao, Datavenda = compra.datavenda, }).ToList(); GVCompras.DataSource = dados; GVCompras.DataBind(); }
protected void GVMaterial_RowCommand(object sender, GridViewCommandEventArgs e) { int idItem = Convert.ToInt32(e.CommandArgument.ToString()); Aula5Entities context = new Aula5Entities(); MATERIAL material = new MATERIAL(); material = context.MATERIAL.First(c => c.id == idItem); if (e.CommandName == "ALTERAR") { Response.Redirect("Material.aspx?idItem=" + idItem); } else if (e.CommandName == "EXCLUIR") { context.MATERIAL.Remove(material); context.SaveChanges(); string msg = "Material excluído com sucesso!"; string titulo = "Informação"; CarregarListaMaterial(); DisplayAlert(titulo, msg, this); } }
protected void GVTipo_RowCommand(object sender, GridViewCommandEventArgs e) { int idItem = Convert.ToInt32(e.CommandArgument.ToString()); Aula5Entities context = new Aula5Entities(); TIPO tipo = new TIPO(); tipo = context.TIPO.First(c => c.id == idItem); if (e.CommandName == "ALTERAR") { Response.Redirect("Tipo.aspx?idItem=" + idItem); } else if (e.CommandName == "EXCLUIR") { context.TIPO.Remove(tipo); context.SaveChanges(); string msg = "Fornecedor excluído com sucesso!"; string titulo = "Informação"; CarregarListaTipo(); DisplayAlert(titulo, msg, this); } }
protected void GVCliente_RowCommand(object sender, GridViewCommandEventArgs e) { int idItem = Convert.ToInt32(e.CommandArgument.ToString()); Aula5Entities context = new Aula5Entities(); CLIENTE cliente = new CLIENTE(); cliente = context.CLIENTE.First(c => c.id == idItem); if (e.CommandName == "ALTERAR") { Response.Redirect("Cliente.aspx?idItem=" + idItem); } else if (e.CommandName == "EXCLUIR") { context.CLIENTE.Remove(cliente); context.SaveChanges(); string msg = "Cliente excluído com sucesso!"; string titulo = "Informação"; CarregarListaCliente(); DisplayAlert(titulo, msg, this); } }
private void LoadGrid() { Aula5Entities context = new Aula5Entities(); List <CLIENTE> lstcliente = context.CLIENTE.ToList <CLIENTE>(); int cont = 0; do { foreach (var item in lstcliente) { string cpf = Convert.ToString(item.cpf.Value); string digito = IsCpf(cpf); item.cpf = Convert.ToInt64((cpf + digito).Substring(0, 11)); } cont++; } while (cont <= (lstcliente.Count) + 1); GVCliente.DataSource = lstcliente; GVCliente.DataBind(); }