Ejemplo n.º 1
0
        public void TestAddResponsePredefinedQuestion()
        {
            CreateNewPagePredefinedQuestion();

            long responseKey = FormRegistry.ResponseDao.CreateSubmitResponse(Constants.UnknownCustomer, null, _currentQuestionnaire.QuestionnaireId, ViewType.CleanSheetOverlay).First;
            Assert.Greater(responseKey, 0);

            ResponsePredefinedQuestion question = new ResponsePredefinedQuestion();
            PredefinedLocalizedQuestionDto lQuestion = FormRegistry.PredefinedQuestionDao.GetLocalizedQuestionByQuestionIdAndLocalizeIdOrPageQuestionId(null, null, _currentPagePredefinedQuestion.PagePredefinedQuestionId);
            question.QuestionInternalId = lQuestion.PQuestionDto.InternalId;
            question.QuestionText = lQuestion.QuestionText;
            question.ResponseId = responseKey;
            question.PagePredefinedQuestionId = _currentPagePredefinedQuestion.PagePredefinedQuestionId;
            PredefinedLocalizedChoiceDto lChoice = FormRegistry.PredefinedQuestionDao.GetLocalizedChoices(null, null, null, _currentPagePredefinedChoices[0].ElementId, null)[0];
            question.ChoiceLabel = lChoice.ChoiceLabel;
            question.FixedValue = lChoice.PChoiceDto.FixedValue;

            Assert.IsTrue(FormRegistry.ResponseDao.Add(question));
        }
Ejemplo n.º 2
0
 private void Write(DbCommand sp, ResponsePredefinedQuestion response)
 {
     _dbLayer.AddInParameter(sp, "@page_predefined_question_id", DbType.Int32, response.PagePredefinedQuestionId);
     _dbLayer.AddInParameter(sp, "@question_internal_id", DbType.String, response.QuestionInternalId);
     _dbLayer.AddInParameter(sp, "@question_text", DbType.String, response.QuestionText);
     _dbLayer.AddInParameter(sp, "@response_id", DbType.Int64, response.ResponseId);
     _dbLayer.AddInParameter(sp, "@choice_label", DbType.String, response.ChoiceLabel);
     _dbLayer.AddInParameter(sp, "@choice_text", DbType.String, response.ChoiceText);
 }
