コード例 #1
0
        public static Dictionary <string, string> GetInternationalLabel(string orderNum, string channel)
        {
            Dictionary <string, string> shippingLabelDic = new Dictionary <string, string>();
            DataRow       orderHeaderInfoDr = MarketplaceDb.Db.GetOrderHeaderDrByOrderNum(orderNum, channel);
            DataTable     orderRowInfoDt    = MarketplaceDb.Db.GetOrderLineDtByOrderNum(orderNum, channel);
            int           weightOz          = 0;
            string        reference         = "";
            List <string> infoList          = new List <string>();

            foreach (DataRow dr in orderRowInfoDt.Rows)
            {
                string  sku          = dr["ItemNum"].ToString();
                DataRow itemDr       = MarketplaceDb.Db.GetItemInfoBySKU(sku);
                int     tempWeightOz = 0;
                if (itemDr == null)
                {
                    tempWeightOz = 4;
                }
                else
                {
                    tempWeightOz = ConvertUtility.ToInt(itemDr["Weight"]);
                }
                weightOz  = weightOz + tempWeightOz;
                reference = reference + sku + "x" + ConvertUtility.ToInt(dr["Quantity"]) + "|";
            }
            infoList.Add(reference);
            InternationalLabelRequest intelLabelReq = new InternationalLabelRequest();
            Credentials dhlCred = new Credentials();

            dhlCred.Username = ConfigurationManager.AppSettings["firstMileAccount"];
            dhlCred.Password = ConfigurationManager.AppSettings["firstMilePassword"];
            intelLabelReq.UserCredentials = dhlCred;
            intelLabelReq.WeightLbs       = weightOz / 16;
            Address shipToAddress = new Address();
            string  accountName   = orderHeaderInfoDr["AccountName"].ToString();

            shipToAddress.Name          = orderHeaderInfoDr["ShipName"].ToString();
            shipToAddress.Address1      = orderHeaderInfoDr["ShipAddress1"].ToString();
            shipToAddress.Address2      = orderHeaderInfoDr["ShipAddress2"].ToString();
            shipToAddress.City          = orderHeaderInfoDr["ShipCity"].ToString();
            shipToAddress.Region        = orderHeaderInfoDr["ShipState"].ToString();
            shipToAddress.RegionCode    = orderHeaderInfoDr["ShipZip"].ToString();
            shipToAddress.Country       = orderHeaderInfoDr["ShipCountry"].ToString();
            shipToAddress.CountryCode   = orderHeaderInfoDr["ShipCountry"].ToString();
            shipToAddress.PhoneNumber   = orderHeaderInfoDr["ShipPhone"].ToString();
            intelLabelReq.ShipToAddress = shipToAddress;
            Address fromAddress = new Address();

            fromAddress.Name              = ConfigurationManager.AppSettings["FromName"];
            fromAddress.Address1          = ConfigurationManager.AppSettings["FromAddress1"];
            fromAddress.Address2          = ConfigurationManager.AppSettings["FromAddress2"];
            fromAddress.City              = ConfigurationManager.AppSettings["FromCity"];
            fromAddress.Region            = ConfigurationManager.AppSettings["FromRegion"];
            fromAddress.RegionCode        = ConfigurationManager.AppSettings["FromRegionCode"];
            fromAddress.Country           = ConfigurationManager.AppSettings["FromCountry"];
            fromAddress.CountryCode       = ConfigurationManager.AppSettings["FromCountryCode"];
            fromAddress.PhoneNumber       = ConfigurationManager.AppSettings["FromPhoneNum"];
            intelLabelReq.FromAddress     = fromAddress;
            intelLabelReq.IsoCurrencyCode = "USD";
            string        shipCountry = orderHeaderInfoDr["ShipCountry"].ToString();
            string        reference2  = "";
            List <string> dhlGmParcelDirectCountryList = ConfigurationManager.AppSettings["DHLGMParcelDirectCountryList"].Split(',').ToList();

            if (weightOz >= 704)
            {
                ExceptionUtility exceptionUtility = new ExceptionUtility();
                exceptionUtility.ErrorWarningMethod("Internation Shipping Over Max Weight: " + orderNum, "Internation Shipping Over Max Weight: " + orderNum, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum);
                shippingLabelDic.Add("EmailSent", "EmailSent");
                return(shippingLabelDic);
            }
            else
            {
                if (dhlGmParcelDirectCountryList.Contains(shipCountry))
                {
                    intelLabelReq.LabelType = LabelType.DhlGMParcelDirect;
                    reference2 = "DhlGMParcelDirect";
                }
                else
                {
                    intelLabelReq.LabelType = LabelType.DhlGMParcelPriority;
                    reference2 = "DhlGMParcelPriority";
                }
            }
            intelLabelReq.TaxIdNumber = ConfigurationManager.AppSettings["TaxId"];
            intelLabelReq.IsTest      = false;
            List <CustomsItem> customsItemList = new List <CustomsItem>();
            CustomsItem        customsItem     = new CustomsItem();

            customsItem.CountryOfOrigin = "CN";
            //etc;
            customsItemList.Add(customsItem);
            intelLabelReq.CustomsItems       = customsItemList.ToArray();
            intelLabelReq.OrderValue         = ConvertUtility.ToDecimal(orderHeaderInfoDr["Subtotal"]);
            intelLabelReq.PackageDescription = ConfigurationManager.AppSettings["PackageDescription"];
            intelLabelReq.GetRate            = true;
            intelLabelReq.OriginZipCode      = ConfigurationManager.AppSettings["FromRegionCode"];
            DhlWebApiClient            client        = new DhlWebApiClient("DhlApi", "http://ifslabelservice.com/api/DhlApi.svc");
            InternationalLabelResponse intelLabelRes = client.GetInternationalLabel(intelLabelReq);

            string[] labelImagesBase64 = intelLabelRes.LabelImagesBase64;

            string trackingNum = intelLabelRes.TrackingNumber;
            InternationalRateResponse irres = intelLabelRes.RateInfo;
            decimal cost          = irres.Cost;
            string  nativeCommand = labelImagesBase64.ToString();

            shippingLabelDic.Add(trackingNum, nativeCommand);
            MarketplaceDb.Db.SaveShipmentInfo(orderNum, channel, accountName, trackingNum, reference, reference2, cost, nativeCommand);
            return(shippingLabelDic);
        }