コード例 #1
0
ファイル: Ingrediente.cs プロジェクト: DIegoFernandes1/TCC
        /******************************************************************** LISTAR INGREDIENTE ********************************************************************/
        public List <Ingrediente> ListarIngredientes()
        {
            //SqlConnection Conexao = new SqlConnection(ConfigurationManager.ConnectionStrings["BancoEstoque"].ConnectionString);
            SqlConnection Conexao = new SqlConnection("Server = DESKTOP-PHTQI5U\\SQLEXPRESS; Database = DRLTCC; Trusted_Connection = True;");

            Conexao.Open();
            SqlCommand Comando = new SqlCommand();

            Comando.Connection = Conexao;

            Comando.CommandText = "SELECT I.*, L.CodigoLote, L.NomeLote FROM Ingrediente I JOIN Lote L ON CodigoLote = FK_CodigoLote;";

            SqlDataReader Leitor = Comando.ExecuteReader();



            while (Leitor.Read())
            {
                Ingrediente I = new Ingrediente();
                I.FK_CodigoLote     = Convert.ToInt32(Leitor["FK_CodigoLote"].ToString());
                I.NomeLote          = Leitor["NomeLote"].ToString();
                I.CodigoIngrediente = Convert.ToInt32(Leitor["CodigoIngrediente"].ToString());
                I.NomeIngrediente   = Leitor["NomeIngrediente"].ToString();
                I.QtdIngrediente    = Convert.ToInt32(Leitor["QtdIngrediente"].ToString());
                I.UnidadeMedida     = Leitor["UnidadeMedida"].ToString();
                I.NivelRisco        = Convert.ToInt32(Leitor["NivelRisco"].ToString());
                I.FK_CodigoLote     = Convert.ToInt32(Leitor["FK_CodigoLote"].ToString());


                Ingredientes.Add(I);
            }
            Conexao.Close();

            teste = Ingredientes.Count();
            return(Ingredientes);
        }