コード例 #1
0
    protected void exportAttachmnts()
    {
        var order = Base.Document.Current;

        PXLongOperation.StartOperation(Base, () =>
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (PX.Common.ZipArchive archive = PX.Common.ZipArchive.CreateFrom(stream, false))
                {
                    UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                    Guid[] uids = PXNoteAttribute.GetFileNotes(Base.Document.Cache, order);
                    foreach (Guid uid in uids)
                    {
                        PX.SM.FileInfo fileInfo = upload.GetFile(uid);
                        archive.AddFile(fileInfo.Name, fileInfo.BinData);
                    }
                }
                PX.SM.FileInfo info = new PX.SM.FileInfo(
                    string.Format("{0}-{1}-Attachmets.zip", order.OrderType, order.OrderNbr),
                    null, stream.ToArray());
                throw new PXRedirectToFileException(info, true);
            }
        });
    }
コード例 #2
0
    private void AttachUploadedFile()
    {
        UploadFileMaintenance filesAccessor = PXGraph.CreateInstance <UploadFileMaintenance>();

        if (Uploader.UploadedFile != null && Uploader.UploadedFile.UID != null &&
            !string.IsNullOrEmpty(PXSiteMap.CurrentScreenID))
        {
            filesAccessor.AttachToScreen(Uploader.UploadedFile.UID.Value, PXSiteMap.CurrentScreenID);
        }
    }
コード例 #3
0
ファイル: ShowPage.cs プロジェクト: blanks88/AcumaticaT100
    private void editor_FileUploaded(object sender, PXFileUploadEventArgs e)
    {
        WikiPage current = this.CurrentRec;

        if (current != null)
        {
            FileInfo file = e.UploadedFile;
            if (file != null)
            {
                UploadFileMaintenance uploadGraph = PXGraph.CreateInstance <UploadFileMaintenance>();
                uploadGraph.AttachToPage((Guid)file.UID, (Guid)current.PageID);
            }
        }
    }
コード例 #4
0
    protected void editor_FileUploaded(object sender, PXFileUploadEventArgs e)
    {
        WikiPage current = (WikiPage)ds.DataGraph.Caches[typeof(WikiPage)].Current;

        if (current != null)
        {
            FileInfo file = e.UploadedFile;
            if (file != null && file.UID != null)
            {
                UploadFileMaintenance uploadGraph = PXGraph.CreateInstance <UploadFileMaintenance>();
                uploadGraph.AttachToPage((Guid)file.UID, (Guid)current.PageID);
            }
        }
    }
コード例 #5
0
        private void PrepareCertificationData(CarrierPlugin cp)
        {
            ICarrierService plugin = CreateCarrierService(this, cp);

            if (plugin != null)
            {
                UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                CarrierResult <IList <CarrierCertificationData> > result = plugin.GetCertificationData();

                if (result != null)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (Message message in result.Messages)
                    {
                        sb.AppendFormat("{0}:{1} ", message.Code, message.Description);
                    }

                    if (result.IsSuccess)
                    {
                        CarrierPlugin copy = (CarrierPlugin)Plugin.Cache.CreateCopy(cp);

                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            ZipArchive zip = new ZipArchive(ms, false);

                            foreach (CarrierCertificationData d in result.Result)
                            {
                                using (System.IO.Stream zipStream = zip.OpenWrite(string.Format("{0}.{1}", d.Description, d.Format)))
                                {
                                    zipStream.Write(d.File, 0, d.File.Length);
                                }
                            }

                            FileInfo file = new FileInfo("CertificationData.zip", null, ms.ToArray());
                            upload.SaveFile(file, FileExistsAction.CreateVersion);
                            PXNoteAttribute.SetFileNotes(Plugin.Cache, copy, file.UID.Value);
                        }

                        Plugin.Update(copy);

                        this.Save.Press();
                    }
                    else
                    {
                        throw new PXException(SO.Messages.CarrierServiceError, sb.ToString());
                    }
                }
            }
        }
