internal IEnumerable <TaxClassCountryInfo> InitTaxClassCountries() { return(new[] { TaxClassDefaultCountry = new TaxClassCountryInfo { CountryID = CountryUSA.CountryID, TaxClassID = TaxClassDefault.TaxClassID, TaxValue = 10 } }); }
/// <summary> /// Sets tax class value in country. Called when the "Set value" button is pressed. /// </summary> private bool SetTaxClassValueInCountry() { // Get the tax class TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("MyNewClass", CMSContext.CurrentSiteName); // Get the country CountryInfo country = CountryInfoProvider.GetCountryInfo("USA"); if ((taxClass != null) && (country != null)) { // Create new tax class country object TaxClassCountryInfo newTaxCountry = new TaxClassCountryInfo(); // Set the properties newTaxCountry.TaxClassID = taxClass.TaxClassID; newTaxCountry.CountryID = country.CountryID; newTaxCountry.TaxValue = 10; newTaxCountry.IsFlatValue = true; // Set the tax class value in country TaxClassCountryInfoProvider.SetTaxClassCountryInfo(newTaxCountry); return true; } return false; }
/// <summary> /// Gets and bulk updates tax class values in country. Called when the "Get and bulk update values" button is pressed. /// Expects the SetTaxClassValueInCountry method to be run first. /// </summary> private bool GetAndBulkUpdateTaxClassValuesInCountry() { // Get the tax class TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("MyNewClass", CMSContext.CurrentSiteName); // Get the country CountryInfo country = CountryInfoProvider.GetCountryInfo("USA"); if ((taxClass != null) && (country != null)) { // Prepare the parameters string where = "TaxClassID = " + taxClass.TaxClassID + " AND CountryID = " + country.CountryID; // Get the data DataSet classCountries = TaxClassCountryInfoProvider.GetTaxClassCountries(where, null); if (!DataHelper.DataSourceIsEmpty(classCountries)) { // Loop through the individual items foreach (DataRow classCountriesDr in classCountries.Tables[0].Rows) { // Create object from DataRow TaxClassCountryInfo modifyClassCountry = new TaxClassCountryInfo(classCountriesDr); // Update the properties modifyClassCountry.TaxValue = 50; // Save the changes TaxClassCountryInfoProvider.SetTaxClassCountryInfo(modifyClassCountry); } return true; } } return false; }
/// <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(); } }