/// <summary>
        /// Initializes a new instance of the <see cref="UPSEListingOwner"/> class.
        /// </summary>
        /// <param name="resultRow">The result row.</param>
        /// <param name="recordIndex">Index of the record.</param>
        /// <param name="mapping">The mapping.</param>
        /// <param name="listingController">The listing controller.</param>
        public UPSEListingOwner(UPCRMResultRow resultRow, int recordIndex,
                                Dictionary <string, UPConfigFieldControlField> mapping, UPSEListingController listingController)
        {
            this.RecordIdentification = resultRow.RecordIdentificationAtIndex(recordIndex);
            this.ListingController    = listingController;
            this.ValueDictionary      = mapping.ValuesFromResultRow(resultRow);
            Dictionary <string, string> displayValueDictionary = mapping.DisplayValuesFromResultRow(resultRow);

            if (!string.IsNullOrEmpty(this.ListingController.ListingLabelFormat))
            {
                this.Label = this.ListingController.ListingLabelFormat;
                foreach (string key in displayValueDictionary.Keys)
                {
                    this.Label = this.Label.Replace($"%%{key}", displayValueDictionary[key]);
                }
            }
            else
            {
                this.Label = displayValueDictionary.ValueOrDefault("Name");
            }

            if (!string.IsNullOrEmpty(this.Label))
            {
                this.Label = this.RecordIdentification;
            }
        }
        private string PhysicalInfoArea(UPCRMResultRow row)
        {
            if (this.fiResultColumnIndex == -1)
            {
                this.fiResultColumnIndex = row.Result.MetaInfo.IndexOfResultInfoAreaIdLinkId("FI", 1);
            }

            if (this.kpResultColumnIndex == -1)
            {
                this.kpResultColumnIndex = row.Result.MetaInfo.IndexOfResultInfoAreaIdLinkId("KP", 1);
            }

            bool   kpRow            = false;
            string physicalInfoArea = null;

            if (this.kpResultColumnIndex != -1)
            {
                string recordIdentification = row.RecordIdentificationAtIndex(this.kpResultColumnIndex);
                if (recordIdentification?.Length > 3)
                {
                    kpRow            = true;
                    physicalInfoArea = row.PhysicalInfoAreaIdAtIndex(this.kpResultColumnIndex);
                }
            }

            if (!kpRow && this.fiResultColumnIndex != -1)
            {
                physicalInfoArea = row.PhysicalInfoAreaIdAtIndex(this.fiResultColumnIndex);
            }

            return(physicalInfoArea);
        }
