private void btnIniciar_Click(object sender, EventArgs e) { Eleitor_DTO obj = new Eleitor_DTO(); string cpf = maskedTextBox1.Text; bool voto; try { obj = Login_BLL.ValidarEleitor(cpf); voto = Login_BLL.VerificarVoto(obj); if (voto == true) { MessageBox.Show("Eleitor já votou!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (obj.Retorno == true) { this.Hide(); Eleicao eleicao = new Eleicao(obj); eleicao.ShowDialog(); this.Dispose(); } else { MessageBox.Show("Eleitor não encontrado!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static string ValidarEleitor(Eleitor_DTO obj) { if (string.IsNullOrWhiteSpace(obj.CPF)) { throw new Exception("Campo CPF vazio!"); } if (string.IsNullOrWhiteSpace(obj.Nome)) { throw new Exception("Campo Nome vazio!"); } if (string.IsNullOrWhiteSpace(obj.Curso)) { throw new Exception("Campo Curso vazio!"); } if (string.IsNullOrWhiteSpace(obj.Modulo)) { throw new Exception("Campo Módulo vazio!"); } try { Convert.ToInt32(obj.Modulo); return(CadEleitor_DAL.CadastrarEleitor(obj)); } catch (Exception) { throw new Exception("O valor usado para o módulo deve ser um numero inteiro"); } }
public static bool VerificarVoto(Eleitor_DTO obj) { try { string script = "SELECT id_eleitor, id_eleicao FROM Eleitor_Eleicao WHERE id_eleitor = @eleitor AND id_eleicao = @eleicao"; SqlCommand cmd = new SqlCommand(script, Conexao_DAL.Conexao()); cmd.Parameters.AddWithValue("@eleitor", obj.Id_Eleitor); cmd.Parameters.AddWithValue("@eleicao", obj.Id_Eleicao); SqlDataReader dados = cmd.ExecuteReader(); while (dados.Read()) { if (dados.HasRows) { return(true); } } return(false); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (Conexao_DAL.Conexao().State != ConnectionState.Closed) { Conexao_DAL.Conexao().Close(); } } }
public static string CadastrarEleitor(Eleitor_DTO obj) { try { string script = "INSERT INTO Eleitor (nome, cpf, turma_cargo, modulo) VALUES (@Nome, @CPF, @Turma, @Modulo)"; SqlCommand cmd = new SqlCommand(script, Conexao_DAL.Conexao()); cmd.Parameters.AddWithValue("@Nome", obj.Nome); cmd.Parameters.AddWithValue("@Cpf", obj.CPF); cmd.Parameters.AddWithValue("@Turma", obj.Curso); cmd.Parameters.AddWithValue("@Modulo", obj.Modulo); cmd.ExecuteNonQuery(); return("Eleitor cadastrado com sucesso"); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (Conexao_DAL.Conexao().State != ConnectionState.Closed) { Conexao_DAL.Conexao().Close(); } } }
public Eleicao(Eleitor_DTO obj) { InitializeComponent(); label2.Text = obj.Nome; label4.Text = obj.CPF; label5.Text = obj.Turma; Eleitor = obj.Id_Eleitor; Eleicao1 = obj.Id_Eleicao; ptbFoto.Image = Properties.Resources.administrator; }
public static bool VerificarVoto(Eleitor_DTO obj) { try { return(Login_DAL.VerificarVoto(obj)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static Eleitor_DTO ValidarEleitor(string cpf) { Eleitor_DTO obj = new Eleitor_DTO(); try { string script = "SELECT id_eleitores, nome, cpf, turma_cargo, id_eleicoes, descricao FROM Eleitor, Eleicao WHERE cpf = @cpf AND ativa = 'Ativa'"; SqlCommand cmd = new SqlCommand(script, Conexao_DAL.Conexao()); cmd.Parameters.AddWithValue("@cpf", cpf); SqlDataReader dados = cmd.ExecuteReader(); while (dados.Read()) { if (dados.HasRows) { obj.Id_Eleitor = Convert.ToInt32(dados["id_eleitores"]); obj.CPF = dados["cpf"].ToString(); obj.Nome = dados["nome"].ToString(); obj.Turma = dados["turma_cargo"].ToString(); obj.Id_Eleicao = Convert.ToInt32(dados["id_eleicoes"]); obj.Descricao = dados["descricao"].ToString(); obj.Retorno = true; return(obj); } } obj.Retorno = false; return(obj); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (Conexao_DAL.Conexao().State != ConnectionState.Closed) { Conexao_DAL.Conexao().Close(); } } }
private void button1_Click(object sender, EventArgs e) { Eleitor_DTO obj = new Eleitor_DTO(); try { obj.CPF = maskedTextBox2.Text; obj.Nome = textBox3.Text; obj.Curso = comboBox1.Text; obj.Modulo = maskedTextBox1.Text; string msg = CadEleitor_BLL.ValidarEleitor(obj); MessageBox.Show(msg, "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); maskedTextBox2.Clear(); textBox3.Clear(); comboBox1.SelectedIndex = -1; maskedTextBox1.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }