Example #1
0
 protected void BindZones()
 {
     ZoneListPanel.Visible = (UseZoneRestriction.SelectedIndex > 0);
     if (ZoneListPanel.Visible)
     {
         ZoneList.DataSource = ShipZoneDataSource.LoadAll("Name");
         ZoneList.DataBind();
         if (ZoneList.Items.Count > 4)
         {
             ZoneList.Rows = 8;
         }
         foreach (ShipZone item in _ShipMethod.ShipZones)
         {
             ListItem listItem = ZoneList.Items.FindByValue(item.Id.ToString());
             if (listItem != null)
             {
                 listItem.Selected = true;
             }
         }
     }
 }
        protected void Page_Init()
        {
            IList <TaxCode> taxCodes = TaxCodeDataSource.LoadAll();

            TaxCodes.DataSource = taxCodes;
            TaxCodes.DataBind();
            TaxCode.Items.Clear();
            TaxCode.Items.Add("");
            TaxCode.DataSource = taxCodes;
            TaxCode.DataBind();
            ZoneList.DataSource = ShipZoneDataSource.LoadAll("Name");
            ZoneList.DataBind();
            GroupList.DataSource = GroupDataSource.LoadAll("Name");
            GroupList.DataBind();

            // ROUNDING RULE
            RoundingRule.Items.Clear();
            RoundingRule.Items.Add(new ListItem("Common Method", ((int)CommerceBuilder.Taxes.RoundingRule.Common).ToString()));
            RoundingRule.Items.Add(new ListItem("Round to Even", ((int)CommerceBuilder.Taxes.RoundingRule.RoundToEven).ToString()));
            RoundingRule.Items.Add(new ListItem("Always Round Up", ((int)CommerceBuilder.Taxes.RoundingRule.AlwaysRoundUp).ToString()));
        }
Example #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     InitJs();
     _ShipZoneId = AlwaysConvert.ToInt(Request.QueryString["ShipZoneId"]);
     _ShipZone   = ShipZoneDataSource.Load(_ShipZoneId);
     if (_ShipZone == null)
     {
         RedirectMe();
     }
     Caption.Text = string.Format(Caption.Text, _ShipZone.Name);
     if (!Page.IsPostBack)
     {
         Name.Text                    = _ShipZone.Name;
         PostalCodeFilter.Text        = _ShipZone.PostalCodeFilter;
         ExcludePostalCodeFilter.Text = _ShipZone.ExcludePostalCodeFilter;
         CountryRule.SelectedIndex    = _ShipZone.CountryRuleId;
         trCountryList.Visible        = CountryRule.SelectedIndex > 0;
         CountryList.Text             = GetCountryList();
         ProvinceRule.SelectedIndex   = _ShipZone.ProvinceRuleId;
         trProvinceList.Visible       = ProvinceRule.SelectedIndex > 0;
         ProvinceList.Text            = GetProvinceList();
     }
 }
Example #4
0
        private void SaveShipMethodMatrix()
        {
            //UPDATE NAME
            _ShipMethod.Name = Name.Text;
            //UPDATE SHIP RATE
            UpdateRanges();
            //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();
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // DUPLICATE TAX RULE NAMES SHOULD NOT BE ALLOWED
                int taxRuleId = TaxRuleDataSource.GetTaxRuleIdByName(Name.Text);
                if (taxRuleId > 0)
                {
                    // TAX RULE(S) WITH SAME NAME ALREADY EXIST
                    CustomValidator customNameValidator = new CustomValidator();
                    customNameValidator.ControlToValidate = "Name";
                    customNameValidator.Text         = "*";
                    customNameValidator.ErrorMessage = "A Tax Rule with the same name already exists.";
                    customNameValidator.IsValid      = false;
                    phNameValidator.Controls.Add(customNameValidator);
                    return;
                }
                //SAVE TAX RULE
                TaxRule taxRule = new TaxRule();
                taxRule.Name              = Name.Text;
                taxRule.TaxRate           = AlwaysConvert.ToDecimal(TaxRate.Text);
                taxRule.UseBillingAddress = AlwaysConvert.ToBool(UseBillingAddress.SelectedValue.Equals("1"), false);
                taxRule.TaxCodeId         = AlwaysConvert.ToInt(TaxCode.SelectedValue);
                taxRule.Priority          = AlwaysConvert.ToInt16(Priority.Text);
                taxRule.UsePerItemTax     = PerUnitCalculation.Checked;
                taxRule.Save();
                //UPDATE TAX CODES
                taxRule.TaxCodes.Clear();
                taxRule.Save();
                foreach (ListItem listItem in TaxCodes.Items)
                {
                    if (listItem.Selected)
                    {
                        TaxCode taxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(listItem.Value));
                        taxRule.TaxCodes.Add(taxCode);
                        listItem.Selected = false;
                    }
                }
                //UPDATE ZONES
                taxRule.ShipZones.Clear();
                if (ZoneRule.SelectedIndex > 0)
                {
                    foreach (ListItem item in ZoneList.Items)
                    {
                        ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value));
                        if (item.Selected)
                        {
                            taxRule.ShipZones.Add(shipZone);
                        }
                    }
                }
                //UPDATE GROUP FILTER
                taxRule.Groups.Clear();
                taxRule.GroupRule = (FilterRule)GroupRule.SelectedIndex;
                if (taxRule.GroupRule != FilterRule.All)
                {
                    foreach (ListItem item in GroupList.Items)
                    {
                        Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                        if (item.Selected)
                        {
                            taxRule.Groups.Add(group);
                        }
                    }
                }
                //IF NO GROUPS ARE SELECTED, APPLY TO ALL GROUPS
                if (taxRule.Groups.Count == 0)
                {
                    taxRule.GroupRule = FilterRule.All;
                }

                // UPDATE ROUNDING RULE
                taxRule.RoundingRuleId = AlwaysConvert.ToByte(RoundingRule.SelectedValue);

                taxRule.Save();
                //UPDATE THE ADD MESSAGE
                Response.Redirect("TaxRules.aspx");
            }
        }