Beispiel #1
0
 public Usuario buscaUsuario(string email, string senha)
 {
     Usuario user = new Usuario();
     LoginDA lda = new LoginDA();
     user = lda.buscaUsuario(email, senha);
     return user;
 }
Beispiel #2
0
 public Usuario buscaUsuarioAtivo(string email)
 {
     UsuarioDA uda = new UsuarioDA();
     Usuario u = new Usuario();
     u = uda.buscaUsuarioAtivo(email);
     return u;
 }
Beispiel #3
0
 public bool existeUsuario(Usuario user)
 {
     SqlConnection conexao = new SqlConnection();
     conexao.ConnectionString = StaticObjects.strConexao;
     SqlCommand comando = new SqlCommand();
     SqlDataReader leitor;
     int count = 0;
     try
     {
         conexao.Open();
         comando.CommandText = @"SELECT email FROM Usuario WHERE email = '" + user.email + "' AND senha = '" + user.senha + "' ";
         comando.Connection = conexao;
         leitor = comando.ExecuteReader();
         while (leitor.Read())
         {
             count++;
         }
         conexao.Close();
         if(count >0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception)
     {
         conexao.Close();
         return false;
     }
 }
Beispiel #4
0
 public Usuario buscaUsuario(string email, string senha)
 {
     Usuario user = new Usuario();
     SqlConnection conexao = new SqlConnection();
     conexao.ConnectionString = StaticObjects.strConexao;
     SqlCommand comando = new SqlCommand();
     SqlDataReader leitor;
     try
     {
         conexao.Open();
         comando.CommandText = @"SELECT email, senha, nome, idEmpresa, tipo, dataFimLicenca, ativo FROM Usuario WHERE email = '" + email + "' AND senha = '" + senha + "'";
         comando.Connection = conexao;
         leitor = comando.ExecuteReader();
         while (leitor.Read())
         {
             user.email = leitor["email"].ToString();
             user.senha = leitor["senha"].ToString();
             user.nome = leitor["nome"].ToString();
             user.idEmpresa = Convert.ToInt16(leitor["idEmpresa"].ToString());
             user.dataFimLicenca = Convert.ToDateTime(leitor["dataFimLicenca"].ToString());
             user.tipo = Convert.ToInt16(leitor["tipo"].ToString());
             user.ativo = Convert.ToInt16(leitor["ativo"]);
         }
     }
     catch (Exception)
     {
         conexao.Close();
         return null;
     }
         conexao.Close();
     return user;
 }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            UsuarioBL ubl = new UsuarioBL();
            Usuario u = new Usuario();
            u = ubl.buscaUsuarioAtivo(Session["email"].ToString());
            lblDataFimLicenca.Text = u.dataFimLicenca.ToShortDateString();
            lblNome01.Text = u.nome;
            lblNome02.Text = u.nome;
            MensagemBL mbl = new MensagemBL();
            lblQntMensagem.Text = mbl.contaMensagens(Session["email"].ToString());

            TarefaBL tbl = new TarefaBL();
            lblQntTarefas.Text = tbl.contaTarefasUsuario(Session["email"].ToString()).ToString();
        }
