Ejemplo n.º 1
0
        public void TestAddPredefinedQuestionResponseDto()
        {
            CreateNewPagePredefinedQuestion();
            long responseKey = FormRegistry.ResponseDao.CreateSubmitResponse(Constants.UnknownCustomer, null, _currentQuestionnaire.QuestionnaireId, ViewType.CleanSheetOverlay).First;
            Assert.Greater(responseKey, 0);

            PredefinedQuestionResponseDto question = new PredefinedQuestionResponseDto();
            PredefinedLocalizedChoiceDto lChoice = FormRegistry.PredefinedQuestionDao.GetLocalizedChoices(null, null, null, _currentPagePredefinedChoices[0].ElementId, null)[0];            
            question.ResponseKey = responseKey;
            question.ChoiceId = _currentPagePredefinedChoices[0].ElementId;
            question.ChoiceLabel = lChoice.ChoiceLabel;
            question.ChoiceText = null;

            Assert.IsTrue(FormRegistry.ResponseDao.Add(question));
        }
Ejemplo n.º 2
0
        private void Write(DbCommand sp, PredefinedQuestionResponseDto dto)
        {
            List<PredefinedQuestionDto> listQuestions = FormRegistry.PredefinedQuestionDao.GetPredefinedQuestions(null, dto.ChoiceId);
            if (listQuestions != null &&
                listQuestions.Count > 0)
            {
                PredefinedQuestionDto pQuestion = listQuestions[0];
                _dbLayer.AddInParameter(sp, "@page_predefined_question_id", DbType.Int32, pQuestion.QuestionId);
                _dbLayer.AddInParameter(sp, "@question_internal_id", DbType.String, pQuestion.InternalId);
                _dbLayer.AddInParameter(sp, "@question_text", DbType.String, pQuestion.QuestionText);
            }

            _dbLayer.AddInParameter(sp, "@response_id", DbType.Int64, dto.ResponseKey);            
            _dbLayer.AddInParameter(sp, "@choice_label", DbType.String, dto.ChoiceLabel);
            _dbLayer.AddInParameter(sp, "@choice_text", DbType.String, dto.ChoiceText);            
        }
Ejemplo n.º 3
0
        public bool Add(PredefinedQuestionResponseDto dto)
        {
            bool retval = false;
            DbCommand sp = null;
            DbConnection connection = null;
            IDataReader reader = null;
            try
            {
                connection = _dbLayer.GetConnection();
                sp = connection.CreateCommand();

                sp.CommandText = "insert_response_predefined_question";
                sp.CommandType = CommandType.StoredProcedure;
                _dbLayer.AddReturnParameter(sp);
                Write(sp, dto);
                sp.ExecuteNonQuery();
                int err = _dbLayer.GetReturnValue(sp);
                if (err == 0)
                {
                    retval = true;
                }
                else
                {
                    Trace.WriteLine("ResponseDao.Add(" + dto + "): returned " + err);
                }
            }
            catch (DbException e)
            {
                Trace.WriteLine("ResponseDao.Add(" + dto + "): " + e.Message);
            }
            finally
            {
                if (reader != null && !reader.IsClosed)
                {
                    reader.Close();
                }

                if (sp != null)
                {
                    sp.Dispose();
                }

                if (connection != null)
                {
                    _dbLayer.ReturnConnection(connection);
                }
                else
                {
                    _dbLayer.ReturnConnection(connection, true);
                }
            }

            return retval;
        }
Ejemplo n.º 4
0
        public override List<ResponseDto> GetResponseDto(long responseId)
        {
            List<ResponseDto> retval = new List<ResponseDto>();
            bIsValidLength = true;

            foreach (Triple<int, string, string> element in _radioTextIds)
            {
                RadioButton b = FindControl(element.Second) as RadioButton;
                if (b != null && b.Checked)
                {
                    int choiceId = element.First;
                    string choiceText = null;
                    int? lovId = null;
                    TextBox tb = null;
                    if (!String.IsNullOrEmpty(element.Third))
                    {
                        tb = FindControl(element.Third) as TextBox;
                        if (tb != null)
                        {
                            choiceText = tb.Text;
                        }
                    }
                    if (Choices != null)
                    {
                        retval.Add(new QuestionResponseDto(responseId, choiceId, choiceText, lovId));
                    }
                    else if (PageQuestionChoices != null)
                    {
                        PredefinedLocalizedChoiceDto lChoice = PredefinedQuestionFacade.GetPredefinedLocalizedChoiceByPagePredefinedChoiceId(choiceId);
                        PagePredefinedQuestionChoiceDto pChoice = null;
                        if(PageQuestionChoices != null)
                            pChoice = PageQuestionChoices.Find(delegate(PagePredefinedQuestionChoiceDto c) { return c.ElementId == choiceId; });
                        if (lChoice != null)
                        {
                            PredefinedQuestionResponseDto pResponse = new PredefinedQuestionResponseDto();
                            pResponse.ResponseKey = responseId;
                            pResponse.ChoiceId = choiceId;
                            pResponse.ChoiceLabel = lChoice.ChoiceLabel;
                            pResponse.ChoiceText = choiceText;
                            retval.Add(pResponse);
                        }

                        if (pChoice.PChoice.SortSequence == 999 && !String.IsNullOrEmpty(pChoice.PChoice.OtherText) && !String.IsNullOrEmpty(pChoice.PChoice.ErrorMessage))
                        {
                            if (choiceText.Length > 4000)
                            {
                                bIsValidLength = false;
                                if ((!_errorHandledByPage) && (Page is ITopErrorHolder))
                                {
                                    _errorHandledByPage = ((ITopErrorHolder)Page).RegisterErrorMessage(this, pChoice.PChoice.ErrorMessage, tb);
                                }
                            }
                        }
                    }
                }
            }

            return retval;
        }
