//SELECT
        public List <MODEL.Combustivel> Select()
        {
            List <MODEL.Combustivel> listCombustivel = new List <MODEL.Combustivel>();

            CAMADAS.DAL.Motorista dalMotorista = new CAMADAS.DAL.Motorista();
            CAMADAS.DAL.Caminhoes dalCaminhoes = new CAMADAS.DAL.Caminhoes();

            SqlConnection conexao = new SqlConnection(strCon);
            string        sql     = "SELECT *FROM Combustivel;";
            SqlCommand    cmd     = new SqlCommand(sql, conexao);

            try
            {
                conexao.Open();
                SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while (dados.Read())
                {
                    MODEL.Combustivel combustivel = new MODEL.Combustivel();
                    combustivel.id          = Convert.ToInt32(dados["id"].ToString());
                    combustivel.estoque     = Convert.ToInt32(dados["estoque"].ToString());
                    combustivel.caminhaoID  = Convert.ToInt32(dados["caminhaoFK"].ToString());
                    combustivel.motoristaID = Convert.ToInt32(dados["motoristaFK"].ToString());

                    CAMADAS.DAL.Motorista   dalMoto   = new CAMADAS.DAL.Motorista();
                    CAMADAS.MODEL.Motorista motorista = dalMoto.SelectIDNome(combustivel.motoristaID);
                    combustivel.nomeMotorista = motorista.nome;

                    CAMADAS.DAL.Caminhoes  dalCam    = new CAMADAS.DAL.Caminhoes();
                    CAMADAS.MODEL.Caminhao caminhoes = dalCam.SelectIDnome(combustivel.caminhaoID);
                    combustivel.placaCaminhao = caminhoes.placa;

                    listCombustivel.Add(combustivel);
                }
            }

            catch
            {
                Console.WriteLine("ERRO AO CONSULTAR BANCO");
            }

            finally
            {
            }

            return(listCombustivel);
        }
Ejemplo n.º 2
0
        //SELECT
        public List <MODEL.Frete> Select()
        {
            List <MODEL.Frete> listFrete = new List <MODEL.Frete>();
            SqlConnection      conexao   = new SqlConnection(strCon);
            string             sql       = "SELECT *FROM Frete;";
            SqlCommand         cmd       = new SqlCommand(sql, conexao);

            try
            {
                conexao.Open();
                SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while (dados.Read())
                {
                    MODEL.Frete frete = new MODEL.Frete();
                    frete.id             = Convert.ToInt32(dados["id"].ToString());
                    frete.produto        = dados["produto"].ToString();
                    frete.localPartida   = dados["localPartida"].ToString();
                    frete.localEntrega   = dados["localEntrega"].ToString();
                    frete.data           = Convert.ToDateTime(dados["data"].ToString());
                    frete.valor          = Convert.ToSingle(dados["valorFrete"].ToString());
                    frete.transportadora = Convert.ToInt32(dados["transportadoraFK"].ToString());
                    frete.motorista      = Convert.ToInt32(dados["motoristaFK"].ToString());

                    CAMADAS.DAL.Motorista   dalMoto   = new CAMADAS.DAL.Motorista();
                    CAMADAS.MODEL.Motorista motorista = dalMoto.SelectIDNome(frete.motorista);
                    frete.nomeMotorista = motorista.nome;

                    CAMADAS.DAL.Transportadora   dalTransportadora = new CAMADAS.DAL.Transportadora();
                    CAMADAS.MODEL.Transportadora transportadora    = dalTransportadora.SelectIDNome(frete.transportadora);
                    frete.nomeTransportadora = transportadora.transportadoraNome;

                    listFrete.Add(frete);
                }
            }

            catch
            {
                Console.WriteLine("ERRO AO CONSULTAR O BANCO DE DADOS!");
            }
            finally
            {
            }

            return(listFrete);
        }
        //Metodo select
        public List <MODEL.Caminhao> Select()
        {
            List <MODEL.Caminhao> listCaminhao = new List <MODEL.Caminhao>();
            SqlConnection         conexao      = new SqlConnection(strCon);
            string     sql = "SELECT *FROM Caminhoes;";
            SqlCommand cmd = new SqlCommand(sql, conexao);

            try
            {
                conexao.Open();
                SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (dados.Read())
                {
                    MODEL.Caminhao caminhao = new MODEL.Caminhao();
                    caminhao.id        = Convert.ToInt32(dados["id"].ToString());
                    caminhao.placa     = dados["placa"].ToString();
                    caminhao.modelo    = dados["modelo"].ToString();
                    caminhao.cor       = Convert.ToInt32(dados["corFK"].ToString());
                    caminhao.motorista = Convert.ToInt32(dados["motoristaFK"].ToString());

                    CAMADAS.DAL.Cor   dalcor = new CAMADAS.DAL.Cor();
                    CAMADAS.MODEL.Cor cor    = dalcor.SelectIDNome(caminhao.cor);
                    caminhao.nomeCor = cor.cor;

                    CAMADAS.DAL.Motorista   dalMoto   = new CAMADAS.DAL.Motorista();
                    CAMADAS.MODEL.Motorista motorista = dalMoto.SelectIDNome(caminhao.motorista);
                    caminhao.nomeMotorista = motorista.nome;

                    listCaminhao.Add(caminhao);
                }
            }

            catch
            {
                Console.WriteLine("ERRO AO CONSULTAR O BANCO DE DADOS!");
            }

            finally
            {
            }

            return(listCaminhao);
        }