private TrackResult Sendle_Track(CarrierAPI api, string trackingNumber) { TrackResult result = new TrackResult(); Sendle_API Sendle = new Sendle_API(api); Sendle_API.TrackResponse Sendle_Result = Sendle.Track(trackingNumber); if (Sendle_Result.tracking_events.Any()) { if (Sendle_Result.tracking_events.Any(e => e.event_type == "Pickup")) { result.PickupDate = Sendle_Result.tracking_events.First(e => e.event_type == "Pickup").scan_time; result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Intransit; } if (Sendle_Result.tracking_events.Any(e => e.event_type == "Delivered")) { result.DeliveryDate = Sendle_Result.tracking_events.First(e => e.event_type == "Delivered").scan_time; result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Delivered; } result.DeliveryNote = Sendle_Result.tracking_events.Select(e => e.scan_time.ToString() + " " + e.description).Last(); } return(result); }
public FedEx_API(CarrierAPI Api) { api_key = Api.ApiKey; api_password = Api.ApiPassword; api_accountNumber = Api.ApiAccount; api_meterNumber = Api.ApiMeter; }
private TrackResult FedEx_Track(CarrierAPI api, string trackingNumber) { TrackResult result = new TrackResult(); FedEx_API FedEx = new FedEx_API(api); TrackReply FedEx_Result = FedEx.Tracking(trackingNumber); if (FedEx_Result.HighestSeverity != NotificationSeverityType.SUCCESS) { throw new Exception(string.Join(";", FedEx_Result.Notifications.Select(n => n.Message).ToArray())); } TrackDetail detail = FedEx_Result.CompletedTrackDetails[0].TrackDetails[0]; if (detail.Events != null) { List <TrackEvent> FedEx_EventList = detail.Events.ToList(); if (FedEx_EventList.Any(e => e.EventType == "PU")) { result.PickupDate = FedEx_EventList.First(e => e.EventType == "PU").Timestamp.ToUniversalTime(); result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Intransit; } result.DeliveryNote = FedEx_EventList.Select(e => e.Timestamp.ToString() + " " + e.EventDescription).First(); if (FedEx_EventList.Any(e => e.EventType == "DL")) { result.DeliveryDate = FedEx_EventList.First(e => e.EventType == "DL").Timestamp.ToUniversalTime(); result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Delivered; } } return(result); }
public void Track_Test(int OrderID) { var package = db.Packages.First(p => p.OrderID.Value.Equals(OrderID)); CarrierAPI api = package.Method.Carriers.CarrierAPI; TrackOrder track = new TrackOrder(package); var result = track.Track(package.TrackingNumber); }
public ActionResult Apicreate(CarrierAPI newApi) { Postmen postmen = new Postmen(newApi.IsTest ? "sandbox" : "production"); CarrierAPI.Create(newApi); CarrierAPI.SaveChanges(); MyHelp.Log("CarrierAPI", null, "新增連線API"); return(RedirectToAction("api", "shipping")); }
public ActionResult Apidelete(int id, [Bind(Include = "start,length,search")] RouteValue routeValue) { CarrierAPI api = CarrierAPI.Get(id); if (api == null) { return(HttpNotFound()); } api.IsEnable = false; CarrierAPI.Update(api); CarrierAPI.SaveChanges(); MyHelp.Log("CarrierAPI", api.Id, "刪除連線API"); return(RedirectToAction("api", "shipping", routeValue)); }
public ActionResult Apiedit(int?id, [Bind(Include = "start,length,search")] RouteValue routeValue) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CarrierAPI api = CarrierAPI.Get(id.Value); if (api == null) { return(HttpNotFound()); } ViewBag.routeValue = routeValue; return(View(api)); }
public IDS_API(CarrierAPI Api) { if (Api == null) { Api = new CarrierAPI() { IsTest = false, ApiAccount = "TW018", ApiPassword = "******" }; } ApiUsername = Api.ApiAccount; ApiPassword = Api.ApiPassword; Endpoint = Api.IsTest ? TestUrl : ProductUrl; //Endpoint = TestUrl; }
public Winit_API(CarrierAPI Api) { db = new QDLogisticsEntities(); if (Api == null) { Api = db.CarrierAPI.AsNoTracking().FirstOrDefault(api => api.Id.Equals(17)); if (Api == null) { throw new Exception("Carrier Api not found!"); } } api_url = string.Format("http://{0}.winit.com.cn/ADInterface/api", Api.IsTest ? "erp.sandbox" : "api"); api_key = Api.ApiKey; api_userName = Api.ApiAccount; api_password = Api.ApiPassword; api_token = _Get_Token(); }
public ActionResult Apiedit(int id, [Bind(Include = "start,length,search")] RouteValue routeValue) { CarrierAPI api = CarrierAPI.Get(id); if (api == null) { return(HttpNotFound()); } if (TryUpdateModel(api) && ModelState.IsValid) { CarrierAPI.SaveChanges(); MyHelp.Log("CarrierAPI", api.Id, "編輯連線API"); return(RedirectToAction("api", "shipping", routeValue)); } ViewBag.routeValue = routeValue; return(View(api)); }
public TrackResult Winit_Track(CarrierAPI api, string trackingNum) { TrackResult result = new TrackResult(); if (string.IsNullOrEmpty(trackingNum)) { return(result); } Winit_API winit = new Winit_API(); OrderTrack track = winit.GetOrderTrack(trackingNum); if (winit.ResultError != null) { throw new Exception(winit.ResultError.msg); } if (track != null) { var Winit_EventList = track.trace.ToList(); if (Winit_EventList.Any(e => e.eventCode == "DIC")) { result.PickupDate = Winit_EventList.FirstOrDefault(e => e.eventCode == "DIC")?.date; result.DeliveryStatus = (int)DeliveryStatusType.Intransit; } result.DeliveryNote = Winit_EventList.OrderBy(e => e.date).Select(e => e.date + " " + e.eventDescription).Last(); if (Winit_EventList.Any(e => e.eventCode == "DLC")) { result.DeliveryDate = Winit_EventList.FirstOrDefault(e => e.eventCode == "DLC")?.date; result.DeliveryStatus = (int)DeliveryStatusType.Delivered; } } return(result); }
private TrackResult DHL_Track(CarrierAPI api, string trackingNumber) { TrackResult result = new TrackResult(); DHL_API DHL = new DHL_API(api); TrackingResponse DHL_Result = DHL.Tracking(trackingNumber); TimeZoneConvert timeZone = new TimeZoneConvert(); if (DHL_Result != null && DHL_Result.AWBInfo.Any(awb => awb.ShipmentInfo != null && !string.IsNullOrEmpty(awb.ShipmentInfo.ConsigneeName))) { List <ShipmentEvent> DHL_EventList = DHL_Result.AWBInfo.First(awb => awb.ShipmentInfo != null && !string.IsNullOrEmpty(awb.ShipmentInfo.ConsigneeName)).ShipmentInfo.Items.Skip(1).Cast <ShipmentEvent>().ToList(); if (DHL_EventList.Any()) { if (DHL_EventList.Any(e => e.ServiceEvent.EventCode == "PU")) { result.PickupDate = DHL_EventList.Where(e => e.ServiceEvent.EventCode == "PU").Select(e => timeZone.InitDateTime(e.Date.Add(e.Time.TimeOfDay), EnumData.TimeZone.TST).Utc).First(); result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Intransit; } result.DeliveryNote = DHL_EventList.Select(e => timeZone.InitDateTime(e.Date.Add(e.Time.TimeOfDay), EnumData.TimeZone.TST).Utc.ToString() + " " + e.ServiceEvent.Description).Last(); if (DHL_EventList.Any(e => e.ServiceEvent.EventCode == "OK")) { result.DeliveryDate = DHL_EventList.Where(e => e.ServiceEvent.EventCode == "OK").Select(e => timeZone.InitDateTime(e.Date.Add(e.Time.TimeOfDay), EnumData.TimeZone.TST).Utc).First(); result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Delivered; } } } else { result.DeliveryNote = DHL_Result.AWBInfo.First().Status.ActionStatus; //result.DeliveryStatus = (int)OrderService.DeliveryStatusType.Delivered; } return(result); }
public TrackResult Track(Box box, CarrierAPI api) { TrackResult result = new TrackResult(); try { switch (api.Type) { case (byte)EnumData.CarrierType.DHL: result = DHL_Track(api, box.TrackingNumber); break; case (byte)EnumData.CarrierType.FedEx: result = FedEx_Track(api, box.TrackingNumber); break; } } catch (Exception e) { throw new Exception(box.BoxID + " - " + e.Message); } return(result); }
private void FedEx_Test(string BoxID) { var boxList = db.Box.Where(b => b.IsEnable && b.MainBox.Equals(BoxID)).ToList(); ShippingMethod method = db.ShippingMethod.Find(boxList.First().FirstMileMethod); DirectLine directLine = db.DirectLine.Find(boxList.First().DirectLine); CarrierAPI api = method.Carriers.CarrierAPI; FedEx_API FedEx = new FedEx_API(api); var result = FedEx.CreateBox(boxList, method, directLine); if (result.HighestSeverity.Equals(FedExShipService.NotificationSeverityType.SUCCESS)) { var Data = result.CompletedShipmentDetail.CompletedPackageDetails.First(); string TrackingNumber = Data.TrackingIds.First().TrackingNumber; //System.IO.File.WriteAllBytes(@"G:\Downloads\FedEx_Test3.pdf", Crop(Data.Label.Parts.First().Image, 29f, 324f, 319f, 762f)); //System.IO.File.WriteAllBytes(@"G:\Downloads\FedEx_Test4.pdf", Data.Label.Parts.First().Image); var zpl = Data.Label.Parts.First().Image; string str = Encoding.ASCII.GetString(zpl); var request = (HttpWebRequest)WebRequest.Create("http://api.labelary.com/v1/printers/8dpmm/labels/4x6.75/"); request.Method = "POST"; request.Accept = "application/pdf"; // omit this line to get PNG images back request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = zpl.Length; var requestStream = request.GetRequestStream(); requestStream.Write(zpl, 0, zpl.Length); requestStream.Close(); try { var response = (HttpWebResponse)request.GetResponse(); var responseStream = response.GetResponseStream(); var fileStream = System.IO.File.Create(@"G:\Downloads\FedEx_Test5.pdf"); // change file name for PNG images responseStream.CopyTo(fileStream); responseStream.Close(); fileStream.Close(); } catch (WebException e) { Console.WriteLine("Error: {0}", e.Status); } } iTextSharp.text.pdf.PdfReader.unethicalreading = true; // Reads the PDF document using (iTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(@"G:\Downloads\FedEx_Test5.pdf")) { using (MemoryStream ms = new MemoryStream()) { // Create a new document //using (iTextSharp.text.Document doc = // new iTextSharp.text.Document(new iTextSharp.text.Rectangle(288f,432f))) using (iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4)) { // Make a copy of the document iTextSharp.text.pdf.PdfSmartCopy smartCopy = new iTextSharp.text.pdf.PdfSmartCopy(doc, ms) { PdfVersion = iTextSharp.text.pdf.PdfWriter.VERSION_1_7 }; smartCopy.CloseStream = false; // Open the newly created document doc.Open(); // Loop through all pages of the source document for (int i = pdfReader.NumberOfPages; i >= 1; i--) { doc.NewPage();// net necessary line // Get a page var page = pdfReader.GetPageN(i); // Copy the content and insert into the new document var copiedPage = smartCopy.GetImportedPage(pdfReader, i); smartCopy.AddPage(copiedPage); if (i.Equals(1)) { doc.NewPage(); smartCopy.AddPage(copiedPage); } } smartCopy.FreeReader(pdfReader); smartCopy.Close(); ms.Position = 0; System.IO.File.WriteAllBytes(@"G:\Downloads\FedEx_Test6.pdf", ms.GetBuffer()); // Close the output document doc.Close(); } } } }
public DHL_API(CarrierAPI Api) { api_siteID = Api.ApiKey; api_password = Api.ApiPassword; api_account = Api.ApiAccount; }
public Sendle_API(CarrierAPI Api) { Endpoint = Api.IsTest ? Sendbox_Server : Product_Server; Sendle_ID = Api.ApiAccount; Api_Key = Api.ApiKey; }