コード例 #1
0
        protected void UpdateRanges()
        {
            //PROCESS MATRIX UPDATES
            int index = 0;

            foreach (GridViewRow row in RateMatrixGrid.Rows)
            {
                ShipRateMatrix matrixItem      = _ShipMethod.ShipRateMatrices[index];
                string         rangeStartValue = GetTextBoxValue(row, "RangeStart");
                if (!string.IsNullOrEmpty(rangeStartValue))
                {
                    matrixItem.RangeStart = AlwaysConvert.ToDecimal(rangeStartValue);
                }
                else
                {
                    matrixItem.RangeStart = null;
                }
                string rangeEndValue = GetTextBoxValue(row, "RangeEnd");
                if (!string.IsNullOrEmpty(rangeEndValue))
                {
                    matrixItem.RangeEnd = AlwaysConvert.ToDecimal(rangeEndValue);
                }
                else
                {
                    matrixItem.RangeEnd = null;
                }
                matrixItem.Rate      = AlwaysConvert.ToDecimal(GetTextBoxValue(row, "Rate"));
                matrixItem.IsPercent = GetCheckBoxValue(row, "IsPercent");
                index++;
            }
        }
コード例 #2
0
        protected void AddRowButton_Click(object sender, EventArgs e)
        {
            UpdateRanges();
            ShipRateMatrix item = new ShipRateMatrix();

            item.ShipMethod = _ShipMethod;
            _ShipMethod.ShipRateMatrices.Add(item);
            _ShipMethod.ShipRateMatrices.Save();
            BindShipRateMatrix();
            RateMatrixAjax.Update();
        }
コード例 #3
0
        protected void BindShipRateMatrix()
        {
            List <ShipRateMatrix> rows = new List <ShipRateMatrix>();

            if (_ShipMethod.ShipRateMatrices.Count == 0)
            {
                //ADD A DEFAULT ROW
                ShipRateMatrix item = new ShipRateMatrix();
                item.ShipMethod = _ShipMethod;
                _ShipMethod.ShipRateMatrices.Add(item);
                _ShipMethod.Save();
            }
            foreach (ShipRateMatrix item in _ShipMethod.ShipRateMatrices)
            {
                rows.Add(item);
            }
            rows.Sort(CompareShipRateMatrix);
            RateMatrixGrid.DataSource = rows;
            RateMatrixGrid.DataBind();
        }
コード例 #4
0
        protected int CompareShipRateMatrix(ShipRateMatrix x, ShipRateMatrix y)
        {
            if (!x.RangeStart.HasValue && !x.RangeEnd.HasValue && x.Rate.Equals(0))
            {
                return(1);
            }
            if (!y.RangeStart.HasValue && !y.RangeEnd.HasValue && y.Rate.Equals(0))
            {
                return(-1);
            }

            // ASSUME NULL VALUE AS ZERO
            decimal xStart = x.RangeStart.HasValue ? x.RangeStart.Value : 0;
            decimal xEnd   = x.RangeEnd.HasValue ? x.RangeEnd.Value : 0;
            decimal yStart = y.RangeStart.HasValue ? y.RangeStart.Value : 0;
            decimal yEnd   = y.RangeEnd.HasValue ? y.RangeEnd.Value : 0;

            if (!xStart.Equals(yStart))
            {
                return(xStart.CompareTo(yStart));
            }
            if (!xEnd.Equals(yEnd))
            {
                //NEED SPECIAL HANDLING, 0 AS RANGEEND INDICATES NO MAXIMUM
                if (xEnd == 0)
                {
                    return(1);
                }
                if (yEnd == 0)
                {
                    return(-1);
                }
                return(xEnd.CompareTo(yEnd));
            }
            if (!x.Rate.Equals(y.Rate))
            {
                return(x.Rate.CompareTo(y.Rate));
            }
            return(0);
        }
コード例 #5
0
        private void SaveShipMethod()
        {
            //UPDATE NAME
            _ShipMethod.Name = Name.Text;
            //UPDATE RATE
            ShipRateMatrix shipRateMatrixItem;

            if (_ShipMethod.ShipRateMatrices.Count != 1)
            {
                _ShipMethod.ShipRateMatrices.DeleteAll();
                shipRateMatrixItem            = new ShipRateMatrix();
                shipRateMatrixItem.ShipMethod = _ShipMethod;
                _ShipMethod.ShipRateMatrices.Add(shipRateMatrixItem);
            }
            else
            {
                shipRateMatrixItem = _ShipMethod.ShipRateMatrices[0];
            }
            shipRateMatrixItem.RangeStart = 0;
            shipRateMatrixItem.RangeEnd   = 0;
            shipRateMatrixItem.Rate       = AlwaysConvert.ToDecimal(Rate.Text);
            shipRateMatrixItem.IsPercent  = false;
            //UPDATE SURCHARGE
            _ShipMethod.Surcharge = AlwaysConvert.ToDecimal(Surcharge.Text);
            if (_ShipMethod.Surcharge < 0)
            {
                _ShipMethod.Surcharge = 0;
            }
            if (_ShipMethod.Surcharge > 0)
            {
                _ShipMethod.SurchargeMode      = (SurchargeMode)AlwaysConvert.ToByte(SurchargeMode.SelectedValue);
                _ShipMethod.SurchargeIsVisible = (SurchargeIsVisible.SelectedIndex > 0);
            }
            else
            {
                _ShipMethod.SurchargeMode      = 0;
                _ShipMethod.SurchargeIsVisible = false;
            }
            if (_ShipMethod.SurchargeIsVisible)
            {
                _ShipMethod.SurchargeTaxCodeId = AlwaysConvert.ToInt(SurchargeTaxCode.SelectedValue);
            }
            else
            {
                _ShipMethod.SurchargeTaxCodeId = 0;
            }
            //UPDATE WAREHOUSES
            _ShipMethod.Warehouses.Clear();
            _ShipMethod.Save();
            if (UseWarehouseRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in WarehouseList.Items)
                {
                    Warehouse warehouse = WarehouseDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _ShipMethod.Warehouses.Add(warehouse);
                    }
                }
            }
            //UPDATE ZONES
            _ShipMethod.ShipZones.Clear();
            _ShipMethod.Save();
            if (UseZoneRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in ZoneList.Items)
                {
                    ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _ShipMethod.ShipZones.Add(shipZone);
                    }
                }
            }
            //UPDATE ROLES
            _ShipMethod.Groups.Clear();
            _ShipMethod.Save();
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                foreach (ListItem item in GroupList.Items)
                {
                    CommerceBuilder.Users.Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _ShipMethod.Groups.Add(group);
                    }
                }
            }
            //UPDATE MIN PURCHASE
            _ShipMethod.MinPurchase = AlwaysConvert.ToDecimal(MinPurchase.Text);
            //UPDATE MAX PURCHASE
            _ShipMethod.MaxPurchase = AlwaysConvert.ToDecimal(MaxPurchase.Text);
            //UPDATE TAX CODES
            _ShipMethod.TaxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(TaxCode.SelectedValue));
            //SAVE METHOD AND REDIRECT TO LIST
            _ShipMethod.Save();
        }