コード例 #1
0
        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();
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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);
            }
        }