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); tb_venda ven = new tb_venda() { id_fornec = fornecedor, id_cli = cliente, id_mat = material, venda_data = datavenda }; VendasDBEntities1 context = new VendasDBEntities1(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { context.tb_venda.Add(ven); lblmsg.Text = "Registro Inserido!"; } else { int id = Convert.ToInt32(valor); tb_venda venda = context.tb_venda.First(c => c.id == id); venda.id_cli = ven.id_cli; venda.id_fornec = ven.id_fornec; venda.id_mat = ven.id_mat; venda.venda_data = ven.venda_data; lblmsg.Text = "Registro Alterado!"; }; context.SaveChanges(); LoadGrid(); }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; tb_venda venda = new tb_venda(); VendasDBEntities1 context = new VendasDBEntities1(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); venda = context.tb_venda.First(c => c.id == idItem); ddlCliente.Equals(venda.id_cli); ddlFornecedor.Equals(venda.id_fornec); ddlMaterial.Equals(venda.id_mat); txtdatavenda.Text = venda.venda_data.ToString(); } }