예제 #1
0
        private decimal GetSurchargeAmt(Order orderItem)
        {
            SitePreference sitePreference = CSFactory.GetCartPrefrence();

            List <SkuShipping> shippingCosts = ShippingDAL.GetSkuShipping();

            decimal surcharge = 0;

            foreach (Sku sku in orderItem.SkuItems)
            {
                if (!sku.AttributeValuesLoaded)
                {
                    sku.LoadAttributeValues();
                }

                if (!sku.SkuCode.ToUpper().Contains("SURCHARGE"))
                {
                    continue;
                }

                CSData.SkuShipping skuShipping = shippingCosts.FirstOrDefault(x =>
                {
                    return(x.PrefId == sitePreference.ShippingPrefID &&
                           x.SkuId == sku.SkuId);
                });

                if (skuShipping != null)
                {
                    surcharge += (skuShipping.Cost * sku.Quantity);
                }
            }

            return(surcharge);
        }
예제 #2
0
        protected void rptSkuItem_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            List <SkuShipping> skuItems = ShippingDAL.GetSkuShipping(false, DefaultSitePrefereceId);

            CSBusiness.Sku skuItem = e.Item.DataItem as CSBusiness.Sku;

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label   lblTitle      = e.Item.FindControl("lblSkuTitle") as Label;
                Label   lblSkuId      = e.Item.FindControl("lblSkuId") as Label;
                TextBox txtPercentage = (TextBox)e.Item.FindControl("txtPercentage");

                SkuShipping itemVal = skuItems.FirstOrDefault(p => p.SkuId == skuItem.SkuId);
                if (itemVal != null)
                {
                    txtPercentage.Text = String.Format("{0:0.##}", itemVal.Cost);
                }
                else
                {
                    txtPercentage.Text = "0";
                }
                lblSkuId.Text = skuItem.SkuId.ToString();
                lblTitle.Text = skuItem.Title + " (" + skuItem.SkuId.ToString() + ")";
            }
        }
예제 #3
0
        private decimal GetMerchandiseSubtotal(Order orderItem)
        {
            SitePreference sitePreference = CSFactory.GetCartPrefrence();

            List <SkuShipping> shippingCosts = ShippingDAL.GetSkuShipping();

            decimal rushCharge = 0;

            foreach (Sku sku in orderItem.SkuItems)
            {
                if (!sku.AttributeValuesLoaded)
                {
                    sku.LoadAttributeValues();
                }

                if (!sku.GetAttributeValue("RushSku", false))
                {
                    continue;
                }

                CSData.SkuShipping skuShipping = shippingCosts.FirstOrDefault(x =>
                {
                    return(x.PrefId == sitePreference.ShippingPrefID &&
                           x.SkuId == sku.SkuId);
                });

                if (skuShipping != null)
                {
                    rushCharge += (skuShipping.Cost * sku.Quantity);
                }
            }

            return(rushCharge);
        }
        public void Calculate(ShoppingManagement.Cart cart, int prefID)
        {
            ShippingPref shippingGetShippingPref = ShippingDAL.GetShippingPref().Where(p => p.PrefId == prefID).FirstOrDefault();

            if (shippingGetShippingPref != null)
            {
                if (cart.SubTotal > 0) //Sri: Reset shipping calculation if there are no items in the cart
                {
                    // add additional shipping charge by specified key
                    ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey);
                    if (shippingCharge != null)
                    {
                        cart.AdditionalShippingCharge = shippingCharge.Cost;
                    }

                    if (_isRushShipping)
                    {
                        cart.RushShippingCost = shippingGetShippingPref.RushShippingCost;
                    }
                    else
                    {
                        cart.ShippingCost = (shippingGetShippingPref.flatShipping ?? 0);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Missing shipping preferences");
            }
        }
예제 #5
0
        public void BindAll()
        {
            SkuManager skuMgr = new SkuManager();

            rptSkuItem.DataSource = skuMgr.GetAllSkus();
            rptSkuItem.DataBind();

            rptRushSkuItem.DataSource = skuMgr.GetAllSkus();
            rptRushSkuItem.DataBind();

            rptItems.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, false, DefaultSitePrefereceId);
            rptItems.DataBind();

            rptRushOrderTotal.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, true, DefaultSitePrefereceId);
            rptItems.DataBind();
            rptRushOrderTotal.DataBind();

            rptOrderWeight.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, false, DefaultSitePrefereceId);
            rptItems.DataBind();
            rptOrderWeight.DataBind();

            rptRushOrderWeight.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, true, DefaultSitePrefereceId);
            rptItems.DataBind();
            rptRushOrderWeight.DataBind();

            rptShippingCharges.DataSource = ShippingDAL.GetShippingChargesByPref(DefaultSitePrefereceId);
            rptShippingCharges.DataBind();
        }
        public void Calculate(Cart cart, int prefID)
        {
            List <ShippingOrderValue> shippingSettings = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, _isRushShipping, prefID).OrderBy(s => s.OrderTotal).ToList();

            decimal cartSubtotal = cart.SubTotal;


            int totalShippingSettings = shippingSettings.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                ShippingOrderValue currentSetting = shippingSettings[i];
                if (cartSubtotal <= currentSetting.OrderTotal ||
                    i == totalShippingSettings - 1)
                {
                    // add additional shipping charge by specified key
                    ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey);
                    if (shippingCharge != null)
                    {
                        cart.AdditionalShippingCharge = shippingCharge.Cost;
                    }

                    if (_isRushShipping)
                    {
                        cart.RushShippingCost = currentSetting.Cost;
                    }
                    else
                    {
                        cart.ShippingCost = currentSetting.Cost;
                    }
                    break;
                }
            }
        }
