protected void Page_Load(object sender, EventArgs e)
    {
        // Check UI element
        CheckUIElementAccessHierarchical(ModuleName.ECOMMERCE, IsMultiStoreConfiguration ? "Tools.Ecommerce.CountriesTaxClasses" : "Configuration.TaxClasses.Countries");

        taxClassId = QueryHelper.GetInteger("objectid", 0);

        TaxClassInfo taxClassObj = TaxClassInfoProvider.GetTaxClassInfo(taxClassId);

        EditedObject = taxClassObj;
        // Check if configured tax class belongs to configured site
        if (taxClassObj != null)
        {
            CheckEditedObjectSiteID(taxClassObj.TaxClassSiteID);
        }

        GridViewCountries.Columns[0].HeaderText = GetString("TaxClass_Country.Country");
        GridViewCountries.Columns[1].HeaderText = GetString("TaxClass_Country.Value");

        DataSet ds = TaxClassCountryInfoProvider.GetCountriesAndTaxValues(taxClassId);

        // Bounded CountryID field
        GridViewCountries.Columns[2].Visible = true;
        GridViewCountries.DataSource         = ds.Tables[0];
        GridViewCountries.DataBind();

        // After id is copied, the CountryID column it's not needed anymore
        GridViewCountries.Columns[2].Visible = false;

        // Set header actions
        CurrentMaster.HeaderActions.AddAction(new SaveAction());
        CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptHelper.RegisterJQuery(this);

        // Check UI element
        CheckUIElementAccessHierarchical(ModuleName.ECOMMERCE, IsMultiStoreConfiguration ? "Tools.Ecommerce.CountriesTaxClasses" : "Configuration.TaxClasses.Countries");

        taxClassId = QueryHelper.GetInteger("objectid", 0);

        TaxClassInfo taxClassObj = TaxClassInfoProvider.GetTaxClassInfo(taxClassId);

        EditedObject = taxClassObj;
        // Check if configured tax class belongs to configured site
        if (taxClassObj != null)
        {
            CheckEditedObjectSiteID(taxClassObj.TaxClassSiteID);

            currencyCode = CurrencyInfoProvider.GetMainCurrencyCode(taxClassObj.TaxClassSiteID);

            // Check presence of main currency
            CheckMainCurrency(taxClassObj.TaxClassSiteID);
        }

        GridViewCountries.Columns[0].HeaderText = GetString("TaxClass_Country.Country");
        GridViewCountries.Columns[1].HeaderText = GetString("TaxClass_Country.Value");
        GridViewCountries.Columns[2].HeaderText = GetString("TaxClass_Country.IsFlat");

        DataSet ds = TaxClassCountryInfoProvider.GetCountriesAndTaxValues(taxClassId);

        GridViewCountries.Columns[3].Visible = true;
        GridViewCountries.DataSource         = ds.Tables[0];
        GridViewCountries.DataBind();
        // After id is copied, the 4th column it's not needed anymore
        GridViewCountries.Columns[3].Visible = false;

        // Init scripts
        string currencySwitchScript = string.Format(@"
function switchCurrency(isFlatValue, labelId){{
  if(isFlatValue)
  {{
    $cmsj('#' + labelId).html('{0}');
  }}else{{
    $cmsj('#' + labelId).html('%');
  }}
}}", ScriptHelper.GetString(HTMLHelper.HTMLEncode(currencyCode), false));

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "CurrencySwitch", currencySwitchScript, true);
        ScriptHelper.RegisterStartupScript(this, typeof(string), "InitializeGrid", "$cmsj('input[id*=\"chkIsFlatValue\"]').change();", true);

        // Set header actions
        CurrentMaster.HeaderActions.AddAction(new SaveAction(this));
        CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;
    }
