private void btnDelete_Click(object sender, EventArgs e) { var r = MetroMessageBox.Show(this, @"Are you sure you want to DELETE this record?", @"eVoting System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (r == DialogResult.Yes) { if (!string.IsNullOrWhiteSpace(txtSearch.Text)) { var candidateRegistration = new CandidateRegistration(); var rowAffected = candidateRegistration.DeleteCandidate(txtSearch.Text); if (rowAffected == 1) { MetroMessageBox.Show(this, @"Record DELETED successfully", @"Electronic Voting System", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearAll(); btnUpdate.Enabled = false; btnDelete.Enabled = false; btnSubmit.Enabled = true; } else if (rowAffected == -1) { MetroMessageBox.Show(this, @"Record NOT found", @"Electronic Voting System", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
public FrmCandidate() { InitializeComponent(); var candidate = new CandidateRegistration(); CandidatePin = candidate.GetCandidatePin(); }
private void btnSearch_Click(object sender, EventArgs e) { var message = ""; var candidate = new Candidate(); var candidateRegistration = new CandidateRegistration(); if (!string.IsNullOrWhiteSpace(txtSearch.Text)) { candidate = candidateRegistration.SearchCandidate(txtSearch.Text.Trim(), out message); if (!string.IsNullOrWhiteSpace(message)) { MetroMessageBox.Show(this, message, @"Voting System", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { CandidatePin = txtSearch.Text; txtFirstname.Text = candidate.Firstname; txtLastname.Text = candidate.Lastname; txtEmail.Text = candidate.Email; txtPhoneNumber.Text = candidate.Phonenumber; picImage.Image = candidate.PicImage; cmbPost.SelectedIndex = cmbPost.FindStringExact(candidate.Post); txtManifesto.Text = candidate.Manifesto; cmbGender.SelectedIndex = candidate.Gender == "Male" ? 0 : 1; btnDelete.Enabled = true; btnUpdate.Enabled = true; btnSubmit.Enabled = false; cmbPost.Enabled = false; } } else { MetroMessageBox.Show(this, @"Search textbox is empty", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void btnSubmit_Click(object sender, EventArgs e) { if (IsValidateData()) { var candidateRegistration = new CandidateRegistration(); var result = candidateRegistration.CountCandidates(cmbPost.Text); if (result) { var r = MetroMessageBox.Show(this, @"Are you sure you want to SUBMIT?", @"eVoting System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (r != DialogResult.Yes) { return; } var candidate = new Candidate { CandidatePin = CandidatePin, Email = txtEmail.Text.Trim(), Firstname = txtFirstname.Text.Trim().ToUpper(), Gender = cmbGender.Text, Lastname = txtLastname.Text.Trim().ToUpper(), Post = cmbPost.Text, Manifesto = txtManifesto.Text, Phonenumber = txtPhoneNumber.Text.Trim(), PicImage = picImage.Image }; //var candidateRegistration = new CandidateRegistration(); int insertedRow = candidateRegistration.InsertCandidate(candidate); if (insertedRow == 1) { MetroMessageBox.Show(this, @"Data Submitted Successfully!", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); ClearAll(); } else { MetroMessageBox.Show(this, @"Error submitting data Successfully!", @"eVoting System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } else { errProvider.SetError(cmbPost, "Sorry! You can't register for this post"); } } }
private void btnUpdate_Click(object sender, EventArgs e) { var candidate = new Candidate(); var candidateRegistration = new CandidateRegistration(); //var result = candidateRegistration.CountCandidates(cmbPost.Text); if (IsValidateData()) { candidate.CandidatePin = CandidatePin; candidate.Firstname = txtFirstname.Text.Trim().ToUpper(); candidate.Lastname = txtLastname.Text.Trim().ToUpper(); candidate.Email = txtEmail.Text.Trim(); candidate.Phonenumber = txtPhoneNumber.Text.Trim(); candidate.Gender = cmbGender.Text; candidate.PicImage = picImage.Image; candidate.Post = cmbPost.Text; candidate.Manifesto = txtManifesto.Text; var r = MetroMessageBox.Show(this, @"Are you sure you want to UPDATE this record?", @"eVoting System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (r == DialogResult.Yes) { var rowAffected = candidateRegistration.UpdateCandidate(candidate); if (rowAffected == -1) { MetroMessageBox.Show(this, @"Record not updated successful", @"Voting System", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (rowAffected == 1) { MetroMessageBox.Show(this, @"Record has been updated successful", @"Voting System", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearAll(); btnUpdate.Enabled = false; btnDelete.Enabled = false; btnSubmit.Enabled = true; } } } cmbPost.Enabled = true; }