예제 #7
0
        public void BindAll(ShippingOptionType type, bool includeRushShipping)
        {
            List <ShippingOrderValue> list = ShippingDAL.GetShippingOrderValue(type, includeRushShipping, DefaultSitePrefereceId);

            if (!includeRushShipping)
            {
                switch (type)
                {
                case ShippingOptionType.TotalAmount:
                    rptItems.DataSource = list;
                    rptItems.DataBind();
                    break;

                case ShippingOptionType.Weight:
                    rptOrderWeight.DataSource = list;
                    rptOrderWeight.DataBind();
                    break;
                }
            }
            else
            {
                switch (type)
                {
                case ShippingOptionType.TotalAmount:
                    rptRushOrderTotal.DataSource = list;
                    rptRushOrderTotal.DataBind();
                    break;

                case ShippingOptionType.Weight:
                    rptRushOrderWeight.DataSource = list;
                    rptRushOrderWeight.DataBind();
                    break;
                }
            }
        }
예제 #8
0
        public static decimal GetMainSkuShippingCost(Cart cart)
        {
            decimal            shippingCost    = 0;
            List <SkuShipping> skuShippingList = ShippingDAL.GetSkuShipping();

            SitePreference sitePreference = CSFactory.GetCartPrefrence(cart);

            if (sitePreference != null)
            {
                foreach (Sku sku in cart.CartItems)
                {
                    if (SiteBasePage.IsMainSku(sku.SkuId))
                    {
                        CSData.SkuShipping skuShipping = skuShippingList.FirstOrDefault(x =>
                        {
                            return(x.PrefId == sitePreference.ShippingPrefID &&
                                   x.SkuId == sku.SkuId);
                        });

                        if (skuShipping != null)
                        {
                            shippingCost += (skuShipping.Cost * sku.Quantity);
                        }
                    }
                }
            }

            return(shippingCost);
            // TODO: add rush sku cost support
        }
예제 #9
0
        public void Calculate(Cart cart, int prefID)
        {
            List <SkuShipping> skuShippingItems = ShippingDAL.GetSkuShipping(_isRushShipping, prefID);
            decimal            shippingCost     = 0;

            int totalShippingSettings = skuShippingItems.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                SkuShipping currentSetting = skuShippingItems[i];
                if (cart.CartItems.Exists(c => c.SkuId == currentSetting.SkuId))
                {
                    bool withQuantity = false;
                    Sku  s            = new Sku();
                    s.SkuId = currentSetting.SkuId;
                    s.LoadAttributeValues();
                    if (s.AttributeValues.ContainsKey("shippingwithquantity"))
                    {
                        if (s.AttributeValues["shippingwithquantity"].BooleanValue)
                        {
                            withQuantity = true;
                        }
                    }
                    if (withQuantity)
                    {
                        foreach (Sku st in cart.CartItems)
                        {
                            if (st.SkuId == currentSetting.SkuId)
                            {
                                shippingCost += currentSetting.Cost * st.Quantity;
                            }
                        }
                    }
                    else
                    {
                        shippingCost += currentSetting.Cost;
                    }
                }
            }

            // add additional shipping charge by specified key
            ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey);

            if (shippingCharge != null)
            {
                cart.AdditionalShippingCharge = shippingCharge.Cost;
            }

            if (_isRushShipping)
            {
                cart.RushShippingCost = shippingCost;
            }
            else
            {
                cart.ShippingCost = shippingCost;
            }
        }
