/// <summary> /// Bind data to the fields in edit mode /// </summary> protected void BindEditData() { TaxRuleAdmin taxAdmin = new TaxRuleAdmin(); TaxRule taxRule = new TaxRule(); if (ItemId > 0) { taxRule = taxAdmin.GetTaxRule(ItemId); // Destination CountryCode if (taxRule.DestinationCountryCode != null) { lstCountries.SelectedValue = taxRule.DestinationCountryCode; if (lstCountries.SelectedValue != null) { BindStates(); } } // Destination StateCode if (taxRule.DestinationStateCode != null) { lstStateOption.SelectedValue = taxRule.DestinationStateCode; if (lstStateOption.SelectedValue != null) { BindCounty(); } } // CountyFIPS if (taxRule.CountyFIPS != null) { lstCounty.SelectedValue = taxRule.CountyFIPS; } // Tax Rates txtSalesTax.Text = taxRule.SalesTax.ToString(); txtVAT.Text = taxRule.VAT.ToString(); txtGST.Text = taxRule.GST.ToString(); txtPST.Text = taxRule.PST.ToString(); txtHST.Text = taxRule.HST.ToString(); // Tax Preferences txtPrecedence.Text = taxRule.Precedence.ToString(); chkTaxInclusiveInd.Checked = taxRule.InclusiveInd; ddlRuleTypes.SelectedValue = taxRule.TaxRuleTypeID.GetValueOrDefault().ToString(); } else { //nothing to do here } }
/// <summary> /// Submit button click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { TaxRuleAdmin taxAdmin = new TaxRuleAdmin(); TaxRule taxRule = new TaxRule(); taxRule.PortalID = ZNodeConfigManager.SiteConfig.PortalID; // If edit mode then retrieve data first if (ItemId > 0) { taxRule = taxAdmin.GetTaxRule(ItemId); } // TaxClassID taxRule.TaxClassID = taxId; // Destination Country if (lstCountries.SelectedValue.Equals("*")) taxRule.DestinationCountryCode = null; else taxRule.DestinationCountryCode = lstCountries.SelectedValue; // Destination State if (lstStateOption.SelectedValue != "0") taxRule.DestinationStateCode = lstStateOption.SelectedValue; else taxRule.DestinationStateCode = null; // CountyFIPS if (lstCounty.SelectedValue != "0") taxRule.CountyFIPS = lstCounty.SelectedValue; else taxRule.CountyFIPS = null; // Tax Rates taxRule.SalesTax = Convert.ToDecimal(txtSalesTax.Text); taxRule.VAT = Convert.ToDecimal(txtVAT.Text); taxRule.GST = Convert.ToDecimal(txtGST.Text); taxRule.PST = Convert.ToDecimal(txtPST.Text); taxRule.HST = Convert.ToDecimal(txtHST.Text); // Tax Preferences taxRule.InclusiveInd = chkTaxInclusiveInd.Checked; taxRule.Precedence = int.Parse(txtPrecedence.Text); if (ddlRuleTypes.SelectedIndex != -1) { taxRule.TaxRuleTypeID = int.Parse(ddlRuleTypes.SelectedValue); } bool retval = false; if (ItemId > 0) { retval = taxAdmin.UpdateTaxRule(taxRule); } else { retval = taxAdmin.AddTaxRule(taxRule); } if (retval) { System.Web.HttpContext.Current.Cache.Remove("InclusiveTaxRules"); //redirect to view page Response.Redirect("~/admin/secure/settings/taxes/view.aspx?taxId=" + taxId); } else { //display error message lblMsg.Text = "An error occurred while updating. Please try again."; } }