private void CPF_KeyPress(object sender, KeyPressEventArgs e) { char digitoSaida = '0'; bool verificado = false; //Aciona o botão Laranja var newstate = Symbol.Keyboard.KeyStates.KEYSTATE_NUMERIC_LOCK; Symbol.Keyboard.KeyPad teclado = new Symbol.Keyboard.KeyPad(); teclado.SetKeyState(newstate, 0, true); if (((TextBox)sender).Text.Length == 14 && e.KeyChar != Convert.ToChar(8)) { e.Handled = true; return; } verificado = UtilMask.ApenasNumero(e.KeyChar, ref digitoSaida); if (verificado) { if (((TextBox)sender).Text.Length == 3) { ((TextBox)sender).Text = ((TextBox)sender).Text + "." + digitoSaida; } else if (((TextBox)sender).Text.Length == 7) { ((TextBox)sender).Text = ((TextBox)sender).Text + "." + digitoSaida; } else if (((TextBox)sender).Text.Length == 11) { ((TextBox)sender).Text = ((TextBox)sender).Text + "-" + digitoSaida; } else { ((TextBox)sender).Text = ((TextBox)sender).Text + digitoSaida; } ((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length; if (((TextBox)sender).Text.Length == 14) { string cpfsonumero = ((TextBox)sender).Text.Replace(".", "").Replace("-", "").Trim(); if (UtilValidacoes.isCPF(cpfsonumero)) { cmbAba3Sexo.Focus(); } else { CaixaMensagem.ExibirOk("Campo CPF inválido!"); txtAba3CPF.Focus(); } } e.Handled = true; } else { if (e.KeyChar != Convert.ToChar(8)) { e.Handled = true; } } }
private bool ValidarCamposAbaDados(bool mudancaAba) { try { TextoCPF = txtAba3CPF.Text; TextoSexo = cmbAba3Sexo.SelectedValue.ToString(); TextoDataDia = cmbAba3DataNascimentoDia.SelectedValue.ToString(); TextoDataMes = cmbAba3DataNascimentoMes.SelectedValue.ToString(); TextoDataAno = cmbAba3DataNascimentoAno.SelectedValue.ToString(); TextoTelefone = txtAba3Telefone.Text; TextoCelular = txtAba3Celular.Text; TextoEmail = txtAba3Email.Text; if (!string.IsNullOrEmpty(txtAba3CPF.Text)) { string cpfsonumero = txtAba3CPF.Text.Replace(".", "").Replace("-", "").Trim(); if (!UtilValidacoes.isCPF(cpfsonumero)) { CaixaMensagem.ExibirOk("Campo CPF inválido!"); txtAba3CPF.Focus(); return(false); } if (ControllerEntrevistado.VerificarEntrevistadoCPF(Program.CodigoEntrevista, txtAba3CPF.Text)) { CaixaMensagem.ExibirOk("CPF já cadastrado na base de dados!"); txtAba3CPF.Focus(); return(false); } } //else //{ // CaixaMensagem.ExibirOk("Campo CPF obrigatório!"); // txtAba3CPF.Focus(); // return false; //} if (Convert.ToInt32(cmbAba3Sexo.SelectedIndex) == 0) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo Sexo é obrigatório!"); cmbAba3Sexo.Focus(); return(false); } if (Convert.ToInt32(cmbAba3DataNascimentoDia.SelectedValue) == 0) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo Data de Nascimento (DIA) é obrigatório!"); cmbAba3DataNascimentoDia.Focus(); return(false); } if (Convert.ToInt32(cmbAba3DataNascimentoMes.SelectedValue) == 0) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo Data de Nascimento (MÊS) é obrigatório!"); cmbAba3DataNascimentoMes.Focus(); return(false); } if (Convert.ToInt32(cmbAba3DataNascimentoAno.SelectedValue) == 0) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo Data de Nascimento (ANO) é obrigatório!"); cmbAba3DataNascimentoAno.Focus(); return(false); } string dataCompleta = cmbAba3DataNascimentoAno.Text + "-" + cmbAba3DataNascimentoMes.Text + "-" + cmbAba3DataNascimentoDia.Text; if ((int)Math.Floor((DateTime.Now - Convert.ToDateTime(dataCompleta)).TotalDays / 365.25) < 18) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo Data de Nascimento deve ser maior que 18 anos!"); cmbAba3DataNascimentoDia.Focus(); return(false); } bool informouTelefoneFixo = txtAba3Telefone.Text.Replace("_", "").Length != 4; bool informouCelular = txtAba3Celular.Text.Replace("_", "").Length != 4; if (!informouTelefoneFixo && !informouCelular) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo Telefone Residencial ou Telefone Celular é obrigatório!"); txtAba3Telefone.Focus(); return(false); } if (informouTelefoneFixo && !informouCelular) { if (!ValidarTelefone()) { return(false); } } if (!informouTelefoneFixo && informouCelular) { if (!ValidarCelular()) { return(false); } } if (informouTelefoneFixo && informouCelular) { if (!ValidarTelefone() || !ValidarCelular()) { return(false); } } if (string.IsNullOrEmpty(txtAba3Email.Text) && mudancaAba) { MostraCursor.CursorAguarde(false); CaixaMensagem.ExibirOk("Campo E-Mail não foi preenchido!"); } else { if (!UtilValidacoes.ValidaEmail(txtAba3Email.Text) && mudancaAba) { CaixaMensagem.ExibirOk("Campo E-Mail inválido!"); txtAba3Email.Focus(); return(false); } } return(true); } catch (Exception ex) { MostraCursor.CursorAguarde(false); LogErro.GravaLog("Erro ao validar Aba Dados.", ex.Message); CaixaMensagem.ExibirOk("Erro ao validar Aba Dados!"); return(false); } }