protected void gvShippingByWeightAndCountry_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "UpdateShippingByWeightAndCountry") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = gvShippingByWeightAndCountry.Rows[index]; HiddenField hfShippingByWeightAndCountryID = row.FindControl("hfShippingByWeightAndCountryID") as HiddenField; DropDownList ddlShippingMethod = row.FindControl("ddlShippingMethod") as DropDownList; DropDownList ddlCountry = row.FindControl("ddlCountry") as DropDownList; DecimalTextBox txtFrom = row.FindControl("txtFrom") as DecimalTextBox; DecimalTextBox txtTo = row.FindControl("txtTo") as DecimalTextBox; CheckBox cbUsePercentage = row.FindControl("cbUsePercentage") as CheckBox; DecimalTextBox txtShippingChargePercentage = row.FindControl("txtShippingChargePercentage") as DecimalTextBox; DecimalTextBox txtShippingChargeAmount = row.FindControl("txtShippingChargeAmount") as DecimalTextBox; int shippingByWeightAndCountryID = int.Parse(hfShippingByWeightAndCountryID.Value); int shippingMethodID = int.Parse(ddlShippingMethod.SelectedItem.Value); int countryID = int.Parse(ddlCountry.SelectedItem.Value); ShippingByWeightAndCountry shippingByWeightAndCountry = ShippingByWeightAndCountryManager.GetByID(shippingByWeightAndCountryID); if (shippingByWeightAndCountry != null) { ShippingByWeightAndCountryManager.UpdateShippingByWeightAndCountry(shippingByWeightAndCountry.ShippingByWeightAndCountryID, shippingMethodID, countryID, txtFrom.Value, txtTo.Value, cbUsePercentage.Checked, txtShippingChargePercentage.Value, txtShippingChargeAmount.Value); } BindData(); } }
private void BindData() { var shippingByWeightAndCountryCollection = ShippingByWeightAndCountryManager.GetAll(); gvShippingByWeightAndCountry.DataSource = shippingByWeightAndCountryCollection; gvShippingByWeightAndCountry.DataBind(); }
private decimal?GetRate(decimal subTotal, decimal weight, int ShippingMethodID, int CountryID) { decimal?shippingTotal = null; bool limitMethodsToCreated = SettingManager.GetSettingValueBoolean("ShippingByWeightAndCountry.LimitMethodsToCreated"); ShippingByWeightAndCountry shippingByWeightAndCountry = null; var shippingByWeightAndCountryCollection = ShippingByWeightAndCountryManager.GetAllByShippingMethodIdAndCountryId(ShippingMethodID, CountryID); foreach (var shippingByWeightAndCountry2 in shippingByWeightAndCountryCollection) { if ((weight >= shippingByWeightAndCountry2.From) && (weight <= shippingByWeightAndCountry2.To)) { shippingByWeightAndCountry = shippingByWeightAndCountry2; break; } } if (shippingByWeightAndCountry == null) { if (limitMethodsToCreated) { return(null); } else { return(decimal.Zero); } } if (shippingByWeightAndCountry.UsePercentage && shippingByWeightAndCountry.ShippingChargePercentage <= decimal.Zero) { return(decimal.Zero); } if (!shippingByWeightAndCountry.UsePercentage && shippingByWeightAndCountry.ShippingChargeAmount <= decimal.Zero) { return(decimal.Zero); } if (shippingByWeightAndCountry.UsePercentage) { shippingTotal = Math.Round((decimal)((((float)subTotal) * ((float)shippingByWeightAndCountry.ShippingChargePercentage)) / 100f), 2); } else { if (ShippingByWeightAndCountryManager.CalculatePerWeightUnit) { shippingTotal = shippingByWeightAndCountry.ShippingChargeAmount * weight; } else { shippingTotal = shippingByWeightAndCountry.ShippingChargeAmount; } } if (shippingTotal < decimal.Zero) { shippingTotal = decimal.Zero; } return(shippingTotal); }
protected void gvShippingByWeightAndCountry_RowDeleting(object sender, GridViewDeleteEventArgs e) { int shippingByWeightAndCountryID = (int)gvShippingByWeightAndCountry.DataKeys[e.RowIndex]["ShippingByWeightAndCountryID"]; ShippingByWeightAndCountry shippingByWeightAndCountry = ShippingByWeightAndCountryManager.GetByID(shippingByWeightAndCountryID); if (shippingByWeightAndCountry != null) { ShippingByWeightAndCountryManager.DeleteShippingByWeightAndCountry(shippingByWeightAndCountry.ShippingByWeightAndCountryID); BindData(); } }
protected void btnAdd_Click(object sender, EventArgs e) { try { int shippingMethodID = int.Parse(this.ddlShippingMethod.SelectedItem.Value); int countryID = int.Parse(this.ddlCountry.SelectedItem.Value); ShippingByWeightAndCountry shippingByWeightAndCountry = ShippingByWeightAndCountryManager.InsertShippingByWeightAndCountry(shippingMethodID, countryID, txtFrom.Value, txtTo.Value, cbUsePercentage.Checked, txtShippingChargePercentage.Value, txtShippingChargeAmount.Value); BindData(); } catch (Exception exc) { ProcessException(exc); } }
private decimal GetRate(decimal subTotal, decimal weight, int ShippingMethodID, int CountryID) { decimal shippingTotal = decimal.Zero; ShippingByWeightAndCountry shippingByWeightAndCountry = null; ShippingByWeightAndCountryCollection shippingByWeightAndCountryCollection = ShippingByWeightAndCountryManager.GetAllByShippingMethodIDAndCountryID(ShippingMethodID, CountryID); foreach (ShippingByWeightAndCountry shippingByWeightAndCountry2 in shippingByWeightAndCountryCollection) { if ((weight >= shippingByWeightAndCountry2.From) && (weight <= shippingByWeightAndCountry2.To)) { shippingByWeightAndCountry = shippingByWeightAndCountry2; break; } } if (shippingByWeightAndCountry == null) { return(decimal.Zero); } if (shippingByWeightAndCountry.UsePercentage && shippingByWeightAndCountry.ShippingChargePercentage <= decimal.Zero) { return(decimal.Zero); } if (!shippingByWeightAndCountry.UsePercentage && shippingByWeightAndCountry.ShippingChargeAmount <= decimal.Zero) { return(decimal.Zero); } if (shippingByWeightAndCountry.UsePercentage) { shippingTotal = Math.Round((decimal)((((float)subTotal) * ((float)shippingByWeightAndCountry.ShippingChargePercentage)) / 100f), 2); } else { shippingTotal = shippingByWeightAndCountry.ShippingChargeAmount * weight; } if (shippingTotal < decimal.Zero) { shippingTotal = decimal.Zero; } return(shippingTotal); }