示例#1
0
        /// <summary>
        /// Alls the fields.
        /// </summary>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public List <UPCRMFieldInfo> AllFields()
        {
            var fieldArray = new List <UPCRMFieldInfo>();
            int count      = this.tableInfo?.FieldCount ?? 0;

            for (var i = 0; i < count; i++)
            {
                var cppFieldInfo = this.tableInfo?.GetFieldInfoByIndex(i);
                var fieldInfo    = UPCRMFieldInfo.Create(this.InfoAreaId, cppFieldInfo);
                fieldArray.Add(fieldInfo);
            }

            return(fieldArray);
        }
示例#2
0
        private Dictionary <int, string> ApplyFieldInfo(
            bool onlyOffline,
            UPCRMFieldInfo fieldInfo,
            string sourceValue,
            Dictionary <int, string> rawValuesForUnknownFields,
            UPCRMLinkInfoField linkInfoField)
        {
            if (fieldInfo == null && !string.IsNullOrWhiteSpace(sourceValue))
            {
                if (rawValuesForUnknownFields == null)
                {
                    rawValuesForUnknownFields = new Dictionary <int, string>
                    {
                        { linkInfoField.FieldId, sourceValue }
                    };
                }
                else
                {
                    rawValuesForUnknownFields[linkInfoField.FieldId] = sourceValue;
                }
            }
            else if (!string.IsNullOrEmpty(sourceValue))
            {
                var fieldValue = this.Record.FieldValueForFieldIndex(linkInfoField.FieldId);
                if (fieldValue == null)
                {
                    this.Record.AddValue(
                        new UPCRMFieldValue(sourceValue, this.infoAreaId, linkInfoField.FieldId, onlyOffline));
                }
                else if (fieldInfo.IsEmptyValue(fieldValue.Value))
                {
                    fieldValue.ChangeValueOldValue(sourceValue, null);
                }
            }

            return(rawValuesForUnknownFields);
        }
示例#3
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);
                        }
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Fields the information for field identifier.
 /// </summary>
 /// <param name="fieldId">
 /// The field identifier.
 /// </param>
 /// <returns>
 /// The <see cref="UPCRMFieldInfo"/>.
 /// </returns>
 public UPCRMFieldInfo FieldInfoForFieldId(int fieldId)
 {
     return(UPCRMFieldInfo.Create(fieldId, this));
 }
示例#5
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);
        }
示例#6
0
 /// <summary>
 /// Fields from field information.
 /// </summary>
 /// <param name="fieldInfo">
 /// The field information.
 /// </param>
 /// <returns>
 /// The <see cref="UPCRMField"/>.
 /// </returns>
 public static UPCRMField FieldFromFieldInfo(UPCRMFieldInfo fieldInfo)
 {
     return(new UPCRMField(fieldInfo.FieldId, fieldInfo.InfoAreaId));
 }