//
        //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.");
        }
        //
        //Of Loading of Form, loads Exam Types
        //
        private void AddExam_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = addExamDetailsLegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            addExamDetailsLegend.Left = groupStartPosition;

            Exam_TypeBS em = new Exam_TypeBS();
            int i = em.getCount();
            if(i>0)
            {
                string[] abc = new string[i];
                abc = em.loadExamType(i);
                for (int j = 0; j < i; j++)
                {
                    examTypeCombo.Items.Add(abc[j]);
                }
            }
            else
                MessageBox.Show("No Data");
            examTypeCombo.SelectedIndex = 0;
        }
        private void AddPictureQuestionMultipleAnswer_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = AddPQMALegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            AddPQMALegend.Left = groupStartPosition;

            //Loads Marks
            for (int j = 0; j <= 5; j++)
            {
                marksCombo.Items.Add(j + 1);
            }
            marksCombo.SelectedIndex = 0;

            //Displays Format
            formatText.Text = "Picture Question: Multiple Answer";

            //Loads Exam Types
            Exam_TypeBS em = new Exam_TypeBS();
            int i = em.getCount();
            string[] abc = new string[i];
            abc = em.loadExamType(i);
            for (int j = 0; j < i; j++)
            {
                examTypeCombo.Items.Add(abc[j]);
            }
            examTypeCombo.SelectedIndex = 0;

            //Loads Sections

            int k = ed.getSectionCount();
            if (k > 0)
            {
                string[] bcd = new string[k];
                bcd = ed.loadSection(k);

                for (int j = 0; j < k; j++)
                {
                    sectioncomboBox.Items.Add(bcd[j]);
                }
                sectioncomboBox.SelectedIndex = 0;
            }
        }
        //
        //On changing the Exam ID
        //
        private void examIDcombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Resets the other controls on change of ExamID, also disables then in case of an invalid selection
            examTypeCombo.ResetText();
            examTypeCombo.Items.Clear();
            examTypeCombo.Enabled = false;
            datePicker.Enabled = false;
            update.Enabled = false;

            if (examIDCombo.SelectedIndex != -1)
            {
                //Gets the details of the selected Exam ID
                Exam_Details et = new Exam_Details();
                Exam_DetailsBS cs = new Exam_DetailsBS();
                et.exam_ID = examIDCombo.SelectedItem.ToString();
                et = cs.getExamDetails(et);

                //Enables the other controls
                examTypeCombo.Enabled = true;
                datePicker.Enabled = true;
                update.Enabled = true;

                //Loads the Exam Types
                Exam_TypeBS em = new Exam_TypeBS();
                int i = em.getCount();
                if (i > 0)
                {
                    string[] abc = new string[i];
                    abc = em.loadExamType(i);
                    for (int j = 0; j < i; j++)
                    {
                        examTypeCombo.Items.Add(abc[j]);
                    }
                }
                else
                    MessageBox.Show("No Data");

                //Loads the Exam Details
                examTypeCombo.SelectedItem = et.exam_Type;
                datePicker.Value = et.datetime;
            }
            else
                MessageBox.Show("Please select a valid Exam ID.");
        }
        //
        //On click of Add button, validates, adds exam type, displays assigned exam type
        //
        private void add_Click(object sender, EventArgs e)
        {
            if ((levelCombo.SelectedIndex == -1 )|| (noOfAttemptsCombo.SelectedIndex == -1))
                MessageBox.Show("Please select a valid entry.");
            else
            {
                Exam_Types em = new Exam_Types();
                Exam_TypeBS cs = new Exam_TypeBS();

                em.subject = subjectText.Text.ToString();
                string temp = levelCombo.Text.ToString();
                em.level_Number = Convert.ToInt32(levelCombo.SelectedItem);
                em.no_Of_Attempts = Convert.ToInt32(noOfAttemptsCombo.SelectedItem);
                //Call to BLL to validate and add Exam Type
                string feedback = cs.addExamType(em);
                MessageBox.Show(feedback, "Add Exam Type");

                subjectText.Text = "";
                levelCombo.SelectedIndex = 0;
                noOfAttemptsCombo.SelectedIndex = 0;
            }
        }
        //
        //On Form Load: Loads the fields of the selected question
        //
        private void UpdatePictureQuestionMultipleAnswer_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = updateQuestionLegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            updateQuestionLegend.Left = groupStartPosition;

            //Exam Type: Loads exam types if present, else shows an empty database message.
            Exam_TypeBS em = new Exam_TypeBS();
            int m = em.getCount();
            if (m > 0)
            {
                //Question ID
                questionIDText.Text = q.question_ID;

                //Exam Types
                string[] abc1 = new string[m];
                abc1 = em.loadExamType(m);
                for (int j = 0; j < m; j++)
                {
                    examTypeCombo.Items.Add(abc1[j]);
                }
                examTypeCombo.SelectedItem = q.exam_Type;

                //Question
                questionText.Text = q.question;

                //Format
                formatText.Text = q.format;

                //Options
                option1Text.Text = q.option1;
                option2Text.Text = q.option2;
                option3Text.Text = q.option3;
                option4Text.Text = q.option4;

                //Solution
                string ans = q.solution;
                if (ans.Contains("1"))
                    option1CheckBox.Checked = true;
                if (ans.Contains("2"))
                    option2CheckBox.Checked = true;
                if (ans.Contains("3"))
                    option3CheckBox.Checked = true;
                if (ans.Contains("4"))
                    option4CheckBox.Checked = true;

                //Marks
                for (int j = 0; j < 8; j++)
                {
                    marksCombo.Items.Add(j + 1);
                }
                marksCombo.SelectedItem = q.marks;

                //Loads Sections

                int k = cs.getSectionCount();
                if (k > 0)
                {
                    string[] bcd = new string[k];
                    bcd = cs.loadSection(k);

                    for (int j = 0; j < k; j++)
                    {
                        sectioncomboBox.Items.Add(bcd[j]);
                    }
                    sectioncomboBox.SelectedIndex = 0;
                }

                //Section
                sectioncomboBox.Text = q.section;

                //Displays the picture
                byte[] image = cs.getImage(q);
                p.image = cs.getImage(q);
                string s = Convert.ToString(DateTime.Now.ToFileTime());
                FileStream fs1 = new FileStream(s, FileMode.CreateNew, FileAccess.Write);
                fs1.Write(image, 0, image.Length);
                fs1.Flush();
                fs1.Close();
                pictureBox.Image = Image.FromFile(s);
            }
            else
                MessageBox.Show("No Exam Types present in the database.", "Error", MessageBoxButtons.OK);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Loads Marks
            for (int j = 0; j <= 5; j++)
            {
                marksCombo.Items.Add(j + 1+"");
            }
            marksCombo.SelectedIndex = 0;

            //Displays Format
            formatText.Text = "Picture Question: Single Answer";

            //Loads Exam Types
            Exam_TypeBS em = new Exam_TypeBS();
            int i = em.getCount();
            string[] abc = new string[i];
            abc = em.loadExamType(i);
            for (int j = 0; j < i; j++)
            {
                examTypeCombo.Items.Add(abc[j]);
            }
            examTypeCombo.SelectedIndex = 0;

            //Loads Sections

            int k = ed.getSectionCount();
            if (k > 0)
            {
                string[] bcd = new string[k];
                bcd = ed.loadSection(k);

                for (int j = 0; j < k; j++)
                {
                    sectioncomboBox.Items.Add(bcd[j]);
                }
                sectioncomboBox.SelectedIndex = 0;
            }
        }
