protected void gvShippingByTotals_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "UpdateShippingByTotal") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = gvShippingByTotals.Rows[index]; HiddenField hfShippingByTotalID = row.FindControl("hfShippingByTotalID") as HiddenField; DropDownList ddlShippingMethod = row.FindControl("ddlShippingMethod") 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 shippingByTotalID = int.Parse(hfShippingByTotalID.Value); int shippingMethodID = int.Parse(ddlShippingMethod.SelectedItem.Value); ShippingByTotal shippingByTotal = ShippingByTotalManager.GetByID(shippingByTotalID); if (shippingByTotal != null) { ShippingByTotalManager.UpdateShippingByTotal(shippingByTotal.ShippingByTotalID, shippingMethodID, txtFrom.Value, txtTo.Value, cbUsePercentage.Checked, txtShippingChargePercentage.Value, txtShippingChargeAmount.Value); } BindData(); } }
private void BindData() { ShippingByTotalCollection shippingByTotalCollection = ShippingByTotalManager.GetAll(); gvShippingByTotals.DataSource = shippingByTotalCollection; gvShippingByTotals.DataBind(); }
protected void gvShippingByTotals_RowDeleting(object sender, GridViewDeleteEventArgs e) { int shippingByTotalID = (int)gvShippingByTotals.DataKeys[e.RowIndex]["ShippingByTotalID"]; ShippingByTotal shippingByTotal = ShippingByTotalManager.GetByID(shippingByTotalID); if (shippingByTotal != null) { ShippingByTotalManager.DeleteShippingByTotal(shippingByTotal.ShippingByTotalID); BindData(); } }
/// <summary> /// Gets a shipping rate /// </summary> /// <param name="subTotal">Subtotal</param> /// <param name="ShippingMethodID">Shipping method identifier</param> /// <returns>Shipping rate</returns> protected decimal?GetRate(decimal subTotal, int ShippingMethodID) { decimal?shippingTotal = null; bool limitMethodsToCreated = SettingManager.GetSettingValueBoolean("ShippingByTotal.LimitMethodsToCreated"); ShippingByTotal shippingByTotal = null; var shippingByTotalCollection = ShippingByTotalManager.GetAllByShippingMethodId(ShippingMethodID); foreach (ShippingByTotal shippingByTotal2 in shippingByTotalCollection) { if ((subTotal >= shippingByTotal2.From) && (subTotal <= shippingByTotal2.To)) { shippingByTotal = shippingByTotal2; break; } } if (shippingByTotal == null) { if (limitMethodsToCreated) { return(null); } else { return(decimal.Zero); } } if (shippingByTotal.UsePercentage && shippingByTotal.ShippingChargePercentage <= decimal.Zero) { return(decimal.Zero); } if (!shippingByTotal.UsePercentage && shippingByTotal.ShippingChargeAmount <= decimal.Zero) { return(decimal.Zero); } if (shippingByTotal.UsePercentage) { shippingTotal = Math.Round((decimal)((((float)subTotal) * ((float)shippingByTotal.ShippingChargePercentage)) / 100f), 2); } else { shippingTotal = shippingByTotal.ShippingChargeAmount; } if (shippingTotal < decimal.Zero) { shippingTotal = decimal.Zero; } return(shippingTotal); }
protected void btnAdd_Click(object sender, EventArgs e) { try { int shippingMethodID = int.Parse(this.ddlShippingMethod.SelectedItem.Value); ShippingByTotal shippingByTotal = ShippingByTotalManager.InsertShippingByTotal(shippingMethodID, txtFrom.Value, txtTo.Value, cbUsePercentage.Checked, txtShippingChargePercentage.Value, txtShippingChargeAmount.Value); BindData(); } catch (Exception exc) { ProcessException(exc); } }
/// <summary> /// Gets a shipping rate /// </summary> /// <param name="subTotal">Subtotal</param> /// <param name="ShippingMethodID">Shipping method identifier</param> /// <returns>Shipping rate</returns> protected decimal GetRate(decimal subTotal, int ShippingMethodID) { decimal shippingTotal = decimal.Zero; ShippingByTotal shippingByTotal = null; ShippingByTotalCollection shippingByTotalCollection = ShippingByTotalManager.GetAllByShippingMethodID(ShippingMethodID); foreach (ShippingByTotal shippingByTotal2 in shippingByTotalCollection) { if ((subTotal >= shippingByTotal2.From) && (subTotal <= shippingByTotal2.To)) { shippingByTotal = shippingByTotal2; break; } } if (shippingByTotal == null) { return(decimal.Zero); } if (shippingByTotal.UsePercentage && shippingByTotal.ShippingChargePercentage <= decimal.Zero) { return(decimal.Zero); } if (!shippingByTotal.UsePercentage && shippingByTotal.ShippingChargeAmount <= decimal.Zero) { return(decimal.Zero); } if (shippingByTotal.UsePercentage) { shippingTotal = Math.Round((decimal)((((float)subTotal) * ((float)shippingByTotal.ShippingChargePercentage)) / 100f), 2); } else { shippingTotal = shippingByTotal.ShippingChargeAmount; } if (shippingTotal < decimal.Zero) { shippingTotal = decimal.Zero; } return(shippingTotal); }