예제 #10
0
        public void PopulateControls()
        {
            ShippingPref val = ShippingDAL.GetShippingPref().First();

            txtFlat.Text     = String.Format("{0:0.##}", val.flatShipping);
            txtRushFlat.Text = String.Format("{0:0.##}", val.RushShippingCost);

            cbRushShippingOption.Checked = (bool)val.InCludeRushShipping;
            rushShippingSettings.Visible = cbRushShippingOption.Checked;

            BindAll();
            switch (val.OptionId)
            {
            case (int)ShippingOptionType.TotalAmount:
                cbOrderSubTotal.Checked = true;
                pnlOrderVal.Visible     = true;
                break;

            case (int)ShippingOptionType.Weight:
                cbOrderWeight.Checked = true;
                pnlWeight.Visible     = true;
                break;

            case (int)ShippingOptionType.SkuBased:
                cbSkuItem.Checked  = true;
                pnlSkuItem.Visible = true;
                break;

            case (int)ShippingOptionType.Flat:
                cbFlat.Checked  = true;
                pnlFlat.Visible = true;
                break;
            }

            switch (val.RushOptionId)
            {
            case (int)ShippingOptionType.TotalAmount:
                cbRushOrderTotal.Checked  = true;
                pnlRushOrderTotal.Visible = true;
                break;

            case (int)ShippingOptionType.Weight:
                cbRushOrderweight.Checked  = true;
                pnlRushOrderweight.Visible = true;
                break;

            case (int)ShippingOptionType.SkuBased:
                cbRushSkuItem.Checked  = true;
                pnlRushSkuItem.Visible = true;
                break;

            case (int)ShippingOptionType.Flat:
                cbRushFlat.Checked  = true;
                pnlRushFlat.Visible = true;
                break;
            }
        }
예제 #11
0
        public void Calculate(Cart cart, int prefID)
        {
            List <ShippingOrderValue> shippingSettings = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, _isRushShipping, prefID).OrderBy(s => s.OrderTotal).ToList();

            bool           withQuantity = false;
            decimal        cartWeight;
            SitePreference sp = CSFactory.GetCacheSitePref();

            if (!sp.AttributeValuesLoaded)
            {
                sp.LoadAttributeValues();
            }
            if (sp.AttributeValues.ContainsKey("qtyinweightbasedshipping"))
            {
                if (sp.AttributeValues["qtyinweightbasedshipping"].BooleanValue)
                {
                    withQuantity = true;
                }
            }
            if (withQuantity)
            {
                cartWeight = cart.CartItems.Sum(c => c.Weight * c.Quantity);
            }
            else
            {
                cartWeight = cart.CartItems.Sum(c => c.Weight);
            }

            int totalShippingSettings = shippingSettings.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                ShippingOrderValue currentSetting = shippingSettings[i];
                if (cartWeight <= currentSetting.OrderTotal ||
                    i == totalShippingSettings - 1)
                {
                    // add additional shipping charge by specified key
                    ShippingCharge shippingCharge = ShippingDAL.GetShippingCharge(prefID, cart.ShippingChargeKey);
                    if (shippingCharge != null)
                    {
                        cart.AdditionalShippingCharge = shippingCharge.Cost;
                    }

                    if (_isRushShipping)
                    {
                        cart.RushShippingCost = currentSetting.Cost;
                    }
                    else
                    {
                        cart.ShippingCost = currentSetting.Cost;
                    }

                    break;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BaseLoad();
                lblSuccess.Text = ResourceHelper.GetResoureValue("LabelSuccess");
                lblCancel.Text  = ResourceHelper.GetResoureValue("LabelCancel");
                if (Request.Params["RId"] != null)
                {
                    RId = Convert.ToInt32(Request.Params["RId"]);
                }

                if (RId > 0)
                {
                    ShippingRegion Item = ShippingDAL.GetShippingRegion(RId);
                    PrefId = Item.PrefId;
                    BindCountries();
                    DropDownListCountry.Items.FindByValue(Item.CountryId.ToString()).Selected = true;

                    BindStates();
                    if (Item.StateId != null)
                    {
                        DropDownListState.Items.FindByValue(Item.StateId.ToString()).Selected = true;
                    }
                    else
                    {
                        DropDownListState.Items[0].Selected = true;
                    }

                    DropDownListCountry.Enabled = false;
                    DropDownListState.Enabled   = false;

                    BindShippingCharges(Item.PrefId);
                }
                else
                {
                    BindCountries();
                    //Default set to US Country
                    DropDownListCountry.Items.FindByValue(ConfigHelper.DefaultCountry).Selected = true;
                    BindStates();
                    cbSitePref.Checked           = true;
                    cbRushSitePref.Checked       = true;
                    rushShippingSettings.Visible = false;
                }

                //pull the Custom Preferences
                LoadShippingPreference(PrefId);
            }
            else
            {
                PrefId = (int)ViewState["PrefId"];
            }
        }
