/// <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); } }
/// <summary> /// The handle result client. /// </summary> /// <param name="result"> /// The result. /// </param> /// <param name="client"> /// The client. /// </param> public void HandleResultClient(UPCRMResult result, bool client) { if (this.queryWithLinkRecord) { if (result.RowCount > 0) { UPCRMResultRow resultRow = (UPCRMResultRow)result.ResultRowAtIndex(0); this.DestinationRecordIdentification = resultRow.RootRecordIdentification; } } else { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(0); if (client) { this.DestinationRecordIdentification = this.RecordIdentificationFromResultRow(row); } else { int position = 0; Dictionary <string, int> linkPositions = new Dictionary <string, int>(); foreach (UPCRMLinkReaderLinkContext context in this.linkContexts) { string linkKey = $"{context.LinkInfo.TargetInfoAreaId}_{(context.LinkInfo.LinkId < 0 ? 0 : context.LinkInfo.LinkId)}"; if (linkPositions.ValueOrDefault(linkKey) == 0) { continue; } this.DestinationRecordIdentification = row.RecordIdentificationAtIndex(++position); if (!string.IsNullOrEmpty(this.DestinationRecordIdentification)) { break; } linkPositions[linkKey] = position - 1; } } } this.TheDelegate?.LinkReaderDidFinishWithResult(this, this.DestinationRecordIdentification); }