Example #8
0
        //
        //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 Form Load: Loads the fields of the selected question
        //
        private void UpdateMatchTheColumn_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = updateQuestionLegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            updateQuestionLegend.Left = groupStartPosition;

            Exam_TypeBS em = new Exam_TypeBS();
            int m = em.getCount();
            if (m > 0)
            {

                //Loads Sections

                int k = cs.getSectionCount();
                if (k > 0)
                {
                    string[] bcd = new string[k];
                    bcd = cs.loadSection(k);

                    for (int j = 0; j < k; j++)
                    {
                        sectioncomboBox.Items.Add(bcd[j]);
                    }
                    sectioncomboBox.SelectedIndex = 0;
                }

                //Question ID
                questionIDText.Text = q.question_ID;

                //Exam Type
                string[] abc1 = new string[m];
                abc1 = em.loadExamType(m);
                for (int j = 0; j < m; j++)
                {
                    examTypeCombo.Items.Add(abc1[j]);
                }
                examTypeCombo.SelectedItem = q.exam_Type;

                //Format
                formatText.Text = q.format;

                //Question Column
                string temp = "";
                int pos;
                temp = q.question;

                temp = temp.Substring(1);
                pos = temp.IndexOf(".");
                textBoxA.Text = temp.Substring(0, pos);

                temp = temp.Substring(pos + 1);
                pos = temp.IndexOf(".");
                textBoxB.Text = temp.Substring(0, pos);

                temp = temp.Substring(pos + 1);
                pos = temp.IndexOf(".");
                textBoxC.Text = temp.Substring(0, pos);

                temp = temp.Substring(pos + 1);
                pos = temp.IndexOf(".");
                textBoxD.Text = temp.Substring(0, pos);

                //Answer Column
                textBox1.Text = q.option1;
                textBox2.Text = q.option2;
                textBox3.Text = q.option3;
                textBox4.Text = q.option4;

                //Solution Order
                solutionText.Text = q.solution;

                //Marks
                for (int j = 0; j < 8; j++)
                {
                    marksCombo.Items.Add(j + 1);
                }
                marksCombo.SelectedItem = q.marks;

                //Section
                sectioncomboBox.Text = q.section;
            }
            else
                MessageBox.Show("No Exam Types present in the database.");
        }
        //
        //On Form Load: Loads the fields of the selected question
        //
        private void UpdateSingleChoiceQuestion_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = updateQuestionLegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            updateQuestionLegend.Left = groupStartPosition;

            Exam_TypeBS em = new Exam_TypeBS();
            int m = em.getCount();
            if (m > 0)
            {
                //Question ID
                questionIDText.Text = q.question_ID;

                //Exam Type

                string[] abc1 = new string[m];
                abc1 = em.loadExamType(m);
                for (int j = 0; j < m; j++)
                {
                    examTypeCombo.Items.Add(abc1[j]);
                }
                examTypeCombo.SelectedItem = q.exam_Type;

                //Question
                questionText.Text = q.question;

                //Format
                formatText.Text = q.format;

                //Options
                option1Text.Text = q.option1;
                option2Text.Text = q.option2;
                option3Text.Text = q.option3;
                option4Text.Text = q.option4;

                //Solution
                switch (q.solution)
                {
                    case "1":
                        option1Radio.Checked = true;
                        break;
                    case "2":
                        option2Radio.Checked = true;
                        break;
                    case "3":
                        option3Radio.Checked = true;
                        break;
                    case "4":
                        option1Radio.Checked = true;
                        break;
                }

                //Marks
                for (int j = 0; j < 8; j++)
                {
                    marksCombo.Items.Add(j + 1);
                }
                marksCombo.SelectedItem = q.marks;

                //Loads Sections

                int k = cs.getSectionCount();
                if (k > 0)
                {
                    string[] bcd = new string[k];
                    bcd = cs.loadSection(k);

                    for (int j = 0; j < k; j++)
                    {
                        sectioncomboBox.Items.Add(bcd[j]);
                    }
                    sectioncomboBox.SelectedIndex = 0;
                }

                //Section
                sectioncomboBox.Text = q.section;

            }
            else
                MessageBox.Show("No Exam Types present in the database.","Error",MessageBoxButtons.OK);
        }
        //
        //On Form Load: Loads the fields of the selected question
        //
        private void UpdateMultipleChoiceQuestions_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = updateQuestionLegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            updateQuestionLegend.Left = groupStartPosition;

            //Exam Type: Loads exam types if present, else shows an empty database message.
            Exam_TypeBS em = new Exam_TypeBS();
            int m = em.getCount();
            if (m > 0)
            {
                //Question ID
                questionIDText.Text = q.question_ID;

                //Exam Types
                string[] abc1 = new string[m];
                abc1 = em.loadExamType(m);
                for (int j = 0; j < m; j++)
                {
                    examTypeCombo.Items.Add(abc1[j]);
                }
                examTypeCombo.SelectedItem = q.exam_Type;

                //Question
                questionText.Text = q.question;

                //Format
                formatText.Text = q.format;

                //Options
                option1Text.Text = q.option1;
                option2Text.Text = q.option2;
                option3Text.Text = q.option3;
                option4Text.Text = q.option4;

                //Solution
                string ans = q.solution;
                if(ans.Contains("1"))
                    option1CheckBox.Checked = true;
                if(ans.Contains("2"))
                    option2CheckBox.Checked = true;
                if(ans.Contains("3"))
                    option3CheckBox.Checked = true;
                if(ans.Contains("4"))
                    option4CheckBox.Checked = true;

                //Loads Sections

                int k = cs.getSectionCount();
                if (k > 0)
                {
                    string[] bcd = new string[k];
                    bcd = cs.loadSection(k);

                    for (int j = 0; j < k; j++)
                    {
                        sectioncomboBox.Items.Add(bcd[j]);
                    }
                    sectioncomboBox.SelectedIndex = 0;
                }
                //Section
                sectioncomboBox.Text = q.section;

                //Marks
                for (int j = 0; j < 8; j++)
                {
                    marksCombo.Items.Add(j + 1);
                }
                marksCombo.SelectedItem = q.marks;

            }
            else
                MessageBox.Show("No Exam Types present in the database.", "Error",MessageBoxButtons.OK);
        }
        //
        //On Form Load
        //
        private void UpdateExamType_Load(object sender, EventArgs e)
        {
            // to allign the Legend(Group Box) to
            // the center of form
            int centerForm;
            int centerGroup;
            int groupStartPosition;

            centerForm = this.Width / 2;
            centerGroup = updateExamTypeLegend.Width / 2;
            groupStartPosition = centerForm - centerGroup;
            updateExamTypeLegend.Left = groupStartPosition;

            // Filling the Exam Type ComboBox
            Exam_TypeBS ed = new Exam_TypeBS();
            int i = ed.getCount();
            if (i > 0)
            {
                abc = new string[i];
                abc = ed.loadExamType(i);
                for (int j = 0; j < i; j++)
                {
                    examTypeCombo.Items.Add(abc[j]);
                }
            }
            else
                MessageBox.Show("No Data");

            //Disabling the other controls
            subjectText.Text = "";
            subjectText.Enabled = false;
            levelCombo.Enabled = false;
            noOfAttemptsCombo.Enabled = false;
            update.Enabled = false;

            //Loads the Level and No Of Attempts
            for (int j = 0; j <= 5; j++)
            {
                levelCombo.Items.Add(j);
                noOfAttemptsCombo.Items.Add(j);
            }
        }
        //
        //On click of Update button
        //
        private void update_Click(object sender, EventArgs e)
        {
            if ((examTypeCombo.SelectedIndex == -1) || (levelCombo.SelectedIndex == -1) || (noOfAttemptsCombo.SelectedIndex == -1))
                MessageBox.Show("Please select a valid entry", "Error");
            else
            {
                //Getting the input
                Exam_TypeBS js = new Exam_TypeBS();
                Exam_Types em = new Exam_Types();
                em.exam_Type = examTypeCombo.SelectedItem.ToString();
                em.subject = subjectText.Text.ToString();
                em.level_Number = (Convert.ToInt32(levelCombo.Text));
                em.no_Of_Attempts = (Convert.ToInt32(noOfAttemptsCombo.Text));

                //Business logic call, forwarded to DAL
                string feedback = js.updateExamType(em);
                MessageBox.Show(feedback, "Update Exam");

                examTypeCombo.SelectedIndex = 0;
                subjectText.Text = "";
                levelCombo.SelectedIndex = 0;
                noOfAttemptsCombo.SelectedIndex = 0;
            }
        }
        //
        //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;
                            }
                        }
                    }
                }
            }
        }