Ejemplo n.º 5
0
        public override List<ResponseDto> GetResponseDto(long responseId)
        {
            //int? listOfValuesId = null;
            //string choiceText = Ux_TheResponse.SelectedItem.Text;
            //int choiceId = 0;
            //if (!Int32.TryParse(Ux_TheResponse.SelectedValue, out choiceId))
            //{
            //    throw new UserCausedException(Constants.UserCausedDataFormatIncorrect);
            //}
            //List<ResponseDto> retval = null;
            //if (choiceId != Choices[0].ChoiceId)
            //{
            //    bIsValidResponse = true;
            //    retval = new List<ResponseDto>();
            //    if (Ux_Choice_TheResponse != null)
            //    {
            //        if (Ux_Choice_TheResponse.Visible.Equals(true))
            //        {
            //            if (Choices.Find(delegate(PageElementChoiceDto c) { return c.ChoiceId == choiceId; }).HasExtraTextField)
            //            {
            //                if (!string.IsNullOrEmpty(Ux_Choice_TheResponse.Text.Trim()))
            //                {
            //                    retval.Add(new QuestionResponseDto(responseId, choiceId, Ux_Choice_TheResponse.Text, listOfValuesId));
            //                }
            //                else
            //                {
            //                    bOtherChoiceValid = false;
            //                    retval.Add(new QuestionResponseDto(responseId, choiceId, string.Empty, listOfValuesId));
            //                }
            //            }
            //            else
            //            {
            //                retval.Add(new QuestionResponseDto(responseId, choiceId, Ux_Choice_TheResponse.Text, listOfValuesId));
            //            }
            //        }
            //        else
            //        {
            //            retval.Add(new QuestionResponseDto(responseId, choiceId, Ux_Choice_TheResponse.Text, listOfValuesId));
            //        }
            //    }
            //    else
            //    {
            //        retval.Add(new QuestionResponseDto(responseId, choiceId, null, listOfValuesId));
            //    }
            //}
            //else
            //{
            //    bIsValidResponse = false;
            //}



            int? listOfValuesId = null;
            string choiceText = string.Empty;
            int choiceId = 0;

            List<ResponseDto> retval = null;
            TextBox tb_mailto = null;

            foreach (Triple<int, string, string> element in _radioTextIds)
            {
                DropDownList Ux_ddTheResponse = FindControl(element.Second) as DropDownList;

                if (Ux_ddTheResponse != null)
                {
                    choiceText = Ux_ddTheResponse.SelectedItem.Text;

                    if (!Int32.TryParse(Ux_ddTheResponse.SelectedValue, out choiceId))
                    {
                        throw new UserCausedException(Constants.UserCausedDataFormatIncorrect);
                    }

                    if (Choices != null)
                    {
                        if (choiceId != Choices[0].ChoiceId)
                        {
                            retval = new List<ResponseDto>();
                            bIsValidResponse = true;
                            retval = new List<ResponseDto>();
                            foreach (Triple<int, string, string> element1 in _radioChoiceTextIds)
                            {
                                tb_mailto = FindControl(element1.Second) as TextBox;
                            }
                            if (tb_mailto != null)
                            {
                                if (tb_mailto.Visible.Equals(true))
                                {
                                    if (Choices.Find(delegate(PageElementChoiceDto c) { return c.ChoiceId == choiceId; }).HasExtraTextField)
                                    {
                                        if (!string.IsNullOrEmpty(tb_mailto.Text.Trim()))
                                        {
                                            retval.Add(new QuestionResponseDto(responseId, choiceId, tb_mailto.Text, listOfValuesId));
                                        }
                                        else
                                        {
                                            bOtherChoiceValid = false;

                                            retval.Add(new QuestionResponseDto(responseId, choiceId, string.Empty, listOfValuesId));
                                        }
                                    }
                                    else
                                    {
                                        retval.Add(new QuestionResponseDto(responseId, choiceId, null, listOfValuesId));
                                    }
                                }
                            }
                            else
                            {
                                retval.Add(new QuestionResponseDto(responseId, choiceId, null, listOfValuesId));
                            }
                        }
                        else
                        {
                            retval = new List<ResponseDto>();

                            if (ElementLabelLiteral.ToString().Contains("*"))
                                bIsValidResponse = false;
                        }
                    }
                    else if (PageQuestionChoices != null)
                    {
                        retval = new List<ResponseDto>();
                        bIsValidResponse = true;
                        retval = new List<ResponseDto>();
                        foreach (Triple<int, string, string> element1 in _radioChoiceTextIds)
                        {
                            tb_mailto = FindControl(element1.Second) as TextBox;
                        }
                        if (tb_mailto != null)
                        {
                            if (tb_mailto.Visible.Equals(true))
                            {
                                PagePredefinedQuestionChoiceDto pChoice = null;
                                if (PageQuestionChoices != null)
                                    pChoice = PageQuestionChoices.Find(delegate(PagePredefinedQuestionChoiceDto c) { return c.ElementId == choiceId; });
                                PredefinedLocalizedChoiceDto lChoice = PredefinedQuestionFacade.GetPredefinedLocalizedChoiceByPagePredefinedChoiceId(choiceId);
                                if (lChoice.PChoiceDto.SortSequence == -1)
                                {
                                    if (ElementLabelLiteral.ToString().Contains("*"))
                                        bIsValidResponse = false;
                                }
                                if (pChoice != null &&
                                    pChoice.PChoice.SortSequence == 999 &&
                                    !String.IsNullOrEmpty(pChoice.PChoice.OtherText) &&
                                    !String.IsNullOrEmpty(pChoice.PChoice.ErrorMessage))
                                {
                                    if (!string.IsNullOrEmpty(tb_mailto.Text.Trim()))
                                    {
                                        if (tb_mailto.Text.Length > 4000)
                                        {
                                            bIsValidLength = false;
                                            if ((!_errorHandledByPage) && (Page is ITopErrorHolder))
                                            {
                                                _errorHandledByPage = ((ITopErrorHolder)Page).RegisterErrorMessage(this, pChoice.PChoice.ErrorMessage, tb_mailto);
                                            }
                                        }
                                        if (lChoice != null)
                                        {
                                            PredefinedQuestionResponseDto pResponse = new PredefinedQuestionResponseDto();
                                            pResponse.ResponseKey = responseId;
                                            pResponse.ChoiceId = choiceId;
                                            pResponse.ChoiceLabel = lChoice.ChoiceLabel;
                                            pResponse.ChoiceText = tb_mailto.Text;
                                            retval.Add(pResponse);
                                        }
                                    }
                                    else
                                    {
                                        if (lChoice != null)
                                        {
                                            bOtherChoiceValid = false;
                                            PredefinedQuestionResponseDto pResponse = new PredefinedQuestionResponseDto();
                                            pResponse.ResponseKey = responseId;
                                            pResponse.ChoiceId = choiceId;
                                            pResponse.ChoiceLabel = lChoice.ChoiceLabel;
                                            pResponse.ChoiceText = String.Empty;

                                            retval.Add(pResponse);
                                        }
                                    }
                                }
                                else
                                {
                                    if (lChoice != null)
                                    {
                                        PredefinedQuestionResponseDto pResponse = new PredefinedQuestionResponseDto();
                                        pResponse.ResponseKey = responseId;
                                        pResponse.ChoiceId = choiceId;
                                        pResponse.ChoiceLabel = lChoice.ChoiceLabel;
                                        pResponse.ChoiceText = null;
                                        retval.Add(pResponse);
                                    }
                                }
                            }
                        }
                        else
                        {
                            PagePredefinedQuestionChoiceDto pChoice = null;
                            if (PageQuestionChoices != null)
                                pChoice = PageQuestionChoices.Find(delegate(PagePredefinedQuestionChoiceDto c) { return c.ElementId == choiceId; });
                            PredefinedQuestionResponseDto pResponse = new PredefinedQuestionResponseDto();
                            PredefinedLocalizedChoiceDto lChoice = PredefinedQuestionFacade.GetPredefinedLocalizedChoiceByPagePredefinedChoiceId(choiceId);
                            if (lChoice.PChoiceDto.SortSequence == -1 && PageQuestion.Required)
                            {
                                if (ElementLabelLiteral.ToString().Contains("*"))
                                    bIsValidResponse = false;
                            }
                            pResponse.ResponseKey = responseId;
                            pResponse.ChoiceId = choiceId;
                            pResponse.ChoiceLabel = pChoice.PChoice.ChoiceLabel;
                            pResponse.ChoiceText = null;
                            retval.Add(pResponse);
                        }
                    }
                }
            }

            return retval;
        }