Ejemplo n.º 1
0
        public static void TestProcessData()
        {
            DhlLabelRequest dhlLabelReq = new DhlLabelRequest();
            Credentials     dhlCred     = new Credentials();

            dhlCred.Username            = "******";
            dhlCred.Password            = "******";
            dhlLabelReq.UserCredentials = dhlCred;
            dhlLabelReq.WeightOz        = 4;
            Address shipToAddress = new Address();

            shipToAddress.Name        = "James White";
            shipToAddress.Address1    = "15 Foggy Glen Dr";
            shipToAddress.City        = "Arden";
            shipToAddress.Region      = "NC";
            shipToAddress.RegionCode  = "NC";
            shipToAddress.Country     = "US";
            shipToAddress.CountryCode = "US";
            shipToAddress.PhoneNumber = "828 674 5026";
            dhlLabelReq.ShipToAddress = shipToAddress;
            Address fromAddress = new Address();

            fromAddress.Name             = "Jack Ng";
            fromAddress.Address1         = "15046 Nelson Ave #15";
            fromAddress.City             = "City Of Industry";
            fromAddress.Region           = "CA";
            fromAddress.RegionCode       = "CA";
            fromAddress.Country          = "US";
            fromAddress.CountryCode      = "US";
            fromAddress.PhoneNumber      = "6264008832";
            dhlLabelReq.FromAddress      = fromAddress;
            dhlLabelReq.IsTest           = true;
            dhlLabelReq.LabelType        = DomesticLabelType.DhlSmParcelsExpedited;
            dhlLabelReq.LabelImageFormat = ImageFormat.Gif;
            dhlLabelReq.LabelSize        = LabelSize.Label4X6;
            dhlLabelReq.Reference1       = "testSKU";
            string          endPointName = ConfigurationManager.AppSettings["pebbledon"];
            DhlWebApiClient client       = new DhlWebApiClient("DhlApi", "http://ifslabelservice.com/api/DhlApi.svc");

            client.Open();
            DhlLabelResponse     dhlLabelRes = client.GetLabel(dhlLabelReq);
            string               tackingNum  = dhlLabelRes.TrackingNumber;
            DomesticRateResponse drres       = dhlLabelRes.RateInfo;

            Console.WriteLine("OK");
        }
        public static Dictionary <string, byte[]> GetDomesticLabel2(string orderNum, string channel)
        {
            Dictionary <string, byte[]> shippingLabelDic = new Dictionary <string, byte[]>();
            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);
            DhlLabelRequest dhlLabelReq = new DhlLabelRequest();
            Credentials     dhlCred     = new Credentials();

            dhlCred.Username            = ConfigurationManager.AppSettings["firstMileAccount"];
            dhlCred.Password            = ConfigurationManager.AppSettings["firstMilePassword"];
            dhlLabelReq.UserCredentials = dhlCred;
            dhlLabelReq.WeightOz        = weightOz;
            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();
            dhlLabelReq.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"];
            dhlLabelReq.FromAddress = fromAddress;
            dhlLabelReq.IsTest      = false;
            string reference2  = "";
            string shipCountry = orderHeaderInfoDr["ShipCountry"].ToString();

            if (weightOz >= 16)
            {
                dhlLabelReq.LabelType = DomesticLabelType.DhlSmParcelPlusExpedited;
                reference2            = "DhlSmParcelPlusExpedited";
            }
            else
            {
                if (weightOz > 240)
                {
                    ExceptionUtility exceptionUtility = new ExceptionUtility();
                    exceptionUtility.ErrorWarningMethod("Domestic Shipping Over Max Weight: " + orderNum, "Domestic Shipping Over Max Weight: " + orderNum, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum);
                    //shippingLabelDic.Add("EmailSent", "EmailSent");
                    return(shippingLabelDic);
                }
                else
                {
                    dhlLabelReq.LabelType = DomesticLabelType.DhlSmParcelsExpedited;
                    reference2            = "DhlSmParcelsExpedited";
                }
            }
            dhlLabelReq.LabelImageFormat = ImageFormat.Gif;
            dhlLabelReq.LabelSize        = LabelSize.Label4X6;

            dhlLabelReq.Reference1    = orderHeaderInfoDr["OrderNum"].ToString();// order number
            dhlLabelReq.DocTabValues  = infoList.ToArray();
            dhlLabelReq.GetRate       = true;
            dhlLabelReq.OriginZipCode = ConfigurationManager.AppSettings["FromRegionCode"];
            DhlWebApiClient  client      = new DhlWebApiClient("DhlApi", "http://ifslabelservice.com/api/DhlApi.svc");
            DhlLabelResponse dhlLabelRes = client.GetLabel(dhlLabelReq);

            //string nativeCommand = dhlLabelRes.NativePrinterCommand;
            byte[] labelImg            = dhlLabelRes.LabelImage;
            string trackingNum         = dhlLabelRes.TrackingNumber;
            DomesticRateResponse drres = dhlLabelRes.RateInfo;
            decimal cost = drres.Cost;

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