Exemple #3
0
        private void HandleOwnerResult(UPCRMResult result)
        {
            int count = result.RowCount;

            if (count > 0)
            {
                List <UPSEListingOwner> relatedOwnersForCurrentOwner = new List <UPSEListingOwner>();
                for (int i = 0; i < count; i++)
                {
                    UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i);
                    string         recordIdentification = row.RecordIdentificationAtIndex(1);
                    if (string.IsNullOrEmpty(recordIdentification))
                    {
                        continue;
                    }

                    UPSEListingOwner relatedOwner = this.listingOwners.ValueOrDefault(row.RecordIdentificationAtIndex(1));
                    if (relatedOwner == null)
                    {
                        relatedOwner = new UPSEListingOwner((UPCRMResultRow)result.ResultRowAtIndex(i), 1, this.ListingOwnerMapping, this);
                        this.loadQueue.Add(relatedOwner);
                        this.listingOwners.SetObjectForKey(relatedOwner, relatedOwner.RecordIdentification);
                    }

                    relatedOwnersForCurrentOwner.Add(relatedOwner);
                }

                this.currentLoadedOwner.RelatedOwners = relatedOwnersForCurrentOwner;
            }

            this.LoadNextItemFromQueue();
        }
        /// <summary>
        /// Creates the node from result row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        protected override UPMCoINode CreateNodeFromResultRow(UPCRMResultRow row)
        {
            if (this.fiResultColumnIndex == -1)
            {
                this.fiResultColumnIndex = row.Result.MetaInfo.IndexOfResultInfoAreaIdLinkId("FI", 1);
            }

            if (this.kpResultColumnIndex == -1)
            {
                this.kpResultColumnIndex = row.Result.MetaInfo.IndexOfResultInfoAreaIdLinkId("KP", 1);
            }

            bool   kpRow = false;
            string recordIdentification = null;
            string virtualInfoArea      = null;
            string physicalInfoArea     = null;

            if (this.kpResultColumnIndex != -1)
            {
                recordIdentification = row.RecordIdentificationAtIndex(this.kpResultColumnIndex);
                if (recordIdentification?.Length > 3)
                {
                    kpRow            = true;
                    virtualInfoArea  = row.VirtualInfoAreaIdAtIndex(this.kpResultColumnIndex);
                    physicalInfoArea = row.PhysicalInfoAreaIdAtIndex(this.kpResultColumnIndex);
                }
            }

            if (!kpRow && this.fiResultColumnIndex != -1)
            {
                recordIdentification = row.RecordIdentificationAtIndex(this.fiResultColumnIndex);
                virtualInfoArea      = row.VirtualInfoAreaIdAtIndex(this.fiResultColumnIndex);
                physicalInfoArea     = row.PhysicalInfoAreaIdAtIndex(this.fiResultColumnIndex);
            }

            if (recordIdentification?.Length > 3)
            {
                virtualInfoArea = virtualInfoArea == physicalInfoArea ? null : virtualInfoArea;
                return(CreateNodeFromResultRow(row, virtualInfoArea, recordIdentification, this.depth, false, this.expandChecker, physicalInfoArea, physicalInfoArea));
            }

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// The row from result row.
        /// </summary>
        /// <param name="crmRow">
        /// The crm row.
        /// </param>
        /// <returns>
        /// The <see cref="UPMResultRow"/>.
        /// </returns>
        public virtual UPMResultRow RowFromResultRow(UPCRMResultRow crmRow)
        {
            RecordIdentifier identifier = new RecordIdentifier(crmRow.RecordIdentificationAtIndex(0));
            UPMResultRow     resultRow  = new UPMResultRow(identifier)
            {
                Invalid = true, DataValid = true
            };

            this.TheDelegate?.ResultRowProviderDidCreateRowFromDataRow(this, resultRow, crmRow);
            return(resultRow);
        }
Exemple #6
0
        private void HandleRootOwnerResult(UPCRMResult result)
        {
            UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(0);

            this.RootRecordIdentification = row.RecordIdentificationAtIndex(0);
            this.ListingOwner             = new UPSEListingOwner(row, 0, this.RootListingOwnerMapping, this);
            if (!string.IsNullOrEmpty(this.ListingOwner.RecordIdentification))
            {
                this.listingOwners = new Dictionary <string, UPSEListingOwner> {
                    { this.ListingOwner.RecordIdentification, this.ListingOwner }
                };
                this.loadQueue = new List <object> {
                    this.ListingOwner
                };
            }

            this.LoadNextItemFromQueue();
        }
Exemple #7
0
        /// <summary>
        /// Adds the dropdown groups for result row.
        /// </summary>
        /// <param name="resultRow">The result row.</param>
        /// <param name="rowContext">The row context.</param>
        /// <param name="expand">The expand.</param>
        public override void AddDropdownGroupsForResultRow(UPMResultRow resultRow, UPCoreMappingResultRowContext rowContext, UPConfigExpand expand)
        {
            UPCoreMappingResultContext resultContext = rowContext.Context;

            if (resultContext.DropdownFields.Any())
            {
                int detailFieldCount = resultContext.DropdownFields.Count;
                if (detailFieldCount > 0)
                {
                    UPCRMResultRow row             = rowContext.Row;
                    string         recordId        = row.RecordIdentificationAtIndex(0);
                    var            detailGroupCol1 =
                        new UPMTimelineDetailsGroup(FieldIdentifier.IdentifierWithInfoAreaIdRecordIdFieldId(this.InfoAreaId, recordId, "DetailField_Left"))
                    {
                        Invalid       = true,
                        ResultContext = resultContext
                    };
                    resultRow.AddDetailGroup(detailGroupCol1);
                }
            }
        }
        private void HandleBundleScaleResult(UPCRMResult result)
        {
            int count = result.RowCount;

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i);
                    string         bundleRecordIdentification = row.RecordIdentificationAtIndex(1);
                    if (!string.IsNullOrEmpty(bundleRecordIdentification))
                    {
                        UPSEBundlePricing root = this.bundleDictionary.ValueOrDefault(row.RecordIdentificationAtIndex(1));
                        if (root != null)
                        {
                            UPSEBundlePricingScale bundleScale = new UPSEBundlePricingScale(row, this.BundleScaleConfigFieldControl, this.Pricing);
                            root.AddScale(bundleScale);
                        }
                    }
                }
            }

            this.FinishedLoadingSuccessfully();
        }
        private void HandleBaseScaleResult(UPCRMResult result)
        {
            int count = result.RowCount;

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    UPCRMResultRow row = (UPCRMResultRow)result.ResultRowAtIndex(i);
                    string         conditionRecordIdentification = row.RecordIdentificationAtIndex(1);
                    if (!string.IsNullOrEmpty(conditionRecordIdentification))
                    {
                        UPSEPricingCondition root = this.conditionDictionary.ValueOrDefault(row.RecordIdentificationAtIndex(1));
                        if (root != null)
                        {
                            UPSEPricingScale pricingScale = new UPSEPricingScale(row, this.ScaleConfigFieldControl, this.Pricing);
                            root.AddScale(pricingScale);
                        }
                    }
                }
            }

            this.StartBundleQuery();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UPSEPricingConditionBase"/> class.
 /// </summary>
 /// <param name="row">The row.</param>
 /// <param name="fieldControl">The field control.</param>
 /// <param name="pricingSet">The pricing set.</param>
 public UPSEPricingConditionBase(UPCRMResultRow row, FieldControl fieldControl, UPSEPricingSet pricingSet)
     : this(row.RecordIdentificationAtIndex(0), fieldControl.FunctionNames(row), pricingSet)
 {
 }
