예제 #1
0
 /// <summary>
 /// Save information from the comboboxes into the databases.
 /// Check if vacancy and candidate meet the requirements
 /// Double for loop used to find if all requirements have been met for each vacancy skill requirements
 /// </summary>
 private void btnSaveApplication_Click(object sender, EventArgs e)
 {
     if ((DM.dtVacancy.Rows[(Convert.ToInt32(cboVacancyID.Text) - 1)]["Status"].ToString()) == "filled")
     {
         MessageBox.Show("Candidates can only apply to current vacancies");
     }
     else
     {
         // Check if vacancy and candidate meet the requirements
         // Double for loop used to find if all requirements have been met for each vacancy skill requirements
         int matchcount         = 0; //To count the amount of matches found during the loop
         int matchtotal         = 0; //To count the amount of requirements that needs to be met
         int lookForVacancyID   = Convert.ToInt32(cboVacancyID.Text);
         int lookForCandidateID = Convert.ToInt32(cboCandidateID.Text);
         foreach (DataRow drVacationSkill in DM.dtVacancySkill.Rows)
         {
             int VacancyID = Convert.ToInt32(drVacationSkill["VacancyID"]);
             if (VacancyID == (lookForVacancyID))
             {
                 int vacancySkillID = Convert.ToInt32(drVacationSkill["SkillID"]); //Convert.ToInt32(DM.dtVacancySkill.Rows[row]["SkillID"]);
                 int vacancyYears   = Convert.ToInt32(drVacationSkill["Years"]);   //Convert.ToInt32(DM.dtVacancySkill.Rows[row]["Years"]);
                 foreach (DataRow drCandidateSkill in DM.dtCandidateSkill.Rows)
                 {
                     int candidateID = Convert.ToInt32(drCandidateSkill["CandidateID"]);
                     if (candidateID == lookForCandidateID)
                     {
                         int candidateSkillID = Convert.ToInt32(drCandidateSkill["SkillID"]);
                         int candidateYears   = Convert.ToInt32(drCandidateSkill["Years"]);
                         if ((candidateSkillID == vacancySkillID) && (candidateYears >= vacancyYears))
                         {
                             matchcount++;//A match has been found
                         }
                     }
                 }
                 matchtotal++;
             }
         }
         // If they do/do not meet requirements
         if ((matchcount == matchtotal) && (matchcount > 0))
         {
             try
             {
                 DataRow newApplicationRow = DM.dtApplication.NewRow();
                 newApplicationRow["VacancyID"]   = cboVacancyID.Text;
                 newApplicationRow["CandidateID"] = cboCandidateID.Text;
                 DM.dtApplication.Rows.Add(newApplicationRow);
                 MessageBox.Show("Application added succesfully", "Success");
                 DM.UpdateApplication();
             }
             catch (ConstraintException)
             {
                 MessageBox.Show("This application has already been added.", "Error");
             }
         }
         else
         {
             MessageBox.Show("The candidates does not have the experience to apply for the vacancy", "Error");
         }
     }
 }
        /// <summary>
        /// if vacancy is current
        /// mark as filled and then delete all application record linked to the vacancy
        /// </summary>
        private void btnMarkVacancy_Click(object sender, EventArgs e)
        {
            if (txtStatus.Text == "current")
            {
                //Search for vacancy
                int lookForVacancyID = Convert.ToInt32(txtVacancyID.Text);
                int vacancy          = 0;
                int count            = 0;

                if (vacancy != 0)
                {
                    MessageBox.Show("Deleting application");
                }
                foreach (DataRow drApplication in DM.dtApplication.Rows)
                {
                    int VacancyID = Convert.ToInt32(drApplication["VacancyID"].ToString());
                    if (VacancyID == (lookForVacancyID))
                    {
                        try
                        {
                            vacancy++;
                            DataRow deleteApplicationRow = DM.dtApplication.Rows[count];
                            deleteApplicationRow.Delete();
                            DM.UpdateApplication();
                        }
                        catch
                        {
                            MessageBox.Show("Error occured while deleting application.");
                        }
                    }
                    count++;
                }
                DataRow updateVacancyRow = DM.dtVacancy.Rows[currencyManager.Position];
                updateVacancyRow["Status"] = "filled";
                currencyManager.EndCurrentEdit();
                DM.UpdateVacancy();
                MessageBox.Show("Vacancy marked as filled.");
            }
            else
            {
                MessageBox.Show("The vacancy is already filled");
            }
        }