Exemplo n.º 1
0
        public List <MODEL.Aluguel> Select()
        {
            List <MODEL.Aluguel> lstAluguel = new List <MODEL.Aluguel>();
            SqlConnection        conexao    = new SqlConnection(strCon);
            string     sql = "Select * from Aluguel";
            SqlCommand cmd = new SqlCommand(sql, conexao);

            try
            {
                conexao.Open();
                SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (dados.Read())
                {
                    MODEL.Aluguel aluguel = new MODEL.Aluguel();
                    aluguel.id        = Convert.ToInt32(dados["id"].ToString());
                    aluguel.clienteID = Convert.ToInt32(dados["clienteID"].ToString());
                    aluguel.data      = Convert.ToDateTime(dados["data"].ToString());


                    //recuperar cliente
                    CAMADAS.BLL.Clientes   bllCli  = new BLL.Clientes();
                    CAMADAS.MODEL.Clientes cliente = bllCli.SelectByID(aluguel.clienteID);
                    aluguel.nome = cliente.nome;
                    lstAluguel.Add(aluguel);
                }
            }
            catch
            {
                Console.WriteLine("Erro ao listar Banco sql-Avioes");
            }
            finally
            {
                conexao.Close();
            }

            return(lstAluguel);
        }
Exemplo n.º 2
0
        public List <MODEL.Emprestimo> Select()
        {
            List <MODEL.Emprestimo> lstEmprestimo = new List <MODEL.Emprestimo>();
            SqlConnection           conexao       = new SqlConnection(strCon);
            string     sql = "SELECT * FROM Emprestimo";
            SqlCommand cmd = new SqlCommand(sql, conexao);

            try
            {
                conexao.Open();
                SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (dados.Read())
                {
                    MODEL.Emprestimo emprestimo = new MODEL.Emprestimo();
                    emprestimo.id        = Convert.ToInt32(dados["id"].ToString());
                    emprestimo.clienteId = Convert.ToInt32(dados["clienteID"].ToString());
                    emprestimo.data      = Convert.ToDateTime(dados["data"].ToString());

                    //recuperar cliente
                    CAMADAS.BLL.Clientes   bllCli  = new BLL.Clientes();
                    CAMADAS.MODEL.Clientes cliente = bllCli.SelectByID(emprestimo.clienteId);
                    emprestimo.cliente = cliente.nome;

                    lstEmprestimo.Add(emprestimo);
                }
            }
            catch
            {
                Console.WriteLine("Erro listar Emprestimo");
            }
            finally
            {
                conexao.Close();
            }
            return(lstEmprestimo);
        }