Exemple #1
0
            private void SubmitUserAnswer(BusinessModel.UserAnswerOptionDetail aSelectedAnswerOption)
            {
                int _hasAnsweredCorrectly;

                if (aSelectedAnswerOption.IsCorrect)
                {
                    _hasAnsweredCorrectly = 1;
                }
                else
                {
                    _hasAnsweredCorrectly = 0;
                }

                List <string> _queriesToExecute = new List <string> ();

                _queriesToExecute.Add(string.Format(
                                          "UPDATE tblUserAnswerOption SET IsSelected=1 WHERE pkUserAnswerOptionID={0}",
                                          aSelectedAnswerOption.UserAnswerOptionID));
                _queriesToExecute.Add(string.Format(
                                          "UPDATE tblUserAnswerOption SET IsSelected=0 " +
                                          "WHERE pkUserAnswerOptionID!={0} AND fkUserQuestionID={1}",
                                          aSelectedAnswerOption.UserAnswerOptionID, aSelectedAnswerOption.UserQuestionID));
                _queriesToExecute.Add(string.Format(
                                          "UPDATE tblUserQuestion SET HasAnswered=1, HasAnsweredCorrectly={0}, AnsweredDateTime='{1}', DoSync=1 " +
                                          "WHERE pkUserQuestionID={2}", _hasAnsweredCorrectly, DateTime.UtcNow, aSelectedAnswerOption.UserQuestionID));

                BusinessModel.SQL.Execute(_queriesToExecute);
                //Update the userquestion session too
                AppSession.SelectedExamUserQuestionList = BusinessModel.UserQuestion.GetUserQuestionsBySQL(string.Format(
                                                                                                               "SELECT * FROM tblUserQuestion " +
                                                                                                               "WHERE fkUserExamID={0} ORDER BY Sequence", AppSession.SelectedUserExam.UserExamID));
            }
Exemple #2
0
            public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
            {
                // NOTE: Don't call the base implementation on a Model class
                // see http://docs.xamarin.com/ios/tutorials/Events%2c_Protocols_and_Delegates
                if (m_showQuestionAnswer)
                {
                    //We dont allow any selection when we already display the answer
                    tableView.DeselectRow(indexPath, false);
                }
                else
                {
                    if (indexPath.Section == (int)UnsubmittedQuestionViewSections.QuestionAnswerOptions)
                    {
                        //Update the source global variable so we can pull the answer data later on
                        BusinessModel.UserAnswerOptionDetail _selectedAnswerOptionObj = null;
                        for (int i = 0; i < m_questionAnswerOptions.Count; i++)
                        {
                            BusinessModel.UserAnswerOptionDetail _answerOptionObj = m_questionAnswerOptions [i];
                            if (i == indexPath.Row)
                            {
                                _answerOptionObj.IsSelected = true;
                                _selectedAnswerOptionObj    = _answerOptionObj;
                            }
                            else
                            {
                                UITableViewCell _cellAtRow = tableView.CellAt(NSIndexPath.FromRowSection(i, (int)UnsubmittedQuestionViewSections.QuestionAnswerOptions));
                                if (_cellAtRow != null)
                                {
                                    _cellAtRow.Selected = false;
                                }
                                _answerOptionObj.IsSelected = false;
                            }
                        }

                        if (AppSession.SelectedUserExam.IsLearningMode && AppSettings.AutoSubmitResponse)
                        {
                            SubmitUserAnswer(_selectedAnswerOptionObj);
                            //For learning mode, we update the interface to show the answer
                            m_currentViewController.ReloadCurrentQuestion();
                        }
                        else if (!AppSession.SelectedUserExam.IsLearningMode && AppSettings.AutoAdvanceQuestion)
                        {
                            SubmitUserAnswer(_selectedAnswerOptionObj);
                            //For examination mode, we go to the next answer
                            if (m_currentViewController.CurrentQuestionToDisplayIndex < m_currentViewController.TotalQuestionInExam - 1)
                            {
                                m_currentViewController.GoToNextQuestion();
                            }
                            else
                            {
                                m_currentViewController.NavigationController.PopViewControllerAnimated(true);
                            }
                        }
                    }
                    else
                    {
                        tableView.DeselectRow(indexPath, false);
                    }
                }
            }