Beispiel #6
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            LoginBL lbl = new LoginBL();

            if ((email.Value.ToString() == "") || (email.Value.Contains("@") == false) || (email.Value.Length < 7))
            {
                Response.Write("<script>alert('Informe um e-mail!')</script>");

            }
            else if(password.Value == "")
            {
                Response.Write("<script>alert('Informe uma senha!')</script>");
            }
            else
            {
                Usuario user = new Usuario();
                user.email = email.Value.ToString();
                string senha = password.Value.ToString();
                user.senha = senha.GetHashCode().ToString();
                bool existeUsuario = lbl.usuarioValido(user);
                if(existeUsuario)
                {
                    Home.userLogged = true;
                    user = lbl.buscaUsuario(user.email, user.senha);
                    Session["email"] = user.email;
                    Session["senha"] = user.senha;
                    Session["empresa"] = user.idEmpresa;
                    Session["nome"] = user.nome;
                    LogEventoBL lel = new LogEventoBL();
                    Log l = new Log();
                    l.email = Session["email"].ToString();
                    l.data = DateTime.Now;
                    l.descricao = "Logou no PDM: " + user.email + " ";
                    lel.adicionaLog(l);
                    Response.Redirect("Home.aspx");
                }
                else
                {
                    LogEventoBL lel = new LogEventoBL();
                    Log l = new Log();
                    l.email = Session["email"].ToString();
                    l.data = DateTime.Now;
                    l.descricao = "Tentativa falha de login " + user.email + " ";
                    lel.adicionaLog(l);
                    Response.Write("<script>alert('Usuário ou Senha Inválidos!')</script>");
                }
            }
        }
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            Usuario user = new Usuario();
            user.email = emailUser.Value;
            user.nome = nomeUser.Value;
            user.idEmpresa = Convert.ToInt16(Session["empresa"]);
            if (senhaUser.Value == senha2User.Value)
            {
                user.senha = senhaUser.Value;
            }
            if (admSim.Checked == true)
            {
                user.tipo = 1;
            }
            else if (admNao.Checked == true)
            {
                user.tipo = 2;
            }
            if (ativoSim.Checked == true)
            {
                user.ativo = 1;
            }
            else if (AtivoNao.Checked == true)
            {
                user.ativo = 0;
            }
            UsuarioBL ubl = new UsuarioBL();
            bool cadastrou = ubl.cadastraUsuario(user);

            LogEventoBL lbl = new LogEventoBL();
            Log l = new Log();
            l.email = Session["email"].ToString();
            l.data = DateTime.Now;
            l.descricao = "Incluído usuário nome: " + user.nome + " ";
            lbl.adicionaLog(l);

            if (cadastrou)
            {
                Response.Write("<script>alert('Registro efetuado com sucesso!')</script>");
            }
        }
Beispiel #8
0
        public void carregaInformativo()
        {
            string email = Session["email"].ToString();
            Usuario u = new Usuario();
            UsuarioBL ubl = new UsuarioBL();
            u = ubl.buscaUsuarioAtivo(email);
            ProjetoBL pbl = new ProjetoBL();
            TarefaBL tbl = new TarefaBL();
            int totaProj = 0, totalTask = 0;
            double projPend = 0, projConc = 0, TaskPend = 0, taskConc = 0;
            try
            {
                totaProj = pbl.contaProjetosEmpresa(u.idEmpresa, "");
                projPend = (pbl.contaProjetosEmpresa(u.idEmpresa, "AND status <> 2 AND status <> 3") * 100) / totaProj;
                projConc = (pbl.contaProjetosEmpresa(u.idEmpresa, "AND status <> 0 AND status <> 1") * 100) / totaProj;
                totalTask = tbl.contaTarefasEmpresa(u.idEmpresa, "");
                TaskPend = (tbl.contaTarefasEmpresa(u.idEmpresa, "AND status <> 2 AND status <> 3") * 100) / totalTask;
                taskConc = (tbl.contaTarefasEmpresa(u.idEmpresa, "AND status <> 0 AND status <> 1") * 100) / totalTask;

                lblQntProj.Text = totaProj.ToString();
                lblProjPendente.Text = projPend.ToString();
                lblProjFim.Text = projConc.ToString();
                lblTotalTarefas.Text = totalTask.ToString();
                lblTarefaTotal.Text = TaskPend.ToString();
                lblTarefaExec.Text = taskConc.ToString();
            }
            catch (Exception ex)
            {
                lblQntProj.Text = "0";
                lblProjPendente.Text = "0";
                lblProjFim.Text = "0";
                lblTotalTarefas.Text = "0";
                lblTarefaTotal.Text = "0";
                lblTarefaExec.Text = "0";
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Request["user_mail"] != null)
            {
                if(Request["user_mail"].ToString() == "ownUser")
                {
                    UsuarioBL ubl = new UsuarioBL();
                    Usuario u = new Usuario();
                    u = ubl.buscaUsuarioAtivo(Session["email"].ToString());
                    emailUser.Value = u.email;
                    nomeUser.Value = u.nome;

                    emp = new Empresa();
                    emp = ebl.buscaEmpresa(u.idEmpresa);
                    EmpresaUser.Value = emp.razao;

                    if (u.tipo == 1)
                    {
                        admSim.Checked = true;
                    }
                    else
                    {
                        admNao.Checked = true;
                    }
                    if (u.ativo == 0)
                    {
                        AtivoNao.Checked = true;
                    }
                    else
                    {
                        ativoSim.Checked = true;
                    }
                }
                else
                {
                    UsuarioBL ubl = new UsuarioBL();
                    Usuario u = new Usuario();
                    u = ubl.buscaUsuarioAtivo(Request["user_mail"].ToString());
                    emailUser.Value = u.email;
                    nomeUser.Value = u.nome;

                    emp = new Empresa();
                    emp = ebl.buscaEmpresa(u.idEmpresa);
                    EmpresaUser.Value = emp.razao;

                    if (u.tipo == 1)
                    {
                        admSim.Checked = true;
                    }
                    else
                    {
                        admNao.Checked = true;
                    }
                    if (u.ativo == 0)
                    {
                        AtivoNao.Checked = true;
                    }
                    else
                    {
                        ativoSim.Checked = true;
                    }
                }
            }
            else
            {

            }
        }
