//delete the current row private void btnDeleteCandidate_Click(object sender, EventArgs e) { DataRow deleteCandidateRow = DM.dtCandidate.Rows[currencyManager.Position]; if (MessageBox.Show("Are you sure you want to delete this record?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { //assign the application table to an array(candidates) candidates = DM.lookingGlassDS.Tables["APPLICATION"].Select(); //use for loop to compare input ID with the candidateID in the application table for (int i = 0; i < candidates.Length; i++) { DataRow drCandidate = candidates[i]; int canID = Convert.ToInt32(txtCandidateID.Text); int canID2 = Convert.ToInt32(drCandidate["CandidateID"]); //if find the same id ,return if (canID == canID2) { MessageBox.Show("You may only delete candidates who have no applications"); return; } } //assign the candidateskill table to an array(candidateskills) candidateskills = DM.lookingGlassDS.Tables["CANDIDATESKILL"].Select(); //use for loop to compare input ID with the candidateID in the candidateskill table for (int i = 0; i < candidateskills.Length; i++) { DataRow drCandidateSkill = candidateskills[i]; int canID = Convert.ToInt32(txtCandidateID.Text); int canID2 = Convert.ToInt32(drCandidateSkill["CandidateID"]); //if find the same id delete the candidate information from the candidateskill table if (canID == canID2) { drCandidateSkill.Delete(); DM.UpdateCandidateSkill(); } } deleteCandidateRow.Delete(); MessageBox.Show("Candidate deleted successfully."); DM.UpdateCandidate(); return; } else { return; } }
private void btnSaveCandidate_Click(object sender, EventArgs e) { //Create a new row that variables will be added into DataRow newCandidateRow = DM.dtCandidate.NewRow(); if ((txtAddCandidateLN.Text == "") || (txtAddCandidateFN.Text == "") || (txtAddCandidateSA.Text == "") || (txtAddCandidateSuburb.Text == "") || (txtAddCandidatePN.Text == "")) { MessageBox.Show("You must type a value for each of the text fields", "Error"); return; } else { newCandidateRow["LastName"] = txtAddCandidateLN.Text; newCandidateRow["FirstName"] = txtAddCandidateFN.Text; newCandidateRow["StreetAddress"] = txtAddCandidateSA.Text; newCandidateRow["Suburb"] = txtAddCandidateSuburb.Text; newCandidateRow["PhoneNumber"] = txtAddCandidatePN.Text; DM.dtCandidate.Rows.Add(newCandidateRow); MessageBox.Show("Candidate added successfully", "Success"); DM.UpdateCandidate(); } return; }