protected void SaveButton_Click(object sender, EventArgs e) { _TaxCode.TaxRules.Clear(); foreach (GridViewRow gvr in TaxRuleGrid.Rows) { int taxRuleId = (int)TaxRuleGrid.DataKeys[gvr.DataItemIndex].Value; TaxRule taxRule = TaxRuleDataSource.Load(taxRuleId); CheckBox Linked = gvr.FindControl("Linked") as CheckBox; if (Linked.Checked) { if (taxRule.TaxCodes.IndexOf(_TaxCode) < 0) { taxRule.TaxCodes.Add(_TaxCode); taxRule.Save(); } _TaxCode.TaxRules.Add(taxRule); } else { if (taxRule.TaxCodes.IndexOf(_TaxCode) > -1) { taxRule.TaxCodes.Remove(_TaxCode); taxRule.Save(); } } } SavedMessage.Visible = true; SavedMessage.Text = string.Format(SavedMessage.Text, LocaleHelper.LocalNow); }
protected void SaveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { // DUPLICATE TAX RULE NAMES SHOULD NOT BE ALLOWED int taxRuleId = TaxRuleDataSource.GetTaxRuleIdByName(Name.Text); if (taxRuleId > 0) { // TAX RULE(S) WITH SAME NAME ALREADY EXIST CustomValidator customNameValidator = new CustomValidator(); customNameValidator.ControlToValidate = "Name"; customNameValidator.Text = "*"; customNameValidator.ErrorMessage = "A Tax Rule with the same name already exists."; customNameValidator.IsValid = false; phNameValidator.Controls.Add(customNameValidator); return; } //SAVE TAX RULE TaxRule taxRule = new TaxRule(); taxRule.Name = Name.Text; taxRule.TaxRate = AlwaysConvert.ToDecimal(TaxRate.Text); taxRule.UseBillingAddress = AlwaysConvert.ToBool(UseBillingAddress.SelectedValue.Equals("1"), false); taxRule.TaxCodeId = AlwaysConvert.ToInt(TaxCode.SelectedValue); taxRule.Priority = AlwaysConvert.ToInt16(Priority.Text); taxRule.UsePerItemTax = PerUnitCalculation.Checked; taxRule.Save(); //UPDATE TAX CODES taxRule.TaxCodes.Clear(); taxRule.Save(); foreach (ListItem listItem in TaxCodes.Items) { if (listItem.Selected) { TaxCode taxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(listItem.Value)); taxRule.TaxCodes.Add(taxCode); listItem.Selected = false; } } //UPDATE ZONES taxRule.ShipZones.Clear(); if (ZoneRule.SelectedIndex > 0) { foreach (ListItem item in ZoneList.Items) { ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { taxRule.ShipZones.Add(shipZone); } } } //UPDATE GROUP FILTER taxRule.Groups.Clear(); taxRule.GroupRule = (FilterRule)GroupRule.SelectedIndex; if (taxRule.GroupRule != FilterRule.All) { foreach (ListItem item in GroupList.Items) { Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { taxRule.Groups.Add(group); } } } //IF NO GROUPS ARE SELECTED, APPLY TO ALL GROUPS if (taxRule.Groups.Count == 0) { taxRule.GroupRule = FilterRule.All; } // UPDATE ROUNDING RULE taxRule.RoundingRuleId = AlwaysConvert.ToByte(RoundingRule.SelectedValue); taxRule.Save(); //UPDATE THE ADD MESSAGE Response.Redirect("TaxRules.aspx"); } }