コード例 #6
0
ファイル: SOShipmentEntry.cs プロジェクト: JeffJave/Ipevo
        protected virtual IEnumerable LumGenerate3PLUKFile(PXAdapter adapter)
        {
            try
            {
                SOShipment soShipment = adapter.Get <SOShipment>()?.FirstOrDefault();
                // Get Csv String Builder
                var result = CombineCSV(soShipment, "P3PL");
                // Upload Graph
                UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                // Create SM.FileInfo
                var      fileName = $"{result.OrderNbr}.csv";
                var      data     = new UTF8Encoding(true).GetBytes(result.csvText.ToString());
                FileInfo fi       = new FileInfo(fileName, null, data);
                // Upload file to FTP
                #region 3PL UK FTP
                var configYusen = SelectFrom <LUM3PLUKSetup> .View.Select(Base).RowCast <LUM3PLUKSetup>().FirstOrDefault();

                FTP_Config config = new FTP_Config()
                {
                    FtpHost = configYusen.FtpHost,
                    FtpUser = configYusen.FtpUser,
                    FtpPass = configYusen.FtpPass,
                    FtpPort = configYusen.FtpPort,
                    FtpPath = configYusen.FtpPath
                };

                var ftpResult = UploadFileByFTP(config, fileName, data);
                //var ftpResult = true;
                if (!ftpResult)
                {
                    throw new Exception("Ftp Upload Fail!!");
                }
                #endregion

                // Upload file to Attachment
                upload.SaveFile(fi);
                PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, fi.UID.Value);
                Base.Document.Current.GetExtension <SOShipmentExt>().UsrSendToWareHouse = true;
                Base.Document.UpdateCurrent();
                Base.Save.Press();
            }
            catch (Exception ex)
            {
                PXProcessing.SetError(ex.Message);
            }

            return(adapter.Get());
        }
コード例 #7
0
    //---------------------------------------------------------------------------
    /// <summary>
    ///
    /// </summary>
    private PXToolBarButton GetAttachedFiles()
    {
        PXToolBarButton btn = Button(_TOOLBAR_FILES);
        string          url = Page.AppRelativeVirtualPath;

        btn.MenuItems.Clear();
        if (string.IsNullOrEmpty(url))
        {
            btn.Visible = false;
            return(btn);
        }

        UploadFileMaintenance filesAccessor = PXGraph.CreateInstance <UploadFileMaintenance>();

        foreach (string filename in filesAccessor.GetFileNamesAttachedToScreen(PXSiteMap.CurrentScreenID))
        {
            PXMenuItem item = new PXMenuItem(FileInfo.GetShortName(filename));
            item.NavigateUrl    = ResolveUrl("~/Frames/GetFile.ashx") + "?file=" + HttpUtility.UrlEncode(filename);
            item.Target         = "_blank";
            item.RenderLink     = false;
            item.Style.CssClass = "MenuItem";
            item.Value          = ResolveUrl("~/Pages/SM/SM202510.aspx") + "?fileID=" + HttpUtility.UrlEncode(filename);
            btn.MenuItems.Add(item);
        }

        PXMenuItem mi = new PXMenuItem("Attach file...");

        mi.ShowSeparator = true;
        mi.PopupPanel    = "Uploader";
        mi.Value         = "notfilelink";
        btn.MenuItems.Add(mi);


        String[] importScenarios = PX.Api.SYImportMaint.GetAvailableMappings(this.ScreenID);
        String[] exportScenarios = PX.Api.SYExportMaint.GetAvailableMappings(this.ScreenID);
        if (importScenarios.Length > 0)
        {
            mi             = new PXMenuItem("Import Scenarios");
            mi.NavigateUrl = "~/pages/sm/SM206036.aspx";
            foreach (String scenario in importScenarios)
            {
                PXMenuItem submi = new PXMenuItem(scenario);
                submi.NavigateUrl = ResolveUrl("~/Main.aspx?ScreenId=SM206036&Name=") + HttpUtility.UrlEncode(scenario);
                submi.Target      = "_blank";
                submi.RenderLink  = false;
                mi.ChildItems.Add(submi);
            }
            if (exportScenarios.Length <= 0)
            {
                mi.ShowSeparator = true;
            }
            btn.MenuItems.Add(mi);
        }
        if (exportScenarios.Length > 0)
        {
            mi             = new PXMenuItem("Export Scenarios");
            mi.NavigateUrl = "~/pages/sm/SM207036.aspx";
            foreach (String scenario in exportScenarios)
            {
                PXMenuItem submi = new PXMenuItem(scenario);
                submi.NavigateUrl = ResolveUrl("~/Main.aspx?ScreenId=SM207036&Name=") + HttpUtility.UrlEncode(scenario);
                submi.Target      = "_blank";
                submi.RenderLink  = false;
                mi.ChildItems.Add(submi);
            }
            mi.ShowSeparator = true;
            btn.MenuItems.Add(mi);
        }

        if (!this.Page.IsCallback)
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "filesMenuIndex", "var __filesMenuIndex=" + tlbTools.Items.IndexOf(Button(_TOOLBAR_FILES)).ToString() + ";", true);
        }
        return(btn);
    }
