Example #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();
            }
        }
Example #2
0
        private void BindData()
        {
            ShippingByWeightCollection shippingByWeightCollection = ShippingByWeightManager.GetAll();

            gvShippingByWeights.DataSource = shippingByWeightCollection;
            gvShippingByWeights.DataBind();
        }
        private decimal?GetRate(decimal subTotal, decimal Weight, int ShippingMethodID)
        {
            decimal?shippingTotal = null;

            bool limitMethodsToCreated = SettingManager.GetSettingValueBoolean("ShippingByWeight.LimitMethodsToCreated");

            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)
            {
                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 = 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);
        }
Example #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();
            }
        }
Example #5
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);
            }
        }
Example #6
0
        private decimal GetRate(decimal subTotal, decimal Weight, int ShippingMethodID)
        {
            decimal shippingTotal = decimal.Zero;

            ShippingByWeight           shippingByWeight           = null;
            ShippingByWeightCollection shippingByWeightCollection = ShippingByWeightManager.GetAllByShippingMethodID(ShippingMethodID);

            foreach (ShippingByWeight 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
            {
                shippingTotal = shippingByWeight.ShippingChargeAmount * Weight;
            }

            if (shippingTotal < decimal.Zero)
            {
                shippingTotal = decimal.Zero;
            }
            return(shippingTotal);
        }