Ejemplo n.º 1
0
        public static Dictionary <string, object> DomesticEndOfDay()
        {
            Dictionary <string, object>     domesticEndOfDayDic = new Dictionary <string, object>();
            CloseDomesticShippingDayRequest request             = new CloseDomesticShippingDayRequest();
            Credentials dhlCred = new Credentials();

            dhlCred.Username        = ConfigurationManager.AppSettings["firstMileAccount"];
            dhlCred.Password        = ConfigurationManager.AppSettings["firstMilePassword"];
            request.UserCredentials = dhlCred;
            request.IsTest          = false;
            DhlWebApiClient client = new DhlWebApiClient("DhlApi", "http://ifslabelservice.com/api/DhlApi.svc");
            CloseDomesticShippingDayResponse reponse = client.CloseDomesticShippingDay(request);

            domesticEndOfDayDic.Add("IsSuccessful", reponse.Successful);
            domesticEndOfDayDic.Add("ErrorMessages", reponse.ErrorMessages);
            domesticEndOfDayDic.Add("Manifest", reponse.Manifest);
            domesticEndOfDayDic.Add("BatchNumber", reponse.BatchNumber);
            domesticEndOfDayDic.Add("BOLDataPDF", reponse.BOLDataPDF);
            domesticEndOfDayDic.Add("ManifestedLabelCount", reponse.ManifestedLabelCount);
            domesticEndOfDayDic.Add("TrackingNumbers", reponse.TrackingNumbers);
            domesticEndOfDayDic.Add("MultipleManifestDetails", reponse.MultipleManifestDetails);

            if (reponse.ErrorMessages != null)
            {
                return(domesticEndOfDayDic);
            }
            else
            {
                File.WriteAllBytes(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\DomesticBOL.pdf", reponse.BOLDataPDF);
                return(null);
            }
        }
Ejemplo n.º 2
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);
        }
        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);
        }