Beispiel #10
0
 public bool editaUsuario(Usuario user)
 {
     SqlConnection conexao = new SqlConnection();
     conexao.ConnectionString = StaticObjects.strConexao;
     SqlCommand comando = new SqlCommand();
     try
     {
         conexao.Open();
         comando.CommandText = @"UPDATE dbo.Usuario SET senha = '" + user.senha.GetHashCode() + "' , nome = '" + user.nome + "' , tipo = " + user.tipo + " " +
                         ", ativo = " + user.ativo + " WHERE email =  '" + user.email + "' ";
         comando.Connection = conexao;
         comando.ExecuteNonQuery();
         conexao.Close();
         return true;
     }
     catch (Exception)
     {
         conexao.Close();
         return false;
     }
 }
Beispiel #11
0
 public bool cadastraUsuario(Usuario user)
 {
     SqlConnection conexao = new SqlConnection();
     conexao.ConnectionString = StaticObjects.strConexao;
     SqlCommand comando = new SqlCommand();
     DateTime licenca = DateTime.Now.AddDays(365);
     try
     {
         conexao.Open();
         comando.CommandText = @"INSERT INTO dbo.Usuario (email,senha,nome,idEmpresa,tipo,dataFimLicenca, ativo) VALUES " +
             "('" + user.email + "', '" + user.senha.GetHashCode() + "', '" + user.nome + "', " + user.idEmpresa + ", " + user.tipo + ", '" + licenca + "', " + user.ativo + ") ";
         comando.Connection = conexao;
         comando.ExecuteNonQuery();
         conexao.Close();
         return true;
     }
     catch (Exception)
     {
         conexao.Close();
         return false;
     }
 }
Beispiel #12
0
 public List<Usuario> buscaUsuariosEmpresa(int empresa)
 {
     List<Usuario> lista = new List<Usuario>();
     SqlConnection conexao = new SqlConnection();
     conexao.ConnectionString = StaticObjects.strConexao;
     SqlCommand comando = new SqlCommand();
     SqlDataReader leitor;
     try
     {
         conexao.Open();
         comando.CommandText = @"SELECT email, senha, nome, idEmpresa, tipo, dataFimLicenca, ativo FROM Usuario WHERE idEmpresa = " + empresa + " ORDER BY nome ";
         comando.Connection = conexao;
         leitor = comando.ExecuteReader();
         while (leitor.Read())
         {
             Usuario user = new Usuario();
             user.email = leitor["email"].ToString();
             user.senha = leitor["senha"].ToString();
             user.nome = leitor["nome"].ToString();
             user.idEmpresa = Convert.ToInt16(leitor["idEmpresa"].ToString());
             user.dataFimLicenca = Convert.ToDateTime(leitor["dataFimLicenca"].ToString());
             user.tipo = Convert.ToInt16(leitor["tipo"].ToString());
             user.ativo = Convert.ToInt16(leitor["ativo"]);
             lista.Add(user);
         }
         conexao.Close();
         return lista;
     }
     catch (Exception)
     {
         conexao.Close();
         return null;
     }
 }
Beispiel #13
0
 public bool usuarioValido(Usuario user)
 {
     LoginDA lda = new LoginDA();
     bool existe = lda.existeUsuario(user);
     return existe;
 }
Beispiel #14
0
 public bool editaUsuario(Usuario user)
 {
     UsuarioDA uDA = new UsuarioDA();
     bool editou = uDA.editaUsuario(user);
     return editou;
 }
Beispiel #15
0
 public bool cadastraUsuario(Usuario user)
 {
     UsuarioDA uDA = new UsuarioDA();
     bool cadastrou = uDA.cadastraUsuario(user);
     return cadastrou;
 }