public virtual IEnumerable createAP(PXAdapter adapter) { UploadFileRevision file = PXSelectJoin <UploadFileRevision, InnerJoin <UploadFile, On <UploadFileRevision.fileID, Equal <UploadFile.fileID>, And <UploadFileRevision.fileRevisionID, Equal <UploadFile.lastRevisionID> > >, InnerJoin <NoteDoc, On <NoteDoc.fileID, Equal <UploadFile.fileID> > > >, Where <NoteDoc.noteID, Equal <Required <CRSMEmail.noteID> >, And <UploadFile.name, Like <pdfExtension> > >, OrderBy <Desc <UploadFileRevision.createdDateTime> > > .Select(Base, Base.Emails.Current.NoteID); string url = null; if (file != null) { string rooturl; if (HttpContext.Current == null) { rooturl = string.Empty; } var applicationpath = string.IsNullOrEmpty(HttpContext.Current.Request.ApplicationPath) ? string.Empty : HttpContext.Current.Request.ApplicationPath + "/"; rooturl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + applicationpath; url = string.Concat(rooturl != null ? rooturl : string.Empty, HandlerURL, file.FileID.GetValueOrDefault(Guid.Empty).ToString("D")); CRSMEmail email = Base.Emails.Current; APInvoiceEntryPXInhExt graph = PXGraph.CreateInstance <APInvoiceEntryPXInhExt>(); graph.Clear(); APInvoice doc = (APInvoice)graph.Document.Cache.CreateInstance(); doc.GetExtension <APInvoiceExt>().UsrFileURL = url; doc.LineCntr = 0; TryFillValuesFromPDF(graph.Document.Cache, doc, Base.Emails.Cache, email); doc = graph.Document.Insert(doc); (email).Selected = false; CRSMEmail copy = PXCache <CRSMEmail> .CreateCopy(email); CRActivity newActivity = (CRActivity)graph.Caches[typeof(CRActivity)].Insert(); copy.BAccountID = newActivity.BAccountID; copy.ContactID = newActivity.ContactID; copy.RefNoteID = newActivity.RefNoteID; copy.MPStatus = MailStatusListAttribute.Processed; copy.Exception = null; PXRefNoteSelectorAttribute.EnsureNotePersistence(Base, Base.entityFilter.Current.Type, Base.entityFilter.Current.RefNoteID); copy = Base.Emails.Update(copy); Base.Save.Press(); PXNoteAttribute.CopyNoteAndFiles(Base.Emails.Cache, Base.Emails.Current, graph.Document.Cache, doc); PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow); } return(adapter.Get()); }
private string ReadTemplateAttachments(SMEmail message) { if (message.Body != null && message.Body.IndexOf("embedded=\"true\"") > -1) { Regex _tempimagesRegex = new Regex("(<(img data-convert=\"view\")[^<>]*(src=\"([^\"]*)\" ([^<>]*)>))"); Regex _tempimagesRegex2 = new Regex("(<img[^<>]*src=(\"[^<>]*GetFile.*;file=([^\"]*)\") ([^<>]*)>)"); List <string> changeimage = new List <string>(); List <int> start = new List <int>(); List <int> length = new List <int>(); foreach (Match match in _tempimagesRegex.Matches(message.Body)) { if (match.Groups[4].Value != null && match.Groups[1].Value.IndexOf("embedded=\"true\"") > -1) { foreach (var result in PXSelectJoin <UploadFile, InnerJoin <UploadFileRevision, On <UploadFile.fileID, Equal <UploadFileRevision.fileID>, And <UploadFile.lastRevisionID, Equal <UploadFileRevision.fileRevisionID> > > >, Where <UploadFile.name, Equal <Required <UploadFile.name> > > > . SelectWindowed(new PXGraph(), 0, 1, HttpUtility.UrlDecode(match.Groups[4].Value))) { UploadFileRevision filedata = result[typeof(UploadFileRevision)] as UploadFileRevision; if (filedata != null) { string tempchangeimage = "<img title=\"\" src=\"data:image/jpeg;base64," + Convert.ToBase64String(filedata.Data) + "\">"; message.Body = message.Body.Replace(match.Groups[1].Value, tempchangeimage); } } } } foreach (Match match in _tempimagesRegex2.Matches(message.Body)) { if (match.Groups[3].Value != null && match.Groups[1].Value.IndexOf("embedded=\"true\"") > -1) { foreach (var result in PXSelectJoin <UploadFile, InnerJoin <UploadFileRevision, On <UploadFile.fileID, Equal <UploadFileRevision.fileID>, And <UploadFile.lastRevisionID, Equal <UploadFileRevision.fileRevisionID> > > >, Where <UploadFile.name, Equal <Required <UploadFile.name> > > > . SelectWindowed(new PXGraph(), 0, 1, HttpUtility.UrlDecode(match.Groups[3].Value))) { UploadFileRevision filedata = result[typeof(UploadFileRevision)] as UploadFileRevision; if (filedata != null) { string tempchangeimage = "<img title=\"\" src=\"data:image/jpeg;base64," + Convert.ToBase64String(filedata.Data) + "\">"; message.Body = message.Body.Replace(match.Groups[1].Value, tempchangeimage); } } } } } return(null); }
public void ShipPackages(SOShipment shiporder, ShipPackagesBaseDelegate BaseInvoke) { #region Custom-code-to-rotate-retrieved-Label PXGraph.InstanceCreated.AddHandler <UploadFileMaintenance>((fileGraph) => { fileGraph.RowInserted.AddHandler <UploadFileRevision>((sender, e) => { UploadFileRevision fileData = (UploadFileRevision)e.Row; }); }); #endregion //Invoke base method BaseInvoke(shiporder); }
public void ShipPackages(SOShipment shiporder, ShipPackagesBaseDelegate BaseInvoke) { #region Custom-code-to-rotate-retrieved-Label //Identify specified Ship-Via/Carrier Shipment is working with var carrier = Carrier.PK.Find(Base, shiporder.ShipVia); //If specified Ship-Via/Carrier is API/Plug-In based if (carrier?.IsExternal == true) { //Identify Connected Carrier Plug-In var plugin = CarrierPlugin.PK.Find(Base, carrier.CarrierPluginID); //If Plug-In is working with UPS if (plugin?.PluginTypeName?.Trim() == typeof(PX.UpsCarrier.UpsCarrier).FullName) { PXGraph.InstanceCreated.AddHandler <UploadFileMaintenance>((fileGraph) => { fileGraph.RowInserted.AddHandler <UploadFileRevision>((sender, e) => { UploadFile fileInfo = (UploadFile)sender.Graph.Caches <UploadFile>()?.Current; if (fileInfo != null) { if (fileInfo.Name.StartsWith("Label #") && (fileInfo.Extansion.ToUpper() == "GIF")) { UploadFileRevision fileData = (UploadFileRevision)e.Row; using (MemoryStream fileMemoryStream = new MemoryStream(fileData?.Data)) { Image labelImage = Image.FromStream(fileMemoryStream); if (labelImage != null) { labelImage.RotateFlip(RotateFlipType.Rotate90FlipNone); ImageConverter imgConverter = new ImageConverter(); fileData.Data = (byte[])imgConverter.ConvertTo(labelImage, typeof(byte[])); } } } } }); }); } } #endregion //Invoke base method BaseInvoke(shiporder); }