private static void ProcessEditField( UPMQuestionnaireGroup questionnaireGroup, UPQuestionnaireQuestion currentQuestion, UPMEditField editField, IQuestionnaireEditFieldContext editFieldContext, UPQuestionnaireCatalogEditField catalogEditField, string surveyAnswer, IList <string> answerIds, bool multiSelect) { if (questionnaireGroup == null) { throw new ArgumentNullException(nameof(questionnaireGroup)); } if (currentQuestion == null) { throw new ArgumentNullException(nameof(currentQuestion)); } if (editFieldContext == null) { throw new ArgumentNullException(nameof(editFieldContext)); } if (answerIds == null) { throw new ArgumentNullException(nameof(answerIds)); } editField.LabelText = currentQuestion.Label; editField.DetailText = currentQuestion.AdditionalInfo; editField.RequiredField = currentQuestion.Mandatory; editFieldContext.Question = currentQuestion; if (multiSelect) { if (catalogEditField != null) { foreach (string a in answerIds) { catalogEditField.AddFieldValue(a); } } } else { editField.FieldValue = surveyAnswer; } editField.ContinuousUpdate = true; var questionnaireQuestion = new UPMQuestionnaireQuestion(editField) { Mandatory = currentQuestion.Mandatory }; questionnaireGroup.AddQuestion(questionnaireQuestion); }
private void ProcessGroup(UPMQuestionnairePage page, int index, UPQuestionnaireQuestionGroup currentGroup) { if (page == null) { throw new ArgumentNullException(nameof(page)); } if (currentGroup == null) { throw new ArgumentNullException(nameof(currentGroup)); } bool firstQuestion = true; var questionnaireGroup = new UPMQuestionnaireGroup(StringIdentifier.IdentifierWithStringId($"group_{currentGroup.Label}")) { LabelText = currentGroup.Label }; page.AddGroup(questionnaireGroup); var questions = this.Survey.VisibleQuestionsForGroup(currentGroup); foreach (var currentQuestion in questions) { if (currentQuestion.Hide) { continue; } UPMEditField editField = null; IQuestionnaireEditFieldContext editFieldContext = null; UPQuestionnaireCatalogEditField catalogEditField = null; if (firstQuestion) { if (string.IsNullOrEmpty(questionnaireGroup.LabelText)) { questionnaireGroup.LabelText = currentQuestion.Label; } firstQuestion = false; } var fieldIdentifier = StringIdentifier.IdentifierWithStringId($"{currentQuestion.RecordIdentification}_{index}"); var surveyAnswer = this.Survey.SurveyAnswerForQuestion(currentQuestion); var answerIds = surveyAnswer.AnswerIds; bool multiSelect = currentQuestion.Multiple; var explicitKeyOrder = new List <string>(); CreateFields( currentQuestion, out editField, out editFieldContext, out catalogEditField, fieldIdentifier, multiSelect, explicitKeyOrder); if (editField != null) { ProcessEditField( questionnaireGroup, currentQuestion, editField, editFieldContext, catalogEditField, surveyAnswer.Answer, answerIds, multiSelect); } } }
private static void CreateFields( UPQuestionnaireQuestion currentQuestion, out UPMEditField editField, out IQuestionnaireEditFieldContext editFieldContext, out UPQuestionnaireCatalogEditField catalogEditField, IIdentifier fieldIdentifier, bool multiSelect, IList <string> explicitKeyOrder) { if (currentQuestion == null) { throw new ArgumentNullException(nameof(currentQuestion)); } if (explicitKeyOrder == null) { throw new ArgumentNullException(nameof(explicitKeyOrder)); } editField = null; editFieldContext = null; catalogEditField = null; switch (currentQuestion.FieldType[0]) { case FieldTypeX: case FieldTypeK: var answers = currentQuestion.Answers(); if (answers == null) { break; } if (answers.Count > 10) { catalogEditField = new UPQuestionnaireCatalogEditField(fieldIdentifier, multiSelect) { CatalogElementViewType = CatalogElementViewType.PopOver }; } else { catalogEditField = new UPQuestionnaireCatalogEditField(fieldIdentifier, multiSelect) { CatalogElementViewType = CatalogElementViewType.Table }; } catalogEditField.NullValueKey = "0"; if (multiSelect) { catalogEditField.MultiSelectMaxCount = answers.Count; } editField = catalogEditField; editFieldContext = catalogEditField; foreach (var answer in answers) { var catalogPossibleValue = new UPMCatalogPossibleValue { TitleLabelField = new UPMStringField(null) { StringValue = answer.AnswerText } }; explicitKeyOrder.Add(answer.AnswerId); catalogEditField.AddPossibleValue(catalogPossibleValue, answer.AnswerId); } catalogEditField.ExplicitKeyOrder = explicitKeyOrder as List <string>; break; case FieldTypeD: editField = new UPQuestionnaireDateTimeEditField(fieldIdentifier); editFieldContext = (IQuestionnaireEditFieldContext)editField; break; default: editField = new UPQuestionnaireStringEditField(fieldIdentifier); editFieldContext = (IQuestionnaireEditFieldContext)editField; break; } }