/// <summary> /// Applies the changes from record. /// </summary> /// <param name="record">The record.</param> public void ApplyChangesFromRecord(UPCRMRecord record) { UPCRMTableInfo tableInfo = this.UndoRequest.DataStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId()); if (record.FieldValues != null) { foreach (UPCRMFieldValue value in record.FieldValues) { UPCRMFieldInfo fieldInfo = tableInfo.FieldInfoForFieldId(value.FieldId); if (fieldInfo != null) { UPCRMUndoField undoField = new UPCRMUndoField(fieldInfo.DatabaseFieldName, value.Value, null); this.AddFieldValue(undoField); } } } if (record.Links != null) { foreach (UPCRMLink link in record.Links) { UPCRMLinkInfo linkInfo = tableInfo.LinkInfoForTargetInfoAreaIdLinkId(link.InfoAreaId, link.LinkId); if (linkInfo?.HasColumn ?? false) { UPCRMUndoField undoField = new UPCRMUndoField(linkInfo.LinkFieldName, link.RecordId, null); this.AddFieldValue(undoField); string infoAreaColumnName = linkInfo.InfoAreaLinkFieldName; if (!string.IsNullOrEmpty(infoAreaColumnName)) { undoField = new UPCRMUndoField(infoAreaColumnName, link.InfoAreaId, null); this.AddFieldValue(undoField); } } } } }
/// <summary> /// Sources the field result row for link. /// </summary> /// <param name="link">The link.</param> /// <returns></returns> List <string> SourceFieldResultRowForLink(UPCRMLink link) { UPCRMTableInfo sourceTableInfo = this.dataStore.TableInfoForInfoArea(link.InfoAreaId); UPCRMLinkInfo linkInfo = this.tableInfo.LinkInfoForTargetInfoAreaIdLinkId(link.InfoAreaId, link.LinkId); bool noFields = true; if (sourceTableInfo == null || linkInfo?.LinkFieldArray == null) { return(null); } List <UPCRMFieldSetterField> fieldMap = new List <UPCRMFieldSetterField>(linkInfo.LinkFieldArray.Count); foreach (UPCRMLinkInfoField field in linkInfo.LinkFieldArray) { UPCRMFieldInfo fieldInfo = sourceTableInfo.FieldInfoForFieldId(field.TargetFieldId); if (fieldInfo != null) { fieldMap.Add(new UPCRMFieldSetterSourceField(field.TargetFieldId)); noFields = false; } else { UPCRMFieldSetterSourceLink sourceLink = null; List <UPCRMLinkInfo> allLinks = sourceTableInfo.LinksWithField(); foreach (UPCRMLinkInfo currentLinkInfo in allLinks) { foreach (UPCRMLinkInfoField linkInfoField in currentLinkInfo.LinkFieldArray) { if (linkInfoField.FieldId == field.TargetFieldId) { UPCRMTableInfo parentTableInfo = this.dataStore.TableInfoForInfoArea(currentLinkInfo.TargetInfoAreaId); UPCRMLinkInfo parentIdentLink = parentTableInfo.IdentLink; if (parentIdentLink != null) { if (parentIdentLink.FirstField.TargetFieldId == linkInfoField.TargetFieldId) { sourceLink = new UPCRMFieldSetterSourceLink(currentLinkInfo.TargetInfoAreaId, currentLinkInfo.LinkId, 0); break; } if (parentIdentLink.SecondField.TargetFieldId == linkInfoField.TargetFieldId) { sourceLink = new UPCRMFieldSetterSourceLink(currentLinkInfo.TargetInfoAreaId, currentLinkInfo.LinkId, 1); break; } } } } if (sourceLink != null) { break; } } if (sourceLink != null) { fieldMap.Add(sourceLink); noFields = false; } else { fieldMap.Add(new UPCRMFieldSetterField()); } } } if (noFields) { return(null); } List <UPCRMField> queryFields = new List <UPCRMField>(); int resultPosition = 0; foreach (UPCRMFieldSetterField fieldSetterField in fieldMap) { if (fieldSetterField.IsField) { queryFields.Add(fieldSetterField.FieldWithInfoAreaId(link.InfoAreaId)); fieldSetterField.ResultPosition = resultPosition++; } } foreach (UPCRMFieldSetterField fieldSetterField in fieldMap) { if (fieldSetterField.IsLink) { queryFields.Add(fieldSetterField.FieldWithInfoAreaId(link.InfoAreaId)); fieldSetterField.ResultPosition = resultPosition++; } } UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(queryFields, linkInfo.TargetInfoAreaId); UPCRMResult result = crmQuery.ReadRecord(link.RecordIdentification); if (result != null && result.RowCount == 1) { UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(0); List <string> resultArray = new List <string>(fieldMap.Count); foreach (UPCRMFieldSetterField field in fieldMap) { if (field.IsField) { resultArray.Add(row.RawValueAtIndex(field.ResultPosition)); } else if (field.IsLink) { string recordId = row.RawValueAtIndex(field.ResultPosition); if (string.IsNullOrEmpty(recordId)) { resultArray.Add(string.Empty); } else if (recordId.StartsWith("new") && recordId.Length == 15) { long offlineLnr = (Convert.ToInt64(recordId.Substring(3, 8), 16) << 16) + Convert.ToInt64(recordId.Substring(11, 4), 16); if (this.offlineStationNumber > 0 && offlineLnr > 0) { if (((UPCRMFieldSetterSourceLink)field).FieldIndex == 0) { resultArray.Add(this.offlineStationNumber.ToString()); } else { resultArray.Add(offlineLnr.ToString()); } } } else if (((UPCRMFieldSetterSourceLink)field).FieldIndex == 0) { resultArray.Add(recordId.StatNoFromRecordIdString()); } else { resultArray.Add(recordId.RecordNoFromRecordIdString()); } } else { resultArray.Add(string.Empty); } } return(resultArray); } return(null); }