I would like to prevent my record from being saved if radiobutton
were not selected.
My code:
private void btnSalvar_Click(object sender, EventArgs e) {
if ((rdbMasculino.Checked == false) && (rdbFeminino.Checked == false)) {
MessageBox.Show("Preencha o Campo Sexo!");
clnFuncionario Sexo = new clnFuncionario();
Sexo.nome = txtNome.Text;
if (rdbMasculino.Checked == true)
Sexo.sexo = "Masculino";
if (rdbFeminino.Checked == true)
Sexo.sexo = "Feminino";
} else {
clnFuncionario Funcionario = new clnFuncionario();
if (txtCodigo.Text != "") {
Funcionario.cod_Funcionario = Convert.ToInt32(txtCodigo.Text);
}
Funcionario.sexo = rdbMasculino.Text;
Funcionario.sexo = rdbFeminino.Text;
if (ObjOperacao == clnFuncoesGerais.Operacao.Inclusao) {
Funcionario.Gravar();
MessageBox.Show("Dados Gravados com Sucesso! ", "Item novo " + txtNome.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
If none of the radiobutton
is checked, it shows the message, however, after showing the message it saves the record anyway. I would like the registry to only be saved if one of the radiobutton
is selected and I would like to know if this code I made is good or better.