Exemple #11
0
        // functionName == nil => all Fields
        private static List <UPMStringField> FieldsForResultRow(UPCRMResultRow row, string functionName, int tabIndex, bool addHidden)
        {
            List <UPMStringField> fields             = new List <UPMStringField>();
            FieldControlTab       sourceFieldControl = row.Result.MetaInfo.SourceFieldControl.TabAtIndex(tabIndex);
            int offset     = tabIndex == 0 ? 0 : row.Result.MetaInfo.SourceFieldControl.TabAtIndex(0).Fields.Count;
            int fieldCount = tabIndex == 0 ? sourceFieldControl.Fields.Count : row.NumberOfColumns;

            for (int rowFieldIndex = 0; rowFieldIndex < fieldCount;)
            {
                string fieldFunctionNames = sourceFieldControl.FieldAtIndex(rowFieldIndex)?.Function ?? string.Empty;
                var    functionNames      = fieldFunctionNames.Split(',').ToList();
                functionNames = functionNames.Count == 0 ? new List <string> {
                    string.Empty
                } : functionNames;
                UPConfigFieldControlField configField = sourceFieldControl.FieldAtIndex(rowFieldIndex);
                FieldAttributes           attributes  = configField?.Attributes;
                bool found = false;
                foreach (string fieldFunctionName in functionNames)
                {
                    if (functionName == null || fieldFunctionName.StartsWith(functionName))
                    {
                        UPMStringField stringField = new UPMStringField(new FieldIdentifier(row.RecordIdentificationAtIndex(0), configField.Field.FieldIdentification));
                        stringField.Hidden = attributes.Hide;
                        if (attributes.FieldCount > 0)
                        {
                            List <string> combineFields = new List <string>();
                            for (int fieldIndex = 0; fieldIndex < attributes.FieldCount; fieldIndex++)
                            {
                                combineFields.Add(row.ValueAtIndex(rowFieldIndex + offset));
                                rowFieldIndex++;
                            }

                            stringField.StringValue = attributes.FormatValues(combineFields);
                        }
                        else
                        {
                            stringField.StringValue = row.ValueAtIndex(rowFieldIndex + offset);
                            rowFieldIndex++;
                        }

                        if (addHidden || !stringField.Hidden)
                        {
                            fields.Add(stringField);
                        }

                        found = true;
                    }
                }

                if (!found)
                {
                    rowFieldIndex++;
                }
            }

            return(fields);
        }
        /// <summary>
        /// The document data for result row.
        /// </summary>
        /// <param name="resultRow">
        /// The result row.
        /// </param>
        /// <returns>
        /// The <see cref="DocumentData"/>.
        /// </returns>
        public DocumentData DocumentDataForResultRow(UPCRMResultRow resultRow)
        {
            var tab    = this.FieldControl.TabAtIndex(0);
            var title  = this.ResultIndexOfTitle >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfTitle) : null;
            var length = this.ResultIndexOfLength >= 0
                             ? resultRow.RawValueAtIndex(this.ResultIndexOfLength).ToUInt64()
                             : 0;
            var dateString = this.ResultIndexOfDate >= 0 ? resultRow.RawValueAtIndex(this.ResultIndexOfDate) : null;
            var mimeType   = this.ResultIndexOfMimeType >= 0
                                  ? resultRow.RawValueAtIndex(this.ResultIndexOfMimeType)
                                  : null;
            var updDateString = this.ResultIndexOfUpdDate >= 0
                                       ? resultRow.RawValueAtIndex(this.ResultIndexOfUpdDate)
                                       : null;
            var updTimeString = this.ResultIndexOfUpdTime >= 0
                                       ? resultRow.RawValueAtIndex(this.ResultIndexOfUpdTime)
                                       : null;
            var displayText = this.ResultIndexOfDisplayText >= 0
                                     ? resultRow.FormattedFieldValueAtIndex(this.ResultIndexOfDisplayText, null, tab)
                                     : null;
            var displayDateString = this.ResultIndexOfDisplayDate >= 0
                                           ? resultRow.FormattedFieldValueAtIndex(this.ResultIndexOfDisplayDate, null, tab)
                                           : null;
            DateTime?documentDate = null;

            if (!string.IsNullOrEmpty(dateString))
            {
                documentDate      = dateString.DateFromCrmValue();
                displayDateString = DateExtensions.LocalizedFormattedDate(documentDate);
            }

            DateTime?updateDate = null;

            if (!string.IsNullOrEmpty(updDateString))
            {
                updateDate = updDateString.DateTimeFromCrmValue();
            }

            string recordIdentification;

            if (resultRow.NumberOfRecordIds() > this.RecordIndex)
            {
                recordIdentification = resultRow.RecordIdentificationAtIndex(this.RecordIndex);
            }
            else
            {
                recordIdentification = resultRow.RootRecordIdentification;
            }

            string d1RecordId = resultRow.RecordIdentificationForLinkInfoAreaIdLinkId("D1", -1);

            return(new DocumentData(
                       recordIdentification,
                       title,
                       mimeType,
                       documentDate,
                       length,
                       updateDate,
                       displayText,
                       displayDateString,
                       d1RecordId));
        }