コード例 #8
0
ファイル: SOShipmentEntry.cs プロジェクト: JeffJave/Ipevo
        protected virtual IEnumerable PrintFedexLabel(PXAdapter adapter)
        {
            var shiporder = Base.Document.Current;
            var carrier   = Carrier.PK.Find(Base, shiporder.ShipVia);

            if (!UseCarrierService(shiporder, carrier))
            {
                return(adapter.Get());
            }

            if (shiporder.ShippedViaCarrier != true)
            {
                // Build Fedex Request object
                ICarrierService cs            = CarrierMaint.CreateCarrierService(Base, shiporder.ShipVia);
                CarrierRequest  cr            = Base.CarrierRatesExt.BuildRequest(shiporder);
                var             warehouseInfo = SelectFrom <INSite> .Where <INSite.siteID.IsEqual <P.AsInt> > .View
                                                .Select(Base, shiporder.SiteID).RowCast <INSite>().FirstOrDefault();

                // Replace ShipTo Info to DCL warehouse
                Address warehouseAddress = PXSelect <Address, Where <Address.addressID, Equal <Required <Address.addressID> > > > .Select(Base, warehouseInfo?.AddressID);

                Contact warehouseContact = PXSelect <Contact, Where <Contact.contactID, Equal <Required <Contact.contactID> > > > .Select(Base, warehouseInfo?.ContactID);

                cr.Destination        = warehouseAddress;
                cr.DestinationContact = warehouseContact;

                if (cr.Packages.Count > 0)
                {
                    // Get Fedex web service data
                    CarrierResult <ShipResult> result = cs.Ship(cr);

                    if (result != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (Message message in result.Messages)
                        {
                            sb.AppendFormat("{0}:{1} ", message.Code, message.Description);
                        }

                        if (result.IsSuccess)
                        {
                            using (PXTransactionScope ts = new PXTransactionScope())
                            {
                                UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();

                                foreach (PackageData pd in result.Result.Data)
                                {
                                    if (pd.Image != null)
                                    {
                                        string   fileName = string.Format("Label #{0}.{1}", pd.TrackingNumber, pd.Format);
                                        FileInfo file     = new FileInfo(fileName, null, pd.Image);
                                        try
                                        {
                                            upload.SaveFile(file);
                                        }
                                        catch (PXNotSupportedFileTypeException exc)
                                        {
                                            throw new PXException(exc, Messages.NotSupportedFileTypeFromCarrier, pd.Format);
                                        }
                                        PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, file.UID.Value);
                                    }
                                    Base.Document.UpdateCurrent();
                                }

                                Base.Save.Press();
                                ts.Complete();
                            }
                            //show warnings:
                            if (result.Messages.Count > 0)
                            {
                                Base.Document.Cache.RaiseExceptionHandling <SOShipment.curyFreightCost>(shiporder, shiporder.CuryFreightCost,
                                                                                                        new PXSetPropertyException(sb.ToString(), PXErrorLevel.Warning));
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(result.RequestData))
                            {
                                PXTrace.WriteError(result.RequestData);
                            }

                            Base.Document.Cache.RaiseExceptionHandling <SOShipment.curyFreightCost>(shiporder, shiporder.CuryFreightCost,
                                                                                                    new PXSetPropertyException(Messages.CarrierServiceError, PXErrorLevel.Error, sb.ToString()));

                            throw new PXException(Messages.CarrierServiceError, sb.ToString());
                        }
                    }
                }
            }

            return(adapter.Get());
        }
