/// <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(); } }
/// <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(); } }
// 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"); } }