Exemple #13
0
        /// <summary>
        /// Edits the contexts for result row.
        /// </summary>
        /// <param name="resultRow">The result row.</param>
        /// <param name="tabConfig">The tab configuration.</param>
        /// <param name="editFieldDictionary">The edit field dictionary.</param>
        /// <param name="initialValues">The initial values.</param>
        /// <param name="fieldPostfix">The field postfix.</param>
        /// <param name="initialRecords">The initial records.</param>
        /// <returns></returns>
        public List <object> EditContextsForResultRow(UPCRMResultRow resultRow, FieldControlTab tabConfig,
                                                      Dictionary <string, UPEditFieldContext> editFieldDictionary, Dictionary <string, object> initialValues, string fieldPostfix, List <UPCRMRecord> initialRecords)
        {
            var recordIdentification = resultRow?.RecordIdentificationAtIndex(0);

            var         fieldArray        = new List <object>();
            UPCRMRecord offlineRootRecord = null;

            if (initialRecords?.Count > 0)
            {
                offlineRootRecord = initialRecords.FirstOrDefault();
            }

            var identifierPrefix = recordIdentification;

            if (string.IsNullOrEmpty(identifierPrefix))
            {
                identifierPrefix = $"{this.TabConfig.FieldControl.UnitName}_{this.TabIndex}";
            }

            var fieldCount = tabConfig?.NumberOfFields ?? 0;

            for (var j = 0; j < fieldCount; j++)
            {
                var fieldConfig = tabConfig?.FieldAtIndex(j);
                if (fieldConfig == null)
                {
                    continue;
                }

                var        fieldAttributes   = fieldConfig.Attributes;
                var        currentInfoAreaId = fieldConfig.InfoAreaId;
                var        currentLinkId     = fieldConfig.LinkId;
                var        fieldIdentifier   = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(identifierPrefix, fieldConfig.Identification);
                UPSelector selector          = null;
                var        selectorDef       = fieldConfig.Attributes?.Selector;
                if (selectorDef != null)
                {
                    var filterParameters = this.EditPageContext?.ViewReference?.ContextValueForKey("copyFields")?.JsonDictionaryFromString();
                    if (resultRow?.Result != null && resultRow.IsNewRow)
                    {
                        selector = UPSelector.SelectorFor(
                            resultRow.RootRecordIdentification?.InfoAreaId(),
                            resultRow.Result.ParentRecordIdentification,
                            resultRow.Result.LinkId,
                            selectorDef,
                            filterParameters,
                            fieldConfig);
                    }
                    else
                    {
                        selector = UPSelector.SelectorFor(resultRow?.RootRecordIdentification, selectorDef, filterParameters, fieldConfig);
                    }

                    selector.Build();
                    if (selector.OptionCount == 0 && selector.IsStaticSelector)
                    {
                        selector = null;
                    }
                }

                var isEditField = this.enableLinkedEditFields ||
                                  selector != null ||
                                  (tabConfig.FieldControl.InfoAreaId == currentInfoAreaId && currentLinkId <= 0);

                var isHidden       = fieldAttributes.Hide;
                var isReadOnly     = isEditField && fieldAttributes.ReadOnly;
                var rawFieldValue0 = resultRow?.RawValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                var fieldInfo      = fieldConfig.Field.FieldInfo;
                if (isEditField && !isReadOnly && !(selector is UPRecordSelector && ((UPRecordSelector)selector).IgnoreFieldInfo))
                {
                    if (fieldInfo.IsReadOnly)
                    {
                        isReadOnly = true;
                    }
                    else if (resultRow?.IsNewRow == true || string.IsNullOrEmpty(rawFieldValue0))
                    {
                        if (fieldInfo.LockedOnNew)
                        {
                            isReadOnly = true;
                        }
                    }
                    else if (fieldInfo.LockedOnUpdate && !fieldInfo.IsEmptyValue(rawFieldValue0))
                    {
                        isReadOnly = true;
                    }
                }

                string             offlineValue = null;
                bool               offlineChanged;
                string             rawFieldValue;
                UPEditFieldContext editFieldContext;
                if (isEditField)
                {
                    List <UPEditFieldContext> childFields = null;
                    if (fieldAttributes.FieldCount > 1 && selector == null)
                    {
                        childFields = new List <UPEditFieldContext>();
                        for (var k = 1; k < fieldAttributes.FieldCount; k++)
                        {
                            var childFieldConfig = tabConfig.FieldAtIndex(++j);
                            if (childFieldConfig != null)
                            {
                                rawFieldValue = resultRow.RawValueAtIndex(childFieldConfig.TabIndependentFieldIndex);
                                if (initialValues != null)
                                {
                                    rawFieldValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, childFieldConfig, initialValues);
                                }

                                offlineChanged = false;

                                if (offlineRootRecord != null)
                                {
                                    offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(childFieldConfig.FieldId);
                                    if (offlineValue != null && !offlineValue.Equals(rawFieldValue))
                                    {
                                        offlineChanged = true;
                                    }
                                }

                                editFieldContext = UPEditFieldContext.ChildFieldContextForFieldConfigValue(childFieldConfig, rawFieldValue);
                                if (offlineChanged)
                                {
                                    editFieldContext.SetOfflineChangeValue(offlineValue);
                                }

                                childFields.Add(editFieldContext);
                            }
                        }
                    }

                    var markAsChanged = false;
                    rawFieldValue = rawFieldValue0;
                    if (initialValues != null)
                    {
                        string initialValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, fieldConfig, initialValues);
                        if (!rawFieldValue.Equals(initialValue))
                        {
                            markAsChanged = true;
                            rawFieldValue = initialValue;
                        }
                    }

                    offlineChanged = false;
                    offlineValue   = null;
                    if (offlineRootRecord != null)
                    {
                        offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(fieldConfig.FieldId);
                        if (offlineValue != null && !offlineValue.Equals(rawFieldValue))
                        {
                            offlineChanged = true;
                        }
                    }

                    if (selector != null)
                    {
                        // Sometimes it makes sense to add the Link field , so you have the link information on the EditPage , but the field is not displayed .
                        // Thus, the field is interpreted as EditField Selector must be set.
                        if (isHidden)
                        {
                            editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else if (isReadOnly && ConfigurationUnitStore.DefaultStore.ConfigValueIsSet("Disable.82213"))
                        {
                            editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else
                        {
                            editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, selector);
                        }
                    }
                    else
                    {
                        if (isHidden)
                        {
                            editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else if (isReadOnly)
                        {
                            editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else
                        {
                            editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, childFields as List <UPEditFieldContext>);
                        }
                    }

                    if (fieldInfo.DateFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId)
                    {
                        editFieldContext.DateOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.DateFieldId, currentInfoAreaId, -1);
                    }
                    else if (fieldInfo.TimeFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId)
                    {
                        editFieldContext.TimeOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.TimeFieldId, currentInfoAreaId, -1);
                    }

                    if (offlineChanged)
                    {
                        editFieldContext.SetOfflineChangeValue(offlineValue);
                    }
                    else if (markAsChanged)
                    {
                        editFieldContext.SetChanged(true);
                    }

                    if (editFieldContext != null)
                    {
                        if (!string.IsNullOrEmpty(fieldPostfix))
                        {
                            editFieldContext.FieldLabelPostfix = fieldPostfix;
                        }

                        if (editFieldDictionary != null)
                        {
                            editFieldDictionary.SetObjectForKey(editFieldContext, fieldConfig.Identification);
                            if (childFields != null)
                            {
                                foreach (var childFieldContext in childFields)
                                {
                                    editFieldDictionary.SetObjectForKey(childFieldContext, childFieldContext.FieldConfig.Identification);
                                }
                            }
                        }

                        fieldArray.Add(editFieldContext);
                    }
                }
                else
                {
                    string fieldValue;
                    if (fieldAttributes.FieldCount > 1)
                    {
                        fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues);
                        }

                        var values = !string.IsNullOrEmpty(fieldValue) ?
                                     new List <string> {
                            fieldValue
                        } :
                        new List <string>();

                        for (var k = 1; k < fieldAttributes.FieldCount; k++)
                        {
                            var childfieldConfig = tabConfig.FieldAtIndex(++j);
                            if (childfieldConfig == null)
                            {
                                continue;
                            }

                            fieldValue = resultRow?.ValueAtIndex(childfieldConfig.TabIndependentFieldIndex);
                            if (string.IsNullOrEmpty(fieldValue))
                            {
                                fieldValue = this.ValueForLinkFieldFromInitialValues(childfieldConfig, initialValues);
                            }

                            if (string.IsNullOrEmpty(fieldValue))
                            {
                                fieldValue = string.Empty;
                            }

                            values.Add(fieldValue);
                        }

                        fieldValue = fieldAttributes.FormatValues(values);
                    }
                    else
                    {
                        fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues);
                        }
                    }

                    UPMField field;
                    if (!isHidden && !string.IsNullOrEmpty(fieldValue))
                    {
                        field = new UPMStringField(fieldIdentifier);
                        ((UPMStringField)field).StringValue = fieldValue;
                    }
                    else
                    {
                        field = null;
                    }

                    if (field != null)
                    {
                        if (!fieldConfig.Attributes.NoLabel)
                        {
                            field.LabelText = fieldConfig.Label;
                        }

                        SetAttributesOnField(fieldAttributes, field);
                        fieldArray.Add(field);
                    }
                }
            }

            return(fieldArray);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UPSEPricingCondition"/> class.
 /// </summary>
 /// <param name="row">The row.</param>
 /// <param name="fieldControl">The field control.</param>
 /// <param name="bundleKeyIndex">Index of the bundle key.</param>
 /// <param name="pricingSet">The pricing set.</param>
 public UPSEPricingCondition(UPCRMResultRow row, FieldControl fieldControl, int bundleKeyIndex, UPSEPricingSet pricingSet)
     : this(row.RecordIdentificationAtIndex(0), fieldControl.FunctionNames(row),
            bundleKeyIndex > 0 ? row.RecordIdentificationAtIndex(bundleKeyIndex) : null,
            pricingSet)
 {
 }
        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();
        }
