private void Calculate() { pnlMessages.Visible = !Validate(); divResult.Visible = !pnlMessages.Visible; if (!pnlMessages.Visible) { var shippingInfo = new ServiceProvider.OrderChinaSvc.ShippingInfo_V01 { Address = new ServiceProvider.OrderChinaSvc.Address_V01 { StateProvinceTerritory = ddlState.SelectedItem.Text, City = ddlCity.SelectedItem.Text, CountyDistrict = ddlDistrict.SelectedItem.Text } }; var provider = this.ShippingProvider as ShippingProvider_CN; var freight = provider.CalculateFreight(shippingInfo, decimal.Parse(txtWeight.Text.Trim())); if (freight != null && !string.IsNullOrEmpty(freight.StoreName)) { var source = new List <FreightInfo> { new FreightInfo() { Shippment = freight.StoreName, State = shippingInfo.Address.StateProvinceTerritory, City = shippingInfo.Address.City, District = shippingInfo.Address.CountyDistrict, Weight = string.Format("{0}kg", txtWeight.Text.Trim()), Freight = getAmountString(freight.EstimatedFreight) } }; grvFreightInfo.DataSource = source; grvFreightInfo.DataBind(); } else { lblError.Text = GetLocalResourceObject("NotSupported") as string; pnlMessages.Visible = true; divResult.Visible = !pnlMessages.Visible; } } }
public FreightSimulationResult CalculateFreight(ServiceProvider.OrderChinaSvc.ShippingInfo_V01 shippingInfo, decimal weight) { var freightSimulationResult = new FreightSimulationResult(); if (shippingInfo == null || shippingInfo.Address == null || weight == 0) { return(freightSimulationResult); } if (Settings.GetRequiredAppSetting("LogShipping", "false").ToLower() == "true") { LogRequest(string.Format("ShippingInfo before CalculateFreight: {0}", OrderCreationHelper.Serialize(shippingInfo))); } if (!string.IsNullOrEmpty(shippingInfo.Address.StateProvinceTerritory) && !string.IsNullOrEmpty(shippingInfo.Address.City) && !string.IsNullOrEmpty(shippingInfo.Address.CountyDistrict)) { if (string.IsNullOrEmpty(shippingInfo.ShippingMethodID)) { var mappings = GetProvinceStoreMapping(); if (mappings != null) { var mapping = mappings.Find(m => m.ProvinceName == shippingInfo.Address.StateProvinceTerritory); if (mapping != null) { shippingInfo.ShippingMethodID = mapping.StoreID.ToString(); } } } if (string.IsNullOrEmpty(shippingInfo.WarehouseCode)) { shippingInfo.WarehouseCode = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode; } var proxy = ServiceClientProvider.GetChinaOrderServiceProxy(); var result = proxy.GetFreightCharge(new ServiceProvider.OrderChinaSvc.GetFreightChargeRequest1(new ServiceProvider.OrderChinaSvc.GetFreightChargeRequest_V01() { ShippingInfo = shippingInfo, Weight = weight })).GetFreightChargeResult as ServiceProvider.OrderChinaSvc.GetFreightChargeResponse_V01; if (result != null && result.Status == ServiceProvider.OrderChinaSvc.ServiceResponseStatusType.Success) { freightSimulationResult.EstimatedFreight = result.Freight; freightSimulationResult.StoreName = result.StoreName; } } if (Settings.GetRequiredAppSetting("LogShipping", "false").ToLower() == "true") { LogRequest(string.Format("ShippingInfo after CalculateFreight: {0}", OrderCreationHelper.Serialize(shippingInfo))); } return(freightSimulationResult); }