コード例 #9
0
        public static void TransferDocProcessingCenter(PXGraph graph, CABatch doc, CABatchExt docExt)
        {
            var pcGraph = PXGraph.CreateInstance <CCProcessingCenterMaint>();

            pcGraph.ProcessingCenter.Current = pcGraph.
                                               ProcessingCenter.
                                               Search <CCProcessingCenter.processingCenterID>
                                                   (docExt.ProcessingCenterID);

            var processingCenter = pcGraph.ProcessingCenter.Current;

            if (processingCenter != null)
            {
                var providerIsDirectDeposit = PXMultipleProviderTypeSelectorAttribute.IsProvider <CCProcessingCenter.processingTypeName, IDDPaymentProcessing>(pcGraph.ProcessingCenter.Cache, processingCenter);
                if (providerIsDirectDeposit)
                {
                    IDDPaymentProcessing provider = null;
                    try
                    {
                        Type providerType = PXBuildManager.GetType(processingCenter.ProcessingTypeName, true);
                        provider = (IDDPaymentProcessing)Activator.CreateInstance(providerType);
                        provider.Initialize(pcGraph);
                    }
                    catch (Exception ex)
                    {
                        throw new PXException(Messages.FailedToCreateDirectDepositProvider, ex.Message);
                    }
                    var fileNotes = PXNoteAttribute.GetFileNotes(graph.Views[graph.PrimaryView].Cache, doc);
                    if (fileNotes.Length == 1)
                    {
                        var fileNote = fileNotes[0];
                        UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                        var    file = upload.GetFile(fileNote);
                        string message;
                        if (!provider.DoTransaction(file.FullName, file.BinData, out message))
                        {
                            throw new PXException(message);
                        }
                        else
                        {
                            docExt.FileTransferTime = DateTime.Now;
                            graph.Views[graph.PrimaryView].Cache.Update(doc);
                            graph.Actions.PressSave();
                        }
                    }
                    else
                    {
                        if (fileNotes.Length > 1)
                        {
                            throw new Exception(Messages.ACHTransferFailMoreThanOneAttachment);
                        }
                        else
                        {
                            throw new PXException(Messages.ACHTransferFailNoAttachment);
                        }
                    }
                }
                else
                {
                    throw new PXException(Messages.ACHTransferFailProviderIsNotForDirectDeposit);
                }
            }
            else
            {
                throw new PXException(Messages.ACHTransferFailNoProcessingCenterSelected);
            }
        }
