private void btnGravar_Click(object sender, EventArgs e)
        {
            CAMADAS.BLL.Carros bllCarro = new CAMADAS.BLL.Carros();
            string             msg      = "";

            if (lblId.Text == "-1")
            {
                msg = "Deseja Inserir um novo Carro?";
            }
            else
            {
                msg = "Deseja Alterar o Carro atual?";
            }
            DialogResult resposta = MessageBox.Show(msg, "Gravar", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (resposta == DialogResult.Yes)
            {
                CAMADAS.MODEL.Carros carro = new CAMADAS.MODEL.Carros();
                carro.id     = Convert.ToInt32(lblId.Text);
                carro.modelo = txtModelo.Text;
                carro.marca  = txtMarca.Text;
                carro.chassi = txtChassi.Text;
                carro.ano    = Convert.ToInt32(txtAno.Text);
                carro.placa  = txtPlaca.Text;

                if (lblId.Text == "-1")
                {
                    bllCarro.Insert(carro);
                }
                else
                {
                    bllCarro.Update(carro);
                }
            }
            else
            {
                MessageBox.Show("Não Gravado", "Gravar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            dtGrvCarro.DataSource = bllCarro.Select();

            //apaga
            limparTxts();
            controlesOnOff(false);
            btnOnOff(true);
        }
示例#2
0
        private void btnGravar_Click(object sender, EventArgs e)
        {
            CAMADAS.MODEL.Aluguel aluguel = new CAMADAS.MODEL.Aluguel();
            CAMADAS.MODEL.Carros  carro   = new CAMADAS.MODEL.Carros();

            aluguel.id        = Convert.ToInt32(lblIdAluguel.Text);
            aluguel.clienteID = Convert.ToInt32(cmbCliente.SelectedValue.ToString());
            aluguel.nome      = cmbCliente.Text;
            aluguel.carroID   = Convert.ToInt32(cmbCarro.SelectedValue.ToString());
            aluguel.modelo    = cmbCarro.Text;

            CAMADAS.BLL.Aluguel bllAlu = new CAMADAS.BLL.Aluguel();
            int idC  = Convert.ToInt32(txtClienteId.Text);
            int idCr = Convert.ToInt32(txtCarroId.Text);

            CAMADAS.MODEL.Aluguel aluguel1 = bllAlu.BuscaCliente(idC);
            CAMADAS.MODEL.Aluguel aluguel2 = bllAlu.BuscaCarro(idCr);


            if (lblIdAluguel.Text == "-1")
            {
                if (aluguel1.clienteID == idC)
                {
                    MessageBox.Show("Cliente ja possui aluguel");
                }
                else if (aluguel2.carroID == idCr)
                {
                    MessageBox.Show("Carro não esta Disponivel");
                }
                else
                {
                    bllAlu.Insert(aluguel);
                }
            }



            dtGvAluguel.DataSource = "";
            dtGvAluguel.DataSource = bllAlu.Select();
        }