protected void gvShippingByTotals_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ShippingByTotal shippingByTotal = (ShippingByTotal)e.Row.DataItem; Button btnUpdate = e.Row.FindControl("btnUpdate") as Button; if (btnUpdate != null) { btnUpdate.CommandArgument = e.Row.RowIndex.ToString(); } DropDownList ddlShippingMethod = e.Row.FindControl("ddlShippingMethod") as DropDownList; ddlShippingMethod.Items.Clear(); ShippingMethodCollection shippingMethodCollection = ShippingMethodManager.GetAllShippingMethods(); foreach (ShippingMethod shippingMethod in shippingMethodCollection) { ListItem item = new ListItem(shippingMethod.Name, shippingMethod.ShippingMethodID.ToString()); ddlShippingMethod.Items.Add(item); if (shippingByTotal.ShippingMethodID == shippingMethod.ShippingMethodID) { item.Selected = true; } } } }
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(); } }
protected void gvShippingByTotals_RowDeleting(object sender, GridViewDeleteEventArgs e) { int shippingByTotalId = (int)gvShippingByTotals.DataKeys[e.RowIndex]["ShippingByTotalId"]; ShippingByTotal shippingByTotal = this.ShippingByTotalService.GetById(shippingByTotalId); if (shippingByTotal != null) { this.ShippingByTotalService.DeleteShippingByTotal(shippingByTotal.ShippingByTotalId); BindData(); } }
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 = IoC.Resolve <ISettingManager>().GetSettingValueBoolean("ShippingByTotal.LimitMethodsToCreated"); ShippingByTotal shippingByTotal = null; var shippingByTotalCollection = IoC.Resolve <IShippingByTotalService>().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 = (decimal)((((float)subTotal) * ((float)shippingByTotal.ShippingChargePercentage)) / 100f); shippingTotal = Math.Round(shippingTotal.Value, 2, MidpointRounding.AwayFromZero); } 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; var 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); }
protected void btnAdd_Click(object sender, EventArgs e) { try { int shippingMethodId = int.Parse(this.ddlShippingMethod.SelectedItem.Value); var shippingByTotal = new ShippingByTotal() { ShippingMethodId = shippingMethodId, From = txtFrom.Value, To = txtTo.Value, UsePercentage = cbUsePercentage.Checked, ShippingChargePercentage = txtShippingChargePercentage.Value, ShippingChargeAmount = txtShippingChargeAmount.Value }; this.ShippingByTotalService.InsertShippingByTotal(shippingByTotal); BindData(); } catch (Exception exc) { processAjaxError(exc); } }
public ShippingByTotal InsertShippingByTotal(ShippingByTotal entity) { return(_iShippingByTotalRepository.InsertShippingByTotal(entity)); }