コード例 #1
0
        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();
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        protected void GVCompras_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int           idItem  = Convert.ToInt32(e.CommandArgument.ToString());
            Aula5Entities context = new Aula5Entities();
            COMPRA        compra  = new COMPRA();

            compra = context.COMPRA.First(c => c.id == idItem);

            if (e.CommandName == "ALTERAR")
            {
                Response.Redirect("Compras.aspx?idItem=" + idItem);
            }
            else if (e.CommandName == "EXCLUIR")
            {
                context.COMPRA.Remove(compra);
                context.SaveChanges();
                string msg    = "Compra excluída com sucesso!";
                string titulo = "Informação";
                CarregarListaCompra();
                DisplayAlert(titulo, msg, this);
            }
        }