Beispiel #1
0
        private void InitializeAndLoadForeignFields()
        {
            List <UPQuestionnaireQuestion>            foreignFieldQuestions  = this.Questionnaire.ForeignFieldQuestions;
            Dictionary <string, UPSurveyForeignField> foreignFieldDictionary = new Dictionary <string, UPSurveyForeignField>(foreignFieldQuestions.Count);
            List <UPCRMField> fieldArray       = new List <UPCRMField>(foreignFieldQuestions.Count);
            string            recordInfoAreaId = this.RootRecordIdentification.InfoAreaId();

            foreach (UPQuestionnaireQuestion question in foreignFieldQuestions)
            {
                UPSurveyForeignField foreignField         = new UPSurveyForeignField(question);
                UPSurveyForeignField existingForeignField = foreignFieldDictionary.ValueOrDefault(foreignField.Key);

                if (existingForeignField != null)
                {
                    existingForeignField.AddQuestion(question);
                }
                else
                {
                    foreignFieldDictionary[foreignField.Key] = foreignField;
                    if (!string.IsNullOrEmpty(recordInfoAreaId))
                    {
                        bool       addField = true;
                        UPCRMField field    = UPCRMField.FieldFromFieldInfo(foreignField.FieldInfo);
                        if (recordInfoAreaId != field.InfoAreaId)
                        {
                            if (!UPCRMDataStore.DefaultStore.InfoAreaIdLinkIdIsParentOfInfoAreaId(recordInfoAreaId, -1, field.InfoAreaId))
                            {
                                addField = false;
                            }
                        }

                        if (addField)
                        {
                            foreignField.PositionInResult = fieldArray.Count;
                            fieldArray.Add(UPCRMField.FieldFromFieldInfo(foreignField.FieldInfo));
                        }
                    }
                }
            }

            this.ForeignFields = foreignFieldDictionary;
            if (string.IsNullOrEmpty(this.RootRecordIdentification))
            {
                this.ForeignFieldsLoaded(null);
            }

            this.crmQuery = new UPContainerMetaInfo(fieldArray, this.RootRecordIdentification.InfoAreaId());
            this.crmQuery.SetLinkRecordIdentification(this.RootRecordIdentification);
            this.loadStep = 4;
            this.crmQuery.Find(this.SourceRequestOption, this);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the changed records.
        /// </summary>
        /// <param name="rootTemplateFilter">The root template filter.</param>
        /// <param name="baseTemplateFilter">The base template filter.</param>
        /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords(UPConfigFilter rootTemplateFilter, UPConfigFilter baseTemplateFilter, bool ignoreDefault)
        {
            UPCRMRecord rootRecord;
            bool        changedRoot = false;

            if (!string.IsNullOrEmpty(this.AnswerRootRecordIdentification))
            {
                rootRecord = new UPCRMRecord(this.AnswerRootRecordIdentification);
            }
            else
            {
                rootRecord = new UPCRMRecord(this.SurveySearchAndList.InfoAreaId);
                rootRecord.AddLink(new UPCRMLink(this.RootRecordIdentification));
                if (this.Questionnaire.Manager.LinkSurveyToQuestionnaire)
                {
                    rootRecord.AddLink(new UPCRMLink(this.Questionnaire.RecordIdentification));
                }

                if (this.SurveyTemplateFilter != null)
                {
                    UPConfigFilter filter = this.SurveyTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true);
                    rootRecord.ApplyValuesFromTemplateFilter(filter);
                }

                changedRoot = true;
            }

            Dictionary <string, UPCRMRecord> foreignFieldDictionary = new Dictionary <string, UPCRMRecord>();
            List <UPCRMRecord> answerRecords = new List <UPCRMRecord>();

            foreach (UPQuestionnaireQuestion question in this.Questionnaire.Questions)
            {
                UPSurveyAnswer     answer = this.surveyAnswers[question.QuestionId];
                List <UPCRMRecord> currentAnswerRecords = answer.ChangedRecords(rootRecord, this.Parameters, ignoreDefault);
                if (currentAnswerRecords.Count > 0)
                {
                    answerRecords.AddRange(currentAnswerRecords);
                }

                if (question.Save)
                {
                    UPSurveyForeignField foreignField = answer.SurveyForeignField;
                    if (!string.IsNullOrEmpty(foreignField.RecordIdentification) && !string.IsNullOrEmpty(foreignField.Value) &&
                        !string.IsNullOrEmpty(answer.Answer) && foreignField.Value != answer.Answer)
                    {
                        UPCRMRecord foreignRecord = foreignFieldDictionary.ValueOrDefault(foreignField.RecordIdentification);
                        if (foreignRecord == null)
                        {
                            foreignRecord = new UPCRMRecord(foreignField.RecordIdentification);
                            foreignFieldDictionary[foreignField.RecordIdentification] = foreignRecord;
                        }

                        UPCRMFieldValue fieldValue = new UPCRMFieldValue(answer.Answer, foreignRecord.InfoAreaId, foreignField.FieldInfo.FieldId, this.Questionnaire.Manager.AutomaticOnlineSaveOfForeignFields);
                        foreignRecord.AddValue(fieldValue);
                    }
                }
            }

            List <UPCRMRecord> changedRecords = new List <UPCRMRecord>();

            if (changedRoot)
            {
                changedRecords.Add(rootRecord);
            }

            if (answerRecords.Count > 0)
            {
                changedRecords.AddRange(answerRecords);
            }

            if (changedRecords.Count > 0)
            {
                UPCRMRecord rootSyncRecord = new UPCRMRecord(rootRecord, "Sync");
                changedRecords.Add(rootSyncRecord);
            }

            if (foreignFieldDictionary.Count > 0)
            {
                changedRecords.AddRange(foreignFieldDictionary.Values);
            }

            if (rootTemplateFilter != null)
            {
                rootTemplateFilter = rootTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true);
                if (rootTemplateFilter != null)
                {
                    UPCRMRecord record = new UPCRMRecord(rootRecord);
                    record.ApplyValuesFromTemplateFilter(rootTemplateFilter);
                    changedRecords.Add(record);
                }
            }

            if (baseTemplateFilter != null)
            {
                baseTemplateFilter = baseTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true);
                if (baseTemplateFilter != null)
                {
                    UPCRMRecord record = new UPCRMRecord(this.RecordIdentification);
                    record.ApplyValuesFromTemplateFilter(baseTemplateFilter);
                    changedRecords.Add(record);
                }
            }

            return(changedRecords);
        }