示例#1
0
 /// <summary>
 /// Copies the question data.
 /// </summary>
 /// <param name="questionData">
 /// The question data.
 /// </param>
 /// <param name="answerItem">
 /// The answer item.
 /// </param>
 /// <param name="map">
 /// The Question-Answer map.
 /// </param>
 public static void CopyQuestionData(ChecklistQuestionData questionData, IEditableRoot answerItem, string map)
 {
     CopyAnswerData(GetAnswerFieldValues(questionData, map), answerItem);
 }
示例#2
0
        /// <summary>
        /// Copies a checklist field.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="fieldName">
        /// The field name.
        /// </param>
        public void CopyChecklistField(IEditableRoot source, IEditableRoot destination, string fieldName)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            if (destination == null)
                throw new ArgumentNullException("destination");

            var destinationChecklist = destination.GetValueByPropertyName(fieldName) as ChecklistEdit;
            if (destinationChecklist == null || destinationChecklist.AnswerProcessList == null)
                return;

            destinationChecklist.AnswerProcessList.Clear();

            var sourceChecklist = source.GetValueByPropertyName(fieldName) as ChecklistEdit;
            if (sourceChecklist == null || sourceChecklist.AnswerProcessList == null)
                return;

            // Modify the QA map to copy from one answer to another.
            var qaMap = ChecklistQAMap.Parse(destinationChecklist.QuestionAnswerMap);
            foreach (var qaMapElement in qaMap.Elements)
            {
                qaMapElement.QuestionFieldSystemName = qaMapElement.AnswerFieldSystemName;
                qaMapElement.QuestionFieldSource = ChecklistQuestionFieldSource.QuestionProcess;
            }

            var answerToAnswerMap = qaMap.ToXml();

            foreach (var sourceAnswer in sourceChecklist.AnswerProcessList.OfType<IEditableRoot>())
            {
                var destinationAnswer = TheDynamicTypeManager.NewEditableChild<IEditableRoot>(destinationChecklist.AnswerProcessSystemName);
                var questionData = new ChecklistQuestionData { QuestionItem = sourceAnswer };

                ChecklistHelper.CopyQuestionData(questionData, destinationAnswer, answerToAnswerMap);

                destinationChecklist.AnswerProcessList.Add(destinationAnswer);
            }
        }
示例#3
0
        /// <summary>
        /// Gets the answer field values.
        /// </summary>
        /// <param name="questionData">
        /// The question data.
        /// </param>
        /// <param name="map">
        /// The question-answer map.
        /// </param>
        /// <returns>
        /// The collection of answer field values.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="questionData"/> parameter is null.
        /// </exception>
        /// <exception cref="VeyronException">
        /// The <paramref name="map"/> has an invalid question-answer map.
        /// </exception>
        public static IList<ChecklistAnswerFieldValue> GetAnswerFieldValues(ChecklistQuestionData questionData, string map)
        {
            if (questionData == null)
                throw new ArgumentNullException("questionData");

            using (new ThreadLocalBypassPropertyCheckContext())
            {
                var qaMap = ChecklistQAMap.Parse(map);
                var answerType = DynamicTypeManager.GetEditableRootType(qaMap.AnswerProcess);
                var fieldValues = new List<ChecklistAnswerFieldValue>();

                foreach (var mapElement in qaMap.Elements)
                {
                    var item = questionData[mapElement.QuestionFieldSource];
                    if (item == null)
                        continue;

                    var questionProperty = item.GetPropertyByName(mapElement.QuestionFieldSystemName);
                    if (questionProperty == null)
                        continue;

                    var answerProperty = answerType.GetPropertyByName(mapElement.AnswerFieldSystemName);
                    if (answerProperty == null)
                        continue;

                    CheckCompatibility(questionProperty, answerProperty);

                    if (IsLocalizable(answerProperty))
                    {
                        foreach (var localizationInfo in answerProperty.DeclaringType.GetCustomAttributes<LocalizationInfoAttribute>())
                        {
                            using (new CultureContext(localizationInfo.CultureName))
                            {
                                var answerFieldName = LocalizationUtils.GetLocalizedFieldName(answerProperty.Name, localizationInfo.CultureName);
                                fieldValues.Add(new ChecklistAnswerFieldValue(answerFieldName, item.GetValueByPropertyName(questionProperty.Name)));
                            }
                        }
                    }
                    else
                    {
                        fieldValues.Add(new ChecklistAnswerFieldValue(answerProperty.Name, item.GetValueByPropertyName(questionProperty.Name)));
                    }

                    if (IsFrequency(answerProperty))
                    {
                        var frequencyType = item.GetValueByPropertyName(GetFrequencyTypePropertyName(questionProperty));
                        if (frequencyType != null)
                            fieldValues.Add(new ChecklistAnswerFieldValue(GetFrequencyTypePropertyName(answerProperty), frequencyType));

                        var selectedFrequency = item.GetValueByPropertyName(GetSelectedFrequencyPropertyName(questionProperty));
                        if (selectedFrequency != null)
                            fieldValues.Add(new ChecklistAnswerFieldValue(GetSelectedFrequencyPropertyName(answerProperty), selectedFrequency));

                        var frequencyHours = item.GetValueByPropertyName(GetFrequencyHoursPropertyName(questionProperty));
                        if (frequencyHours != null)
                            fieldValues.Add(new ChecklistAnswerFieldValue(GetFrequencyHoursPropertyName(answerProperty), frequencyHours));
                    }

                    if (IsSampleType(answerProperty))
                    {
                        var trueLabel = item.GetValueByPropertyName(GetSampleTrueLabelPropertyName(questionProperty));
                        if (trueLabel != null)
                            fieldValues.Add(new ChecklistAnswerFieldValue(GetSampleTrueLabelPropertyName(answerProperty), trueLabel));

                        var falseLabel = item.GetValueByPropertyName(GetSampleFalseLabelPropertyName(questionProperty));
                        if (falseLabel != null)
                            fieldValues.Add(new ChecklistAnswerFieldValue(GetSampleFalseLabelPropertyName(answerProperty), falseLabel));
                    }
                }

                return fieldValues;
            }
        }