protected override bool RealValidate(HP.Rfg.Common.Questionnaire.IResponseElementProvider elementToValidate, HP.Rfg.Common.Questionnaire.QuestionnaireDto questionnaire)
 {
     bool retval = base.RealValidate(elementToValidate, questionnaire);
     if (retval)
     {
         List<ResponseDto> responses = elementToValidate.GetResponseDto(-1);
         bool valid = HP.Rfg.lib.utility.CheckEntryToRegex(constants.REGEX_EMAIL, ((QuestionResponseDto)responses[0]).ChoiceText);
         if (!valid)
             elementToValidate.SetValidationHints(new List<int>(new int[]{ PageElementWithErrorDto.InvalidEmail }));
         retval = elementToValidate.IsValid = valid;
         return retval;
     }
     return false;
 }
Example #2
0
        protected override bool RealValidate(HP.Rfg.Common.Questionnaire.IResponseElementProvider elementToValidate, HP.Rfg.Common.Questionnaire.QuestionnaireDto questionnaire)
        {
            bool retval = false;
            bool hasElement = false;
            bool hasMinLength = false;
            bool hasEmptyElements = false;
            bool isEqual = false;

            List<ResponseDto> responses = elementToValidate.GetResponseDto(-1);
            List<int> validationHints = new List<int>();

            if (responses != null && responses.Count > 0)
            {
                PersonalResponseDto personal = ((PersonalResponseDto)responses[0]);
                if (personal != null)
                {
                    hasElement = true;
                    if (String.IsNullOrEmpty(personal.Pwd) && String.IsNullOrEmpty(personal.Pwdconfirm))
                    {
                        hasEmptyElements = true;
                    }
                    else
                    {
                        if ((personal.Pwd.Length > MaxPwdLength) || (personal.Pwdconfirm.Length > MaxPwdLength))
                        {
                            validationHints.Add(PageElementWithErrorDto.InvalidInputTooLong);
                        }
                    }

                    if (!hasEmptyElements)
                    {
                        isEqual = string.Equals(personal.Pwd, personal.Pwdconfirm);
                        if (!isEqual) validationHints.Add(PageElementWithErrorDto.PasswordsDontMatch);
                        hasMinLength = (personal.Pwd.Length >= MinPwdLength) && (personal.Pwdconfirm.Length >= MinPwdLength);
                        if (!hasMinLength) validationHints.Add(PageElementWithErrorDto.PasswordsToShort);
                    }
                }
                else
                {
                    throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Password validator does not accept a response of type \"" + responses[0].GetType().Name + "\"");
                }
                

                if (validationHints.Count == 0)
                {
                    if (elementToValidate.PageElement.IsRequired)
                    {
                        if (!hasEmptyElements && hasElement && hasMinLength)
                        {
                            retval = isEqual;
                        }
                    }
                    else
                    {
                        retval = (hasMinLength && isEqual) || hasEmptyElements;
                    }
                }
                else
                {
                    elementToValidate.SetValidationHints(validationHints);
                }
            }
            
            elementToValidate.IsValid = retval;
            return retval;
        }
Example #3
0
        protected override bool RealValidate(HP.Rfg.Common.Questionnaire.IResponseElementProvider elementToValidate, HP.Rfg.Common.Questionnaire.QuestionnaireDto questionnaire)
        {
            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)
                {
                    FileUploadResponseDto fileUploadResponse = response as FileUploadResponseDto;

                    if (fileUploadResponse != null)
                    {
                        hasElement = true;
                        if (String.IsNullOrEmpty(fileUploadResponse.FileName))
                        {
                            hasEmptyElements = true;
                            break;
                        }
                        else
                        {
                            string regex_pattern = utility.getParameter("regex_allowed_file_types");
                            if (!Regex.IsMatch(fileUploadResponse.FileName, regex_pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase))
                            {                                
                                validationHints = new List<int>();
                                validationHints.Add(PageElementWithErrorDto.InvalidFileType);
                            }

                            if (fileUploadResponse.FileBuffer.Length / (1024 * 1024) > 18 && validationHints == null)
                            {
                                validationHints = new List<int>();
                                validationHints.Add(PageElementWithErrorDto.InvalidFileType);
                            }
                        }
                    }
                    else
                    {
                        throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "File Upload validator does not accept a response of type \"" + response.GetType().Name + "\"");
                    }
                }
            }
            bool retval = false;

            if (validationHints == null)
            {
                if (elementToValidate.PageElement.IsRequired)
                {
                    if (!hasEmptyElements && hasElement)
                    {
                        retval = true;
                    }
                }
                else
                {
                    retval = true;
                }
            }
            else
            {
                elementToValidate.SetValidationHints(validationHints);
            }
            elementToValidate.IsValid = retval;
            return retval;
        }
        protected override bool  RealValidate(HP.Rfg.Common.Questionnaire.IResponseElementProvider elementToValidate, HP.Rfg.Common.Questionnaire.QuestionnaireDto questionnaire)
        {            
            bool hasMissingShippingData = false;
            List<ResponseDto> responses = elementToValidate.GetResponseDto(-1);
            List<int> validationHints = new List<int>();

            PersonalDataSectionDto personalDataSectionDto =  FormRegistry.PersonalDao.GetByPageId(elementToValidate.PageElement.PageId);
            if (responses != null && responses.Count > 0)
            {
                //check if any literature is selected
                List<ResponseDto> listOfQuestionResponses = responses.FindAll(r => r.GetType() == typeof(QuestionResponseDto));
                if (listOfQuestionResponses != null && listOfQuestionResponses.Count > 0)
                {
                    foreach (ResponseDto response in listOfQuestionResponses)
                    {
                        QuestionResponseDto questionResponse = response as QuestionResponseDto;
                        if (questionResponse != null)
                        {
                            PageElementChoiceDto choice = elementToValidate.Choices.Find(delegate(PageElementChoiceDto cur) { return cur.ChoiceId == questionResponse.ChoiceId; });
                            if (choice == null)
                            {
                                throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Literature validator found response (" + questionResponse.ChoiceId + ") which does not have a corresponding choice");
                            }                            
                        }
                        else
                        {
                            throw new BugException("Literature validator does not accept a response of type \"" + response.GetType().Name + "\"");
                        }
                    }        
                }

                ResponseDto shippingAddressResponse = responses.Find(pr => pr.GetType() == typeof(ShippingAddressResponseDto));
                {
                    if (shippingAddressResponse != null)
                    {
                        ShippingAddressResponseDto shAddress = shippingAddressResponse as ShippingAddressResponseDto;
                        if (!shAddress.UseProfileFlag && personalDataSectionDto != null)
                        {
                            ValidateShippingAddress(shAddress, elementToValidate, validationHints, personalDataSectionDto);                            
                        }
                    }
                    else
                        hasMissingShippingData = true;
                }

            }
            bool retval = false;
            if (elementToValidate.PageElement.IsRequired)
            {
                if (!hasMissingShippingData)
                {
                    if (validationHints.Count > 0)
                    {
                        elementToValidate.SetValidationHints(validationHints);
                    }
                    else
                    {
                        retval = true;
                    }
                }
            }
            else
            {
                retval = true;
            }            
            elementToValidate.IsValid = retval;
            return retval;
        }