Exemple #16
0
        private void HandlePricingResult(UPCRMResult result)
        {
            int count = result.RowCount;
            Dictionary <string, UPSEPrice> articleDictionary = new Dictionary <string, UPSEPrice>(count);
            bool pricingByItemNumber    = this.PricingItemNumber.Length > 0;
            int  pricingItemNumberIndex = 0;

            if (pricingByItemNumber)
            {
                pricingItemNumberIndex = result.MetaInfo.IndexOfFunctionName(this.PricingItemNumber);
                Logger.LogError($"cannot execute pricing by item number because function name {this.PricingItemNumber} was not found in the pricing result");
                if (pricingItemNumberIndex < 0)
                {
                    pricingByItemNumber = false;
                }
            }

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow row             = (UPCRMResultRow)result.ResultRowAtIndex(i);
                string         articleRecordId = pricingByItemNumber ? row.RawValueAtIndex(pricingItemNumberIndex) : row.RecordIdentificationAtIndex(1).RecordId();

                if (articleRecordId == null)
                {
                    continue;
                }

                UPSEPrice price         = new UPSEPrice(row, articleRecordId, this);
                UPSEPrice existingPrice = articleDictionary.ValueOrDefault(articleRecordId);
                if (existingPrice == null)
                {
                    articleDictionary.SetObjectForKey(price, articleRecordId);
                }
                else
                {
                    bool checkCurrency = true;
                    foreach (string priorityColumn in this.PriceListPriorityColumns)
                    {
                        string existingValue = existingPrice.DataDictionary.ValueOrDefault(priorityColumn) as string;
                        string currentValue  = price.DataDictionary.ValueOrDefault(priorityColumn) as string;

                        if (string.IsNullOrEmpty(existingValue) || existingValue == "0")
                        {
                            if (!string.IsNullOrEmpty(currentValue) && currentValue != "0")
                            {
                                articleDictionary[articleRecordId] = price;
                                checkCurrency = false;
                                break;
                            }
                        }
                        else if (string.IsNullOrEmpty(currentValue) || currentValue == "0")
                        {
                            checkCurrency = false;
                            break;
                        }
                    }

                    if (checkCurrency)
                    {
                        if (price.Currency > 0 && this.Currency == price.Currency)
                        {
                            articleDictionary.SetObjectForKey(price, articleRecordId);
                        }
                        else if (existingPrice.Currency != this.Currency)
                        {
                            int baseCurrency = 0;
                            if (this.CurrencyConversion != null)
                            {
                                baseCurrency = this.CurrencyConversion.BaseCurrency.CatalogCode;
                            }
                            if (baseCurrency != existingPrice.Currency)
                            {
                                if (price.Currency == baseCurrency)
                                {
                                    articleDictionary.SetObjectForKey(price, articleRecordId);
                                }
                            }
                        }
                    }
                }
            }

            this.priceForArticle = articleDictionary;
            if (this.BulkVolumes != null)
            {
                this.BulkVolumes.Load(this.filterParameters, this.SerialEntry.RequestOption);
            }
            else
            {
                this.HandleBulkVolumesResult();
            }
        }