Example #3
0
    /// <summary>
    /// Saves the taxes values.
    /// </summary>
    private void Save()
    {
        // Check permissions
        CheckConfigurationModification();

        string errorMessage = String.Empty;
        bool   saved        = false;

        // Loop through countries
        foreach (GridViewRow row in GridViewCountries.Rows)
        {
            Label lblCountryId = (Label)row.Cells[3].Controls[0];
            int   countryId    = ValidationHelper.GetInteger(lblCountryId.Text, 0);

            if (countryId > 0)
            {
                string      countryName = ((Label)row.Cells[0].Controls[1]).Text;
                TextBox     txtValue    = (TextBox)row.Cells[1].Controls[1];
                CMSCheckBox chkIsFlat   = (CMSCheckBox)row.Cells[2].Controls[1];

                if ((changedTextBoxes[txtValue.ID] != null) || (changedCheckBoxes[chkIsFlat.ID]) != null)
                {
                    // Remove country tax information if tax value is empty
                    if (String.IsNullOrEmpty(txtValue.Text))
                    {
                        TaxClassCountryInfoProvider.RemoveCountryTaxValue(countryId, taxClassId);
                        chkIsFlat.Checked = false;
                        saved             = true;
                    }
                    // Update country tax information if tax value is not empty
                    else
                    {
                        // Valid percentage or flat tax value
                        if ((!chkIsFlat.Checked && ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(txtValue.Text, -1))) || (chkIsFlat.Checked && ValidationHelper.IsPositiveNumber(txtValue.Text)))
                        {
                            TaxClassCountryInfo countryInfo = TaxClassCountryInfoProvider.GetTaxClassCountryInfo(countryId, taxClassId);
                            countryInfo = countryInfo ?? new TaxClassCountryInfo();

                            countryInfo.CountryID   = countryId;
                            countryInfo.TaxClassID  = taxClassId;
                            countryInfo.TaxValue    = ValidationHelper.GetDouble(txtValue.Text, 0);
                            countryInfo.IsFlatValue = chkIsFlat.Checked;

                            TaxClassCountryInfoProvider.SetTaxClassCountryInfo(countryInfo);
                            saved = true;
                        }
                        // Invalid tax value
                        else
                        {
                            errorMessage += countryName + ", ";
                        }
                    }
                }
            }
        }

        // Error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            // Remove last comma
            if (errorMessage.EndsWithCSafe(", "))
            {
                errorMessage = errorMessage.Remove(errorMessage.Length - 2, 2);
            }

            // Show error message
            ShowError(String.Format("{0} - {1}", errorMessage, GetString("Com.Error.TaxValue")));
        }

        // Display info message if some records were saved
        if (String.IsNullOrEmpty(errorMessage) || saved)
        {
            // Show message
            ShowChangesSaved();
        }
    }
    /// <summary>
    /// Saves the taxes values.
    /// </summary>
    private void Save()
    {
        // Check permissions
        CheckConfigurationModification();

        string errorMessage = String.Empty;
        bool   saved        = false;

        // Loop through countries
        foreach (GridViewRow row in GridViewCountries.Rows)
        {
            Label lblCountryId = (Label)row.Cells[2].Controls[0];
            int   countryId    = ValidationHelper.GetInteger(lblCountryId.Text, 0);

            if (countryId > 0)
            {
                string  countryName = ((Label)row.Cells[0].Controls[1]).Text;
                TextBox txtValue    = (TextBox)row.Cells[1].Controls[1];

                if (changedTextBoxes[txtValue.ID] != null)
                {
                    // Remove country tax information if tax value is empty
                    if (String.IsNullOrEmpty(txtValue.Text))
                    {
                        TaxClassCountryInfoProvider.RemoveCountryTaxValue(countryId, taxClassId);
                        saved = true;
                    }
                    // Update country tax information if tax value is not empty
                    else
                    {
                        var taxValue = ValidationHelper.GetDecimal(txtValue.Text, -1);

                        // Save tax value if valid
                        if (ValidationHelper.IsInRange(0, 100, taxValue))
                        {
                            TaxClassCountryInfoProvider.SetCountryTaxValue(countryId, taxClassId, taxValue);
                            saved = true;
                        }
                        else
                        {
                            errorMessage += countryName + ", ";
                        }
                    }
                }
            }
        }

        // Error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            // Remove last comma
            if (errorMessage.EndsWithCSafe(", "))
            {
                errorMessage = errorMessage.Remove(errorMessage.Length - 2, 2);
            }

            // Show error message
            ShowError(String.Format("{0} - {1}", errorMessage, GetString("Com.Error.TaxValue")));
        }

        // Display info message if some records were saved
        if (String.IsNullOrEmpty(errorMessage) || saved)
        {
            // Show message
            ShowChangesSaved();
        }
    }
