Пример #1
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();
            }
        }
        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();
        }
        protected void DiscountLevelGrid_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int index = e.RowIndex;

            SaveDiscount();
            VolumeDiscount discount = _VolumeDiscount;

            if (discount.Levels.Count >= (index + 1))
            {
                discount.Levels.DeleteAt(index);
                discount.Save();
            }
            DiscountLevelGrid.DataSource = discount.Levels;
            DiscountLevelGrid.DataBind();
        }
        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();
            }
        }