//assign skill to candidate private void btnAssignSkill_Click(object sender, EventArgs e) { //use "try catch" to stop the same assign try { //stop the empty text or more than 30 in the year text area if ((txtYears.Text == "") || (Convert.ToInt32(txtYears.Text) > 30)) { MessageBox.Show("Please set the right value of years(1-30)"); } //assign skill to vacancy else { DataRow newCandidateSkill = DM.dtCandidateSkill.NewRow(); newCandidateSkill["Years"] = txtYears.Text; newCandidateSkill["CandidateID"] = dgvCandidate["CandidateID", cmCandidate.Position].Value; newCandidateSkill["SkillID"] = dgvSkill["SkillID", cmSkill.Position].Value; DM.lookingGlassDS.Tables["CandidateSkill"].Rows.Add(newCandidateSkill); DM.UpdateCandidateSkill(); MessageBox.Show("Skill assigned successfully"); } } catch (ConstraintException) { MessageBox.Show("Skill has already been assigned to this Candidate."); } }
private void btnAssignSkillC_Click(object sender, EventArgs e) { try { if (txtYearsC.Text == "")//if user didn't type in any number,return { MessageBox.Show("You must type a valid number", "Error"); } else if (DM.dtSkill.Rows[cmSkill.Position]["SkillID"] != DM.dtCandidateSkill.Rows[cmCandidateSkill.Position]["SkillID"]) { DataRow newCandidateSkill = DM.dtCandidateSkill.NewRow(); newCandidateSkill["CandidateID"] = dgvCandidate["CandidateID", cmCandidate.Position].Value; newCandidateSkill["Years"] = Convert.ToInt32(this.txtYearsC.Text); newCandidateSkill["SkillID"] = dgvCSkill["SkillID", cmSkill.Position].Value; DM.dsLookingGlass.Tables["CandidateSkill"].Rows.Add(newCandidateSkill); DM.UpdateCandidateSkill(); MessageBox.Show("Skill assigned successfully", "Success"); } } catch { MessageBox.Show("This skill has already been assigned to this candidate"); } }
//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 btnDeleteCandidate_Click(object sender, EventArgs e) { CurrencyManager cmCandidateSkill; cmCandidateSkill = (CurrencyManager)this.BindingContext[DM.dsLookingGlass, "CandidateSkill"]; int aCandidateID = Convert.ToInt32(txtCandidateID.Text); cmCandidateSkill.Position = DM.candidateSkillView.Find(aCandidateID); DataRow[] CandidateSkillRow = DM.dtCandidateSkill.Select("CandidateID = " + aCandidateID); DataRow deleteCandidateRow = DM.dtCandidate.Rows[currencyManager.Position]; DataRow[] ApplicationRow = deleteCandidateRow.GetChildRows(DM.dtCandidate.ChildRelations["Candidate_Application"]); if (ApplicationRow.Length == 0) { if (MessageBox.Show("Are you sure you want to delete this candidate record?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { foreach (DataRow dcr in CandidateSkillRow)//use loop to delete multiple row { dcr.Delete(); } deleteCandidateRow.Delete(); //Update two table. DM.UpdateCandidateSkill(); DM.UpdateCandidate(); MessageBox.Show("Candidate deleted successfully", "Success"); MessageBox.Show("Candidate Skills deleted successfully", "Success"); } else { return; } } else { MessageBox.Show("You may only delete candidates who have no applications", "Error"); } return; }