Exemple #3
0
            private void btnSubmitQuestionAnswer_Click(object sender, EventArgs e)
            {
                BusinessModel.UserAnswerOption _previousSelectedAnswer = BusinessModel.UserAnswerOption.GetFirstUserAnswerOptionBySQL(string.Format(
                                                                                                                                          "SELECT * FROM tblUserAnswerOption WHERE fkUserQuestionID={0} AND IsSelected=1", m_userQuestion.UserQuestionID));
                BusinessModel.UserAnswerOptionDetail _selectedAnswerOption =
                    (from x in m_questionAnswerOptions where x.IsSelected select x).FirstOrDefault();
                if (_selectedAnswerOption == null)
                {
                    UIAlertView _requiredFieldAlert = new UIAlertView("Selection Required", "Please select an answer before continuing", null, "Ok", null);
                    _requiredFieldAlert.Show();
                    return;
                }


                if (_previousSelectedAnswer == null || _selectedAnswerOption.UserAnswerOptionID == _previousSelectedAnswer.UserAnswerOptionID)
                {
                    SubmitUserAnswer(_selectedAnswerOption);

                    if (AppSession.SelectedUserExam.IsLearningMode)
                    {
                        //For learning mode, we update the interface to show the answer
                        m_currentViewController.ReloadCurrentQuestion();
                    }
                    else
                    {
                        //For examination mode, we go to the next answer
                        if (m_currentViewController.CurrentQuestionToDisplayIndex < m_currentViewController.TotalQuestionInExam - 1)
                        {
                            m_currentViewController.GoToNextQuestion();
                        }
                        else
                        {
                            m_currentViewController.NavigationController.PopViewControllerAnimated(true);
                        }
                    }
                }
                else
                {
                    //The submit button should only shown in learning mode if the user has not answered, so we only need to code the examination mode to advance to next question
                    //For examination mode, we go to the next answer
                    if (AppSession.SelectedUserExam.IsLearningMode)
                    {
                        throw new Exception("There should not be any submit button in learning mode when question has been answered");
                    }
                    else
                    {
                        if (m_currentViewController.CurrentQuestionToDisplayIndex < m_currentViewController.TotalQuestionInExam - 1)
                        {
                            m_currentViewController.GoToNextQuestion();
                        }
                        else
                        {
                            m_currentViewController.NavigationController.PopViewControllerAnimated(true);
                        }
                    }
                }
            }
