protected void LoadGridViewData() { gvStates.Columns[4].Visible = true; mCountryId = ValidationHelper.GetInteger(drpCountry.SelectedValue, 0); DataSet ds = TaxClassStateInfoProvider.GetStatesAndTaxValues(mTaxClassId, mCountryId); gvStates.DataSource = ds.Tables[0]; gvStates.DataBind(); gvStates.Columns[4].Visible = false; }
private void LoadGridViewData() { // Binding StateID column gvStates.Columns[3].Visible = true; countryId = ValidationHelper.GetInteger(drpCountry.SelectedValue, 0); DataSet ds = TaxClassStateInfoProvider.GetStatesAndTaxValues(taxClassId, countryId); gvStates.DataSource = ds.Tables[0]; gvStates.DataBind(); gvStates.Columns[3].Visible = false; }
/// <summary> /// Saves values. /// </summary> protected void Save() { // Check permissions CheckConfigurationModification(); string errorMessage = String.Empty; bool saved = false; // Loop through states for (int i = 0; i < gvStates.Rows.Count; i++) { Label lblStateId = (Label)gvStates.Rows[i].Cells[4].Controls[0]; int stateId = ValidationHelper.GetInteger(lblStateId.Text, 0); TaxClassStateInfo stateInfo; string stateName = null; TextBox txtValue = null; CheckBox chkIsFlat = null; if (stateId > 0) { stateName = ((Label)gvStates.Rows[i].Cells[0].Controls[1]).Text; txtValue = (TextBox)gvStates.Rows[i].Cells[2].Controls[1]; chkIsFlat = (CheckBox)gvStates.Rows[i].Cells[3].Controls[1]; if ((this.mChangedTextBoxes[txtValue.ID] != null) || (this.mChangedCheckBoxes[chkIsFlat.ID] != null)) { // Remove state tax information if tax value is empty if (String.IsNullOrEmpty(txtValue.Text)) { TaxClassStateInfoProvider.RemoveStateTaxValue(this.mTaxClassId, 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))) { stateInfo = TaxClassStateInfoProvider.GetTaxClassStateInfo(this.mTaxClassId, stateId); stateInfo = stateInfo ?? new TaxClassStateInfo(); stateInfo.StateID = stateId; stateInfo.TaxClassID = mTaxClassId; 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.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"); } }
/// <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(); } }
/// <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[3].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]; if (changedTextBoxes[txtValue.ID] != null) { // Remove state tax information if tax value is empty if (String.IsNullOrEmpty(txtValue.Text)) { TaxClassStateInfoProvider.RemoveStateTaxValue(taxClassId, stateId); saved = true; } // Update state 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)) { TaxClassStateInfoProvider.SetStateTaxValue(taxClassId, stateId, taxValue); saved = true; } 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(); } }