internal IEnumerable <TaxClassStateInfo> InitTaxClassStates() { return(new[] { TaxClassDefaultState = new TaxClassStateInfo { StateID = StateWashington.StateID, TaxClassID = TaxClassDefault.TaxClassID, TaxValue = 20 } }); }
/// <summary> /// Sets tax class value in state. Called when the "Set value" button is pressed. /// </summary> private bool SetTaxClassValueInState() { // Get the tax class TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("MyNewClass", CMSContext.CurrentSiteName); // Get the state StateInfo state = StateInfoProvider.GetStateInfo("Alabama"); if ((taxClass != null) && (state != null)) { // Create new tax class state TaxClassStateInfo newTaxState = new TaxClassStateInfo(); // Set the properties newTaxState.TaxClassID = taxClass.TaxClassID; newTaxState.StateID = state.StateID; newTaxState.TaxValue = 10; newTaxState.IsFlatValue = true; // Set the tax class value in state TaxClassStateInfoProvider.SetTaxClassStateInfo(newTaxState); return true; } return false; }
/// <summary> /// Gets and bulk updates tax class values in state. Called when the "Get and bulk update values" button is pressed. /// Expects the SetTaxClassValueInState method to be run first. /// </summary> private bool GetAndBulkUpdateTaxClassValuesInState() { // Get the tax class TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("MyNewClass", CMSContext.CurrentSiteName); // Get the state StateInfo state = StateInfoProvider.GetStateInfo("Alabama"); if ((taxClass != null) && (state != null)) { // Prepare the parameters string where = "TaxClassID = " + taxClass.TaxClassID + " AND StateID = " + state.StateID; // Get the data DataSet classStates = TaxClassStateInfoProvider.GetTaxClassStates(where, null); if (!DataHelper.DataSourceIsEmpty(classStates)) { // Loop through the individual items foreach (DataRow classStatesDr in classStates.Tables[0].Rows) { // Create object from DataRow TaxClassStateInfo modifyClassState = new TaxClassStateInfo(classStatesDr); // Update the properties modifyClassState.TaxValue = 50; // Save the changes TaxClassStateInfoProvider.SetTaxClassStateInfo(modifyClassState); } return true; } } return false; }
/// <summary> /// Saves values. /// </summary> private void Save() { // Check permissions CheckConfigurationModification(); string errorMessage = String.Empty; bool saved = false; // Loop through states foreach (GridViewRow row in gvStates.Rows) { Label lblStateId = (Label)row.Cells[4].Controls[0]; int stateId = ValidationHelper.GetInteger(lblStateId.Text, 0); if (stateId > 0) { string stateName = ((Label)row.Cells[0].Controls[1]).Text; TextBox txtValue = (TextBox)row.Cells[2].Controls[1]; CMSCheckBox chkIsFlat = (CMSCheckBox)row.Cells[3].Controls[1]; if ((changedTextBoxes[txtValue.ID] != null) || (changedCheckBoxes[chkIsFlat.ID] != null)) { // Remove state tax information if tax value is empty if (String.IsNullOrEmpty(txtValue.Text)) { TaxClassStateInfoProvider.RemoveStateTaxValue(taxClassId, stateId); chkIsFlat.Checked = false; saved = true; } // Update state 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))) { TaxClassStateInfo stateInfo = TaxClassStateInfoProvider.GetTaxClassStateInfo(taxClassId, stateId); stateInfo = stateInfo ?? new TaxClassStateInfo(); stateInfo.StateID = stateId; stateInfo.TaxClassID = taxClassId; stateInfo.TaxValue = ValidationHelper.GetDouble(txtValue.Text, 0); stateInfo.IsFlatValue = chkIsFlat.Checked; TaxClassStateInfoProvider.SetTaxClassStateInfo(stateInfo); saved = true; } // Invalid tax value else { errorMessage += stateName + ", "; } } } } } // 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(); } }