Пример #1
0
        private void btnNovo_Click(object sender, EventArgs e)
        {
            bloquearBtnExcluirEditar();
            string CPF;
            string Telefone;

            if (validarCPF(txtCPF.Text.ToString()))
            {
                CPF = txtCPF.Text.Trim();
                CPF = txtCPF.Text.Replace(",", "").Replace("-", "");

                Telefone = txtTelefone.Text.Trim();
                Telefone = txtTelefone.Text.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");

                if (btnNovo.Text.Equals("Novo"))
                {
                    btnNovo.Text = "Salvar";
                    status       = "novo";
                    desbloquearCampos();
                    CarregarCb();
                }
                else
                {
                    if (status.Equals("editar"))
                    {
                        if (ConferirCamposVazios())
                        {
                            bll.EditCliente(new DtoCliente(int.Parse(dtgvCliente[0, pegarLinha()].Value.ToString()), txtNome.Text.ToString(), CPF.ToString(), Telefone.ToString(), Convert.ToChar(cbEspecificacao.Text[0])));
                        }
                    }
                    else if (status.Equals("novo"))
                    {
                        if (ConferirCamposVazios())
                        {
                            var cliente = new DtoCliente(1,
                                                         txtNome.Text.ToString(),
                                                         CPF.ToString(),
                                                         Telefone.ToString(),
                                                         Convert.ToChar(cbEspecificacao.Text[0]));

                            bll.InsertCliente(cliente);
                        }
                    }

                    BindData(this.GetData());

                    btnNovo.Text = "Novo";
                    bloquearCampos();
                    limparCampos();
                    status = String.Empty;
                    EsvaziarCb();
                }
            }
            else
            {
                MessageBox.Show("CPF Incorreto");
                status = string.Empty;
            }
        }