//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); }
private void FormCaminhoes_Load(object sender, EventArgs e) { limparcontrole(); CAMADAS.DAL.Caminhoes dalCaminhoes = new CAMADAS.DAL.Caminhoes(); CAMADAS.DAL.Motorista dalMotorista = new CAMADAS.DAL.Motorista(); CAMADAS.DAL.Cor dalcor = new CAMADAS.DAL.Cor(); DGCaminhoes.DataSource = ""; DGCaminhoes.DataSource = dalCaminhoes.Select(); //COMBOBOX MOTORISTA cmbMotorista.DisplayMember = "nome"; cmbMotorista.ValueMember = "id"; cmbMotorista.DataSource = dalMotorista.Select(); cmbCor.DisplayMember = "cor"; cmbCor.ValueMember = "id"; cmbCor.DataSource = dalcor.Select(); }