Ejemplo n.º 1
0
        private void btnGravar_Click(object sender, EventArgs e)
        {
            Camadas.BLL.Cliente   bllCli  = new Camadas.BLL.Cliente();
            Camadas.Model.Cliente cliente = new Camadas.Model.Cliente();
            int id = Convert.ToInt32(lblId.Text);

            string msg;

            if (id == -1)
            {
                msg = "Confirma inserção dos dados?";
            }
            else
            {
                msg = "Confirma alteração dos dados?";
            }

            DialogResult resp;

            resp = MessageBox.Show(msg, "Gravar", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (resp == DialogResult.Yes)
            {
                cliente.id       = id;
                cliente.nome     = txtNome.Text;
                cliente.endereco = txtEndereco.Text;
                cliente.numero   = txtNumero.Text;
                cliente.cidade   = txtCidade.Text;
                cliente.estado   = txtEstado.Text;
                cliente.fone     = txtFone.Text;

                if (id == -1)
                {
                    bllCli.Insert(cliente);
                }
                else
                {
                    bllCli.Uptade(cliente);
                }
            }
            dgvClientes.DataSource = "";
            dgvClientes.DataSource = bllCli.Select();
            limparCampos();
            Habilitar(false);
        }