Exemplo n.º 1
0
        /// <summary>
        /// The query for link link record.
        /// </summary>
        /// <param name="linkInfo">
        /// The link info.
        /// </param>
        /// <param name="recordIdentification">
        /// The record identification.
        /// </param>
        /// <returns>
        /// The <see cref="UPContainerMetaInfo"/>.
        /// </returns>
        public UPContainerMetaInfo QueryForLinkLinkRecord(UPCRMLinkInfo linkInfo, string recordIdentification)
        {
            UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(null, linkInfo.TargetInfoAreaId);

            crmQuery.SetLinkRecordIdentification(recordIdentification, linkInfo.LinkId);
            return(crmQuery);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UPCRMLinkReaderLinkContext"/> class.
        /// </summary>
        /// <param name="linkInfo">
        /// The link info.
        /// </param>
        /// <param name="linkReader">
        /// The link reader.
        /// </param>
        public UPCRMLinkReaderLinkContext(UPCRMLinkInfo linkInfo, UPCRMLinkReader linkReader)
        {
            this.LinkInfo = linkInfo;
            if (this.LinkInfo.IsGeneric)
            {
            }
            else if (this.LinkInfo.UseLinkFields)
            {
                List <UPCRMField> linkFields = new List <UPCRMField>();
                foreach (UPCRMLinkInfoField linkInfoField in this.LinkInfo.LinkFieldArray)
                {
                    if (linkInfoField.FieldId >= 0)
                    {
                        linkFields.Add(UPCRMField.FieldWithFieldIdInfoAreaId(linkInfoField.FieldId, linkReader.InfoAreaId));
                    }
                }

                this.FieldLinkFields = linkFields;
            }
            else
            {
                this.LinkField = UPCRMLinkField.FieldWithLinkInfoAreaIdLinkIdInfoAreaId(
                    this.LinkInfo.TargetInfoAreaId,
                    this.LinkInfo.LinkId,
                    linkReader.InfoAreaId);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Alls the links.
        /// </summary>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List <UPCRMLinkInfo> AllLinks()
        {
            var linkArray = new List <UPCRMLinkInfo>();
            int count     = this.tableInfo?.LinkCount ?? 0;

            for (var i = 0; i < count; i++)
            {
                var cppLinkInfo = this.tableInfo?.GetLink(i);
                var linkInfo    = new UPCRMLinkInfo(this.InfoAreaId, cppLinkInfo);
                linkArray.Add(linkInfo);
            }

            return(linkArray);
        }
Exemplo n.º 4
0
        /// <summary>
        /// The link reader contexts for parent link string.
        /// </summary>
        /// <param name="parentLinkString">
        /// The parent link string.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List <UPCRMLinkReaderLinkContext> LinkReaderContextsForParentLinkString(string parentLinkString)
        {
            List <UPCRMLinkReaderLinkContext> linkReaderContext = new List <UPCRMLinkReaderLinkContext>();

            if (parentLinkString != null)
            {
                string[] infoAreaIds = parentLinkString.Split(';');
                foreach (string linkString in infoAreaIds)
                {
                    UPCRMLinkInfo linkInfo = this.LinkInfoFromParentLinkString(linkString);
                    if (linkInfo != null)
                    {
                        UPCRMLinkReaderLinkContext context = new UPCRMLinkReaderLinkContext(linkInfo, this);
                        linkReaderContext.Add(context);
                    }
                }
            }

            return(linkReaderContext.Count > 0 ? linkReaderContext : null);
        }
Exemplo n.º 5
0
        /// <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);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        private void FillLinkInfo(bool onlyOffline, long intStatNo, long intRecordNo, UPCRMLinkInfo linkInfo)
        {
            if (intStatNo < 0 || intRecordNo < 0)
            {
                return;
            }

            var ignore = false;

            foreach (var infoField in linkInfo.LinkFieldArray)
            {
                if (infoField.TargetFieldId < 0 && !string.IsNullOrEmpty(infoField.TargetValue))
                {
                    var fieldValue = this.Record.FieldValueForFieldIndex(infoField.FieldId);
                    if (fieldValue != null && fieldValue.Value != infoField.TargetValue)
                    {
                        ignore = true;
                        break;
                    }
                }
            }

            if (!ignore)
            {
                string linkRecordIdentification;
                if (intStatNo == this.offlineStationNumber && this.offlineStationNumber > 0)
                {
                    // Format: "%@.new%08lx%04x"
                    linkRecordIdentification =
                        $"{linkInfo.TargetInfoAreaId}.new{intRecordNo >> 16:X8)}{intRecordNo & 65535:X4)}";
                }
                else
                {
                    linkRecordIdentification = linkInfo.TargetInfoAreaId.InfoAreaIdRecordId(
                        StringExtensions.RecordIdFromStatNoRecordNo(intStatNo, intRecordNo));
                }

                if (!string.IsNullOrWhiteSpace(linkRecordIdentification))
                {
                    this.Record.AddLink(new UPCRMLink(linkRecordIdentification, linkInfo.LinkId, onlyOffline));
                }
            }
        }