private void HandleBundleResult(UPCRMResult result)
        {
            int count = result.RowCount;

            if (count > 0)
            {
                this.bundleDictionary = new Dictionary <string, UPSEBundlePricing>(count);
                for (int i = 0; i < count; i++)
                {
                    UPSEBundlePricing bundle = new UPSEBundlePricing((UPCRMResultRow)result.ResultRowAtIndex(i), this.ConfigFieldControl, this.Pricing);
                    this.bundleDictionary[bundle.RecordIdentification] = bundle;
                }

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

            if (count > 0)
            {
                this.conditionDictionary = new Dictionary <string, UPSEPricingCondition>(count);
                int bundleKeyIndex = 0;
                if (this.BundleConfigFieldControl != null)
                {
                    int infoAreaIndex = this.currentQuery.IndexOfResultInfoAreaIdLinkId(this.BundleConfigFieldControl.InfoAreaId, -1);
                    if (infoAreaIndex > 0)
                    {
                        bundleKeyIndex = infoAreaIndex;
                    }
                }

                for (int i = 0; i < count; i++)
                {
                    UPSEPricingCondition condition = new UPSEPricingCondition(
                        (UPCRMResultRow)result.ResultRowAtIndex(i), this.ConfigFieldControl, bundleKeyIndex, this);

                    this.conditionDictionary[condition.RecordIdentification] = condition;
                }

                this.StartBaseScaleQuery();
            }
            else
            {
#if  PRICINGDEMO
                this.conditionDictionary = NSMutableDictionary.TheNew();
                this.bundleDictionary    = NSMutableDictionary.TheNew();
                UPSEPricingCondition condition     = UPSEPricingCondition.DemoBase();
                UPSEBundlePricing    bundlePricing = UPSEPricingCondition.DemoBundle();
                this.conditionDictionary.SetObjectForKey(condition, condition.RecordIdentification);
                this.bundleDictionary.SetObjectForKey(bundlePricing, bundlePricing.RecordIdentification);
#endif

                this.FinishedLoadingSuccessfully();
            }
        }
        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();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UPSEComputedBundlePricing"/> class.
        /// </summary>
        /// <param name="bundlePricing">The bundle pricing.</param>
        /// <param name="rowRecordId">The row record identifier.</param>
        /// <param name="rows">The rows.</param>
        public UPSEComputedBundlePricing(UPSEBundlePricing bundlePricing, string rowRecordId, List <UPSERow> rows)
            : base(bundlePricing.RecordIdentification, bundlePricing.DataDictionary, null)
        {
            this.OtherQuantity = 0;
            this.RowRecordId   = rowRecordId;
            bool reduceByPrice = bundlePricing.HasPriceBoundaries;

            foreach (UPSERow row in rows)
            {
                if (row.RowRecordId == this.RowRecordId || row.RowPricing.BundleConditions.RecordIdentification != this.RecordIdentification)
                {
                    continue;
                }

                if (this.otherPositions == null)
                {
                    this.otherPositions = new List <UPSERow> {
                        row
                    };
                }
                else
                {
                    this.otherPositions.Add(row);
                }

                if (reduceByPrice)
                {
                    this.OtherEndPrice += row.EndPriceWithoutDiscount;
                }
                else
                {
                    this.OtherQuantity += (int)row.Quantity;
                }
            }

            if (reduceByPrice)
            {
                if (this.OtherEndPrice == 0)
                {
                    this.scales = bundlePricing.Scales;
                }
                else if (bundlePricing.Scales.Count > 0)
                {
                    List <UPSEPricingBase> scaleArray = new List <UPSEPricingBase>();
                    foreach (UPSEBundlePricingScale scale in bundlePricing.Scales)
                    {
                        UPSEBundlePricingScale adjustedScale = scale.BundlePricingByReducingPrice(this.OtherEndPrice);
                        if (adjustedScale != null)
                        {
                            scaleArray.Add(adjustedScale);
                        }
                    }

                    this.scales = scaleArray;
                }
            }
            else if (this.OtherQuantity == 0)
            {
                this.scales = bundlePricing.Scales;
            }
            else if (bundlePricing.Scales.Count > 0)
            {
                List <UPSEPricingBase> scaleArray = new List <UPSEPricingBase>();
                foreach (UPSEBundlePricingScale scale in bundlePricing.Scales)
                {
                    UPSEBundlePricingScale adjustedScale = scale.BundlePricingByReducingQuantity(this.OtherQuantity);
                    if (adjustedScale != null)
                    {
                        scaleArray.Add(adjustedScale);
                    }
                }

                this.scales = scaleArray;
            }
        }