/// <summary> /// Check if years is not empty /// Assign skill to vacancy /// catch format and constraint errors /// </summary> private void btnAssignSkill_Click(object sender, EventArgs e) { try { if (txtYears.Text != "") { DataRow newVacancySkill = DM.dtVacancySkill.NewRow(); newVacancySkill["VacancyID"] = dgvVacancy["VacancyID", cmVacancy.Position].Value; newVacancySkill["SkillID"] = dgvSkill["SkillID", cmSkill.Position].Value; newVacancySkill["Years"] = Convert.ToInt32(txtYears.Text); DM.dsLookingGlass.Tables["VacancySkill"].Rows.Add(newVacancySkill); DM.UpdateVacancySkill(); MessageBox.Show("Skill assigned successfully"); } else { MessageBox.Show("Please enter a number in years.", "Error"); } } catch (ConstraintException) { MessageBox.Show("This skill has already been assigned to this vacancy.", "Error"); } catch (FormatException) { MessageBox.Show("Please enter a number in years.", "Error"); } }
/// <summary> /// Check if vacancy is in application /// If not prompt user to confirm deleteion, if yes, delete vacancy and all skill asign to it /// </summary> private void btnDeleteVacancy_Click(object sender, EventArgs e) { DataRow deleteVacancyRow = DM.dtVacancy.Rows[currencyManager.Position]; int lookForVacancyID = Convert.ToInt32(txtVacancyID.Text); int vacancy = 0;//Count amount of vacancy id in application table int row = 0; foreach (DataRow drApplication in DM.dtApplication.Rows) { int VacancyID = Convert.ToInt32(drApplication["VacancyID"].ToString()); if (VacancyID == (lookForVacancyID)) { vacancy++; } } if (vacancy == 0) { if (MessageBox.Show("Do you want to delete this vacancy? Once deleted it will disappear from the database permanently.", "Delete Vacancy", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (DataRow drSkill in DM.dtVacancySkill.Rows) { int VacancyID = Convert.ToInt32(drSkill["VacancyID"].ToString()); if (VacancyID == (lookForVacancyID)) { try { DataRow deleteVacancySkillRow = DM.dtVacancySkill.Rows[row]; deleteVacancySkillRow.Delete(); } catch { MessageBox.Show("Something went wrong when trying to delete skill."); } } row++; } DM.UpdateVacancySkill(); try { deleteVacancyRow.Delete(); DM.UpdateVacancy(); MessageBox.Show("Vacancy deleted successfully"); } catch { MessageBox.Show("Error occured while deleting Vacancy"); } } } else { MessageBox.Show("You may only delete a vacancy that has no applications"); } }