protected void btnSalvar_Click(object sender, EventArgs e)
    {
        LOCAR.Camadas.Model.Cliente cliente = new LOCAR.Camadas.Model.Cliente();
        cliente.IdCliente = Convert.ToInt32(lblId.Text);
        cliente.Nome      = txtNome.Text;
        cliente.CNH       = txtCnh.Text;
        cliente.RG        = txtRg.Text;
        cliente.CPF       = txtCpf.Text;
        cliente.Rua       = txtRua.Text;
        cliente.Numero    = txtNumero.Text;
        cliente.Bairro    = txtBairro.Text;
        cliente.Cidade    = txtCidade.Text;
        cliente.Estado    = txtEstado.Text;
        LOCAR.Camadas.BLL.Cliente bllCliente = new LOCAR.Camadas.BLL.Cliente();

        if (Cache["OP"].Equals('I'))
        {
            bllCliente.Insert(cliente);
        }

        else if (Cache["OP"].Equals('U'))
        {
            bllCliente.Update(cliente);
        }

        if (Cache["OP"].Equals('I'))
        {
            grvClientes.SetPageIndex(grvClientes.PageCount);
        }

        lblId.Text = "0";
        HabilitaCampos(false);
        Cache["OP"] = "S";
    }
    protected void btnRemover_Click(object sender, EventArgs e)
    {
        LOCAR.Camadas.Model.Cliente cliente = new LOCAR.Camadas.Model.Cliente();
        cliente.IdCliente = Convert.ToInt32(lblId.Text);
        cliente.Nome      = txtNome.Text;
        cliente.CNH       = txtCnh.Text;
        cliente.RG        = txtRg.Text;
        cliente.CPF       = txtCpf.Text;
        cliente.Rua       = txtRua.Text;
        cliente.Numero    = txtNumero.Text;
        cliente.Bairro    = txtBairro.Text;
        cliente.Cidade    = txtCidade.Text;
        cliente.Estado    = txtEstado.Text;
        LOCAR.Camadas.BLL.Cliente bllCliente = new LOCAR.Camadas.BLL.Cliente();
        //lblId.Text = "0";
        if (Convert.ToInt32(lblId.Text) > 0)
        {
            bllCliente.Delete(cliente);
        }

        lblId.Text     = "0";
        txtNome.Text   = "";
        txtCnh.Text    = "";
        txtRg.Text     = "";
        txtCpf.Text    = "";
        txtRua.Text    = "";
        txtNumero.Text = "";
        txtBairro.Text = "";
        txtCidade.Text = "";
        txtEstado.Text = "";
        HabilitaCampos(false);
        Cache["OP"] = "S";
    }
    protected void HabilitaCampos(bool habilita)
    {
        txtNome.Enabled    = habilita;
        txtCnh.Enabled     = habilita;
        txtRg.Enabled      = habilita;
        txtCpf.Enabled     = habilita;
        txtRua.Enabled     = habilita;
        txtNumero.Enabled  = habilita;
        txtBairro.Enabled  = habilita;
        txtCidade.Enabled  = habilita;
        txtEstado.Enabled  = habilita;
        btnInserir.Enabled = !habilita;

        if (Convert.ToInt32(lblId.Text) == 0)
        {
            btnAlterar.Enabled  = habilita;
            btnRemover.Enabled  = habilita;
            btnCancelar.Enabled = habilita;
            btnSalvar.Enabled   = habilita;
            txtNome.Text        = "";
            txtCnh.Text         = "";
            txtRg.Text          = "";
            txtCpf.Text         = "";
            txtRua.Text         = "";
            txtNumero.Text      = "";
            txtBairro.Text      = "";
            txtCidade.Text      = "";
            txtEstado.Text      = "";
        }
        else
        {
            btnAlterar.Enabled  = !habilita;
            btnRemover.Enabled  = !habilita;
            btnCancelar.Enabled = habilita;
            btnSalvar.Enabled   = habilita;
        }

        LOCAR.Camadas.BLL.Cliente bllCliente = new LOCAR.Camadas.BLL.Cliente();
        grvClientes.DataSource = bllCliente.Select();
        grvClientes.DataBind();
    }