protected string GetCountryNames(object dataItem) { ShipZone shipZone = (ShipZone)dataItem; if (shipZone.CountryRule == FilterRule.All) { return("All"); } List <string> countries = new List <string>(); foreach (Country country in shipZone.Countries) { countries.Add(country.Name); } string countryList = string.Join(", ", countries.ToArray()); if (countryList.Length > 100) { countryList = (countryList.Substring(0, 100) + "..."); } if (shipZone.CountryRule == FilterRule.ExcludeSelected) { countryList = "All Except: " + countryList; } return(countryList); }
protected string GetProvinceNames(object dataItem) { ShipZone shipZone = (ShipZone)dataItem; if (shipZone.ProvinceRule == FilterRule.All) { return("All"); } List <string> provinces = new List <string>(); foreach (Province province in shipZone.Provinces) { provinces.Add(province.Name); } provinces.Sort(); string provinceList = string.Join(", ", provinces.ToArray()); if (provinceList.Length > 100) { provinceList = (provinceList.Substring(0, 100) + "..."); } if (shipZone.ProvinceRule == FilterRule.ExcludeSelected) { provinceList = "All Except: " + provinceList; } return(provinceList); }
protected void AddShipZoneButton_Click(object sender, EventArgs e) { ShipZone shipZone = new ShipZone(); shipZone.Name = AddShipZoneName.Text; shipZone.Save(); Response.Redirect("EditShipZone.aspx?ShipZoneId=" + shipZone.Id.ToString()); }
protected void ShipZoneGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Copy") { int shipZoneId = (int)ShipZoneGrid.DataKeys[Int32.Parse(e.CommandArgument.ToString())].Value; ShipZone copy = ShipZone.Copy(shipZoneId, true); if (copy != null) { // THE NAME SHOULD NOT EXCEED THE MAX 255 CHARS String newName = "Copy of " + copy.Name; if (newName.Length > 255) { newName = newName.Substring(0, 252) + "..."; } copy.Name = newName; copy.Save(); ShipZoneGrid.DataBind(); } } }
protected string GetPostalCodes(object dataItem) { //pad with spaces to allow column to wrap ShipZone shipZone = (ShipZone)dataItem; StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(shipZone.PostalCodeFilter)) { string includesCodes = shipZone.PostalCodeFilter; if (!includesCodes.StartsWith("@")) { includesCodes = includesCodes.Replace(",", ", "); } if (includesCodes.Length > 50) { includesCodes = includesCodes.Substring(0, 47) + "..."; } sb.Append("Inc: " + includesCodes); } if (!string.IsNullOrEmpty(shipZone.ExcludePostalCodeFilter)) { if (sb.Length > 0) { sb.Append("<br />"); } string excludesCodes = shipZone.ExcludePostalCodeFilter; if (!excludesCodes.StartsWith("@")) { excludesCodes = excludesCodes.Replace(",", ", "); } if (excludesCodes.Length > 50) { excludesCodes = excludesCodes.Substring(0, 47) + "..."; } sb.Append("Exc: " + excludesCodes); } return(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { InitJs(); _ShipZoneId = AlwaysConvert.ToInt(Request.QueryString["ShipZoneId"]); _ShipZone = ShipZoneDataSource.Load(_ShipZoneId); if (_ShipZone == null) { RedirectMe(); } Caption.Text = string.Format(Caption.Text, _ShipZone.Name); if (!Page.IsPostBack) { Name.Text = _ShipZone.Name; PostalCodeFilter.Text = _ShipZone.PostalCodeFilter; ExcludePostalCodeFilter.Text = _ShipZone.ExcludePostalCodeFilter; CountryRule.SelectedIndex = _ShipZone.CountryRuleId; trCountryList.Visible = CountryRule.SelectedIndex > 0; CountryList.Text = GetCountryList(); ProvinceRule.SelectedIndex = _ShipZone.ProvinceRuleId; trProvinceList.Visible = ProvinceRule.SelectedIndex > 0; ProvinceList.Text = GetProvinceList(); } }
private void SaveShipMethodMatrix() { //UPDATE NAME _ShipMethod.Name = Name.Text; //UPDATE SHIP RATE UpdateRanges(); //UPDATE SURCHARGE _ShipMethod.Surcharge = AlwaysConvert.ToDecimal(Surcharge.Text); if (_ShipMethod.Surcharge < 0) { _ShipMethod.Surcharge = 0; } if (_ShipMethod.Surcharge > 0) { _ShipMethod.SurchargeMode = (SurchargeMode)AlwaysConvert.ToByte(SurchargeMode.SelectedValue); _ShipMethod.SurchargeIsVisible = (SurchargeIsVisible.SelectedIndex > 0); } else { _ShipMethod.SurchargeMode = 0; _ShipMethod.SurchargeIsVisible = false; } if (_ShipMethod.SurchargeIsVisible) { _ShipMethod.SurchargeTaxCodeId = AlwaysConvert.ToInt(SurchargeTaxCode.SelectedValue); } else { _ShipMethod.SurchargeTaxCodeId = 0; } //UPDATE WAREHOUSES _ShipMethod.Warehouses.Clear(); _ShipMethod.Save(); if (UseWarehouseRestriction.SelectedIndex > 0) { foreach (ListItem item in WarehouseList.Items) { Warehouse warehouse = WarehouseDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { _ShipMethod.Warehouses.Add(warehouse); } } } //UPDATE ZONES _ShipMethod.ShipZones.Clear(); _ShipMethod.Save(); if (UseZoneRestriction.SelectedIndex > 0) { foreach (ListItem item in ZoneList.Items) { ShipZone shipZone = ShipZoneDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { _ShipMethod.ShipZones.Add(shipZone); } } } //UPDATE ROLES _ShipMethod.Groups.Clear(); _ShipMethod.Save(); if (UseGroupRestriction.SelectedIndex > 0) { foreach (ListItem item in GroupList.Items) { CommerceBuilder.Users.Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value)); if (item.Selected) { _ShipMethod.Groups.Add(group); } } } //UPDATE MIN PURCHASE _ShipMethod.MinPurchase = AlwaysConvert.ToDecimal(MinPurchase.Text); //UPDATE MAX PURCHASE _ShipMethod.MaxPurchase = AlwaysConvert.ToDecimal(MaxPurchase.Text); //UPDATE TAX CODES _ShipMethod.TaxCode = TaxCodeDataSource.Load(AlwaysConvert.ToInt(TaxCode.SelectedValue)); //SAVE METHOD AND REDIRECT TO LIST _ShipMethod.Save(); }
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"); } }
protected string GetShipMethods(object dataItem) { ShipZone shipZone = (ShipZone)dataItem; return(shipZone.ShipMethods.Count.ToString()); }
protected string GetTaxRules(object dataItem) { ShipZone shipZone = (ShipZone)dataItem; return(shipZone.TaxRules.Count.ToString()); }