示例#1
0
        private void SaveDiscount()
        {
            VolumeDiscount discount = _VolumeDiscount;

            discount.Name = _Product.Name;
            //LOOP THROUGH GRID ROWS AND SET MATRIX
            int rowIndex = 0;

            foreach (GridViewRow row in DiscountLevelGrid.Rows)
            {
                if (discount.Levels.Count < (rowIndex + 1))
                {
                    // ADD A NEW DISCOUNT LEVEL FOR NEW ROWS
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    newDiscountLevel.VolumeDiscountId = _VolumeDiscountId;
                    discount.Levels.Add(newDiscountLevel);
                }
                decimal             minValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MinValue")).Text);
                decimal             maxValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MaxValue")).Text);
                decimal             discountAmount = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("DiscountAmount")).Text);
                bool                isPercent      = false;
                VolumeDiscountLevel thisLevel      = discount.Levels[rowIndex];
                thisLevel.MinValue       = minValue;
                thisLevel.MaxValue       = maxValue;
                thisLevel.DiscountAmount = discountAmount;
                thisLevel.IsPercent      = isPercent;
                rowIndex++;
            }
            //SCOPE
            discount.IsGlobal = false;
            discount.Save();
        }
示例#2
0
        protected void Page_Init(object sender, EventArgs e)
        {
            _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            _Product   = ProductDataSource.Load(_ProductId);
            if (_Product != null)
            {
                if (_Product.VolumeDiscounts.Count > 0)
                {
                    _VolumeDiscountId = _Product.VolumeDiscounts[0].Id;
                    _VolumeDiscount   = _Product.VolumeDiscounts[0];
                    _IsAdd            = false;
                }
                else
                {
                    _IsAdd               = true;
                    _VolumeDiscount      = new VolumeDiscount();
                    _VolumeDiscount.Name = _Product.Name;
                    _VolumeDiscount.Products.Add(_Product);
                    _VolumeDiscount.Save();
                    _VolumeDiscountId = _VolumeDiscount.Id;
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    _VolumeDiscount.Levels.Add(newDiscountLevel);
                }

                DiscountLevelGrid.DataSource = _VolumeDiscount.Levels;
                DiscountLevelGrid.DataBind();
            }
        }
        public static decimal GetShopPrice(OrderItem item)
        {
            if (item.OrderItemType == OrderItemType.Discount)
            {
                return(0);
            }

            if (item.Product == null || !item.Product.VolumeDiscounts.Any() || !item.Product.VolumeDiscounts[0].Levels.Any())
            {
                return(Math.Abs(item.Price));
            }

            VolumeDiscount      volumeDiscount = item.Product.VolumeDiscounts[0];
            VolumeDiscountLevel lastLevel      = volumeDiscount.Levels.Last();
            decimal             discountAmount = 0;

            foreach (var rec in volumeDiscount.Levels)
            {
                if (item.Quantity >= rec.MinValue && item.Quantity <= rec.MaxValue)
                {
                    discountAmount = rec.DiscountAmount;
                    break;
                }
            }

            if (item.Quantity >= lastLevel.MinValue)
            {
                discountAmount = lastLevel.DiscountAmount;
            }

            return(discountAmount);
        }
        protected void AddRowButton_Click(object sender, EventArgs e)
        {
            SaveDiscount();
            VolumeDiscount      discount         = _VolumeDiscount;
            VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel(discount, 0, 0, 0, true);

            discount.Levels.Add(newDiscountLevel);
            discount.Save();
            DiscountLevelGrid.DataSource = discount.Levels;
            DiscountLevelGrid.DataBind();
        }
        private void SaveDiscount()
        {
            VolumeDiscount discount = _VolumeDiscount;

            discount.Name         = Name.Text;
            discount.IsValueBased = IsValueBased.SelectedIndex == 1 ? true : false;
            //LOOP THROUGH GRID ROWS AND SET MATRIX
            int rowIndex = 0;

            foreach (GridViewRow row in DiscountLevelGrid.Rows)
            {
                if (discount.Levels.Count < (rowIndex + 1))
                {
                    // ADD A NEW DISCOUNT LEVEL FOR NEW ROWS
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    newDiscountLevel.Id = _VolumeDiscountId;
                    discount.Levels.Add(newDiscountLevel);
                }
                decimal             minValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MinValue")).Text);
                decimal             maxValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MaxValue")).Text);
                decimal             discountAmount = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("DiscountAmount")).Text);
                bool                isPercent      = (((DropDownList)row.FindControl("IsPercent")).SelectedIndex == 0);
                VolumeDiscountLevel thisLevel      = discount.Levels[rowIndex];
                thisLevel.MinValue       = minValue;
                thisLevel.MaxValue       = maxValue;
                thisLevel.DiscountAmount = discountAmount;
                thisLevel.IsPercent      = isPercent;
                thisLevel.Save();
                rowIndex++;
            }
            //SCOPE
            discount.IsGlobal = (UseGlobalScope.SelectedIndex == 0);
            //GROUP RESTRICTION
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                _VolumeDiscount.Groups.Clear();
                _VolumeDiscount.Save();
                foreach (ListItem item in GroupList.Items)
                {
                    Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _VolumeDiscount.Groups.Add(group);
                    }
                }
            }
            else
            {
                _VolumeDiscount.Groups.Clear();
            }
            discount.Save();
        }
