Example #1
0
        protected void grdCountryTaxRates_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                DropDownList ddlCountries = (DropDownList)e.Item.FindControl("ddlCountries");
                string       countryCode  = ddlCountries.SelectedValue;

                DropDownList ddlRegions = (DropDownList)e.Item.FindControl("ddlRegions");
                string       regionCode = null;
                if (ddlRegions != null && ddlRegions.Visible)
                {
                    regionCode = ddlRegions.SelectedValue;
                }

                TextBox txtTaxRate = (TextBox)e.Item.FindControl("txtTaxRate");
                string  value      = txtTaxRate.Text;
                TextBox txtZipCode = (TextBox)e.Item.FindControl("txtZipCode");
                decimal taxRate;
                Decimal.TryParse(value, out taxRate);

                CountryTaxInfo countryTaxInfo = new CountryTaxInfo
                {
                    CountryCode = countryCode,
                    RegionCode  = regionCode,
                    ZipCode     = txtZipCode.Text,
                    TaxRate     = taxRate
                };

                CountryTaxRates countryTaxRates = (CountryTaxRates)ViewState["Store_CountryTaxRates"];
                countryTaxRates.TaxRates.Add(countryTaxInfo);
                countryTaxRates.TaxRates.Sort();
                BindTaxRates(countryTaxRates);
            }
        }
Example #2
0
        public void Fill(System.Data.IDataReader dr)
        {
            KeyID            = Convert.ToInt32(dr["PortalID"]);
            DefaultTaxRate   = Convert.ToDecimal(Null.SetNull(dr["DefaultTaxRate"], DefaultTaxRate));
            ShowTax          = Convert.ToBoolean(dr["ShowTax"]);
            _defaultTaxRates = Convert.ToString(Null.SetNull(dr["DefaultTaxRates"], _defaultTaxRates));
            if (!string.IsNullOrEmpty(_defaultTaxRates))
            {
                CountryTaxes = (CountryTaxRates)ProviderSettingsHelper.DeserializeSettings(_defaultTaxRates, typeof(CountryTaxRates));
            }

            if (CountryTaxes == null)
            {
                CountryTaxes = new CountryTaxRates();
            }
        }
Example #3
0
        private static decimal GetCountryRegionTaxRate(string countryCode, string regionCode, string zipCode, CountryTaxRates countryTaxes, decimal defaultTaxRate)
        {
            decimal taxRate = defaultTaxRate;
            List <CountryTaxInfo> taxRates = countryTaxes.TaxRates;

            if (!string.IsNullOrEmpty(countryCode) && taxRates != null && taxRates.Count > 0)
            {
                bool regionCodeIsEmpty = string.IsNullOrEmpty(regionCode);
                bool zipCodeIsNotEmpty = !string.IsNullOrEmpty(zipCode);
                foreach (CountryTaxInfo taxInfo in taxRates)
                {
                    if (countryCode.Equals(taxInfo.CountryCode, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (regionCodeIsEmpty && string.IsNullOrEmpty(taxInfo.RegionCode))
                        {
                            taxRate = taxInfo.TaxRate;
                            break;
                        }
                        if (taxInfo.RegionCode == "*")
                        {
                            taxRate = taxInfo.TaxRate;
                            break;
                        }
                        if (regionCode.Equals(taxInfo.RegionCode, StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (taxInfo.ZipCode == "*")
                            {
                                taxRate = taxInfo.TaxRate;
                                break;
                            }

                            int    posStar  = taxInfo.ZipCode.IndexOf('*');
                            string zipStart = posStar != Null.NullInteger ? taxInfo.ZipCode.Substring(0, posStar) : taxInfo.ZipCode;

                            if (zipCodeIsNotEmpty && zipCode.StartsWith(zipStart))
                            {
                                taxRate = taxInfo.TaxRate;
                                break;
                            }
                        }
                    }
                }
            }
            return(taxRate / 100);
        }
Example #4
0
 private void BindTaxRates(CountryTaxRates countryTaxRates)
 {
     ViewState["Store_CountryTaxRates"] = countryTaxRates;
     grdCountryTaxRates.DataSource      = countryTaxRates.TaxRates;
     grdCountryTaxRates.DataBind();
 }
Example #5
0
        private void SaveTaxRates()
        {
            if (!Page.IsValid)
            {
                return;
            }

            bool    enableTax      = cbEnableTax.Checked;
            decimal defaultTaxRate = Null.NullDecimal;

            if (enableTax)
            {
                defaultTaxRate = Decimal.Parse(txtDefaultTaxRate.Text);
            }

            CountryTaxRates countryTaxRates = (CountryTaxRates)ViewState["Store_CountryTaxRates"];
            List <int>      deletedItems    = new List <int>();

            foreach (DataGridItem gridItem in grdCountryTaxRates.Items)
            {
                CheckBox chkDelete = (CheckBox)gridItem.FindControl("chkDelete");
                if (chkDelete != null && chkDelete.Checked)
                {
                    deletedItems.Add(gridItem.ItemIndex);
                }
                else
                {
                    TextBox txtTaxRate = (TextBox)gridItem.FindControl("txtTaxRate");
                    if (txtTaxRate != null)
                    {
                        string textTaxRate = txtTaxRate.Text;
                        if (!string.IsNullOrEmpty(textTaxRate))
                        {
                            decimal taxRate;
                            if (decimal.TryParse(textTaxRate, out taxRate))
                            {
                                countryTaxRates.TaxRates[gridItem.ItemIndex].TaxRate = taxRate;
                            }
                        }
                    }
                }
            }

            if (deletedItems.Count > 0)
            {
                deletedItems.Reverse();
                foreach (int deletedItem in deletedItems)
                {
                    countryTaxRates.TaxRates.RemoveAt(deletedItem);
                }
            }

            countryTaxRates.TaxRates.Sort();

            string taxRates = ProviderSettingsHelper.SerializeSettings(countryTaxRates, typeof(CountryTaxRates));

            TaxController controller = new TaxController();

            controller.UpdateTaxRates(PortalId, defaultTaxRate, cbEnableTax.Checked, taxRates);

            BindTaxRates(countryTaxRates);
        }