Пример #1
0
        protected override bool RealValidate(IResponsePredefinedQuestionProvider elementToValidate, QuestionnaireDto questionnaire, ref Boolean isLengthCorrect, ref string incorrectLengthMsg)
        {
            bool hasElement = false;
            bool hasEmptyElements = false;
            List<ResponseDto> responses = elementToValidate.GetResponseDto(-1);
            List<int> validationHints = null;
            if (responses != null && responses.Count > 0)
            {
                foreach (ResponseDto response in responses)
                {
                    PredefinedQuestionResponseDto questionResponse = response as PredefinedQuestionResponseDto;

                    if (questionResponse != null)
                    {
                        hasElement = true;
                        if (String.IsNullOrEmpty(questionResponse.ChoiceText))
                        {
                            hasEmptyElements = true;
                            break;
                        }
                        else
                        {
                            if (questionResponse.ChoiceText.Length > 4000)
                            {
                                validationHints = new List<int>();
                                validationHints.Add(PageElementWithErrorDto.InvalidInputTooLong);
                            }
                        }
                    }
                    else
                    {
                        throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator does not accept a response of type \"" + response.GetType().Name + "\"");
                    }
                }
            }
            bool retval = false;

            if (validationHints == null)
            {
                if (elementToValidate.PageQuestion.Required)
                {
                    if (!hasEmptyElements && hasElement)
                    {
                        retval = true;
                    }
                }
                else
                {
                    retval = true;
                }
            }
            else
            {
                elementToValidate.SetValidationHints(validationHints);
            }
            elementToValidate.IsValid = retval;
            return retval;
        }
Пример #2
0
 protected override bool RealValidate(IResponsePredefinedQuestionProvider elementToValidate, QuestionnaireDto questionnaire, ref Boolean isLengthCorrect, ref string incorrectLengthMsg)
 {
     return true;
 }
Пример #3
0
        protected override bool RealValidate(IResponsePredefinedQuestionProvider elementToValidate, QuestionnaireDto questionnaire, ref Boolean isLengthCorrect, ref string incorrectLengthMsg)
        {
            bool hasElements = false;
            bool hasMissingTexts = false;
            isLengthCorrect = true;
            List<ResponseDto> responses = elementToValidate.GetResponseDto(-1);
            if (responses != null && responses.Count > 0)
            {
                List<PagePredefinedQuestionChoiceDto> choices = elementToValidate.PageQuestionChoices;

                if (choices == null || choices.Count < 1)
                {
                    throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Drop down validator requires choices to validate");
                }
                if (responses != null && responses.Count > 0)
                {
                    foreach (ResponseDto response in responses)
                    {
                        PredefinedQuestionResponseDto questionResponse = response as PredefinedQuestionResponseDto;
                        if (questionResponse != null)
                        {
                            hasElements = true;                            
                            PredefinedLocalizedChoiceDto pChoice = PredefinedQuestionFacade.GetPredefinedLocalizedChoiceByPagePredefinedChoiceId(questionResponse.ChoiceId);
                            if (pChoice != null && pChoice.PChoiceDto != null)
                            {
                                if (pChoice.PChoiceDto.SortSequence == -1 && elementToValidate.PageQuestion.Required)
                                {
                                    hasMissingTexts = true;                                    
                                }

                                if (pChoice.PChoiceDto.SortSequence == 999 && !String.IsNullOrEmpty(pChoice.OtherText) && !String.IsNullOrEmpty(pChoice.ErrorMessage))
                                {
                                    if (String.IsNullOrEmpty(questionResponse.ChoiceText))
                                    {
                                        hasMissingTexts = true;
                                    }
                                    else
                                    {
                                        if (questionResponse.ChoiceText.Length > 4000)
                                        {
                                            incorrectLengthMsg = pChoice.ErrorMessage;
                                            hasMissingTexts = true;
                                            isLengthCorrect = false;
                                        }
                                    }
                                }
                            }                            
                        }
                        else
                        {
                            throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator does not accept a response of type \"" + response.GetType().Name + "\"");
                        }
                    }
                }
            }


            bool retval = false;
            if (elementToValidate.PageQuestion.Required)
            {
                if (hasElements)
                {
                    if (!hasMissingTexts && isLengthCorrect)
                    {
                        retval = true;
                    }
                }
            }
            else
            {
                if (!(hasMissingTexts) && isLengthCorrect)
                {
                    retval = true;
                }                
            }
            elementToValidate.IsValid = retval;

            return retval;
        }
        private static void AddPreDefinedQuestions(StringBuilder preDefinedQuestions, IResponsePredefinedQuestionProvider element,
            List<ResponseDto> response)
        {
            String newlineSubstitute = utility.getParameter("newline_substitute");
            //Initial - english values
            PagePredefinedQuestionDto question = PredefinedQuestionFacade.
                GetPagePredefinedQuestionByPagePredefinedQuestionId(element.PageQuestion.PagePredefinedQuestionId);
            if (question != null)
            {
                if (question.PQuestion.HppId.HasValue)
                {
                    preDefinedQuestions.Append(question.PQuestion.HppId.Value.ToString());
                    preDefinedQuestions.Append(utility.getParameter("crm_summary_delimiter_hppid_seprator"));
                }
                preDefinedQuestions.Append(utility.parse_string(question.PQuestion.QuestionText, utility.newline, newlineSubstitute));
                preDefinedQuestions.Append(Configuration.CrmSummaryDelimiterBeforeAnswer);
                foreach (PredefinedQuestionResponseDto singleAnswer in response)
                {
                    if (!preDefinedQuestions.ToString().EndsWith(Configuration.CrmSummaryDelimiterBeforeAnswer))
                    {
                        preDefinedQuestions.Append(",");
                    }
                    //add answer and delimiter for separating answer from next question
                    PagePredefinedQuestionChoiceDto choice = element.PageQuestionChoices.
                        Find(delegate(PagePredefinedQuestionChoiceDto pecd) { return pecd.ElementId == singleAnswer.ChoiceId; });
                    if (choice != null)
                    {
                        if (!string.IsNullOrEmpty(choice.PChoice.ChoiceLabel.Trim()))
                        {
                            preDefinedQuestions.Append(utility.parse_string(choice.PChoice.ChoiceLabel, utility.newline, newlineSubstitute));

                            if (!string.IsNullOrEmpty(singleAnswer.ChoiceText))
                            {
                                preDefinedQuestions.Append(" - " + utility.parse_string(singleAnswer.ChoiceText, utility.newline, newlineSubstitute));
                            }
                        }
                        else
                        {
                            preDefinedQuestions.Append(utility.parse_string(singleAnswer.ChoiceText, utility.newline, newlineSubstitute));
                        }
                    }
                }                
            }
        }