示例#6
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            VolumeDiscount newDiscount = new VolumeDiscount();

            newDiscount.Store = AbleContext.Current.Store;
            newDiscount.Name  = "New Discount";
            newDiscount.Save();

            VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel(newDiscount, 0, 0, 0, true);

            newDiscount.Levels.Add(newDiscountLevel);
            newDiscount.Save();
            Response.Redirect("EditDiscount.aspx?VolumeDiscountId=" + newDiscount.Id.ToString() + "&IsAdd=1");
        }
示例#7
0
        protected void DiscountLevelGrid_PreRender(object sender, EventArgs e)
        {
            VolumeDiscount discount = _VolumeDiscount;

            if (discount != null)
            {
                if (discount.Levels.Count == 0)
                {
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    discount.Levels.Add(newDiscountLevel);
                }
            }

            //Moved DataBind to Page_Init
        }
        protected void DiscountLevelGrid_PreRender(object sender, EventArgs e)
        {
            VolumeDiscount discount = _VolumeDiscount;

            if (discount != null)
            {
                if (discount.Levels.Count == 0)
                {
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    discount.Levels.Add(newDiscountLevel);
                }

                DiscountLevelGrid.DataSource = _VolumeDiscount.Levels;
                DiscountLevelGrid.DataBind();
            }
        }
示例#9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            bool    discountsFound = false;
            int     _ProductId     = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            Product _Product       = ProductDataSource.Load(_ProductId);

            if (_Product != null)
            {
                IList <VolumeDiscount> availableDiscounts = VolumeDiscountDataSource.GetAvailableDiscounts(_ProductId);
                if (availableDiscounts.Count > 0)
                {
                    //SEE WHETHER THERE IS ONE DISCOUNT
                    //AND IT ALWAYS HAS NO VALUE
                    bool show = true;
                    if (availableDiscounts.Count == 1)
                    {
                        VolumeDiscount testDiscount = availableDiscounts[0];
                        if (testDiscount.Levels.Count == 1)
                        {
                            VolumeDiscountLevel testLevel = testDiscount.Levels[0];
                            show = ((testLevel.MinValue > 1) || (testLevel.DiscountAmount > 0));
                        }
                    }
                    if (show)
                    {
                        phCaption.Text           = this.Caption;
                        DiscountsGrid.DataSource = availableDiscounts;
                        DiscountsGrid.DataBind();
                        discountsFound = true;
                    }
                }
            }
            //DO NOT DISPLAY THIS CONTROL IF NO DISCOUNTS AVAILABLE
            if (!discountsFound)
            {
                this.Controls.Clear();
            }
        }