/// <summary>
 /// Check if years is not empty
 /// Assign skill to candidate
 /// catch format and constraint errors
 /// </summary>
 private void btnAssignSkill_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtYears.Text != "")
         {
             DataRow newCandidateSkill = DM.dtCandidateSkill.NewRow();
             newCandidateSkill["CandidateID"] = dgvCandidate["CandidateID", cmCandidate.Position].Value;
             newCandidateSkill["SkillID"]     = dgvSkill["SkillID", cmSkill.Position].Value;
             newCandidateSkill["Years"]       = Convert.ToInt32(txtYears.Text);
             DM.dsLookingGlass.Tables["CandidateSkill"].Rows.Add(newCandidateSkill);
             DM.UpdateCandidateSkill();
             MessageBox.Show("Skill assigned successfully", "Succcess");
         }
         else
         {
             MessageBox.Show("Please enter a number in years.", "Error");
         }
     }
     catch (ConstraintException)
     {
         MessageBox.Show("This skill has already been assigned to this candidate.", "Error");
     }
     catch (FormatException)
     {
         MessageBox.Show("Please enter a number in years.", "Error");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Check if candidate is in the application table
        /// If no candidate, prompt user for delete confirmation
        /// If yes, delete candidate and its skill from the database
        /// </summary>
        private void btnDeleteCandidate_Click(object sender, EventArgs e)
        {
            DataRow deleteCandidateRow = DM.dtCandidate.Rows[currencyManager.Position];
            int     lookForCandidateID = Convert.ToInt32(txtCandidateID.Text);
            int     candidate          = 0;//Count amount of candidate id in application table
            int     row = 0;

            foreach (DataRow drApplication in DM.dtApplication.Rows)
            {
                int CandidateID = Convert.ToInt32(drApplication["CandidateID"].ToString());
                if (CandidateID == (lookForCandidateID))
                {
                    candidate++;
                }
            }
            if (candidate == 0)
            {
                if (MessageBox.Show("Do you want to delete this candidate? Once deleted it will disappear from the database permanently.", "Delete Candidate", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    foreach (DataRow drSkill in DM.dtCandidateSkill.Rows)
                    {
                        int CandidateID = Convert.ToInt32(drSkill["CandidateID"].ToString());
                        if (CandidateID == (lookForCandidateID))
                        {
                            try
                            {
                                DataRow deleteCandidateSkillRow = DM.dtCandidateSkill.Rows[row];
                                deleteCandidateSkillRow.Delete();
                            }
                            catch
                            {
                                MessageBox.Show("Something went wrong when trying to delete skill.");
                            }
                        }
                        row++;
                    }
                    DM.UpdateCandidateSkill();

                    try
                    {
                        deleteCandidateRow.Delete();
                        DM.UpdateCandidate();
                        MessageBox.Show("Candidate deleted successfully.");
                    }
                    catch
                    {
                        MessageBox.Show("Something went wrong when trying to delete candidate.");
                    }
                }
            }
            else
            {
                MessageBox.Show("You may only delete candidate who have no application");
            }
        }