Exemple #4
0
            public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            {
                UITableViewCell cell;

                if (m_showQuestionAnswer)
                {
                    switch (indexPath.Section)
                    {
                    case (int)SubmittedQuestionViewSections.QuestionStemAndImages:
                        //cell.BackgroundView = new UIView (RectangleF.Empty); // The question stem/images will not have separators
                        //cell.Layer.BorderWidth=0;
                        if (indexPath.Row == 0)
                        {
                            cell = tableView.DequeueReusableCell("cell");
                            if (cell == null)
                            {
                                cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                            }
                            cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                            cell.TextLabel.Text          = m_question.Stem;
                            cell.TextLabel.Lines         = 0;
                            cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        }
                        else if (indexPath.Row == m_questionImages.Count + 1)
                        {
                            cell = tableView.DequeueReusableCell("cell");
                            if (cell == null)
                            {
                                cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                            }
                            cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                            cell.TextLabel.Text          = m_question.LeadIn;
                            cell.TextLabel.Lines         = 0;
                            cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        }
                        else
                        {
                            cell = tableView.DequeueReusableCell("imageCell");
                            if (cell == null)
                            {
                                cell = new CustomImageCell("imageCell");
                            }
                            UIImage _imageAtRow = UIImage.FromFile(m_questionImages [indexPath.Row - 1].FilePath);
                            cell.ImageView.Image = _imageAtRow;
                            cell.ImageView.GestureRecognizers = new UIGestureRecognizer[] { };

                            if (_imageAtRow != null)
                            {
                                cell.ImageView.UserInteractionEnabled = true;
                                UITapGestureRecognizer _tapGesture = new UITapGestureRecognizer();
                                _tapGesture.AddTarget(() => {
                                    HandleImageTapGesture(_tapGesture, m_questionImages [indexPath.Row - 1].ImageID);
                                });
                                cell.ImageView.AddGestureRecognizer(_tapGesture);
                            }
                        }
                        break;

                    case (int)SubmittedQuestionViewSections.QuestionAnswerOptions:
                        cell = tableView.DequeueReusableCell("answerOptionCell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "answerOptionCell");
                        }
                        BusinessModel.UserAnswerOptionDetail _answerOption = m_questionAnswerOptions [indexPath.Row];
                        cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                        cell.TextLabel.Text          = (Char)(Convert.ToInt32('A') + _answerOption.Sequence) + ". " + _answerOption.AnswerOptionText;
                        cell.TextLabel.Lines         = 0;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        if (_answerOption.IsCorrect)
                        {
                            cell.BackgroundColor = UIColor.Green;
                        }
                        else
                        {
                            if (_answerOption.IsSelected)
                            {
                                cell.BackgroundColor = UIColor.Red;
                            }
                            else
                            {
                                cell.BackgroundColor = UIColor.White;
                            }
                        }
                        break;

                    case (int)SubmittedQuestionViewSections.QuestionCommentary:
                        cell = tableView.DequeueReusableCell("cell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                        }
                        cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                        cell.TextLabel.Text          = m_question.Commentary;
                        cell.TextLabel.Lines         = 0;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        break;

                    case (int)SubmittedQuestionViewSections.QuestionReferences:
                        cell = tableView.DequeueReusableCell("cell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                        }
                        cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                        cell.TextLabel.Text          = m_question.Reference;
                        cell.TextLabel.Lines         = 0;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        break;

                    default:
                        cell = tableView.DequeueReusableCell("cell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                        }
                        break;
                    }
                }
                else
                {
                    switch (indexPath.Section)
                    {
                    case (int)UnsubmittedQuestionViewSections.QuestionStemAndImages:
                        //cell.BackgroundView = new UIView (RectangleF.Empty); // The question stem/images will not have separators
                        //cell.Layer.BorderWidth=0;
                        if (indexPath.Row == 0)
                        {
                            cell = tableView.DequeueReusableCell("cell");
                            if (cell == null)
                            {
                                cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                            }
                            cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                            cell.TextLabel.Text          = m_question.Stem.Replace("<br />", "\n");
                            cell.TextLabel.Lines         = 0;
                            cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        }
                        else if (indexPath.Row == m_questionImages.Count + 1)
                        {
                            cell = tableView.DequeueReusableCell("cell");
                            if (cell == null)
                            {
                                cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                            }
                            cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                            cell.TextLabel.Text          = m_question.LeadIn;
                            cell.TextLabel.Lines         = 0;
                            cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        }
                        else
                        {
                            cell = tableView.DequeueReusableCell("imageCell");
                            if (cell == null)
                            {
                                cell = new CustomImageCell("imageCell");
                            }
                            UIImage _imageAtRow = UIImage.FromFile(m_questionImages [indexPath.Row - 1].FilePath);
                            cell.ImageView.Image = _imageAtRow;
                            cell.ImageView.GestureRecognizers = new UIGestureRecognizer[] { };

                            if (_imageAtRow != null)
                            {
                                cell.ImageView.UserInteractionEnabled = true;
                                UITapGestureRecognizer _tapGesture = new UITapGestureRecognizer();
                                _tapGesture.AddTarget(() => {
                                    HandleImageTapGesture(_tapGesture, m_questionImages [indexPath.Row - 1].ImageID);
                                });
                                cell.ImageView.AddGestureRecognizer(_tapGesture);
                            }
                        }
                        break;

                    case (int)UnsubmittedQuestionViewSections.QuestionAnswerOptions:
                        cell = tableView.DequeueReusableCell("answerOptionCell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "answerOptionCell");
                        }
                        BusinessModel.UserAnswerOptionDetail _answerOption = m_questionAnswerOptions [indexPath.Row];
                        cell.TextLabel.Font          = UIFont.SystemFontOfSize(14);
                        cell.TextLabel.Text          = (Char)(Convert.ToInt32('A') + _answerOption.Sequence) + ". " + _answerOption.AnswerOptionText;
                        cell.TextLabel.Lines         = 0;
                        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
                        break;

                    case (int)UnsubmittedQuestionViewSections.SubmitAnswerButton:
                        cell = tableView.DequeueReusableCell("buttonCell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "buttonCell");
                        }

                        btnSubmitQuestionAnswer = new UIButton(UIButtonType.RoundedRect);
                        btnSubmitQuestionAnswer.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
                        btnSubmitQuestionAnswer.Frame            = new System.Drawing.RectangleF(0, 0, cell.ContentView.Frame.Width, 36);
                        btnSubmitQuestionAnswer.SetTitle("Submit", UIControlState.Normal);
                        btnSubmitQuestionAnswer.TouchUpInside += btnSubmitQuestionAnswer_Click;

                        foreach (UIView _subview in cell.ContentView.Subviews)
                        {
                            _subview.RemoveFromSuperview();
                        }
                        cell.ContentView.AddSubview(btnSubmitQuestionAnswer);
                        break;

                    default:
                        cell = tableView.DequeueReusableCell("cell");
                        if (cell == null)
                        {
                            cell = new UITableViewCell(UITableViewCellStyle.Default, "cell");
                        }
                        break;
                    }
                }
                return(cell);
            }