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();
        }
예제 #2
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");
        }
예제 #3
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();
        }
예제 #4
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 SaveButton_Click(object sender, EventArgs e)
        {
            //CLEAR OUT EXISTING ASSIGNMENTS
            foreach (GridViewRow row in DiscountGrid.Rows)
            {
                int            discountId = (int)DiscountGrid.DataKeys[row.DataItemIndex].Value;
                VolumeDiscount discount   = VolumeDiscountDataSource.Load(discountId);
                CheckBox       attached   = (CheckBox)row.FindControl("Attached");
                if ((attached != null) && attached.Checked)
                {
                    if (!discount.Products.Contains(_Product))
                    {
                        discount.Products.Add(_Product);
                    }
                }
                else
                {
                    if (discount.Products.Contains(_Product))
                    {
                        discount.Products.Remove(_Product);
                    }
                }

                discount.Save();
            }
            SavedMessage.Visible = true;
        }
        private void SetLink(int productId, bool linked)
        {
            int index = _VolumeDiscount.Products.IndexOf(productId);

            if (linked && (index < 0))
            {
                Product product = ProductDataSource.Load(productId);
                _VolumeDiscount.Products.Add(product);
                _VolumeDiscount.Save();
            }
            else if (!linked && (index > -1))
            {
                _VolumeDiscount.Products.RemoveAt(index);
                _VolumeDiscount.Save();
            }
        }
        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();
        }
예제 #9
0
 protected void VolumeDiscountGrid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("Copy"))
     {
         int            volumeDiscountId = AlwaysConvert.ToInt(e.CommandArgument);
         VolumeDiscount volumeDiscount   = VolumeDiscountDataSource.Load(volumeDiscountId);
         VolumeDiscount copy             = volumeDiscount.Copy(true);
         if (copy != null)
         {
             copy.Name = "Copy of " + copy.Name;
             copy.Save();
         }
         VolumeDiscountGrid.DataBind();
     }
 }