当前位置: 首页>>代码示例>>C#>>正文


C# Ship.Rate方法代码示例

本文整理汇总了C#中Ship.Rate方法的典型用法代码示例。如果您正苦于以下问题:C# Ship.Rate方法的具体用法?C# Ship.Rate怎么用?C# Ship.Rate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ship的用法示例。


在下文中一共展示了Ship.Rate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUSPSRate

        public decimal GetUSPSRate(Rates objRates, CurrentUserInfo uinfo, Delivery delivery, string strShippingOptionName)
        {
            decimal decRate = 0;

            try
            {
                // Cache the data for 10 minutes with a key
                using (CachedSection<Rates> cs = new CachedSection<Rates>(ref objRates, 60, true, null, "USPS-" + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, "")))
                {
                    if (cs.LoadData)
                    {

                        //Get real-time shipping rates from USPS using dotNETShip
                        Ship objShip = new Ship();
                        objShip.USPSLogin = strUSPSLogin;
                        objShip.OrigZipPostal = SettingsKeyInfoProvider.GetValue("SourceZip", "90001");
                        string[] strCountryState = SettingsKeyInfoProvider.GetValue("SourceCountryState", "US").Split(';');
                        CountryInfo ci = CountryInfoProvider.GetCountryInfo(ValidationHelper.GetString(strCountryState[0], "USA"));
                        objShip.OrigCountry = ci.CountryTwoLetterCode;
                        StateInfo si = StateInfoProvider.GetStateInfo(ValidationHelper.GetString(strCountryState[1], "California"));
                        objShip.OrigStateProvince = si.StateCode;

                        objShip.DestZipPostal = delivery.DeliveryAddress.AddressZip;
                        objShip.DestCountry = delivery.DeliveryAddress.GetCountryTwoLetterCode();
                        objShip.DestStateProvince = delivery.DeliveryAddress.GetStateCode();

                        objShip.Length = 12;
                        objShip.Width = 12;
                        objShip.Height = 12;

                        objShip.Weight = (float)delivery.Weight;

                        objShip.Rate("USPS");

                        cs.Data = objShip.Rates;
                    }

                    objRates = cs.Data;
                }

                foreach (Rate rate in objRates)
                {
                    if (rate.Name.ToLower() == strShippingOptionName.ToLower())
                    {
                        decRate = ValidationHelper.GetDecimal(rate.Charge, 0);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                //Log the error
                EventLogProvider.LogException("MultiCarrier - GetUSPSRate", "EXCEPTION", ex);
                //Set some base rate for the shipping
                decRate = 10;
            }

            return decRate;
        }
开发者ID:petrsvihlik,项目名称:Samples,代码行数:59,代码来源:MultiCarrier.cs


注:本文中的Ship.Rate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。