Example #1
0
 public List <SetorUsuario> Listar_Setor()
 {
     try
     {
         List <SetorUsuario> lista_setor = new List <SetorUsuario>();
         sqlCommand.CommandText = "select * from SetorUsuario";
         sqlCommand.Connection  = conexao.conectar();
         sqldataReader          = sqlCommand.ExecuteReader();
         while (sqldataReader.Read())
         {
             SetorUsuario setorusuario = new SetorUsuario();
             setorusuario.setorusuario_id       = sqldataReader.GetInt32(0);
             setorusuario.setorusuario_setor_id = sqldataReader.GetInt32(1);
             setorusuario.setorusuario_usu_id   = sqldataReader.GetInt32(2);
             lista_setor.Add(setorusuario);
         }
         return(lista_setor);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         sqldataReader.Close();
         sqlCommand.Parameters.Clear();
         conexao.desconectar();
     }
 }
        public static List <SetorUsuario> GetSetorUsuario()
        {
            List <SetorUsuario> lista_setorusuario = new List <SetorUsuario>();

            using (SqlConnection con = new SqlConnection(GetStringConexao()))
            {
                con.Open();
                //ConexaoSQL.conectar();
                using (SqlCommand sqlcommand = new SqlCommand("select * from SetorUsuario", con))
                {
                    using (SqlDataReader sqlDataReader = sqlcommand.ExecuteReader())
                    {
                        if (sqlDataReader != null)
                        {
                            while (sqlDataReader.Read())
                            {
                                var setorUsuario = new SetorUsuario();
                                setorUsuario.setorusuario_id       = int.Parse(sqlDataReader["setorusuario_id"].ToString());
                                setorUsuario.setorusuario_setor_id = int.Parse(sqlDataReader["setorusuario_setor_id"].ToString());
                                setorUsuario.setorusuario_usu_id   = int.Parse(sqlDataReader["setorusuario_usu_id"].ToString());
                                lista_setorusuario.Add(setorUsuario);
                            }
                        }
                        return(lista_setorusuario);
                    }
                }
            }
        }
Example #3
0
        public List <SetorUsuario> BuscaSetorPorUsuarioeSetor(int usu_id, int cod_setor)
        {
            List <SetorUsuario> lista        = new List <SetorUsuario>();
            SetorUsuario        setorUsuario = new SetorUsuario();

            try
            {
                sqlCommand.CommandText = "select * from SetorUsuario " +
                                         "where setorusuario_setor_id = @setor and setorusuario_usu_id = @usuario";
                sqlCommand.Parameters.AddWithValue("@usuario", usu_id);
                sqlCommand.Parameters.AddWithValue("@setor", cod_setor);
                sqlCommand.Connection = conexao.conectar();
                sqldataReader         = sqlCommand.ExecuteReader();
                while (sqldataReader.Read())
                {
                    setorUsuario.setorusuario_id       = int.Parse(sqldataReader["setorusuario_id"].ToString());
                    setorUsuario.setorusuario_usu_id   = int.Parse(sqldataReader["setorusuario_usu_id"].ToString());
                    setorUsuario.setorusuario_setor_id = int.Parse(sqldataReader["setorusuario_setor_id"].ToString());
                    lista.Add(setorUsuario);
                }
                return(lista);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                sqldataReader.Close();
                sqlCommand.Parameters.Clear();
                conexao.desconectar();
            }
        }
Example #4
0
        public List <SetorUsuario> readAllSetor()
        {
            string              url_base  = "http://" + server + ":8080/webapi/webapi/usuario/setor/all";
            string              url       = string.Format(url_base);
            dynamic             setorJSON = this.request(url);
            List <SetorUsuario> result    = new List <SetorUsuario>();

            if (!(setorJSON is null))
            {
                foreach (dynamic setor in setorJSON)
                {
                    SetorUsuario set = new SetorUsuario();
                    set.id        = setor.id;
                    set.descricao = setor.descricao;
                    result.Add(setor);
                }
            }
            return(result);
        }
Example #5
0
        public List <SetorUsuario> BuscaSetorPorUsuario(int usu_id)
        {
            List <SetorUsuario> lista_setorUsuarios = new List <SetorUsuario>();
            SetorUsuario        setorUsuario        = new SetorUsuario();
            Setor setor = new Setor();

            try
            {
                sqlCommand.CommandText = "select * from SetorUsuario su " +
                                         "inner join Usuario u on u.usu_id = su.setorusuario_usu_id inner join Setor s on " +
                                         "s.setor_id = su.setorusuario_setor_id where su.setorusuario_usu_id = @id";
                sqlCommand.Parameters.AddWithValue("@id", usu_id);
                sqlCommand.Connection = conexao.conectar();
                sqldataReader         = sqlCommand.ExecuteReader();
                while (sqldataReader.Read())
                {
                    Setor setor1 = new Setor();
                    setorUsuario.setorusuario_id       = int.Parse(sqldataReader["setorusuario_id"].ToString());
                    setorUsuario.setorusuario_usu_id   = int.Parse(sqldataReader["setorusuario_usu_id"].ToString());
                    setorUsuario.setorusuario_setor_id = int.Parse(sqldataReader["setorusuario_setor_id"].ToString());
                    setorUsuario.Usuario.usu_id        = int.Parse(sqldataReader["usu_id"].ToString());
                    setorUsuario.Usuario.usu_nome      = sqldataReader["usu_nome"].ToString();
                    setor1.setor_id   = int.Parse(sqldataReader["setor_id"].ToString());
                    setor1.setor_nome = sqldataReader["setor_nome"].ToString();
                    setorUsuario.Setor.Add(setor1);
                    lista_setorUsuarios.Add(setorUsuario);
                }
                return(lista_setorUsuarios);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                sqldataReader.Close();
                sqlCommand.Parameters.Clear();
                conexao.desconectar();
            }
        }