Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["email"] != null)
     {
         DALUsuario du = new DALUsuario();
         Usuario    u  = du.GetRegistro(Session["email"].ToString());
         lbNome.Text    = u.Nome;
         lbEmail.Text   = u.Email;
         IUser.ImageUrl = "imagens/usuarios/" + u.Foto;
     }
 }
Example #2
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            DALUsuario dal = new DALUsuario();
            Usuario    cat = new Usuario();

            string msg = "";

            cat.Nome  = txtAutor.Text;
            cat.Email = txtEmail.Text;
            cat.Senha = txtSenha.Text;
            Usuario valida = dal.GetRegistro(cat.Email);

            try
            {
                if (btnSalvar.Text == "Inserir")
                {
                    //  Validação email
                    if (valida.Id == 0)
                    {
                        dal.Inserir(cat);
                        msg = "<script>alert('o codigo gerado foi: " + cat.Id.ToString() + "')</script>";
                    }
                    else
                    {
                        msg = "<script>alert('Esse email já foi cadastrado!.')</script>";
                    }
                }
                else
                {
                    //alterar
                    cat.Id = int.Parse(txtId.Text);

                    if ((valida.Id != 0 && valida.Id == cat.Id) || valida.Id == 0)
                    {
                        dal.Alterar(cat);
                        msg = "<script>alert('Registro atualizado com sucesso!.')</script>";
                    }
                    else
                    {
                        msg = "<script>alert('Já há um email cadastrado com esse nome.')</script>";
                    }
                    //  Validação Email
                }
                Response.Write(msg);
                Limpar();
            }
            catch (Exception error)
            {
                msg = "<script>alert('Houve um erro: " + error.Message + "')</script>";
            }
            AtualizaGrid();
            Limpar();
        }
Example #3
0
        protected void btSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                DALUsuario dal = new DALUsuario();
                Usuario    obj = new Usuario();
                obj.Nome  = txbNome.Text;
                obj.Email = txbEmail.Text;
                obj.Senha = txbSenha.Text;
                if (cbAdm.Checked)
                {
                    obj.Administrador = 1;
                }
                else
                {
                    obj.Administrador = 0;
                }
                String caminho = Server.MapPath(@"imagens\usuarios\");
                //faz o upload da foto e salva o nome no obj
                if (fuFoto.PostedFile.FileName != "")
                {
                    obj.Foto = DateTime.Now.Millisecond.ToString() + fuFoto.PostedFile.FileName;
                    String img = caminho + obj.Foto;
                    fuFoto.PostedFile.SaveAs(img);
                }
                string msg = "<script> alert('Registro atualizado com sucesso!!!!'); </script>";

                if (txbId.Text == "")
                {
                    //inserir
                    dal.Inserir(obj);
                    msg = "<script> alert('O código gerado foi: " + obj.Id.ToString() + "'); </script>";
                }
                else
                {
                    obj.Id = Convert.ToInt32(txbId.Text);
                    //verificar se existe foto existe e deletar
                    Usuario uold = dal.GetRegistro(obj.Id);
                    if (uold.Foto != "")
                    {
                        File.Delete(caminho + uold.Foto);
                    }
                    dal.Alterar(obj);
                }
                Response.Write(msg);
                GridView1.DataBind();
                LimpaCampos();
            }
            catch (Exception erro)
            {
                Response.Write("<script> alert('" + erro.Message + "'); </script>");
            }
        }
Example #4
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int        id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text);
            DALUsuario du = new DALUsuario();
            Usuario    u  = du.GetRegistro(id);

            if (u.Foto != "")
            {
                String caminho = Server.MapPath(@"imagens\usuarios\");
                File.Delete(caminho + u.Foto);
            }
        }
Example #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["email"] == null)
     {
         // Response.Redirect("~/login.aspx");
     }
     else
     {
         DALUsuario du = new DALUsuario();
         Usuario    u  = du.GetRegistro(Session["email"].ToString());
         AlteraMenu(u.Administrador);
     }
 }
Example #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("~/wfLogin.aspx");
            }
            else
            {
                DALUsuario dal = new DALUsuario();
                Usuario    usu = dal.GetRegistro(Session["email"].ToString());

                lNome.Text  = usu.Nome;
                lEmail.Text = usu.Email;
            }
        }
Example #7
0
        protected void btlogar_Click(object sender, EventArgs e)
        {
            string email = txbLogin.Text;
            string senha = txbSenha.Text;

            DALUsuario du = new DALUsuario();
            Usuario    u  = du.GetRegistro(email);

            if (email == u.Email && senha == u.Senha)
            {
                Session["id"]    = u.Id;
                Session["nome"]  = u.Nome;
                Session["email"] = email;
                Response.Redirect("~/Default.aspx");
            }
        }
Example #8
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int        id = Convert.ToInt32(GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text);
            DALUsuario du = new DALUsuario();
            Usuario    u  = du.GetRegistro(id);

            txbId.Text    = id.ToString();
            txbEmail.Text = u.Email;
            txbNome.Text  = u.Nome;
            if (u.Administrador == 1)
            {
                cbAdm.Checked = true;
            }
            else
            {
                cbAdm.Checked = false;
            }
            btSalvar.Text = "Alterar";
        }
Example #9
0
 protected void gvDadosUsuario_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         int        i   = gvDadosUsuario.SelectedIndex;
         int        cod = Convert.ToInt32(gvDadosUsuario.Rows[i].Cells[0].Text);
         DALUsuario cat = new DALUsuario();
         Usuario    c   = cat.GetRegistro(cod);
         if (c.Id != 0)
         {
             txtAutor.Text  = c.Nome;
             txtEmail.Text  = c.Email;
             txtId.Text     = c.Id.ToString();
             btnSalvar.Text = "Alterar";
         }
     }
     catch (Exception error)
     {
         throw new Exception(error.Message);
     }
 }
Example #10
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            DALUsuario cat = new DALUsuario();
            Usuario    usu = new Usuario();

            usu.Email = txtEmail.Text;
            usu.Senha = txtSenha.Text;
            Usuario valida = cat.GetRegistro(usu.Email);
            string  msg    = "";

            if (valida.Id != 0 && usu.Senha == valida.Senha)
            {
                Session["id"]    = valida.Id;
                Session["nome"]  = valida.Nome;
                Session["email"] = valida.Email;
                Response.Redirect("~/Default.aspx");
            }
            else
            {
                msg = "<script>alert('NÃO Existe esse usuario')</script>";
            }
            Response.Write(msg);
        }
Example #11
0
        protected void gvDadosUsuario_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                string msg = "";
                int    i   = Convert.ToInt32(e.RowIndex);
                int    c   = Convert.ToInt32(gvDadosUsuario.Rows[i].Cells[0].Text);

                DALUsuario cat = new DALUsuario();
                Usuario    uou = cat.GetRegistro(c);

                cat.Excluir(c);
                msg = "<script>alert('o codigo excluído foi: " + c.ToString() + "')</script>";
                Response.Write(msg);
            }
            catch (Exception error)
            {
                throw new Exception(error.Message);
            }

            AtualizaGrid();
            Limpar();
        }