public Result QuestionSetupListShowByQuestionLevel(QuestionSetup oQuestionSetup)
        {
            Result oResult = new Result();
            QuestionDAO oQuestionDAO = new QuestionDAO();

            try
            {
                oResult = oQuestionDAO.QuestionSetupListShowByQuestionLevel(oQuestionSetup);
            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultMessage = "Exception occured during QuestionSetupListShowByQuestionLevel..";
                oResult.ResultException = oEx;
            }

            return oResult;
        }
        public Result QuestionSetupListShow(QuestionSetup oQuestionSetup)
        {
            //new CLogger("Start QuestionSetupListShow QuestionBO+BO", FileNameManagerInDLL.sLogFileName, 1).WriteLog("Start QuestionSetupListShow QuestionBO+BO", ELogLevel.Debug);

            Result oResult = new Result();
            QuestionDAO oQuestionDAO = new QuestionDAO();

            try
            {
                oResult = oQuestionDAO.QuestionSetupListShow(oQuestionSetup);
            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultMessage = "Exception occured during Question Setup List Show..";
                oResult.ResultException = oEx;

                //new CLogger("Exception QuestionSetupListShow QuestionBO+BO", FileNameManagerInDLL.sLogFileName, 1).WriteLog("Exception QuestionSetupListShow QuestionBO+BO", ELogLevel.Debug, oEx);
            }

            //new CLogger("Out QuestionSetupListShow QuestionBO+BO", FileNameManagerInDLL.sLogFileName, 1).WriteLog("Out QuestionSetupListShow QuestionBO+BO", ELogLevel.Debug);

            return oResult;
        }
        /// <summary>
        /// This method show the questions according to category,type,questionlevel.
        /// And these questions are shown to setup them for an exam
        /// </summary>
        /// <param name="oQuestion"> It takes Question Object </param>
        /// <param name="oExam"> It takes Exam Object </param>
        /// <returns> It returns Result Object </returns>
        public Result QuestionListShowForSetupByQuestionLevel(Question oQuestion, Exam oExam)
        {
            logger.Info("Start QuestionListShowForSetupByQuestionLevel QuestionDAO+DAO");

            Result oResult = new Result();
            DAOUtil oDAOUtil = new DAOUtil();

            SqlDataReader oSqlDataReader = null;

            String sSelect = String.Empty;
            String sChoiceSelect = String.Empty;

            List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>();

            try
            {
                //sSelect = "select distinct QuestionID,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID,"
                //    + " QuestionTypeID,QuestionPossibleAnswerTime,QuestionLabelID,EX_Label.LabelName,EX_Label.LabelPrerequisite"
                //    + " from EX_Question left join EX_Label on EX_Question.QuestionLabelID=EX_Label.LabelID where QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID +
                //    "' and QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "'";

                if (oQuestion.QuestionCreator.SystemUserName.ToLower().Equals("administrator"))
                {
                    //sSelect = "select distinct EX_Question.QuestionID as EntryQuestionID,EX_QuestionGeneration.QuestionID as GeneratedQuestionID,EX_QuestionGeneration.SetupQuestionMark,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID,QuestionTypeID,EX_Question.QuestionPossibleAnswerTime from EX_Question left join EX_QuestionGeneration on EX_Question.QuestionID=EX_QuestionGeneration.QuestionID where EX_Question.QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID + "' and EX_Question.QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "'";

                    //sSelect = "select distinct QuestionID,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID," +
                    //"QuestionTypeID,QuestionPossibleAnswerTime,QuestionLabelID from EX_Question where QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID +
                    //"' and QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "' and QuestionLabelID='"+oQuestion.QuestionLevel.LevelID+"'";

                    sSelect = "select distinct QuestionID,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID,"
                        + " QuestionTypeID,QuestionPossibleAnswerTime,QuestionLabelID,EX_Label.LabelName,EX_Label.LabelPrerequisite"
                        + " from EX_Question inner join EX_Label on EX_Question.QuestionLabelID=EX_Label.LabelID where QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID +
                        "' and QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "' and QuestionLabelID='" + oQuestion.QuestionLevel.LevelID + "'";
                }
                else
                {
                    //sSelect = "select distinct EX_Question.QuestionID as EntryQuestionID,EX_QuestionGeneration.QuestionID as GeneratedQuestionID,EX_QuestionGeneration.SetupQuestionMark,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID,QuestionTypeID,EX_Question.QuestionPossibleAnswerTime from EX_Question left join EX_QuestionGeneration on EX_Question.QuestionID=EX_QuestionGeneration.QuestionID where EX_Question.QuestionCreatorID='" + oQuestion.QuestionCreator.SystemUserID + "' and EX_Question.QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID + "' and EX_Question.QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "'";

                    //sSelect = "select distinct QuestionID,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID," +
                    //"QuestionTypeID,QuestionPossibleAnswerTime,QuestionLabelID from EX_Question where QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID +
                    //"' and QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "' and QuestionLabelID='" + oQuestion.QuestionLevel.LevelID + "'";

                    sSelect = "select distinct QuestionID,QuestionText,QuestionCreatorID,QuestionDefaultMark,QuestionCategoryID,"
                        + " QuestionTypeID,QuestionPossibleAnswerTime,QuestionLabelID,EX_Label.LabelName,EX_Label.LabelPrerequisite"
                        + " from EX_Question inner join EX_Label on EX_Question.QuestionLabelID=EX_Label.LabelID where QuestionCategoryID='" + oQuestion.QuestionCategory.CategoryID +
                        "' and QuestionTypeID='" + oQuestion.QuestionQuestionType.QuestionTypeID + "' and QuestionLabelID='" + oQuestion.QuestionLevel.LevelID + "'";
                }

                oSqlDataReader = oDAOUtil.GetReader(sSelect);

                while (oSqlDataReader.Read())
                {
                    QuestionSetup oPopulatedQuestionSetup = new QuestionSetup();

                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionID = new Guid(oSqlDataReader["QuestionID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionText = oSqlDataReader["QuestionText"].ToString();
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionCreator.SystemUserID = new Guid(oSqlDataReader["QuestionCreatorID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionDefaultMark = float.Parse(oSqlDataReader["QuestionDefaultMark"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionCategory.CategoryID = int.Parse(oSqlDataReader["QuestionCategoryID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionQuestionType.QuestionTypeID = int.Parse(oSqlDataReader["QuestionTypeID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionPossibleAnswerTime = float.Parse(oSqlDataReader["QuestionPossibleAnswerTime"].ToString());

                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelID = new Guid(oSqlDataReader["QuestionLabelID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelName = oSqlDataReader["LabelName"].ToString();
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelDescription = oSqlDataReader["LabelPrerequisite"].ToString();

                    oPopulatedQuestionSetup.QuestionSetupMark = oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionDefaultMark;
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionIsUsed = false;

                    //if (oSqlDataReader["GeneratedQuestionID"].ToString().Length > 0)
                    //{
                    //    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionIsUsed = true;
                    //}

                    //if (oSqlDataReader["SetupQuestionMark"].ToString().Length > 0)
                    //{
                    //    oPopulatedQuestionSetup.QuestionSetupMark = float.Parse(oSqlDataReader["SetupQuestionMark"].ToString());
                    //}

                    oListQuestionSetup.Add(oPopulatedQuestionSetup);
                }

                oSqlDataReader.Close();

                if (oQuestion.QuestionQuestionType.QuestionTypeID == 0) //enum should be used here
                {
                    foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetup)
                    {
                        sChoiceSelect = "select ObjectiveAnswer,ObjectiveAnswerIsValid from EX_Objective where ObjectiveQuestionID='" + oQuestionSetupInList.QuestionSetupQuestion.QuestionID + "'";

                        List<Choice> oListChoice = new List<Choice>();

                        oSqlDataReader = oDAOUtil.GetReader(sChoiceSelect);

                        while (oSqlDataReader.Read())
                        {
                            //prepare the choices for a particular questtion......
                            //and populate oListQuestion
                            Choice oChoice = new Choice();

                            oChoice.ChoiceName = oSqlDataReader["ObjectiveAnswer"].ToString();
                            oChoice.ChoiceIsValid = Convert.ToBoolean(oSqlDataReader["ObjectiveAnswerIsValid"].ToString());

                            oListChoice.Add(oChoice);
                        }

                        oSqlDataReader.Close();

                        oQuestionSetupInList.QuestionSetupQuestion.QuestionObjectiveType.ListOfChoices = oListChoice;
                    }
                }

                foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetup)
                {
                    sSelect = "select distinct EX_QuestionGeneration.QuestionID as GeneratedQuestionID,EX_QuestionGeneration.SetupQuestionMark from EX_QuestionGeneration where EX_QuestionGeneration.QuestionID='" + oQuestionSetupInList.QuestionSetupQuestion.QuestionID + "' and EX_QuestionGeneration.ExamID='" + oExam.ExamID + "'";

                    oSqlDataReader = oDAOUtil.GetReader(sSelect);

                    if (oSqlDataReader.HasRows)
                    {
                        oQuestionSetupInList.QuestionSetupQuestion.QuestionIsUsed = true;

                        while (oSqlDataReader.Read())
                        {
                            if (oSqlDataReader["SetupQuestionMark"].ToString().Length > 0)
                            {
                                oQuestionSetupInList.QuestionSetupMark = float.Parse(oSqlDataReader["SetupQuestionMark"].ToString());
                            }
                        }
                    }

                    oSqlDataReader.Close();
                }

                oResult.ResultObject = oListQuestionSetup;
                oResult.ResultMessage = "QuestionListShowForSetupByQuestionLevel Success...";
                oResult.ResultIsSuccess = true;
            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultMessage = "Exception occured during QuestionListShowForSetupByQuestionLevel...";
                oResult.ResultException = oEx;

                logger.Info("Exception QuestionListShowForSetupByQuestionLevel QuestionDAO+DAO", oEx);
            }
            finally
            {
                if (oSqlDataReader != null && !oSqlDataReader.IsClosed)
                {
                    oSqlDataReader.Close();
                }
            }

            logger.Info("End QuestionListShowForSetupByQuestionLevel QuestionDAO+DAO");

            return oResult;
        }
        public Result LoadAllQuestionsOfAnExam(Exam oSelectedExam)
        {
            logger.Info("Start LoadAllQuestionsOfAnExam QuestionDAO+DAO");

            Result oResult = new Result();
            DAOUtil oDAOUtil = new DAOUtil();

            SqlDataReader oSqlDataReader = null;

            String sSelect = String.Empty;

            List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>();

            try
            {
                sSelect="select distinct EX_QuestionGeneration.ExamID,"
                +" EX_QuestionGeneration.SetupQuestionMark,"
                +" EX_QuestionGeneration.GeneratorID,"
                +" EX_Question.QuestionID,"
                +" EX_Question.QuestionText,EX_Question.QuestionTypeID,"
                +" EX_Question.QuestionPossibleAnswerTime,"
                +" EX_Label.LabelID,"
                +" EX_Label.LabelName,"
                +" EX_Category.CategoryID,EX_Category.CategoryName"
                +" from EX_QuestionGeneration,EX_Question,EX_Category,EX_Label"
                +" where EX_Question.QuestionLabelID=EX_Label.LabelID"
                +" and EX_Question.QuestionCategoryID=EX_Category.CategoryID"
                +" and EX_Question.QuestionID=EX_QuestionGeneration.QuestionID"
                +" and EX_QuestionGeneration.ExamID='" + oSelectedExam.ExamID + "'"
                +" order by EX_Category.CategoryName,EX_Label.LabelName,EX_Question.QuestionTypeID asc";

                oSqlDataReader = oDAOUtil.GetReader(sSelect);

                while (oSqlDataReader.Read())
                {
                    QuestionSetup oPopulatedQuestionSetup = new QuestionSetup();

                    oPopulatedQuestionSetup.QuestionSetupExam.ExamID = new Guid(oSqlDataReader["ExamID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupMark = float.Parse(oSqlDataReader["SetupQuestionMark"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupSystemUser.SystemUserID = new Guid(oSqlDataReader["GeneratorID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionID = new Guid(oSqlDataReader["QuestionID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionText = oSqlDataReader["QuestionText"].ToString();
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionQuestionType.QuestionTypeID = int.Parse(oSqlDataReader["QuestionTypeID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionPossibleAnswerTime = float.Parse(oSqlDataReader["QuestionPossibleAnswerTime"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelID = new Guid(oSqlDataReader["LabelID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelName = oSqlDataReader["LabelName"].ToString();
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionCategory.CategoryID = int.Parse(oSqlDataReader["CategoryID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionCategory.CategoryName = oSqlDataReader["CategoryName"].ToString();

                    oListQuestionSetup.Add(oPopulatedQuestionSetup);
                }

                oSqlDataReader.Close();

                foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetup)
                {
                    if (oQuestionSetupInList.QuestionSetupQuestion.QuestionQuestionType.QuestionTypeID == 0)
                    {
                        sSelect = "select EX_Objective.ObjectiveQuestionID,EX_Objective.ObjectiveAnswer,"
                        +" EX_Objective.ObjectiveAnswerIsValid from EX_Objective"
                        + " where EX_Objective.ObjectiveQuestionID = '" + oQuestionSetupInList.QuestionSetupQuestion.QuestionID + "'";

                        List<Choice> oListChoice = new List<Choice>();

                        oSqlDataReader = oDAOUtil.GetReader(sSelect);

                        while (oSqlDataReader.Read())
                        {
                            Choice oChoice = new Choice();

                            oChoice.ChoiceName = oSqlDataReader["ObjectiveAnswer"].ToString();
                            oChoice.ChoiceIsValid = Convert.ToBoolean(oSqlDataReader["ObjectiveAnswerIsValid"].ToString());

                            oListChoice.Add(oChoice);
                        }

                        oSqlDataReader.Close();

                        oQuestionSetupInList.QuestionSetupQuestion.QuestionObjectiveType.ListOfChoices = oListChoice;
                    }

                }

                oResult.ResultObject = oListQuestionSetup;
                oResult.ResultMessage = "LoadAllQuestionsOfAnExam success...";
                oResult.ResultIsSuccess = true;

            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultMessage = "Exception occured during LoadAllQuestionsOfAnExam...";
                oResult.ResultException = oEx;

                logger.Info("Exception LoadAllQuestionsOfAnExam QuestionDAO+DAO", oEx);
            }
            finally
            {
                if (oSqlDataReader != null && !oSqlDataReader.IsClosed)
                {
                    oSqlDataReader.Close();
                }
            }

            logger.Info("End LoadAllQuestionsOfAnExam QuestionDAO+DAO");

            return oResult;
        }
        /// <summary>
        /// This method show the questions according to question level.
        /// And these questions are already been setup.
        /// </summary>
        /// <param name="oQuestionSetup"> It takes QuestionSetup Object </param>
        /// <returns> It returns Result Object </returns>
        public Result QuestionSetupListShowByQuestionLevel(QuestionSetup oQuestionSetup)
        {
            logger.Info("Start QuestionSetupListShowByQuestionLevel QuestionDAO+DAO");

            Result oResult = new Result();
            DAOUtil oDAOUtil = new DAOUtil();

            String sSelect = String.Empty;

            List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>();

            SqlDataReader oSqlDataReader = null;

            try
            {
                if (oQuestionSetup.QuestionSetupQuestion.QuestionCreator.SystemUserName.Equals("administrator"))
                {
                    sSelect = "select EX_QuestionGeneration.ExamID,EX_QuestionGeneration.QuestionID,EX_QuestionGeneration.SetupQuestionMark,EX_QuestionGeneration.GeneratorID,"
                    +" EX_Question.QuestionText,EX_Question.QuestionTypeID,EX_Question.QuestionCategoryID,EX_Question.QuestionPossibleAnswerTime,"
                    +" EX_Question.QuestionLabelID,EX_Label.LabelName,EX_Label.LabelPrerequisite"
                    +" from EX_Label inner join EX_Question on EX_Label.LabelID=EX_Question.QuestionLabelID inner join"
                    + " EX_QuestionGeneration on EX_Question.QuestionID=EX_QuestionGeneration.QuestionID"
                    +" where EX_QuestionGeneration.ExamID='" + oQuestionSetup.QuestionSetupExam.ExamID + "' and EX_Question.QuestionTypeID='" + oQuestionSetup.QuestionSetupQuestion.QuestionQuestionType.QuestionTypeID + "'"
                    +" and EX_Question.QuestionCategoryID='" + oQuestionSetup.QuestionSetupQuestion.QuestionCategory.CategoryID + "'"
                    +" and EX_Question.QuestionLabelID='" + oQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelID+"'";
                }
                else
                {
                    sSelect = "select EX_QuestionGeneration.ExamID,EX_QuestionGeneration.QuestionID,EX_QuestionGeneration.SetupQuestionMark,EX_QuestionGeneration.GeneratorID,"
                        + " EX_Question.QuestionText,EX_Question.QuestionTypeID,EX_Question.QuestionCategoryID,EX_Question.QuestionPossibleAnswerTime,"
                        + " EX_Question.QuestionLabelID,EX_Label.LabelName,EX_Label.LabelPrerequisite"
                        + " from EX_Label inner join EX_Question on EX_Label.LabelID=EX_Question.QuestionLabelID inner join"
                        + " EX_QuestionGeneration on EX_Question.QuestionID=EX_QuestionGeneration.QuestionID"
                        +" where EX_QuestionGeneration.ExamID='" + oQuestionSetup.QuestionSetupExam.ExamID + "' and EX_QuestionGeneration.GeneratorID='" + oQuestionSetup.QuestionSetupQuestion.QuestionCreator.SystemUserID + "'"
                        +" and EX_Question.QuestionTypeID='" + oQuestionSetup.QuestionSetupQuestion.QuestionQuestionType.QuestionTypeID + "' and EX_Question.QuestionCategoryID='" + oQuestionSetup.QuestionSetupQuestion.QuestionCategory.CategoryID + "'"
                        + " and EX_Question.QuestionLabelID='" + oQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelID+"'";
                }

                oSqlDataReader = oDAOUtil.GetReader(sSelect);

                while (oSqlDataReader.Read())
                {
                    QuestionSetup oPopulatedQuestionSetup = new QuestionSetup();

                    oPopulatedQuestionSetup.QuestionSetupExam.ExamID = new Guid(oSqlDataReader["ExamID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionID = new Guid(oSqlDataReader["QuestionID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupMark = float.Parse(oSqlDataReader["SetupQuestionMark"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupSystemUser.SystemUserID = new Guid(oSqlDataReader["GeneratorID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionText = oSqlDataReader["QuestionText"].ToString();
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionQuestionType.QuestionTypeID = int.Parse(oSqlDataReader["QuestionTypeID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionCategory.CategoryID = int.Parse(oSqlDataReader["QuestionCategoryID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionPossibleAnswerTime = float.Parse(oSqlDataReader["QuestionPossibleAnswerTime"].ToString());

                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelID = new Guid(oSqlDataReader["QuestionLabelID"].ToString());
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelName = oSqlDataReader["LabelName"].ToString();
                    oPopulatedQuestionSetup.QuestionSetupQuestion.QuestionLevel.LevelDescription = oSqlDataReader["LabelPrerequisite"].ToString();

                    oListQuestionSetup.Add(oPopulatedQuestionSetup);
                }

                oSqlDataReader.Close();

                oResult.ResultObject = oListQuestionSetup;
                oResult.ResultMessage = "QuestionSetupListShowByQuestionLevel success...";
                oResult.ResultIsSuccess = true;
            }
            catch (Exception oEx)
            {
                oResult.ResultIsSuccess = false;
                oResult.ResultException = oEx;
                oResult.ResultMessage = "Exception occured during QuestionSetup ListShow ByQuestionLevel...";

                logger.Info("Exception QuestionSetupListShowByQuestionLevel QuestionDAO+DAO", oEx);
            }
            finally
            {
                if (oSqlDataReader != null && !oSqlDataReader.IsClosed)
                {
                    oSqlDataReader.Close();
                }
            }

            logger.Info("End QuestionSetupListShowByQuestionLevel QuestionDAO+DAO");

            return oResult;
        }
    protected void btn_Setup_Click(object sender, EventArgs e)
    {
        String sHiddenFiledValue = HiddenFieldForStoreChkBoxIndex.Value;
        String sHiddenFiledMark = HiddenFieldForStoreTxtBoxMark.Value;
        String sCheckedRowIndex = String.Empty;
        String sNewRowMark = String.Empty;

        Exam oExam = new Exam();
        Result oResult = new Result();
        QuestionBO oQuestionBO = new QuestionBO();

        List<QuestionSetup> oListQuestionSetupForShow = new List<QuestionSetup>();
        List<QuestionSetup> oListQuestionSetup = new List<QuestionSetup>();

        float fTotalMarks = 0f;
        float fTotalTime = 0f;

        bool IsRandomSelection = false;
        //bool IsSetupSuccessByLevelOrFromList = false;
        bool IsBylevelSelection = false;

        try
        {
            if (oObject!= null)
            {
                oExam = (Exam)oObject;

                //oExam.ExamConstraint="some value from the UI";
                //update EX_Exam in the DAO by the oExam.ExamConstraint.
                //oExam.ExamConstraint is defaultly =0;

                if(IsBeforeExamStarted(oExam))
                {
                    if (dr_ListOrRandom.SelectedValue.Equals("By Question Level"))
                    {
                        IsBylevelSelection = true;
                    }

                    if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]") && !lbl_Questions.Text.Equals(String.Empty) && (dr_ListOrRandom.SelectedValue.Equals("From List") || (dr_ListOrRandom.SelectedValue.Equals("By Question Level") && !drdnSelectQuestionLevel.SelectedValue.Equals("[Select One]"))))
                    {
                        int iNextStartIndex = 0;
                        int Index = 0;
                        int i = 0;
                        int j = 0;
                        float f = 0f;
                        Boolean flag = false;

                        //oListQuestionSetupForShow = (List<QuestionSetup>)Utils.GetSession(SessionManager.csStoreGridView);
                        oListQuestionSetupForShow = (List<QuestionSetup>)this.ViewState[SessionManager.csStoreGridView];

                        int[] iarrChecked = new int[oListQuestionSetupForShow.Count];
                        float[] iarrNewMark = new float[oListQuestionSetupForShow.Count];

                        for (j = 0; j < iarrChecked.Length; j++)
                        {
                            iarrChecked[j] = 0;
                            iarrNewMark[j] = oListQuestionSetupForShow[j].QuestionSetupMark;
                        }

                        while (iNextStartIndex < sHiddenFiledValue.Length && sHiddenFiledValue.IndexOf(':', iNextStartIndex) >= 0)
                        {
                            Index = sHiddenFiledValue.IndexOf(':', iNextStartIndex);

                            sCheckedRowIndex = sHiddenFiledValue.Substring(iNextStartIndex, Index - iNextStartIndex);

                            if (int.TryParse(sCheckedRowIndex, out i))
                            {
                                iarrChecked[Grid_Questions.PageIndex * Grid_Questions.PageSize + int.Parse(sCheckedRowIndex)] = 1; //marked
                                flag = true;
                            }

                            iNextStartIndex = Index + 1;
                        }

                        if (flag)
                        {
                            iNextStartIndex = 0;
                            Index = 0;

                            //get the marks from the text boxes in the GridView
                            i = 0;
                            while (iNextStartIndex < sHiddenFiledMark.Length && sHiddenFiledMark.IndexOf(':', iNextStartIndex) >= 0)
                            {
                                Index = sHiddenFiledMark.IndexOf(':', iNextStartIndex);

                                sNewRowMark = sHiddenFiledMark.Substring(iNextStartIndex, Index - iNextStartIndex);

                                if (float.TryParse(sNewRowMark, out f))
                                {
                                    iarrNewMark[Grid_Questions.PageIndex * Grid_Questions.PageSize + i] = float.Parse(sNewRowMark); //marked
                                }
                                //else
                                //{
                                //    iarrNewMark[Grid_Questions.PageIndex * Grid_Questions.PageSize + i] = oListQuestionSetupForShow[Grid_Questions.PageIndex * Grid_Questions.PageSize + i].QuestionSetupMark;
                                //}

                                i++;
                                iNextStartIndex = Index + 1;
                            }

                            oResult = oQuestionBO.GetTotalLastSetupQuestionMark(oExam);

                            if (oResult.ResultIsSuccess)
                            {
                                fTotalMarks = (float)oResult.ResultObject;

                                //populate the List of QuestionSetupObject

                                i = 0;
                                foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow)
                                {
                                    QuestionSetup oQuestionSetup = new QuestionSetup();

                                    oQuestionSetup.QuestionSetupExam = oExam;
                                    oQuestionSetup.QuestionSetupGenerationTime = DateTime.Now;
                                    oQuestionSetup.QuestionSetupSystemUser = oSystemUser;
                                    oQuestionSetup.QuestionSetupMark = iarrNewMark[i];

                                    if (!oQuestionSetupInList.QuestionSetupQuestion.QuestionIsUsed && iarrChecked[i]==1)
                                    {
                                        fTotalMarks = fTotalMarks + iarrNewMark[i];
                                    }

                                    oQuestionSetup.QuestionSetupQuestion = oQuestionSetupInList.QuestionSetupQuestion;

                                    oListQuestionSetup.Add(oQuestionSetup);

                                    i++;
                                }

                                if (fTotalMarks <= (float)oExam.ExamTotalMarks)
                                {
                                    oResult = oQuestionBO.GetTotalLastSetupQuestionTime(oExam);

                                    if (oResult.ResultIsSuccess)
                                    {
                                        //sum the fTotalTime by the Grid's possible time for each question

                                        fTotalTime = (float)oResult.ResultObject;

                                        i=0;

                                        foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow)
                                        {
                                            if (!oQuestionSetupInList.QuestionSetupQuestion.QuestionIsUsed && iarrChecked[i] == 1)
                                            {
                                                fTotalTime = fTotalTime + oQuestionSetupInList.QuestionSetupQuestion.QuestionPossibleAnswerTime;
                                            }

                                            i++;
                                        }

                                        if (fTotalTime <= (float)(oExam.ExamDurationinHour * 60f))
                                        {
                                            //now call the BO to insert question
                                            oResult = oQuestionBO.QuestionSetup(oListQuestionSetup, iarrChecked);

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

                                                i = 0;

                                                foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetup)
                                                {
                                                    oListQuestionSetupForShow[i].QuestionSetupMark = oQuestionSetupInList.QuestionSetupMark;

                                                    i++;
                                                }

                                                //Utils.SetSession(SessionManager.csStoreGridView, oListQuestionSetupForShow);
                                                this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionSetupForShow);

                                                //LoadCategoryfromSession();
                                                //LoadQuestionType();
                                                //LoadSelectionDropdownList();

                                                //IsSetupSuccessByLevelOrFromList = true;
                                            }
                                            else
                                            {
                                                lbl_error.ForeColor = Color.Red;
                                                lbl_error.Text = oResult.ResultMessage;
                                            }
                                        }
                                        else
                                        {
                                            lbl_error.ForeColor = Color.Red;
                                            lbl_error.Text = "Total Time OverFlow.";
                                        }

                                    }
                                    else
                                    {
                                        lbl_error.ForeColor = Color.Red;
                                        lbl_error.Text = oResult.ResultMessage;
                                    }
                                }
                                else
                                {
                                    lbl_error.ForeColor = Color.Red;
                                    lbl_error.Text = "Total Marks OverFlow.";
                                }
                            }
                            else
                            {
                                lbl_error.ForeColor = Color.Red;
                                lbl_error.Text = oResult.ResultMessage;
                            }
                        }
                        else
                        {
                            lbl_error.ForeColor = Color.Red;
                            lbl_error.Text = "Select a Question please.";
                        }
                    }
                    else if (!dr_Category.SelectedValue.Equals("[Select One]") && !dr_Type.SelectedValue.Equals("[Select One]") && lbl_Questions.Text.Equals(String.Empty) && dr_ListOrRandom.SelectedValue.Equals("Random"))
                    {

                        IsRandomSelection = true;

                        oListQuestionSetupForShow = (List<QuestionSetup>)this.ViewState[SessionManager.csStoreGridView];

                        int j = 0;
                        int iTotalRandomQuestions = 0;
                        int iFullfillTotalRandomnumber = 0;
                        int iNextRandomIndex = -1000;

                        int[] iarrChecked = new int[oListQuestionSetupForShow.Count];
                        int[] iarrRandomIndexChecked = new int[oListQuestionSetupForShow.Count];

                        for (j = 0; j < iarrChecked.Length; j++)
                        {
                            iarrChecked[j] = 0;
                            iarrRandomIndexChecked[j] = 0;

                        }

                        if (IsValidPositiveInteger(txt_RandomQuestions.Text))
                        {
                            if (int.Parse(txt_RandomQuestions.Text) <= oListQuestionSetupForShow.Count)
                            {
                                iTotalRandomQuestions = int.Parse(txt_RandomQuestions.Text);

                                while (iFullfillTotalRandomnumber < iTotalRandomQuestions)
                                {
                                    iNextRandomIndex = new Random().Next(0, oListQuestionSetupForShow.Count);

                                    if (iarrRandomIndexChecked[iNextRandomIndex] == 0)
                                    {
                                        iFullfillTotalRandomnumber = iFullfillTotalRandomnumber + 1;
                                        iarrRandomIndexChecked[iNextRandomIndex] = 1;
                                        iarrChecked[iNextRandomIndex] = 1;
                                    }
                                }

                                if (iFullfillTotalRandomnumber == iTotalRandomQuestions)
                                {
                                    foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow)
                                    {
                                        oQuestionSetupInList.QuestionSetupExam = oExam;
                                        oQuestionSetupInList.QuestionSetupGenerationTime = DateTime.Now;
                                        oQuestionSetupInList.QuestionSetupSystemUser = oSystemUser;
                                    }

                                    oResult = oQuestionBO.QuestionSetup(oListQuestionSetupForShow, iarrChecked);

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

                                        //Utils.SetSession(SessionManager.csStoreGridView, oListQuestionSetupForShow);
                                        this.ViewState.Add(SessionManager.csStoreGridView, oListQuestionSetupForShow);

                                        //LoadCategoryfromSession();
                                        //LoadQuestionType();
                                        //LoadSelectionDropdownList();
                                    }
                                    else
                                    {
                                        lbl_error.ForeColor = Color.Red;
                                        lbl_error.Text = oResult.ResultMessage;
                                    }
                                }

                                lbl_RandomQuestions.Visible = true;
                                txt_RandomQuestions.Visible = true;

                                lblRandomOutOf.Visible = true;
                                txtRandomOutOf.Visible = true;

                                btn_View.Visible = false;

                            }
                            else
                            {
                                lbl_error.ForeColor = Color.Red;
                                lbl_error.Text = "Random question number must less than Total question Number";

                                lbl_RandomQuestions.Visible = true;
                                txt_RandomQuestions.Visible = true;

                                lblRandomOutOf.Visible = true;
                                txtRandomOutOf.Visible = true;

                                btn_View.Visible = false;
                            }
                        }
                        else
                        {
                            lbl_error.ForeColor = Color.Red;
                            lbl_error.Text = "Random question number must greater than zero ";

                            lbl_RandomQuestions.Visible = true;
                            txt_RandomQuestions.Visible = true;

                            lblRandomOutOf.Visible = true;
                            txtRandomOutOf.Visible = true;

                            btn_View.Visible = false;
                        }
                    }
                    else
                    {
                        lbl_error.ForeColor = Color.Red;
                        lbl_error.Text = "Please Select Category,Type & SelectionType.";

                        if (dr_ListOrRandom.SelectedValue.Equals("By Question Level") && drdnSelectQuestionLevel.SelectedValue.Equals("[Select One]"))
                        {
                            lbl_error.Text = "Please Select Category,Type,SelectionType & Question Level.";
                        }

                    }
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = "Can not setup Question After Exam Started.";
                }
            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = "Select an Exam please.";
            }

            //rdo_QuestionSelection.Items[0].Selected = false;
            //rdo_QuestionSelection.Items[1].Selected = false;

            if (!IsRandomSelection)
            {
                if (IsBylevelSelection)
                {
                    lblQuestionLevel.Visible = true;
                    drdnSelectQuestionLevel.Visible = true;
                }

                if (oListQuestionSetupForShow.Count > 0)
                {
                    lbl_Questions.Text = "Questions";

                    Grid_Questions.Visible = true;

                    //List<Question> oListQuestionForGridViewBind = new List<Question>();

                    //foreach (QuestionSetup oQuestionSetupInList in oListQuestionSetupForShow)
                    //{
                    //    oListQuestionForGridViewBind.Add(oQuestionSetupInList.QuestionSetupQuestion);
                    //}

                    Grid_Questions.DataSource = oListQuestionSetupForShow;

                    //Grid_Questions.DataSource = oListQuestionForGridViewBind;
                    Grid_Questions.DataBind();

                    pnl_questions.Visible = true;
                    pnl_questions.ScrollBars = ScrollBars.Auto;
                    //pnl_questions.Controls.Add(Grid_Questions);
                }
                else
                {
                    lbl_Questions.Text = String.Empty;
                }
            }

            //LoadSelectionDropdownList();

            //lbl_Questions.Text = String.Empty;

            //if (pnl_questions.Controls.Contains(Grid_Questions))
            //{
            //    pnl_questions.Controls.Remove(Grid_Questions);
            //}

        }
        catch (Exception oEx)
        {

        }
    }