예제 #13
0
        private decimal GetRushShippingCost(List <Sku> skuItems, ref ShippingMethodEnum shippingMethod)
        {
            SitePreference sitePreference = CSFactory.GetCartPrefrence();

            List <SkuShipping> shippingCosts = ShippingDAL.GetSkuShipping();

            decimal rushCharge = 0;

            foreach (Sku sku in skuItems)
            {
                if (!sku.AttributeValuesLoaded)
                {
                    sku.LoadAttributeValues();
                }

                if (!sku.GetAttributeValue("RushSku", false))
                {
                    continue;
                }

                CSData.SkuShipping skuShipping = shippingCosts.FirstOrDefault(x =>
                {
                    return(x.PrefId == sitePreference.ShippingPrefID &&
                           x.SkuId == sku.SkuId);
                });

                if (skuShipping != null)
                {
                    // this will set shippingmethod to last one in list - there should really be on rush sku in cart, however
                    switch (sku.SkuCode.ToUpper())
                    {
                    case "OVERNIGHT":
                        shippingMethod = ShippingMethodEnum.NextDay;
                        break;

                    case "002UPS":
                        shippingMethod = ShippingMethodEnum.SecondDay;
                        break;
                    }

                    rushCharge += (skuShipping.Cost * sku.Quantity);
                }
            }

            return(rushCharge);
        }
예제 #14
0
        //This will return site level shipping preference
        public static SitePreference GetCartPrefrence()
        {
            SitePreference prefObject = new SitePreference();

            //Site Level Settings
            SitePref item = CSFactory.GetSitePreference();

            prefObject.PrefID = item.PrefId;
            prefObject.IncludeShippingCostInTaxCalculation = item.OrderTotalShipping;
            prefObject.OrderProcessType   = (OrderProcessTypeEnum)item.OrderProcessType;
            prefObject.GeoLocationService = item.GeoTargetService;
            prefObject.VersionItems       = GetAllVersion();
            prefObject.CouponItems        = GetAllCoupon();

            prefObject.LoadAttributeValues();

            //Shipping Preferences
            ShippingPref val = ShippingDAL.GetShippingPref().Where(p => p.PrefId == 1).First();

            prefObject.ShippingPrefID     = val.PrefId;
            prefObject.RushShippingPrefID = val.PrefId;

            prefObject.ShippingOptionId = (ShippingOptionType)val.OptionId;
            if (val.RushOptionId.HasValue)
            {
                prefObject.RushShippingOptionID = (ShippingOptionType)val.RushOptionId.Value;
            }
            else
            {
                prefObject.RushShippingOptionID = prefObject.ShippingOptionId;
            }

            prefObject.IncludeRushShipping = val.InCludeRushShipping;
            prefObject.RushShippingCost    = val.RushShippingCost;
            prefObject.FlatShippingCost    = val.flatShipping;

            //Default Settings
            prefObject.PaymentGatewayService   = item.PaymentGatewayService;
            prefObject.FulfillmentHouseService = item.FulfillmentHouseService;

            return(prefObject);
        }
        //shipping details list
        public List <Shipping> GetShippingDetails(string username)
        {
            List <Shipping> shippings = new List <Shipping>();

            try
            {
                ShippingDAL shippingDAL = new ShippingDAL();
                //call to ShippingDAL function
                shippings = shippingDAL.ViewShippingDetail(username);
            }
            catch (RecipeIngredientSystemExceptions)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(shippings);
        }
        public decimal CalculateSkuBaseShipping(int skuId)
        {
            //Order orderData = CSResolve.Resolve<IOrderService>().GetOrderDetails(orderId);
            SitePreference     shippingPreferences = CSFactory.GetCartPrefrence(CartContext.CartInfo);
            int                prefid           = shippingPreferences.ShippingPrefID;
            List <SkuShipping> skuShippingItems = ShippingDAL.GetSkuShipping();
            decimal            shippingCost     = 0;

            int totalShippingSettings = skuShippingItems.Count;

            for (int i = 0; i < totalShippingSettings; i++)
            {
                SkuShipping currentSetting = skuShippingItems[i];
                if (skuId == currentSetting.SkuId && prefid == currentSetting.PrefId)
                {
                    shippingCost += currentSetting.Cost;
                }
            }
            return(shippingCost);
        }
