// //On changing the Exam Type // private void examTypeCombo_SelectedIndexChanged(object sender, EventArgs e) { //Resets the other controls on change of Exam Type, also disables then in case of an invalid selection levelCombo.Enabled = false; noOfAttemptsCombo.Enabled = false; subjectText.Text = ""; subjectText.Enabled = false; update.Enabled = false; if (examTypeCombo.SelectedIndex != -1) { //Gets the details of the selected Exam Type Exam_Types et = new Exam_Types(); Exam_TypeBS cs = new Exam_TypeBS(); et.exam_Type = examTypeCombo.SelectedItem.ToString(); et = cs.getExamType(et); //Enables the other controls levelCombo.Enabled = true; noOfAttemptsCombo.Enabled = true; subjectText.Enabled = true; update.Enabled = true; //Loads the Exam Type subjectText.Text = et.subject; levelCombo.SelectedItem = et.level_Number; noOfAttemptsCombo.SelectedItem = et.no_Of_Attempts; } else MessageBox.Show("Please select a valid Exam Type."); }
// //On form load: Displays the employee name and his result // private void Result_Load(object sender, EventArgs e) { employeeNameLabel.Text = emp.first_Name + " " + emp.last_Name; Results re = new Results(); re.Employee_ID = emp.employee_Id; re.exam_ID = ed.exam_ID; re = r.getResult(re); ResultStatus rs = new ResultStatus(); rs.employee_ID = emp.employee_Id; rs.exam_Type = ed.exam_Type; ResultStatusBS rsb = new ResultStatusBS(); rs = rsb.getResultStatus(rs); Exam_Types m = new Exam_Types(); m.exam_Type = ed.exam_Type; Exam_TypeBS exd = new Exam_TypeBS(); m = exd.getExamType(m); examLabel.Text = "Exam ID: " + ed.exam_ID + " Exam Type: " + ed.exam_Type + " Subject: " + m.subject + " Level: " + m.level_Number + " Attempt No: " + rs.attempt_No; if (rs.status == "Passed") congratulationsLabel.Text = "Congratulations ! You have passed! Your score is"+re.score+". Percentage: "+re.percentage+"%"; else { if (rs.attempt_No == m.no_Of_Attempts) { congratulationsLabel.Text = "Sorry, You have Failed in this Examination . Your score is" + re.score + ". Percentage: " + re.percentage + "%. You have no more attempts left for this exam"; } congratulationsLabel.Text = "Sorry , You have Failed in this Examination . Your score is"+re.score+". Percentage: "+re.percentage+"%. You have got " +(m.no_Of_Attempts-rs.attempt_No) + " attempts left for this exam"; } }
// //On click of Add button, validates and adds applicants // private void add_Click(object sender, EventArgs e) { if (employeeIDCombo.SelectedIndex == -1 || examIDCombo.SelectedIndex == -1) { MessageBox.Show("Please select a valid entry.", "Error"); } else { //Creates Results objects Results r = new Results(); string id = employeeIDCombo.Text.ToString(); int pos = id.IndexOf(":"); r.employee_ID = id.Substring(0, pos); r.exam_ID = examIDCombo.Text.ToString(); //Gets exam type of exam ID Exam_Details ed = new Exam_Details(); ed.exam_ID = r.exam_ID; ed = edb.getExamDetails(ed); //Gets number of attempts for exam type Exam_Types et = new Exam_Types(); Exam_TypeBS etb = new Exam_TypeBS(); et.exam_Type = ed.exam_Type; et = etb.getExamType(et); //Creates ResultStatus objects ResultStatus rs = new ResultStatus(); rs.employee_ID = r.employee_ID; rs.exam_Type = ed.exam_Type; //Gets the attempts_no and status ResultStatusBS rsb = new ResultStatusBS(); rs = rsb.getResultStatus(rs); ResultsBS rb = new ResultsBS(); //Unscheduled if (rs.status == "Unscheduled") { rs.attempt_No = 1; rs.status = "Scheduled"; string feedback = rsb.addResultStatus(rs); if (feedback == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); } else { string feed = rb.addApplicant(r); if (feed == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); rsb.deleteResultStatus(rs); } else { //Succesfully scheduled MessageBox.Show(feed + feedback, "Scheduled", MessageBoxButtons.OK); examIDCombo.SelectedIndex = employeeIDCombo.SelectedIndex = 0; } } } //Scheduled else if (rs.status == "Scheduled") { MessageBox.Show("Employee " + rs.employee_ID + " already has an exam scheduled for exam type " + rs.exam_Type + ".", "Already Scheduled", MessageBoxButtons.OK); } //Passed else if (rs.status == "Passsed") { MessageBox.Show("Employee " + rs.employee_ID + " has passed an exam of exam type " + rs.exam_Type + ".", "Passed", MessageBoxButtons.OK); } //Failed else if (rs.status == "Failed") { ///Exhausted Attempts if (rs.attempt_No == et.no_Of_Attempts) { MessageBox.Show("Employee " + rs.employee_ID + " has used up the maximum number of attempts for exam type " + rs.exam_Type + ".", "Exhausted Attempts", MessageBoxButtons.OK); } //Attempts left else { rs.Attempt_No++; rs.status = "Scheduled"; string feedback = rsb.updateResultStatus(rs); if (feedback == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); } else { string feed = rb.addApplicant(r); if (feed == "Error") { MessageBox.Show("Some error occured. Sorry for the inconvenience."); rs.attempt_No--; rsb.updateResultStatus(rs); } else { //Succesfully scheduled MessageBox.Show(feed + feedback, "Scheduled", MessageBoxButtons.OK); examIDCombo.SelectedIndex = employeeIDCombo.SelectedIndex = 0; } } } } } }