/// <summary> /// Initializes a new instance of the <see cref="UPCRMLinkParticipant"/> class. /// </summary> /// <param name="resultRow">The result row.</param> /// <param name="index">The index.</param> public UPCRMLinkParticipant(UPCRMResultRow resultRow, int index) : base(resultRow.RootRecordIdentification) { this.RecordIdentification = resultRow.RootRecordIdentification; this.LinkRecordIdentification = resultRow.RecordIdentificationAtIndex(index); this.IsNewParticipant = false; var functionNameValues = resultRow.ValuesWithFunctions(); this.RequirementText = (string)functionNameValues["Requirement"]; this.AcceptanceText = (string)functionNameValues["Acceptance"]; this.OriginalAcceptanceText = this.AcceptanceText; UPContainerInfoAreaMetaInfo infoAreaMetaInfo = resultRow.Result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(index); this._name = TableCaptionForInfoAreaIdResultRow(this.LinkRecordIdentification.InfoAreaId(), resultRow); if (string.IsNullOrEmpty(this._name)) { this._name = string.Empty; foreach (UPContainerFieldMetaInfo field in infoAreaMetaInfo.Fields) { string val = resultRow.ValueForField(field); if (!string.IsNullOrEmpty(val)) { this._name = this._name.Length > 0 ? $"{this._name} {val}" : val; } } } }
/// <summary> /// Searches the operation did finish with result. /// </summary> /// <param name="operation">The operation.</param> /// <param name="result">The result.</param> public override void SearchOperationDidFinishWithResult(Operation operation, UPCRMResult result) { if (this.crmQuery != null) { int count = result.RowCount; int infoAreaCount = result.MetaInfo.NumberOfResultInfoAreaMetaInfos(); for (int i = 0; i < count; i++) { UPCRMResultRow resultRow = (UPCRMResultRow)result.ResultRowAtIndex(i); for (int j = 1; j < infoAreaCount; j++) { string linkRecordIdentification = resultRow.RecordIdentificationAtIndex(j); if (linkRecordIdentification?.Length > 6) { UPCRMLinkParticipant linkParticipant = new UPCRMLinkParticipant(resultRow, j); this.AddLinkParticipant(linkParticipant); if (!string.IsNullOrEmpty(this.ProtectedLinkRecordIdentification) && this.ProtectedLinkRecordIdentification == linkParticipant.LinkRecordIdentification) { linkParticipant.MayNotBeDeleted = true; } break; } else { UPContainerInfoAreaMetaInfo iaMeta = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(j); UPCRMLinkReader _linkReader = new UPCRMLinkReader(resultRow.RootRecordIdentification, iaMeta.InfoAreaIdWithLink, null); string linkRecordId = _linkReader.RequestLinkRecordOffline(); if (!string.IsNullOrEmpty(linkRecordId) && UPCRMDataStore.DefaultStore.RecordExistsOffline(linkRecordId)) { UPCRMLinkParticipant linkParticipant = new UPCRMLinkParticipant(resultRow, linkRecordId); this.AddLinkParticipant(linkParticipant); break; } } } } this.Finished(null); } else { base.SearchOperationDidFinishWithResult(operation, result); } }
private void ProcessResult(UPCRMResult result) { UPRecordCopyStep currentStep = this.stepQueue[0]; this.stepQueue.RemoveAt(0); UPConfigQueryTable queryTable = currentStep.QueryTable; int count = result.RowCount; int resultTableCount = result.NumberOfResultTables; UPContainerInfoAreaMetaInfo copyResultInfoArea = null; if (queryTable.InfoAreaId == currentStep.FieldControl.InfoAreaId) { copyResultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(0); } for (int i = 0; i < count; i++) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i); UPCRMRecord record = new UPCRMRecord(queryTable.InfoAreaId); if (currentStep.DestinationRecord != null) { record.AddLink(new UPCRMLink(currentStep.DestinationRecord, queryTable.LinkId)); } for (int j = 1; j < resultTableCount; j++) { string linkRecordIdentification = row.RecordIdentificationAtIndex(j); if (string.IsNullOrEmpty(linkRecordIdentification) && !result.IsServerResult) { UPContainerInfoAreaMetaInfo resultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(j); UPCRMLinkReader linkReader = new UPCRMLinkReader(StringExtensions.InfoAreaIdRecordId(currentStep.FieldControl.InfoAreaId, row.RootRecordId), $"{resultInfoArea.InfoAreaId}:{resultInfoArea.LinkId}", null); linkRecordIdentification = linkReader.RequestLinkRecordOffline(); } int linkId = -1; if (linkRecordIdentification?.Length > 8) { if (currentStep.DestinationRecord == null || queryTable.LinkId != linkId || linkRecordIdentification.InfoAreaId() != currentStep.DestinationRecord.InfoAreaId) { record.AddLink(new UPCRMLink(linkRecordIdentification, linkId)); } } } Dictionary <string, object> fieldsWithFunctions = row.ValuesWithFunctions(); UPConfigQueryTable replacedTable = queryTable.QueryTableByApplyingValueDictionary(fieldsWithFunctions); if (copyResultInfoArea != null) { foreach (UPContainerFieldMetaInfo field in copyResultInfoArea.Fields) { string val = row.RawValueAtIndex(field.PositionInResult); if (!string.IsNullOrEmpty(val)) { record.AddValue(new UPCRMFieldValue(val, field.InfoAreaId, field.FieldId)); } } } if (replacedTable != null) { record.ApplyValuesFromTemplateFilter(replacedTable, true); } int numberOfSubTables = queryTable.NumberOfSubTables; if (numberOfSubTables > 0) { for (int k = 0; k < numberOfSubTables; k++) { UPRecordCopyStep subStep = new UPRecordCopyStep(); subStep.QueryTable = queryTable.SubTableAtIndex(k); subStep.SourceRecordIdentification = row.RootRecordIdentification; subStep.DestinationRecord = record; this.ConfigForStepFromQueryTable(subStep, subStep.QueryTable); this.stepQueue.Add(subStep); } } this.recordArray.Add(record); } this.ExecuteNextStep(); }
/// <summary> /// Loads this instance. /// </summary> /// <returns></returns> public bool Load() { bool isRecordLink = false; if (string.IsNullOrEmpty(this.QuestionnaireLinkName)) { this.QuestionnaireLinkName = "RecordLink"; } this.loadStep = 1; this.crmQuery = this.SourceCopyFieldGroup != null ? new UPContainerMetaInfo(this.SourceCopyFieldGroup) : new UPContainerMetaInfo(new List <UPCRMField>(), this.RecordIdentification.InfoAreaId()); if (this.QuestionnaireLinkName == "RecordLink") { isRecordLink = true; UPQuestionnaireManager questionnaireManager = null; //ServerSession.CurrentSession.QuestionnaireManager; if (this.SourceRequestOption == UPRequestOption.Offline || ((this.SourceRequestOption == UPRequestOption.FastestAvailable || this.SourceRequestOption == UPRequestOption.Default) && UPCRMDataStore.DefaultStore.RecordExistsOffline(this.RecordIdentification))) { UPCRMLinkField questionnairelinkField = new UPCRMLinkField(questionnaireManager.QuestionnaireList.InfoAreaId, -1, this.RecordIdentification.InfoAreaId()); List <UPContainerFieldMetaInfo> fieldMetaInfos = this.crmQuery.AddCrmFields(new List <UPCRMField> { questionnairelinkField }); if (fieldMetaInfos.Count > 0) { this.questionnairelinkFieldMetaInfo = fieldMetaInfos[0]; } } else { UPCRMField questionnairelinkField = new UPCRMField(0, questionnaireManager?.QuestionnaireList.InfoAreaId, -1); UPContainerInfoAreaMetaInfo subInfoAreaMetaInfo = this.crmQuery.RootInfoAreaMetaInfo.SubTableForInfoAreaIdLinkId(questionnaireManager?.QuestionnaireList.InfoAreaId, -1); if (subInfoAreaMetaInfo == null) { this.crmQuery.RootInfoAreaMetaInfo.AddTable(new UPContainerInfoAreaMetaInfo(questionnaireManager?.QuestionnaireList.InfoAreaId, -1)); } this.crmQuery.AddCrmFields(new List <UPCRMField> { questionnairelinkField }); } } this.crmQuery.SetLinkRecordIdentification(this.RecordIdentification); if (isRecordLink && this.SourceRequestOption == UPRequestOption.BestAvailable) { this.loadStep = 11; if (this.crmQuery.Find(UPRequestOption.Online, this) == null) { this.TrySourceCopyFieldGroupOfflineWithRecordLink(); } } else { this.crmQuery.Find(this.SourceRequestOption, this); } return(true); }