Exemple #1
0
        private void BtnInserir_Click(object sender, EventArgs e)
        {
            if (txtPlaca.Text != "" && txtModelo.Text != "" && txtIdCor.Text != "" && txtModelo.Text != "")
            {
                CAMADAS.BLL.Caminhoes  bllCaminhoes = new CAMADAS.BLL.Caminhoes();
                CAMADAS.MODEL.Caminhao caminhoes    = new CAMADAS.MODEL.Caminhao();

                caminhoes.placa     = txtPlaca.Text;
                caminhoes.modelo    = txtModelo.Text;
                caminhoes.cor       = Convert.ToInt32(txtIdCor.Text);
                caminhoes.motorista = Convert.ToInt32(txtIdMotorista.Text);
                bllCaminhoes.Insert(caminhoes);

                limparcontrole();

                DGCaminhoes.DataSource = "";
                DGCaminhoes.DataSource = bllCaminhoes.Select();

                MessageBox.Show("CAMINHÃO INSERIDO COM SUCESSO!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else
            {
                MessageBox.Show("TODOS OS ITENS DEVEM SER PREENCHIDOS!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void BtnEditar_Click(object sender, EventArgs e)
        {
            if (txtID.Text != "-1")
            {
                CAMADAS.MODEL.Caminhao caminhao = new CAMADAS.MODEL.Caminhao();

                caminhao.id        = Convert.ToInt32(txtID.Text);
                caminhao.placa     = txtPlaca.Text;
                caminhao.modelo    = txtModelo.Text;
                caminhao.cor       = Convert.ToInt32(txtIdCor.Text);
                caminhao.motorista = Convert.ToInt32(txtIdMotorista.Text);

                CAMADAS.BLL.Caminhoes bllCaminhoes = new CAMADAS.BLL.Caminhoes();
                bllCaminhoes.Update(caminhao);

                MessageBox.Show("Alteração Realizada com Sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);

                limparcontrole();

                DGCaminhoes.DataSource = "";
                DGCaminhoes.DataSource = bllCaminhoes.Select();
            }

            else
            {
                MessageBox.Show("Nenhum Caminhão Selecionado para Edição", "Editar", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //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);
        }