Exemplo n.º 1
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            DALFrase dal = new DALFrase();
            Frase    cat = new Frase();
            string   msg = "";

            cat.Text      = txtFrase.Text;
            cat.Autor     = Convert.ToInt32(ddlAutor.SelectedValue);
            cat.Categoria = Convert.ToInt32(ddlCategoria.SelectedValue);

            try
            {
                if (btnSalvar.Text == "Inserir")
                {
                    dal.Inserir(cat);
                    msg = "<script>alert('o codigo gerado foi: " + cat.Id.ToString() + "')</script>";
                }
                else
                {
                    //alterar
                    cat.Id = int.Parse(txtId.Text);
                    dal.Alterar(cat);
                    msg = "<script>alert('Registro atualizado com sucesso!.')</script>";
                }
                Response.Write(msg);
                Limpar();
                AtualizaGrid();
            }
            catch (Exception error)
            {
                msg = "<script>alert('Houve um erro: " + error.Message + "')</script>";
            }
        }
Exemplo n.º 2
0
        public void AtualizaGrid()
        {
            DALFrase cat = new DALFrase();

            gvDadosFrase.DataSource = cat.Localizar();
            gvDadosFrase.DataBind();
        }