//
        //Deletes the selected Exam & pops up a Success or Error message
        //
        protected void delete_Click(object sender, EventArgs e)
        {
            if (empIDexamIDcombo.SelectedIndex != -1)
            {
                //DialogResult result = MessageBox.Show("Are you sure you want delete " + empIDexamIDcombo.SelectedItem.ToString() + "?", "Delete Applciant", MessageBoxButtons.YesNo);

                    //Results Object
                    Results r = new Results();
                    string temp = empIDexamIDcombo.SelectedItem.ToString();
                    int pos = temp.IndexOf(":");
                    r.employee_ID = temp.Substring(0, pos);
                    r.exam_ID = temp.Substring(pos + 1);

                    //Gets Exam type
                    Exam_Details ed = new Exam_Details();
                    ed.exam_ID = r.exam_ID;
                    Exam_DetailsBS edb = new Exam_DetailsBS();
                    ed = edb.getExamDetails(ed);

                    //ResultStatus object
                    ResultStatus rs = new ResultStatus();
                    rs.employee_ID = r.employee_ID;
                    rs.exam_Type = ed.exam_Type;

                    //Gets Attempt No
                    ResultStatusBS rsb = new ResultStatusBS();
                    rs = rsb.getResultStatus(rs);

                    if (rs.attempt_No == 1)
                    {
                        //First Timer
                        string feedback = em.deleteResults(r);
                        if (feedback != "Error")
                        {
                            rsb.deleteResultStatus(rs);
                            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Succesfully deleted.')</SCRIPT>");
                            //essageBox.Show("Succesfully deleted.", "Delete Applicant", MessageBoxButtons.OK);
                        }
                        else
                            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Unsuccessful attempt. Sorry for the inconvenience')</SCRIPT>");
                            //MessageBox.Show("Unsuccessful attempt. Sorry for the inconvenience.", "Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        //Repeater
                        rs.attempt_No--;
                        string feedback = em.deleteResults(r);
                        if (feedback != "Error")
                        {
                            rsb.updateResultStatus(rs);
                            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Succesfully deleted.')</SCRIPT>");
                            //MessageBox.Show("Succesfully deleted.", "Delete Applicant", MessageBoxButtons.OK);
                        }
                        else
                            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Unsuccessful attempt. Sorry for the inconvenience')</SCRIPT>");
                            //MessageBox.Show("Unsuccessful attempt. Sorry for the inconvenience.", "Error", MessageBoxButtons.OK);
                    }
            }
            else
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Please select a valid entry')</SCRIPT>");
                //MessageBox.Show("Please select a valid entry.", "Error");
            this.Page_Load(sender, e);
        }
        //
        //Deletes the selected Exam & pops up a Success or Error message
        //
        private void delete_Click(object sender, EventArgs e)
        {
            if(empIDexamIDcombo.SelectedIndex != -1)
            {
                DialogResult result = MessageBox.Show("Are you sure you want delete " + empIDexamIDcombo.SelectedItem.ToString()+ "?", "Delete Applciant", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    //Results Object
                    Results r = new Results();
                    string temp = empIDexamIDcombo.SelectedItem.ToString();
                    int pos = temp.IndexOf(":");
                    r.employee_ID = temp.Substring(0, pos);
                    r.exam_ID = temp.Substring(pos+1);

                    //Gets Exam type
                    Exam_Details ed = new Exam_Details();
                    ed.exam_ID = r.exam_ID;
                    Exam_DetailsBS edb = new Exam_DetailsBS();
                    ed = edb.getExamDetails(ed);

                    //ResultStatus object
                    ResultStatus rs = new ResultStatus();
                    rs.employee_ID = r.employee_ID;
                    rs.exam_Type = ed.exam_Type;

                    //Gets Attempt No
                    ResultStatusBS rsb = new ResultStatusBS();
                    rs= rsb.getResultStatus(rs);

                    if (rs.attempt_No == 1)
                    {
                        //First Timer
                        string feedback = em.deleteResults(r);
                        if(feedback !="Error")
                        {
                            rsb.deleteResultStatus(rs);
                            MessageBox.Show("Succesfully deleted.", "Delete Applicant", MessageBoxButtons.OK);
                        }
                        else
                            MessageBox.Show("Unsuccessful attempt. Sorry for the inconvenience.", "Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        //Repeater
                        rs.attempt_No--;
                        string feedback = em.deleteResults(r);
                        if (feedback != "Error")
                        {
                            rsb.updateResultStatus(rs);
                            MessageBox.Show("Succesfully deleted.", "Delete Applicant",MessageBoxButtons.OK);
                        }
                        else
                            MessageBox.Show("Unsuccessful attempt. Sorry for the inconvenience.","Error",MessageBoxButtons.OK);
                    }
                }
            }
            else
                MessageBox.Show("Please select a valid entry.", "Error");
            this.DeleteApplicant_Load(sender, e);
        }
        //
        //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;
                            }
                        }
                    }
                }
            }
        }