Example #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptHelper.RegisterJQuery(this);

        // Check permissions for CMS Desk -> Ecommerce
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Ecommerce", "Configuration.TaxClasses.Countries"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Ecommerce", "Configuration.TaxClasses.Countries");
        }

        mTaxClassId = QueryHelper.GetInteger("taxclassid", 0);

        mTaxClassObj = TaxClassInfoProvider.GetTaxClassInfo(mTaxClassId);
        EditedObject = mTaxClassObj;
        // Check if configured tax class belongs to configured site
        if (mTaxClassObj != null)
        {
            CheckEditedObjectSiteID(mTaxClassObj.TaxClassSiteID);

            currencyCode = CurrencyInfoProvider.GetMainCurrencyCode(mTaxClassObj.TaxClassSiteID);

            // Check presence of main currency
            string currencyErr = CheckMainCurrency(mTaxClassObj.TaxClassSiteID);
            if (!string.IsNullOrEmpty(currencyErr))
            {
                // Show message
                lblError.Text    = currencyErr;
                lblError.Visible = true;
            }
        }

        GridViewCountries.Columns[0].HeaderText = GetString("TaxClass_Country.Country");
        GridViewCountries.Columns[1].HeaderText = GetString("TaxClass_Country.Value");
        GridViewCountries.Columns[2].HeaderText = GetString("TaxClass_Country.IsFlat");
        DataSet ds = TaxClassCountryInfoProvider.GetCountriesAndTaxValues(mTaxClassId);

        GridViewCountries.Columns[3].Visible = true;
        GridViewCountries.DataSource         = ds.Tables[0];
        GridViewCountries.DataBind();
        // After id is copied, the 4th column it's not needed anymore
        GridViewCountries.Columns[3].Visible = false;
        GridViewCountries.GridLines          = GridLines.Horizontal;

        // Init scripts
        string currencySwitchScript = string.Format(@"
function switchCurrency(isFlatValue, labelId){{
  if(isFlatValue)
  {{
    jQuery('#'+labelId).html('({0})');
  }}else{{
    jQuery('#'+labelId).html('(%)');
  }}
}}", ScriptHelper.GetString(currencyCode, false));

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "CurrencySwitch", currencySwitchScript, true);
        ScriptHelper.RegisterStartupScript(this, typeof(string), "InitializeGrid", "jQuery('input[id*=\"chkIsFlatValue\"]').change();", true);

        mSave = GetString("general.save");

        // Set header actions
        string[,] actions = new string[1, 10];

        actions[0, 0] = HeaderActions.TYPE_SAVEBUTTON;
        actions[0, 1] = this.GetString("Header.Settings.SaveChanged");
        actions[0, 2] = String.Empty;
        actions[0, 3] = String.Empty;
        actions[0, 4] = String.Empty;
        actions[0, 5] = this.GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png");
        actions[0, 6] = "save";
        actions[0, 8] = true.ToString();

        this.CurrentMaster.HeaderActions.Actions          = actions;
        this.CurrentMaster.HeaderActions.ActionPerformed += this.HeaderActions_ActionPerformed;
    }
Example #6
0
    // Saves
    protected void Save()
    {
        // Check permissions
        CheckConfigurationModification();

        string errorMessage = String.Empty;
        bool   saved        = false;

        // Loop through countries
        for (int i = 0; i < this.GridViewCountries.Rows.Count; i++)
        {
            Label lblCountryId = (Label)this.GridViewCountries.Rows[i].Cells[3].Controls[0];
            int   countryId    = ValidationHelper.GetInteger(lblCountryId.Text, 0);

            TaxClassCountryInfo countryInfo;
            string   countryName = null;
            TextBox  txtValue    = null;
            CheckBox chkIsFlat   = null;

            if (countryId > 0)
            {
                countryName = ((Label)GridViewCountries.Rows[i].Cells[0].Controls[1]).Text;
                txtValue    = (TextBox)GridViewCountries.Rows[i].Cells[1].Controls[1];
                chkIsFlat   = (CheckBox)GridViewCountries.Rows[i].Cells[2].Controls[1];

                if ((this.mChangedTextBoxes[txtValue.ID] != null) || (this.mChangedCheckBoxes[chkIsFlat.ID]) != null)
                {
                    // Remove country tax information if tax value is empty
                    if (String.IsNullOrEmpty(txtValue.Text))
                    {
                        TaxClassCountryInfoProvider.RemoveCountryTaxValue(countryId, this.mTaxClassId);
                        chkIsFlat.Checked = false;
                        saved             = true;
                    }
                    // Update country tax information if tax value is not empty
                    else
                    {
                        // Valid percentage or flat tax value
                        if ((!chkIsFlat.Checked && ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(txtValue.Text, -1))) || (chkIsFlat.Checked && ValidationHelper.IsPositiveNumber(txtValue.Text)))
                        {
                            countryInfo = TaxClassCountryInfoProvider.GetTaxClassCountryInfo(countryId, this.mTaxClassId);
                            countryInfo = countryInfo ?? new TaxClassCountryInfo();

                            countryInfo.CountryID   = countryId;
                            countryInfo.TaxClassID  = mTaxClassId;
                            countryInfo.TaxValue    = ValidationHelper.GetDouble(txtValue.Text, 0);
                            countryInfo.IsFlatValue = chkIsFlat.Checked;

                            TaxClassCountryInfoProvider.SetTaxClassCountryInfo(countryInfo);
                            saved = true;
                        }
                        // Invalid tax value
                        else
                        {
                            errorMessage += countryName + ", ";
                        }
                    }
                }
            }
        }

        // Error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            // Remove last comma
            if (errorMessage.EndsWith(", "))
            {
                errorMessage = errorMessage.Remove(errorMessage.Length - 2, 2);
            }

            this.lblError.Visible = true;
            this.lblError.Text    = String.Format("{0} - {1}", errorMessage, GetString("Com.Error.TaxValue"));
        }

        // Display info message if some records were saved
        if (String.IsNullOrEmpty(errorMessage) || saved)
        {
            // Info message
            this.lblInfo.Visible = true;
            this.lblInfo.Text    = GetString("General.ChangesSaved");
        }
    }