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

            fornecedor = context.FORNECEDOR.First(c => c.id == idItem);

            if (e.CommandName == "ALTERAR")
            {
                Response.Redirect("Fornecedor.aspx?idItem=" + idItem);
            }
            else if (e.CommandName == "EXCLUIR")
            {
                context.FORNECEDOR.Remove(fornecedor);
                context.SaveChanges();
                string msg    = "Fornecedor excluído com sucesso!";
                string titulo = "Informação";
                CarregarListaFornecedor();
                DisplayAlert(titulo, msg, this);
            }
        }