private void LoadQuestionsRandomlyAccordingToCategoryAndType(Category oCategory, QuestionType oQuestionTypeInList)
    {
        try
        {
            Result oResult = new Result();
            CandidateExamProcessBO oCandidateExamProcessBO = new CandidateExamProcessBO();

            List<CandidateAnswerQuestion> oSubListCandidateAnswerQuestion = new List<CandidateAnswerQuestion>();

            CandidateForExam oCandidateForExam = Utils.GetSession(SessionManager.csLoggedUser) as CandidateForExam;

            oResult = oCandidateExamProcessBO.LoadQuestionsForACandidateInExamByCategoryAndType(oCategory,oQuestionTypeInList,oCandidateForExam);

            if (oResult.ResultIsSuccess)
            {
                oSubListCandidateAnswerQuestion = RandomizeQuestions((List<CandidateAnswerQuestion>)oResult.ResultObject);

                oListCandidateAnswerQuestion.AddRange(oSubListCandidateAnswerQuestion);
            }
        }
        catch (Exception oEx)
        {

        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Result oResult = new Result();
        CandidateExamProcessBO oCandidateExamProcessBO = new CandidateExamProcessBO();

        try
        {
            List<CandidateAnswerQuestion> oListCandidateAnswerQuestion = new List<CandidateAnswerQuestion>();

            oListCandidateAnswerQuestion = (List<CandidateAnswerQuestion>)Utils.GetSession(SessionManager.csExamProcess);

            CandidateForExam oCandidateForExam = Utils.GetSession(SessionManager.csLoggedUser) as CandidateForExam;

            oCandidateForExam.CadidateCandidateExam.CandidateAnsweredQuestions = oListCandidateAnswerQuestion;

            //save candidate Descriptive answer File
            try
            {
                if (!Directory.Exists(DirectoryManager.csCandidateCVDirectory + oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamName + "\\" + oCandidateForExam.CandidateForExamCandidate.CandidateCompositeID + "\\"))
                {
                    Directory.CreateDirectory(DirectoryManager.csCandidateCVDirectory + oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamName + "\\" + oCandidateForExam.CandidateForExamCandidate.CandidateCompositeID + "\\");
                }

                foreach (CandidateAnswerQuestion oCandidateAnswerQuestioninList in oCandidateForExam.CadidateCandidateExam.CandidateAnsweredQuestions)
                {
                    if (oCandidateAnswerQuestioninList.QuestionForCandidateAnswer.QuestionQuestionType.QuestionTypeID==1)
                    {
                        if (oCandidateAnswerQuestioninList.ClientFileBytes != null && oCandidateAnswerQuestioninList.ClientFileBytes.Length > 0)
                        {

                            File.WriteAllBytes(DirectoryManager.csCandidateCVDirectory + oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamName + "\\" + oCandidateForExam.CandidateForExamCandidate.CandidateCompositeID + "\\" + oCandidateAnswerQuestioninList.QuestionForCandidateAnswer.QuestionID.ToString() + "_" + oCandidateAnswerQuestioninList.sAnswerAttachFilePath, oCandidateAnswerQuestioninList.ClientFileBytes);
                            oCandidateAnswerQuestioninList.sAnswerAttachFilePath = oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamName + "\\" + oCandidateForExam.CandidateForExamCandidate.CandidateCompositeID + "\\" + oCandidateAnswerQuestioninList.QuestionForCandidateAnswer.QuestionID.ToString() + "_" + oCandidateAnswerQuestioninList.sAnswerAttachFilePath;

                            //oCandidateAnswerQuestioninList.ClientFile.SaveAs(DirectoryManager.csCandidateCVDirectory + oCandidate.CadidateCandidateExam.CandiadteExamExam.ExamName + "\\" + oCandidate.CandidateCompositeID + "\\" + oCandidateAnswerQuestioninList.QuestionForCandidateAnswer.QuestionID.ToString() + oCandidateAnswerQuestioninList.ClientFile.FileName);
                            //oCandidateAnswerQuestioninList.sAnswerAttachFilePath = oCandidate.CadidateCandidateExam.CandiadteExamExam.ExamName + "\\" + oCandidate.CandidateCompositeID + "\\" + oCandidateAnswerQuestioninList.QuestionForCandidateAnswer.QuestionID.ToString() + oCandidateAnswerQuestioninList.ClientFile.FileName; // Here sAnswerAttachFilePath is used to store the Descriptive Answer Attached File Path
                        }
                        else
                        {
                            oCandidateAnswerQuestioninList.sAnswerAttachFilePath = String.Empty;
                        }
                    }
                    else
                    {
                        oCandidateAnswerQuestioninList.sAnswerAttachFilePath = String.Empty;
                    }
                }
            }
            catch (Exception oEx1)
            {

            }
            //End save candidate Descriptive answer File

            oResult = oCandidateExamProcessBO.SaveCandidateAnswers(oCandidateForExam);

            if (oResult.ResultIsSuccess)
            {
                lbl_error.ForeColor = Color.Green;
                lbl_error.Text = oResult.ResultMessage;
            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = oResult.ResultMessage;
            }

            Session.Abandon();

        }
        catch (Exception oEx2)
        {
            Session.Abandon();
        }
    }
    private void LoadCategoriesWithType()
    {
        Result oResult = new Result();
        CandidateExamProcessBO oCandidateExamProcessBO = new CandidateExamProcessBO();

        List<CandidateMenu> oListCandidateMenu = new List<CandidateMenu>();

        try
        {
            CandidateForExam oCandidateForExam = Utils.GetSession(SessionManager.csLoggedUser) as CandidateForExam;

            lbl_CandidateName.Text = oCandidateForExam.CandidateForExamCandidate.CandidateName;
            lbl_ExamName.Text = oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamName;
            lbl_ExamDuration.Text = oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamDurationinHour.ToString();
            lbl_ExamTotal.Text = oCandidateForExam.CadidateCandidateExam.CandiadteExamExam.ExamTotalMarks.ToString();

            ShowExamConstraint(oCandidateForExam.CadidateCandidateExam.CandiadteExamExam);

            oResult = oCandidateExamProcessBO.LoadCategoriesWithType(oCandidateForExam);

            if (oResult.ResultIsSuccess)
            {
                oListCandidateMenu = oResult.ResultObject as List<CandidateMenu>;

                TreeNode oCategoryRoot = new TreeNode("Categories", "Categories");

                treeViewQuestions.Nodes.Add(oCategoryRoot);

                foreach (CandidateMenu oCandidateMenuInList in oListCandidateMenu) //CandidateMenu= Category Name
                {
                    TreeNode oCategoryName = new TreeNode(oCandidateMenuInList.CandidateMenuCategory.CategoryName, oCandidateMenuInList.CandidateMenuCategory.CategoryID.ToString());

                    oCategoryRoot.ChildNodes.Add(oCategoryName);

                    foreach (QuestionType oQuestionTypeInList in oCandidateMenuInList.CandidateMenuCategoryQuestionType)
                    {
                        TreeNode oTypeName = new TreeNode(oQuestionTypeInList.QuestionTypeName, oQuestionTypeInList.QuestionTypeName+":"+oQuestionTypeInList.QuestionTypeTotalQuestions.ToString());

                        oCategoryName.ChildNodes.Add(oTypeName);

                        LoadQuestionsRandomlyAccordingToCategoryAndType(oCandidateMenuInList.CandidateMenuCategory, oQuestionTypeInList);

                    }
                }

                SetoListCandidateAnswerQuestionIntoSession();

                if (treeViewQuestions.Nodes[0].ChildNodes[0].ChildNodes[0] != null)
                {
                    treeViewQuestions.Nodes[0].ChildNodes[0].ChildNodes[0].Selected = true;
                    //treeViewQuestions.Nodes[0].ChildNodes[0].Selected = true;
                }
            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = oResult.ResultMessage;
            }
        }
        catch (Exception oEx)
        {

        }
    }