示例#1
0
        public List<Usuario> buscar(String nome)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Usuarios where Nome LIKE '%" + nome+"%'";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Usuario> listaUsuarios = new List<Usuario>();

            while (reader.Read())
            {
                Usuario usuario = new Usuario();
                usuario.id_user = Int32.Parse(string.Format("{0}", reader[0]));
                usuario.nome = string.Format("{0}", reader[1]);
                usuario.login = string.Format("{0}", reader[2]);
                usuario.tipo_permissao = Int32.Parse(string.Format("{0}", reader[4]));

                listaUsuarios.Add(usuario);
            }

            con.closeConnection();
            return listaUsuarios;
        }
示例#2
0
 public Boolean editar(Usuario usuario)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     String sql = "UPDATE Usuarios set Nome='"+usuario.nome+"', Login ='******',  Senha='"+usuario.senha+"', NivelPrivilegio="+usuario.tipo_permissao+" where Id_user = "+usuario.id_user;
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }
示例#3
0
        public Boolean deletar(Usuario usuario)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "DELETE Usuarios WHERE Id_user = " + usuario.id_user;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            con.closeConnection();

            return true;
        }
示例#4
0
 public int getPermissao(Usuario usuario)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     SqlDataReader reader;
     string sql = "SELECT * FROM Usuarios where Login ='******' and Senha='" + usuario.senha + "' ";
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     reader = command.ExecuteReader();
     while (reader.Read())
     {
         int retorno = Int32.Parse(string.Format("{0}", reader[4]));
         return retorno;
     }
     con.closeConnection();
     return 2;
 }
示例#5
0
 public Usuario getUsuariobyId(Usuario usuario)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     SqlDataReader reader;
     string sql = "SELECT * FROM Usuarios where Id_user ="******"{0}", reader[0]));
         returnUsuario.nome = string.Format("{0}", reader[1]);
         returnUsuario.login = string.Format("{0}", reader[2]);
         returnUsuario.senha = string.Format("{0}", reader[3]);
         returnUsuario.tipo_permissao = Int32.Parse(string.Format("{0}", reader[4]));
     }
     con.closeConnection();
     return returnUsuario;
 }
示例#6
0
 public Boolean login(Usuario usuario)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     SqlDataReader reader;
     string sql = "SELECT * FROM Usuarios where Login ='******' and Senha='" + usuario.senha + "' ";
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     reader = command.ExecuteReader();
     while (reader.Read())
     {
         return true;
     }
     con.closeConnection();
     return false;
 }
示例#7
0
        public Boolean inserir(Usuario usuario)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            string sql = "INSERT INTO Usuarios (Nome,Login,Senha,NivelPrivilegio) VALUES('" + usuario.nome + "','" + usuario.login + "','" + usuario.senha + "'," + usuario.tipo_permissao+ ")";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            command.ExecuteNonQuery();

            con.closeConnection();

            return true;
        }