Esempio n. 1
0
        private void cmdClear_Click(object sender, RoutedEventArgs e)
        {
            MInterval v = (MInterval)(sender as Button).Tag;

            cfg.RemoveInterval(v);
            cfg.IsModified = true;
        }
Esempio n. 2
0
        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox   tb    = sender as TextBox;
            String    value = tb.Text;
            MInterval vi    = (MInterval)tb.Tag;

            if (value.Trim().Equals(""))
            {
                vi.ToValue = vi.OldToValue;
                return;
            }

            double toQty   = CUtil.StringToDouble(value);
            double fromQty = CUtil.StringToDouble(vi.FromValue);

            if (toQty <= fromQty)
            {
                vi.ToValue = vi.OldToValue;
                return;
            }

            cfg.ArrangeInterval();
        }
        public CPrice getStepPrice(MIntervalConfig ivc, CBasketItem bi)
        {
            ArrayList intervals = new ArrayList();

            int idx = 0;

            foreach (MInterval iv in ivc.IntervalItems)
            {
                iv.Used = 0.00;
                intervals.Add(iv);
                idx++;
            }

            if (intervals.Count <= 0)
            {
                return(null);
            }

            double left = bi.Quantity;

            int cnt = ivc.IntervalItems.Count;

            idx = 0;

            while (left > 0)
            {
                MInterval iv    = (MInterval)intervals[idx];
                double    from  = CUtil.StringToDouble(iv.FromValue);
                double    to    = CUtil.StringToDouble(iv.ToValue);
                double    value = CUtil.StringToDouble(iv.ConfigValue);
                double    gap   = to - from;
                iv.RepeatCount++;

                double used = 0.00;
                if (left > gap)
                {
                    left = left - gap;
                    used = gap;
                }
                else
                {
                    used = left;
                    left = 0.00;
                }

                iv.Used = iv.Used + used;
                idx++;
                if (idx >= cnt)
                {
                    idx = 0;
                }
            }

            double total = 0.00;

            foreach (MInterval vi in intervals)
            {
                if (ivc.StepScopeType == 1)
                {
                    total = total + vi.RepeatCount * CUtil.StringToDouble(vi.ConfigValue);
                }
                else
                {
                    //0 - by unit price
                    total = total + vi.Used * CUtil.StringToDouble(vi.ConfigValue);
                }
            }

            CPrice p = new CPrice();

            p.TotalAmount = total;
            p.UnitPrice   = total / bi.Quantity;

            return(p);
        }
        protected CPrice getStepDiscount(MIntervalConfig ivc, CBasketItem bi)
        {
            ArrayList intervals = new ArrayList();
            MPackage  pkg       = getPackage();

            int idx = 0;

            foreach (MInterval iv in ivc.IntervalItems)
            {
                iv.Used = 0.00;
                intervals.Add(iv);
                idx++;
            }

            double qty = 0.00;

            if (ivc.MappingType == 0)
            {
                qty = bi.Quantity;
            }
            else
            {
                //Map by amount
                //We can use both total bill amount or amount that we use for looking up
                qty = bi.GetAmount();
            }
            double left = qty;

            int cnt = ivc.IntervalItems.Count;

            idx = 0;

            while (left > 0)
            {
                MInterval iv    = (MInterval)intervals[idx];
                double    from  = CUtil.StringToDouble(iv.FromValue);
                double    to    = CUtil.StringToDouble(iv.ToValue);
                double    value = CUtil.StringToDouble(iv.ConfigValue);
                double    gap   = to - from;
                iv.RepeatCount++;

                double used = 0.00;
                if (left > gap)
                {
                    left = left - gap;
                    used = gap;
                }
                else
                {
                    used = left;
                    left = 0.00;
                }

                iv.Used = iv.Used + used;
                idx++;
                if (idx >= cnt)
                {
                    idx = 0;
                }
            }

            double total = 0.00;

            foreach (MInterval vi in intervals)
            {
                if (ivc.TierScopeType == 0)
                {
                    //Fixed
                    total = total + vi.RepeatCount * CUtil.StringToDouble(vi.ConfigValue);
                }
                else if (ivc.TierScopeType == 1)
                {
                    //Per unit
                    if (ivc.MappingType == 0)
                    {
                        //Map by quantity
                        total = total + vi.Used * CUtil.StringToDouble(vi.ConfigValue);
                    }
                }
                else
                {
                    //2 - Percent of amount
                    if (ivc.MappingType == 1)
                    {
                        //Map by amount
                        //For step, we can use the vi.Used from the amount that we split it up
                        total = total + vi.Used * CUtil.StringToDouble(vi.ConfigValue) / 100;
                    }
                }
            }

            CPrice p = new CPrice();

            p.DiscountAmount = total;

            return(p);
        }