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"]; } }
protected void dlVersionList_ItemDataBound(object sender, DataListItemEventArgs e) { ShippingRegion item = e.Item.DataItem as ShippingRegion; if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { ITextControl lblCountryTitle = e.Item.FindControl("lblCountryTitle") as ITextControl; ITextControl lblStateTitle = e.Item.FindControl("lblStateTitle") as ITextControl; ITextControl lblPrefId = e.Item.FindControl("lblPrefId") as ITextControl; HyperLink hlEdit = e.Item.FindControl("hlEdit") as HyperLink; LinkButton lbRemove = e.Item.FindControl("lbRemove") as LinkButton; hlEdit.NavigateUrl = "CustomShipping.aspx?RId=" + item.RegionId; lblCountryTitle.Text = CountryManager.CountryName(item.CountryId); lblPrefId.Text = item.PrefId.ToString(); if (item.StateId != null) { lblStateTitle.Text = StateManager.GetStateName(Convert.ToInt32(item.StateId)); } } }
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); }
/// <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"); }