コード例 #10
0
        public override void Persist()
        {
            // Current Data
            var _currData = (LumItemsCOC)_viewLine.Cache.Current;
            // Create Upload Image Graph
            UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
            // Html to Image and Upload to Server
            Action <string, string> htmlToImage = (_html, _fileName) =>
            {
                HtmlDocument _doc = new HtmlDocument();
                _doc.LoadHtml(_html);
                if (string.IsNullOrEmpty(_doc.DocumentNode.InnerText))
                {
                    return;
                }
                var      htmlNode = _doc.DocumentNode.SelectSingleNode("//html");
                HtmlNode newNode  = HtmlNode.CreateNode(@"<meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" />");
                htmlNode.InsertBefore(newNode, htmlNode.ChildNodes[0]);
                var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter();
                var jpegBytes       = htmlToImageConv.GenerateImage(_doc.DocumentNode.OuterHtml, NReco.ImageGenerator.ImageFormat.Jpeg);

                FileInfo file = new FileInfo($"{_fileName}.jpeg", null, jpegBytes);
                upload.SaveFile(file, FileExistsAction.CreateVersion);

                //To Attach file to Entity
                PXNoteAttribute.SetFileNotes(_viewLine.Cache, _viewLine.Cache.Current, file.UID.Value);
            };

            // Process All Tab


            #region MaterialProductDesc

            if (!CheckInnerTextIsEmpty(_currData.MaterialProductDesc))
            {
                htmlToImage(_currData.MaterialProductDesc, $"COC_{_currData.InventoryID}_MaterialProductDesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.materialProductDesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            #region MaterialProductDesc2
            if (!CheckInnerTextIsEmpty(_currData.MaterialProductDesc2))
            {
                htmlToImage(_currData.MaterialProductDesc2, $"COC_{_currData.InventoryID}_MaterialProductDesc2");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.materialProductDesc2>(_viewLine.Cache.Current, null);
            }
            #endregion ;

            #region COCProductDesc
            if (!CheckInnerTextIsEmpty(_currData.COCProductDesc))
            {
                htmlToImage(_currData.COCProductDesc, $"COC_{_currData.InventoryID}_COCProductDesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.cOCProductDesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            #region TESTProductDesc

            if (!CheckInnerTextIsEmpty(_currData.TESTProductDesc))
            {
                htmlToImage(_currData.TESTProductDesc, $"COC_{_currData.InventoryID}_TESTProductDesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.tESTProductDesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            #region REROHSProductDesc

            if (!CheckInnerTextIsEmpty(_currData.REROHSProductDesc))
            {
                htmlToImage(_currData.REROHSProductDesc, $"COC_{_currData.InventoryID}_REROHSProductDesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.rEROHSProductDesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            #region REACHProductDesc
            if (!CheckInnerTextIsEmpty(_currData.REACHProductDesc))
            {
                htmlToImage(_currData.REACHProductDesc, $"COC_{_currData.InventoryID}_REACHProductDesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.rEACHProductDesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            #region REACHProductDesc2
            if (!CheckInnerTextIsEmpty(_currData.REACHProductDesc2))
            {
                htmlToImage(_currData.REACHProductDesc2, $"COC_{_currData.InventoryID}_REACHProductDesc2");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.rEACHProductDesc2>(_viewLine.Cache.Current, null);
            }

            #endregion

            #region Compliantproductdesc
            if (!CheckInnerTextIsEmpty(_currData.Compliantproductdesc))
            {
                htmlToImage(_currData.Compliantproductdesc, $"COC_{_currData.InventoryID}_Compliantproductdesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.compliantproductdesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            #region QCProductDesc
            if (!CheckInnerTextIsEmpty(_currData.QCProductDesc))
            {
                htmlToImage(_currData.QCProductDesc, $"COC_{_currData.InventoryID}_QCProductDesc");
            }
            else
            {
                _viewLine.Cache.SetValue <LumItemsCOC.qCProductDesc>(_viewLine.Cache.Current, null);
            }
            #endregion

            base.Persist();
        }
コード例 #11
0
        public void RefreshRecordFileList(string screenID, string folderName, string folderID, Guid?refNoteID, bool isForcingSync)
        {
            var tokenHandler = PXGraph.CreateInstance <UserTokenHandler>();

            //Get list of files contained in the record folder. RecurseDepth=0 will retrieve all subfolders
            List <BoxUtils.FileFolderInfo> boxFileList = BoxUtils.GetFileList(tokenHandler, folderID, (int)BoxUtils.RecursiveDepth.Unlimited).Result;

            // Remove files from cache if they don't exist on Box server
            foreach (PXResult <BoxFileCache, UploadFileRevisionNoData, UploadFile, NoteDoc> result in FilesByNoteID.Select(refNoteID))
            {
                BoxUtils.FileFolderInfo boxFile = boxFileList.FirstOrDefault(f => f.ID == ((BoxFileCache)result).FileID);
                if (boxFile == null)
                {
                    //File was deleted
                    FilesByNoteID.Delete(result);
                    UploadFiles.Delete(result);
                    UploadFileRevisions.Delete(result);
                    NoteDocs.Delete(result);
                }
                else
                {
                    // File still exists, remove it from in-memory list
                    // so we don't process it as a new file in the next loop
                    boxFileList.Remove(boxFile);
                }
            }

            // Remove any files/folders coming from activities stored beneath the current record, they've been processed above
            var filesFoundOnlyOnServer = boxFileList.Where(x => !x.Name.StartsWith(Messages.ActivitiesFolderName)).ToList();

            //Check for underlying activities records
            BoxFolderCache currentFolder = FoldersByFolderID.Select(folderID);

            if (currentFolder != null && boxFileList.Any(x => x.Name.StartsWith(Messages.ActivitiesFolderName)))
            {
                // If nullOrEmpty, Folder may have been created manually
                if (string.IsNullOrEmpty(currentFolder.ActivityFolderID))
                {
                    //Find actual folder ID and save in BoxFolderCache's ActivityFolderID field
                    BoxUtils.FileFolderInfo activityFolderinfo = BoxUtils.FindFolder(tokenHandler, folderID, Messages.ActivitiesFolderName).Result;
                    if (activityFolderinfo != null)
                    {
                        currentFolder.ActivityFolderID = activityFolderinfo?.ID;
                        FoldersByFolderID.Update(currentFolder);
                    }
                }

                if (currentFolder.ActivityFolderID != null)
                {
                    SynchronizeFolderContentsWithScreen(ActivityMaintScreenId, currentFolder.ActivityFolderID, isForcingSync);
                }
            }

            //Remaining files aren't found in cache but are in Box server.
            if (filesFoundOnlyOnServer.Any())
            {
                if (refNoteID == null)
                {
                    // User may have created some folder manually with a name not matching to any record, or record
                    // may have been deleted in Acumatica. We can safely ignore it, but let's write to trace.
                    PXTrace.WriteWarning(string.Format("No record found for folder {0} (screen {1}, ID {2})", folderName, screenID, folderID));
                    return;
                }

                UploadFileMaintenance ufm = PXGraph.CreateInstance <UploadFileMaintenance>();
                ufm.IgnoreFileRestrictions = true;

                ufm.RowInserting.AddHandler <UploadFileRevision>(delegate(PXCache sender, PXRowInsertingEventArgs e)
                {
                    ((UploadFileRevision)e.Row).BlobHandler = Guid.NewGuid();
                });
                //Add files to the caches
                foreach (BoxUtils.FileFolderInfo boxFile in filesFoundOnlyOnServer)
                {
                    ufm.Clear();
                    string   fileName = string.Format("{0}\\{1}", folderName, boxFile.Name.Replace(Path.GetInvalidPathChars(), ' '));
                    FileInfo fileInfo = ufm.GetFileWithNoData(fileName);
                    Guid?    blobHandlerGuid;
                    if (fileInfo == null)
                    {
                        fileInfo = new FileInfo(fileName, null, new byte[0]);
                        //The SaveFile call will trigger a Load() on the BoxBlobStorageProvider which can be skipped
                        PXContext.SetSlot <bool>("BoxDisableLoad", true);
                        try
                        {
                            if (!ufm.SaveFile(fileInfo))
                            {
                                throw new PXException(Messages.ErrorAddingFileSaveFileFailed, fileName);
                            }
                        }
                        finally
                        {
                            PXContext.SetSlot <bool>("BoxDisableLoad", false);
                        }

                        if (!fileInfo.UID.HasValue)
                        {
                            throw new PXException(Messages.ErrorAddingFileUIDNull, fileName);
                        }

                        UploadFileMaintenance.SetAccessSource(fileInfo.UID.Value, null, screenID);
                        NoteDoc noteDoc = (NoteDoc)NoteDocs.Cache.CreateInstance();
                        noteDoc.NoteID = refNoteID;
                        noteDoc.FileID = fileInfo.UID;
                        NoteDocs.Insert(noteDoc);

                        blobHandlerGuid = ufm.Revisions.Current.BlobHandler;
                    }
                    else
                    {
                        //File already exists in the database, retrieve BlobHandler
                        if (!fileInfo.UID.HasValue)
                        {
                            throw new PXException(Messages.GetFileWithNoDataReturnedUIDNull, fileName);
                        }
                        blobHandlerGuid = GetBlobHandlerForFileID(fileInfo.UID.Value);

                        //Clear old references of this blob handler from cache; it will be reinserted with up-to-date info
                        var bfcOrphan = (BoxFileCache)FilesByBlobHandler.Select(blobHandlerGuid);
                        if (bfcOrphan != null)
                        {
                            FilesByBlobHandler.Delete(bfcOrphan);
                        }

                        //Update NoteDoc entry if existing file was moved to new NoteID or create it if not there
                        NoteDoc nd = (NoteDoc)NoteDocsByFileID.Select(fileInfo.UID);
                        if (nd == null)
                        {
                            nd        = (NoteDoc)NoteDocs.Cache.CreateInstance();
                            nd.NoteID = refNoteID;
                            nd.FileID = fileInfo.UID;
                            NoteDocs.Insert(nd);
                        }
                        else if (nd.NoteID != refNoteID)
                        {
                            nd.NoteID = refNoteID;
                            NoteDocs.Update(nd);
                        }
                    }

                    var bfc = (BoxFileCache)FilesByBlobHandler.Cache.CreateInstance();
                    bfc.BlobHandler    = blobHandlerGuid;
                    bfc.FileID         = boxFile.ID;
                    bfc.ParentFolderID = boxFile.ParentFolderID;
                    bfc = FilesByBlobHandler.Insert(bfc);
                }
            }
        }
コード例 #12
0
 public LienWaiverReportCreator(PXGraph graph)
 {
     printEmailLienWaiversProcess = (PrintEmailLienWaiversProcess)graph;
     uploadFileMaintenance        = PXGraph.CreateInstance <UploadFileMaintenance>();
 }
コード例 #13
0
ファイル: SOOrderEntry.cs プロジェクト: JeffJave/Ipevo
        protected virtual IEnumerable LumGenerate3PLUKFile(PXAdapter adapter, [PXDate] DateTime?shipDate, [PXInt] int?siteID, [SOOperation.List] string operation)
        {
            try
            {
                // Create SOShipment Graph
                var graph   = PXGraph.CreateInstance <SOShipmentEntry>();
                var soOrder = adapter.Get <SOOrder>().FirstOrDefault();
                using (PXTransactionScope sc = new PXTransactionScope())
                {
                    // FBM wont create Shipment, only upload file to FTP
                    if (soOrder.OrderType == "FM")
                    {
                        // Combine csv data
                        var result = graph.GetExtension <SOShipmentEntryExt>().CombineCSVForFBM(soOrder, "P3PL");
                        // Upload Graph
                        UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                        // Create SM.FileInfo
                        var      fileName = $"{soOrder.OrderNbr}.csv";
                        var      data     = new UTF8Encoding(true).GetBytes(result.csvText.ToString());
                        FileInfo fi       = new FileInfo(fileName, null, data);

                        // upload file to FTP
                        #region 3PL UK FTP
                        var configYusen = SelectFrom <LUM3PLUKSetup> .View.Select(Base).RowCast <LUM3PLUKSetup>().FirstOrDefault();

                        FTP_Config config = new FTP_Config()
                        {
                            FtpHost = configYusen.FtpHost,
                            FtpUser = configYusen.FtpUser,
                            FtpPass = configYusen.FtpPass,
                            FtpPort = configYusen.FtpPort,
                            FtpPath = configYusen.FtpPath
                        };

                        var ftpResult = graph.GetExtension <SOShipmentEntryExt>().UploadFileByFTP(config, fileName, data);
                        //var ftpResult = true;
                        if (!ftpResult)
                        {
                            throw new Exception("Ftp Upload Fail!!");
                        }
                        #endregion

                        // upload file to Attachment
                        upload.SaveFile(fi);
                        PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, fi.UID.Value);
                        Base.Save.Press();
                        PXProcessing.SetProcessed();
                    }
                    else
                    {
                        // Create Shipment
                        Base.CreateShipmentIssue(adapter, shipDate, siteID);
                        if (PXProcessing <SOOrder> .GetItemMessage().ErrorLevel != PXErrorLevel.RowInfo)
                        {
                            return(null);
                        }

                        // Find SOShipment
                        var _soOrderShipment =
                            FbqlSelect <SelectFromBase <SOOrderShipment, TypeArrayOf <IFbqlJoin> .Empty> .Where <BqlChainableConditionBase <TypeArrayOf <IBqlBinary> .FilledWith <And <Compare <SOOrderShipment.orderType, Equal <P.AsString> > > > > .And <BqlOperand <SOOrderShipment.orderNbr, IBqlString> .IsEqual <P.AsString> > >, SOOrderShipment> .View.Select(Base, soOrder.OrderType, soOrder.OrderNbr)
                            .RowCast <SOOrderShipment>().FirstOrDefault();

                        // Create new Adapter
                        var newAdapter = new PXAdapter(graph.Document)
                        {
                            Searches = new Object[] { _soOrderShipment.ShipmentNbr }
                        };
                        // Generate UK csv file and upload to FTP
                        graph.GetExtension <SOShipmentEntryExt>().lumGenerate3PLUKFile.PressButton(newAdapter);
                        // Remove Hold
                        graph.releaseFromHold.PressButton(newAdapter);
                    }
                    if (PXProcessing <SOOrder> .GetItemMessage().ErrorLevel == PXErrorLevel.RowInfo)
                    {
                        sc.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                PXProcessing.SetError <SOOrder>(ex.Message);
            }
            return(adapter.Get());
        }