Ejemplo n.º 3
0
        public bool Add(ResponsePredefinedQuestion response)
        {
            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, response);
                sp.ExecuteNonQuery();
                int err = _dbLayer.GetReturnValue(sp);
                if (err == 0)
                {
                    retval = true;
                }
                else
                {
                    Trace.WriteLine("ResponseDao.Add(" + response + "): returned " + err);
                }
            }
            catch (DbException e)
            {
                Trace.WriteLine("ResponseDao.Add(" + response + "): " + 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
        /// <summary>
        /// This method validate predefined question in submission. If it validated correctly, we can add it to predefinedQuestionsResponses
        /// All responses should be submited in separate method
        /// </summary>
        /// <param name="definitionNode"></param>
        /// <param name="submitedNode"></param>

        protected void ValidateAndSubmitPredefinedQuestion(XmlNode definitionNode, XmlNode submitedNode)
        {
            string questionText = String.Empty;
            string questionInternalId = String.Empty;
            int pagePredefinedQuestionId;
            bool isRequired = true;

            XmlNode nodeToCheck = null;
            do
            {
                if (nodeToCheck == null)
                    nodeToCheck = definitionNode.FirstChild;
                else
                    nodeToCheck = nodeToCheck.NextSibling;
                if (nodeToCheck.Name.ToLower() == "required")
                {
                    isRequired = nodeToCheck.InnerText.Equals("1") ? true : false;
                }
            } while (nodeToCheck.Name.ToLower() != "required");

            List<ResponsePredefinedQuestion> listOfResponses = new List<ResponsePredefinedQuestion>();

            questionInternalId = definitionNode.Attributes["ID"].Value.Replace("aid_d_", "");

            PredefinedLocalizedQuestionDto lQuestion = PredefinedQuestionFacade.GetPredefinedLocalizedQuestionTextByQuestionInternalIdAndQuestionnaireID(QuestionnaireId, questionInternalId);
            if (lQuestion != null)
            {
                questionText = lQuestion.QuestionText;
                pagePredefinedQuestionId = lQuestion.ElementId;

                bool validated = true;
                //we know that definition contains question with such id
                //check if submitedNode is correct
                foreach (XmlNode predefinedQuestionChoice in submitedNode.ChildNodes)
                {
                    if (predefinedQuestionChoice.Name.ToLower().Equals("value"))
                    {
                        //if node is other textbox value
                        if (predefinedQuestionChoice.Attributes.Count > 0 &&
                            predefinedQuestionChoice.Attributes["id"] != null &&
                            predefinedQuestionChoice.Attributes["type"] != null &&
                            predefinedQuestionChoice.Attributes["type"].Value.Equals("tb"))
                        {
                            string otherLabel = String.Empty;
                            string otherText = String.Empty;
                            string otherValue = String.Empty;
                            string otherFixedValue = String.Empty;

                            bool alreadyFound = false;
                            for (int i = 0; i < definitionNode.ChildNodes.Count && !alreadyFound; i++)
                            {
                                if (definitionNode.ChildNodes[i].Name.ToLower().Equals("item") &&
                                    definitionNode.ChildNodes[i].Attributes.Count > 0 &&
                                    definitionNode.ChildNodes[i].Attributes["id"] != null &&
                                    definitionNode.ChildNodes[i].Attributes["id"].Value.Equals(predefinedQuestionChoice.Attributes["id"].Value))
                                {
                                    if (definitionNode.ChildNodes[i].Attributes["showextratextfieldID"] != null &&
                                        definitionNode.ChildNodes[i].Attributes["showextratextfieldID"].Value.Replace("tb_", "") == predefinedQuestionChoice.Attributes["id"].Value &&
                                        definitionNode.ChildNodes[i].Attributes["showextratextfield"] != null &&
                                        definitionNode.ChildNodes[i].Attributes["showextratextfield"].Value.Equals("true"))
                                    {
                                        otherText = definitionNode.ChildNodes[i].InnerText;
                                        otherValue = predefinedQuestionChoice.Value;
                                        otherFixedValue = definitionNode.ChildNodes[i].Attributes["id"].Value;
                                        if (otherLabel != String.Empty)
                                            alreadyFound = true;
                                    }
                                    else
                                    {
                                        otherLabel = definitionNode.ChildNodes[i].InnerText;
                                        if (otherText != String.Empty &&
                                            otherValue != String.Empty &&
                                            otherFixedValue != String.Empty)
                                            alreadyFound = true;
                                    }
                                }
                            }
                            if (!alreadyFound && isRequired)
                            {
                                validated = false;
                                DataRow FormSubmissionMissedChoiceMappings = QuestionChoiceInvalidMappings.NewRow();
                                FormSubmissionMissedChoiceMappings["FormFieldID"] = definitionNode.Attributes["ID"].Value;
                                FormSubmissionMissedChoiceMappings["ChoiceID"] = predefinedQuestionChoice.Attributes["id"].Value;
                                FormSubmissionMissedChoiceMappings["ChoiceText"] = predefinedQuestionChoice.Value;
                                if (QuestionChoiceInvalidMappings.Rows.Find(FormSubmissionMissedChoiceMappings) == null)
                                    QuestionChoiceInvalidMappings.Rows.Add(FormSubmissionMissedChoiceMappings);
                            }
                            else //other succesfully validated 
                            {
                                ResponsePredefinedQuestion temp = new ResponsePredefinedQuestion();
                                temp.ChoiceLabel = otherLabel;
                                temp.ChoiceText = otherValue;
                                temp.QuestionInternalId = questionInternalId;
                                temp.PagePredefinedQuestionId = pagePredefinedQuestionId;
                                temp.QuestionText = questionText;
                                temp.FixedValue = otherFixedValue;
                                listOfResponses.Add(temp);
                            }
                        }
                        //else it is a standard choice
                        else
                        {
                            string fixedValue = predefinedQuestionChoice.InnerText;
                            string choiceLabel = String.Empty;
                            bool alreadyFound = false;
                            for (int i = 0; i < definitionNode.ChildNodes.Count && !alreadyFound; i++)
                            {
                                if (definitionNode.ChildNodes[i].Name.ToLower().Equals("item") &&
                                    definitionNode.ChildNodes[i].Attributes.Count > 0 &&
                                    definitionNode.ChildNodes[i].Attributes["id"] != null &&
                                    definitionNode.ChildNodes[i].Attributes["id"].Value.Equals(fixedValue))
                                {
                                    alreadyFound = true;
                                    choiceLabel = definitionNode.ChildNodes[i].InnerText;
                                }
                            }
                            if (!alreadyFound && isRequired)
                            {
                                validated = false;
                                DataRow FormSubmissionMissedChoiceMappings = QuestionChoiceInvalidMappings.NewRow();
                                FormSubmissionMissedChoiceMappings["FormFieldID"] = definitionNode.Attributes["ID"].Value;
                                FormSubmissionMissedChoiceMappings["ChoiceID"] = fixedValue;
                                FormSubmissionMissedChoiceMappings["ChoiceText"] = fixedValue;
                                bool contains = false;
                                for (int j = 0; j < QuestionChoiceInvalidMappings.Rows.Count && !contains; j++)
                                {
                                    if (QuestionChoiceInvalidMappings.Rows[j]["FormFieldID"].Equals(FormSubmissionMissedChoiceMappings["FormFieldID"]))
                                        contains = true;
                                }
                                if (!contains)
                                    QuestionChoiceInvalidMappings.Rows.Add(FormSubmissionMissedChoiceMappings);
                            }
                            else
                            {
                                ResponsePredefinedQuestion temp = new ResponsePredefinedQuestion();
                                temp.ChoiceLabel = choiceLabel;
                                temp.ChoiceText = null;
                                temp.QuestionInternalId = questionInternalId;
                                temp.PagePredefinedQuestionId = pagePredefinedQuestionId;
                                temp.QuestionText = questionText;
                                temp.FixedValue = fixedValue;
                                listOfResponses.Add(temp);
                            }
                        }
                    }
                    else if (isRequired)
                    {
                        validated = false;
                        DataRow FormSubmissionMissedChoiceMappings = QuestionChoiceInvalidMappings.NewRow();
                        FormSubmissionMissedChoiceMappings["FormFieldID"] = definitionNode.Attributes["ID"].Value;
                        FormSubmissionMissedChoiceMappings["ChoiceID"] = predefinedQuestionChoice.Attributes["id"].Value;
                        FormSubmissionMissedChoiceMappings["ChoiceText"] = predefinedQuestionChoice.Value;
                        bool contains = false;
                        for (int j = 0; j < QuestionChoiceInvalidMappings.Rows.Count && !contains; j++)
                        {
                            if (QuestionChoiceInvalidMappings.Rows[j]["FormFieldID"].Equals(FormSubmissionMissedChoiceMappings["FormFieldID"]))
                                contains = true;
                        }
                        if (!contains)
                            QuestionChoiceInvalidMappings.Rows.Add(FormSubmissionMissedChoiceMappings);
                    }
                }

                if (validated && listOfResponses != null && listOfResponses.Count > 0)
                {
                    foreach (ResponsePredefinedQuestion response in listOfResponses)
                    {
                        if (predefinedQuestionsResponses.Find(p =>
                            p.ChoiceLabel == response.ChoiceLabel &&
                            p.ChoiceText == response.ChoiceText &&
                            p.FixedValue == response.FixedValue &&
                            p.PagePredefinedQuestionId == response.PagePredefinedQuestionId &&
                            p.QuestionInternalId == response.QuestionInternalId &&
                            p.QuestionText == response.QuestionText &&
                            p.ResponseId == response.ResponseId) == null)
                            predefinedQuestionsResponses.Add(response);
                        if (!listOfPagePredefinedQuestionsId.Contains(response.PagePredefinedQuestionId))
                            listOfPagePredefinedQuestionsId.Add(response.PagePredefinedQuestionId);
                    }
                }
            }

        }