예제 #17
0
 public static void RemoveShippingRegion(int prefId)
 {
     ShippingDAL.RemoveShippingRegion(prefId);
 }
예제 #18
0
        public static SitePreference GetCartPrefrence(Cart cart)
        {
            SitePreference defaultSetting = GetCartPrefrence();

            if (cart.ShippingAddress.CountryId > 0)
            {
                List <ShippingRegion> shippingRegions = ShippingDAL.GetShippingRegion();
                ShippingRegion        region          = null;
                if (cart.ShippingAddress.StateProvinceId > 0)
                {
                    region = shippingRegions.Where(r =>
                                                   r.CountryId == cart.ShippingAddress.CountryId &&
                                                   (!r.StateId.HasValue || r.StateId.Value == cart.ShippingAddress.StateProvinceId))
                             .FirstOrDefault();
                }
                else
                {
                    region = shippingRegions.Where(r =>
                                                   r.CountryId == cart.ShippingAddress.CountryId &&
                                                   !r.StateId.HasValue)
                             .FirstOrDefault();
                }

                if (region != null)
                {
                    SitePreference settingsToReturn = new SitePreference();
                    ShippingPref   val = ShippingDAL.GetShippingPref(region.PrefId);


                    if (val != null)
                    {
                        if ((ShippingOptionType)val.OptionId == ShippingOptionType.SiteLevelPref)
                        {
                            settingsToReturn.ShippingPrefID   = defaultSetting.ShippingPrefID;
                            settingsToReturn.ShippingOptionId = defaultSetting.ShippingOptionId;
                            settingsToReturn.FlatShippingCost = defaultSetting.FlatShippingCost;
                        }
                        else
                        {
                            settingsToReturn.ShippingPrefID   = val.PrefId;
                            settingsToReturn.ShippingOptionId = (ShippingOptionType)val.OptionId;
                            settingsToReturn.FlatShippingCost = val.flatShipping;
                        }

                        if ((ShippingOptionType)val.RushOptionId == ShippingOptionType.SiteLevelPref)
                        {
                            settingsToReturn.RushShippingPrefID   = defaultSetting.RushShippingPrefID;
                            settingsToReturn.RushShippingOptionID = defaultSetting.RushShippingOptionID;
                            settingsToReturn.RushShippingCost     = defaultSetting.RushShippingCost;
                        }
                        else
                        {
                            settingsToReturn.RushShippingPrefID = val.PrefId;
                            if (val.RushOptionId.HasValue)
                            {
                                settingsToReturn.RushShippingOptionID = (ShippingOptionType)val.RushOptionId.Value;
                            }
                            else
                            {
                                settingsToReturn.RushShippingOptionID = (ShippingOptionType)val.OptionId;
                            }
                            settingsToReturn.RushShippingCost = val.RushShippingCost;
                        }

                        settingsToReturn.IncludeRushShipping = val.InCludeRushShipping;
                        //Overrider Custom Shipping
                        settingsToReturn.IncludeShippingCostInTaxCalculation = defaultSetting.IncludeShippingCostInTaxCalculation;
                        return(settingsToReturn);
                    }
                }
            }
            return(defaultSetting);
        }
 public void BindShippingCharges(int prefId)
 {
     rptShippingCharges.DataSource = ShippingDAL.GetShippingChargesByPref(prefId);
     rptShippingCharges.DataBind();
 }
