Exemplo n.º 1
0
        public static List <Instrumentos> ListarEspecifico(Int32 ID, bool limite)
        {
            SqlConnection Conexao = new SqlConnection(ConfigurationManager.ConnectionStrings["SymphonyaBCD"].ConnectionString);

            Conexao.Open();

            SqlCommand Comando = new SqlCommand();

            Comando.Connection = Conexao;
            if (limite)
            {
                Comando.CommandText = "	SELECT TOP 3 Instrumento.ID,Instrumento.Nome, Instrumento.Icone, Nivel FROM Instrumento, Usuario_Has_Instrumentos WHERE Instrumento.ID = InstrumentoID AND UsuarioID = @ID;";
            }
            else
            {
                Comando.CommandText = "	SELECT Instrumento.ID,Instrumento.Nome, Instrumento.Icone, Nivel FROM Instrumento, Usuario_Has_Instrumentos WHERE Instrumento.ID = InstrumentoID AND UsuarioID = @ID;";
            }

            Comando.Parameters.AddWithValue("@ID", ID);

            SqlDataReader Leitor = Comando.ExecuteReader();

            List <Instrumentos> Instrumentos = new List <Instrumentos>();

            while (Leitor.Read())
            {
                Instrumentos Instrumento = new Instrumentos();
                Instrumento.ID    = (Int32)Leitor["ID"];
                Instrumento.Nome  = (String)Leitor["Nome"];
                Instrumento.Icone = (String)Leitor["Icone"];
                int maestria = (Int32)Leitor["Nivel"];
                switch (maestria)
                {
                case 1: Instrumento.Maestria = 25; break;

                case 2: Instrumento.Maestria = 50; break;

                case 3: Instrumento.Maestria = 75; break;

                case 4: Instrumento.Maestria = 100; break;

                default: break;
                }

                Instrumentos.Add(Instrumento);
            }

            if (!Leitor.HasRows)
            {
                Conexao.Close();
                return(null);
            }

            Conexao.Close();

            return(Instrumentos);
        }
Exemplo n.º 2
0
        public static List <Instrumentos> Listar()
        {
            SqlConnection Conexao = new SqlConnection(ConfigurationManager.ConnectionStrings["SymphonyaBCD"].ConnectionString);

            Conexao.Open();

            SqlCommand Comando = new SqlCommand();

            Comando.Connection  = Conexao;
            Comando.CommandText = "SELECT * FROM Instrumento";

            SqlDataReader Leitor = Comando.ExecuteReader();

            List <Instrumentos> Instrumentos = new List <Instrumentos>();

            while (Leitor.Read())
            {
                Instrumentos Instrumento = new Instrumentos();
                Instrumento.ID            = (Int32)Leitor["ID"];
                Instrumento.Nome          = (String)Leitor["Nome"];
                Instrumento.Classificacao = (String)Leitor["Classificacao"];
                Instrumento.Icone         = (String)Leitor["Icone"];

                Instrumentos.Add(Instrumento);
            }

            if (!Leitor.HasRows)
            {
                Conexao.Close();
                return(null);
            }

            Conexao.Close();

            return(Instrumentos);
        }