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);
            }
        }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
0
        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);
            }
        }