예제 #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BaseLoad();

                ShippingPref val = ShippingDAL.GetShippingPref().First();
                txtFlat.Text     = String.Format("{0:0.##}", val.flatShipping);
                txtRushFlat.Text = String.Format("{0:0.##}", val.RushShippingCost);

                cbRushShippingOption.Checked = (bool)val.InCludeRushShipping;
                rushShippingSettings.Visible = cbRushShippingOption.Checked;

                BindAll();
                switch (val.OptionId)
                {
                case (int)ShippingOptionType.TotalAmount:
                    cbOrderSubTotal.Checked = true;
                    pnlOrderVal.Visible     = true;
                    break;

                case (int)ShippingOptionType.Weight:
                    cbOrderWeight.Checked = true;
                    pnlWeight.Visible     = true;
                    break;

                case (int)ShippingOptionType.SkuBased:
                    cbSkuItem.Checked  = true;
                    pnlSkuItem.Visible = true;
                    break;

                case (int)ShippingOptionType.Flat:
                    cbFlat.Checked  = true;
                    pnlFlat.Visible = true;
                    break;
                }

                switch (val.RushOptionId)
                {
                case (int)ShippingOptionType.TotalAmount:
                    cbRushOrderTotal.Checked  = true;
                    pnlRushOrderTotal.Visible = true;
                    break;

                case (int)ShippingOptionType.Weight:
                    cbRushOrderweight.Checked  = true;
                    pnlRushOrderweight.Visible = true;
                    break;

                case (int)ShippingOptionType.SkuBased:
                    cbRushSkuItem.Checked  = true;
                    pnlRushSkuItem.Visible = true;
                    break;

                case (int)ShippingOptionType.Flat:
                    cbRushFlat.Checked  = true;
                    pnlRushFlat.Visible = true;
                    break;
                }
            }
        }
 public static void RemoveShippingCharge(int shippingChargeId)
 {
     ShippingDAL.RemoveShippingCharge(shippingChargeId);
 }
 private void BindRegion()
 {
     dlVersionList.DataSource   = ShippingDAL.GetShippingRegion();
     dlVersionList.DataKeyField = "RegionId";
     dlVersionList.DataBind();
 }
 public static List <ShippingCharge> GetAllShippingCharges()
 {
     return(ShippingDAL.GetAllShippingCharges());
 }
        /// <summary>
        /// Save Command Operation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                ShippingOptionType option     = ShippingOptionType.SiteLevelPref;
                ShippingOptionType optionRush = ShippingOptionType.SiteLevelPref;
                int?stateId = null;
                int countryId;
                if (DropDownListState.SelectedItem.Value.Length > 0)
                {
                    stateId = Convert.ToInt32(DropDownListState.SelectedItem.Value);
                }
                countryId = Convert.ToInt32(DropDownListCountry.SelectedItem.Value);

                if (PrefId == 0) //New Region Defined in the system
                {
                    //Check User Creating same Custom Shipping again or not
                    if (!ShippingDAL.IsValidShippingRegion(countryId, stateId))
                    {
                        using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                        {
                            ShippingPref item = new ShippingPref
                            {
                                flatShipping        = (pnlFlat.Visible) ? Convert.ToDecimal(txtFlat.Text) : 0,
                                RushShippingCost    = (pnlRushFlat.Visible) ? Convert.ToDecimal(txtRushFlat.Text) : 0,
                                RushOptionId        = (int)optionRush,
                                OptionId            = (int)option,
                                InCludeRushShipping = cbRushShippingOption.Checked,
                                IsCustomized        = true
                            };

                            context.ShippingPrefs.InsertOnSubmit(item);
                            context.SubmitChanges();

                            PrefId = item.PrefId;


                            //Associate PrefId to Region Table
                            ShippingRegion newRegion = new ShippingRegion
                            {
                                CountryId = countryId,
                                StateId   = stateId,
                                PrefId    = PrefId
                            };
                            context.ShippingRegions.InsertOnSubmit(newRegion);
                            context.SubmitChanges();
                        }
                    }
                    else
                    {
                        //fire Existing Item Message
                    }
                }

                if (PrefId > 0)
                {
                    if (pnlOrderVal.Visible)
                    {
                        option = ShippingOptionType.TotalAmount;
                        if (this.rptItems.Items.Count > 0)
                        {
                            using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                            {
                                foreach (RepeaterItem lst in rptItems.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                        TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                        TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                        ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                        if (order != null)
                                        {
                                            order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                            order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                            order.PrefId     = PrefId;
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    } //end if for Shipping OrderValue

                    if (pnlWeight.Visible)
                    {
                        option = ShippingOptionType.Weight;
                        if (this.rptOrderWeight.Items.Count > 0)
                        {
                            using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                            {
                                foreach (RepeaterItem lst in rptOrderWeight.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                        TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                        TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                        ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                        if (order != null)
                                        {
                                            order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                            order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                            order.PrefId     = PrefId;
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }//end if for Shipping OrderWeight

                    if (pnlSkuItem.Visible)
                    {
                        option = ShippingOptionType.SkuBased;
                        if (this.rptSkuItem.Items.Count > 0)
                        {
                            using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                            {
                                foreach (RepeaterItem lst in rptSkuItem.Items)
                                {
                                    if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                    {
                                        int         Id         = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text);
                                        TextBox     txtCostVal = (TextBox)lst.FindControl("txtPercentage");
                                        SkuShipping order      = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == false) && (p.PrefId == PrefId));
                                        if (order != null)
                                        {
                                            order.Cost = Convert.ToDecimal(txtCostVal.Text);
                                            context.SubmitChanges();
                                        }
                                        else
                                        {
                                            SkuShipping item = new SkuShipping();
                                            item.SkuId = Id;
                                            item.Cost  = Convert.ToDecimal(txtCostVal.Text);
                                            item.IncludeRushShipping = false;
                                            item.PrefId = PrefId;
                                            context.SkuShippings.InsertOnSubmit(item);
                                            context.SubmitChanges();
                                        }
                                    }
                                }
                            }
                        }
                    }//end if for Shipping SkuItem level

                    if (pnlFlat.Visible)
                    {
                        option = ShippingOptionType.Flat;
                    }

                    if (cbSitePref.Checked)
                    {
                        option = ShippingOptionType.SiteLevelPref;
                    }

                    if (cbRushShippingOption.Checked)
                    {
                        if (pnlRushOrderTotal.Visible)
                        {
                            optionRush = ShippingOptionType.TotalAmount;
                            if (this.rptRushOrderTotal.Items.Count > 0)
                            {
                                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                                {
                                    foreach (RepeaterItem lst in rptRushOrderTotal.Items)
                                    {
                                        if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                        {
                                            int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                            TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                            TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                            ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                            if (order != null)
                                            {
                                                order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                                order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                                order.PrefId     = PrefId;
                                                context.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (pnlRushOrderweight.Visible)
                        {
                            optionRush = ShippingOptionType.Weight;
                            if (this.rptRushOrderWeight.Items.Count > 0)
                            {
                                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                                {
                                    foreach (RepeaterItem lst in rptRushOrderWeight.Items)
                                    {
                                        if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                        {
                                            int                Id          = Convert.ToInt32(((Label)lst.FindControl("lblShippingId")).Text);
                                            TextBox            txtOrderVal = (TextBox)lst.FindControl("txtOrderItem");
                                            TextBox            txtCostVal  = (TextBox)lst.FindControl("txtCostItem");
                                            ShippingOrderValue order       = context.ShippingOrderValues.Single(p => p.ShippingId == Id);
                                            if (order != null)
                                            {
                                                order.OrderTotal = Convert.ToDecimal(txtOrderVal.Text);
                                                order.Cost       = Convert.ToDecimal(txtCostVal.Text);
                                                order.PrefId     = PrefId;
                                                context.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (pnlRushSkuItem.Visible)
                        {
                            optionRush = ShippingOptionType.SkuBased;
                            if (this.rptRushSkuItem.Items.Count > 0)
                            {
                                using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                                {
                                    foreach (RepeaterItem lst in rptRushSkuItem.Items)
                                    {
                                        if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                                        {
                                            int         Id         = Convert.ToInt32(((Label)lst.FindControl("lblSkuId")).Text);
                                            TextBox     txtCostVal = (TextBox)lst.FindControl("txtPercentage");
                                            SkuShipping order      = context.SkuShippings.FirstOrDefault(p => (p.SkuId == Id) && (p.IncludeRushShipping == true) && (p.PrefId == PrefId));
                                            if (order != null)
                                            {
                                                order.Cost = Convert.ToDecimal(txtCostVal.Text);
                                                context.SubmitChanges();
                                            }
                                            else
                                            {
                                                SkuShipping item = new SkuShipping();
                                                item.SkuId = Id;
                                                item.Cost  = Convert.ToDecimal(txtCostVal.Text);
                                                item.IncludeRushShipping = true;
                                                item.PrefId = PrefId;
                                                context.SkuShippings.InsertOnSubmit(item);
                                                context.SubmitChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (pnlRushFlat.Visible)
                    {
                        optionRush = ShippingOptionType.Flat;
                    }

                    if (cbRushSitePref.Checked)
                    {
                        optionRush = ShippingOptionType.SiteLevelPref;
                    }

                    using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                    {
                        ShippingPref Val = context.ShippingPrefs.FirstOrDefault(x => x.PrefId == PrefId);
                        if (Val != null)
                        {
                            if (pnlFlat.Visible)
                            {
                                Val.flatShipping = Convert.ToDecimal(txtFlat.Text);
                            }
                            if (pnlRushFlat.Visible)
                            {
                                Val.RushShippingCost = Convert.ToDecimal(txtRushFlat.Text);
                            }
                            if (cbRushShippingOption.Checked)
                            {
                                Val.RushOptionId = (int)optionRush;
                            }
                            Val.OptionId = (int)option;

                            Val.InCludeRushShipping = cbRushShippingOption.Checked;
                            context.SubmitChanges();
                        }
                    }
                }// prefId check

                // save additional charges
                if (this.rptShippingCharges.Items.Count > 0)
                {
                    List <int> deleteList = new List <int>();

                    using (CSCommerceDataContext context = new CSCommerceDataContext(ConfigHelper.GetDBConnection()))
                    {
                        foreach (RepeaterItem lst in rptShippingCharges.Items)
                        {
                            if ((lst.ItemType == ListItemType.Item) || (lst.ItemType == ListItemType.AlternatingItem))
                            {
                                int      id        = Convert.ToInt32(((HiddenField)lst.FindControl("hidShippingChargeId")).Value);
                                CheckBox chkDelete = (CheckBox)lst.FindControl("chkDelete");

                                if (chkDelete.Checked)
                                {
                                    deleteList.Add(id);
                                }
                                else
                                {
                                    TextBox txtKey   = (TextBox)lst.FindControl("txtKey");
                                    TextBox txtCost  = (TextBox)lst.FindControl("txtCost");
                                    TextBox txtLabel = (TextBox)lst.FindControl("txtLabel");

                                    ShippingCharge shippingCharge = context.ShippingCharges.Single(p => p.ShippingChargeId == id);

                                    shippingCharge.Key           = txtKey.Text;
                                    shippingCharge.Cost          = Convert.ToDecimal(txtCost.Text);
                                    shippingCharge.FriendlyLabel = txtLabel.Text;
                                    context.SubmitChanges();
                                }
                            }
                        }
                    }

                    if (deleteList.Count > 0)
                    {
                        foreach (int id in deleteList)
                        {
                            CSBusiness.Shipping.ShippingManager.RemoveShippingCharge(id);
                        }
                    }
                }
            }//end of save

            Response.Redirect("CustomShippingList.aspx");
        }
 public static List <ShippingCharge> GetShippingChargesByPref(int prefId)
 {
     return(ShippingDAL.GetShippingChargesByPref(prefId));
 }
        public void LoadShippingPreference(int PrefId)
        {
            SkuManager skuMgr = new SkuManager();

            rptSkuItem.DataSource = skuMgr.GetAllSkus();
            rptSkuItem.DataBind();

            rptRushSkuItem.DataSource = skuMgr.GetAllSkus();
            rptRushSkuItem.DataBind();

            if (PrefId > 0)
            {
                ShippingPref val = ShippingDAL.GetShippingPref(PrefId);
                txtFlat.Text                 = String.Format("{0:0.##}", val.flatShipping);
                txtRushFlat.Text             = String.Format("{0:0.##}", val.RushShippingCost);
                cbRushShippingOption.Checked = (bool)val.InCludeRushShipping;
                rushShippingSettings.Visible = cbRushShippingOption.Checked;



                rptItems.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, false, PrefId);
                rptItems.DataBind();
                rptItems.DataBind();

                rptRushOrderTotal.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.TotalAmount, true, PrefId);
                rptItems.DataBind();
                rptRushOrderTotal.DataBind();

                rptOrderWeight.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, false, PrefId);
                rptItems.DataBind();
                rptOrderWeight.DataBind();

                rptRushOrderWeight.DataSource = ShippingDAL.GetShippingOrderValue(ShippingOptionType.Weight, true, PrefId);
                rptItems.DataBind();
                rptRushOrderWeight.DataBind();


                switch (val.OptionId)
                {
                case (int)ShippingOptionType.TotalAmount:
                    cbOrderSubTotal.Checked = true;
                    pnlOrderVal.Visible     = true;
                    break;

                case (int)ShippingOptionType.Weight:
                    cbOrderWeight.Checked = true;
                    pnlWeight.Visible     = true;
                    break;

                case (int)ShippingOptionType.SkuBased:
                    cbSkuItem.Checked  = true;
                    pnlSkuItem.Visible = true;
                    break;

                case (int)ShippingOptionType.Flat:
                    cbFlat.Checked  = true;
                    pnlFlat.Visible = true;
                    break;

                case (int)ShippingOptionType.SiteLevelPref:
                    cbSitePref.Checked = true;
                    break;
                }

                switch (val.RushOptionId)
                {
                case (int)ShippingOptionType.TotalAmount:
                    cbRushOrderTotal.Checked  = true;
                    pnlRushOrderTotal.Visible = true;
                    break;

                case (int)ShippingOptionType.Weight:
                    cbRushOrderweight.Checked  = true;
                    pnlRushOrderweight.Visible = true;
                    break;

                case (int)ShippingOptionType.SkuBased:
                    cbRushSkuItem.Checked  = true;
                    pnlRushSkuItem.Visible = true;
                    break;

                case (int)ShippingOptionType.Flat:
                    cbRushFlat.Checked  = true;
                    pnlRushFlat.Visible = true;
                    break;

                case (int)ShippingOptionType.SiteLevelPref:
                    cbRushSitePref.Checked = true;
                    break;
                }
            }
        }