示例#1
0
        protected void gvShippingByWeights_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UpdateShippingByWeight")
            {
                int         index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row   = gvShippingByWeights.Rows[index];

                HiddenField    hfShippingByWeightID = row.FindControl("hfShippingByWeightID") 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 shippingByWeightID            = int.Parse(hfShippingByWeightID.Value);
                int shippingMethodID              = int.Parse(ddlShippingMethod.SelectedItem.Value);
                ShippingByWeight shippingByWeight = ShippingByWeightManager.GetByID(shippingByWeightID);

                if (shippingByWeight != null)
                {
                    ShippingByWeightManager.UpdateShippingByWeight(shippingByWeight.ShippingByWeightID,
                                                                   shippingMethodID, txtFrom.Value, txtTo.Value, cbUsePercentage.Checked,
                                                                   txtShippingChargePercentage.Value, txtShippingChargeAmount.Value);
                }

                BindData();
            }
        }
示例#2
0
        protected void gvShippingByWeights_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ShippingByWeight shippingByWeight = (ShippingByWeight)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 (shippingByWeight.ShippingMethodID == shippingMethod.ShippingMethodID)
                    {
                        item.Selected = true;
                    }
                }
            }
        }
        private decimal?GetRate(decimal subTotal, decimal Weight, int ShippingMethodID)
        {
            decimal?shippingTotal = null;

            bool limitMethodsToCreated = IoC.Resolve <ISettingManager>().GetSettingValueBoolean("ShippingByWeight.LimitMethodsToCreated");

            ShippingByWeight shippingByWeight = null;
            var shippingByWeightCollection    = IoC.Resolve <IShippingByWeightService>().GetAllByShippingMethodId(ShippingMethodID);

            foreach (var shippingByWeight2 in shippingByWeightCollection)
            {
                if ((Weight >= shippingByWeight2.From) && (Weight <= shippingByWeight2.To))
                {
                    shippingByWeight = shippingByWeight2;
                    break;
                }
            }
            if (shippingByWeight == null)
            {
                if (limitMethodsToCreated)
                {
                    return(null);
                }
                else
                {
                    return(decimal.Zero);
                }
            }
            if (shippingByWeight.UsePercentage && shippingByWeight.ShippingChargePercentage <= decimal.Zero)
            {
                return(decimal.Zero);
            }
            if (!shippingByWeight.UsePercentage && shippingByWeight.ShippingChargeAmount <= decimal.Zero)
            {
                return(decimal.Zero);
            }
            if (shippingByWeight.UsePercentage)
            {
                shippingTotal = (decimal)(((float)subTotal) * ((float)shippingByWeight.ShippingChargePercentage) / 100f);
                //shippingTotal = Math.Round(shippingTotal.Value, 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                if (IoC.Resolve <IShippingByWeightService>().CalculatePerWeightUnit)
                {
                    shippingTotal = shippingByWeight.ShippingChargeAmount * Weight;
                }
                else
                {
                    shippingTotal = shippingByWeight.ShippingChargeAmount;
                }
            }
            if (shippingTotal < decimal.Zero)
            {
                shippingTotal = decimal.Zero;
            }
            return(shippingTotal);
        }
示例#4
0
        protected void gvShippingByWeights_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int shippingByWeightID            = (int)gvShippingByWeights.DataKeys[e.RowIndex]["ShippingByWeightID"];
            ShippingByWeight shippingByWeight = ShippingByWeightManager.GetByID(shippingByWeightID);

            if (shippingByWeight != null)
            {
                ShippingByWeightManager.DeleteShippingByWeight(shippingByWeight.ShippingByWeightID);
                BindData();
            }
        }
        protected void gvShippingByWeights_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int shippingByWeightId            = (int)gvShippingByWeights.DataKeys[e.RowIndex]["ShippingByWeightId"];
            ShippingByWeight shippingByWeight = this.ShippingByWeightService.GetById(shippingByWeightId);

            if (shippingByWeight != null)
            {
                this.ShippingByWeightService.DeleteShippingByWeight(shippingByWeight.ShippingByWeightId);
                BindData();
            }
        }
        private decimal GetRate(decimal subTotal, decimal Weight, int ShippingMethodID)
        {
            decimal shippingTotal = decimal.Zero;

            ShippingByWeight shippingByWeight = null;
            var shippingByWeightCollection    = ShippingByWeightManager.GetAllByShippingMethodId(ShippingMethodID);

            foreach (var shippingByWeight2 in shippingByWeightCollection)
            {
                if ((Weight >= shippingByWeight2.From) && (Weight <= shippingByWeight2.To))
                {
                    shippingByWeight = shippingByWeight2;
                    break;
                }
            }
            if (shippingByWeight == null)
            {
                return(decimal.Zero);
            }
            if (shippingByWeight.UsePercentage && shippingByWeight.ShippingChargePercentage <= decimal.Zero)
            {
                return(decimal.Zero);
            }
            if (!shippingByWeight.UsePercentage && shippingByWeight.ShippingChargeAmount <= decimal.Zero)
            {
                return(decimal.Zero);
            }
            if (shippingByWeight.UsePercentage)
            {
                shippingTotal = Math.Round((decimal)((((float)subTotal) * ((float)shippingByWeight.ShippingChargePercentage)) / 100f), 2);
            }
            else
            {
                if (ShippingByWeightManager.CalculatePerWeightUnit)
                {
                    shippingTotal = shippingByWeight.ShippingChargeAmount * Weight;
                }
                else
                {
                    shippingTotal = shippingByWeight.ShippingChargeAmount;
                }
            }
            if (shippingTotal < decimal.Zero)
            {
                shippingTotal = decimal.Zero;
            }
            return(shippingTotal);
        }
示例#7
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                int shippingMethodID = int.Parse(this.ddlShippingMethod.SelectedItem.Value);
                ShippingByWeight shippingByWeight = ShippingByWeightManager.InsertShippingByWeight(shippingMethodID,
                                                                                                   txtFrom.Value, txtTo.Value, cbUsePercentage.Checked,
                                                                                                   txtShippingChargePercentage.Value, txtShippingChargeAmount.Value);

                BindData();
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                int shippingMethodId = int.Parse(this.ddlShippingMethod.SelectedItem.Value);
                var shippingByWeight = new ShippingByWeight()
                {
                    ShippingMethodId = shippingMethodId,
                    From             = txtFrom.Value,
                    To                       = txtTo.Value,
                    UsePercentage            = cbUsePercentage.Checked,
                    ShippingChargePercentage = txtShippingChargePercentage.Value,
                    ShippingChargeAmount     = txtShippingChargeAmount.Value
                };
                this.ShippingByWeightService.InsertShippingByWeight(shippingByWeight);

                BindData();
            }
            catch (Exception exc)
            {
                processAjaxError(exc);
            }
        }
 public ShippingByWeight InsertShippingByWeight(ShippingByWeight entity)
 {
     return(_iShippingByWeightRepository.InsertShippingByWeight(entity));
 }