Как экспортировать вложенные файлы (любого типа) в каждую строку pxgrid в acumatica в zip-папку одним щелчком мыши по действию / кнопке - PullRequest
0 голосов
/ 17 апреля 2020
public class ServiceOrderEntry_Extension : PXGraphExtension<ServiceOrderEntry>
  {
    #region Event Handlers
     public PXSelectJoin<FSServiceOrder, InnerJoin<NoteDoc, On<FSServiceOrder.noteID, Equal<NoteDoc.noteID>>,
              InnerJoin<UploadFile, On<NoteDoc.fileID, Equal<UploadFile.fileID>>,
              InnerJoin<UploadFileRevision, On<UploadFile.fileID, Equal<UploadFileRevision.fileID>>>>>,
              Where<FSServiceOrder.refNbr, Equal<Current<FSServiceOrder.refNbr>>, And<FSServiceOrder.srvOrdType, Equal<Current<FSServiceOrder.srvOrdType>>>>> sofiles;

     public PXAction<FSSODetService> ExportFiles;
        [PXUIField(DisplayName = "Export Files", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXButton]
        protected virtual void exportFiles()
        {
            using (ZipFile zip = new ZipFile())
            {
                zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                zip.AddDirectoryByName("ExportFiles");
                foreach (PXResult<FSServiceOrder, NoteDoc, UploadFile, UploadFileRevision> record in sofiles.Select())
                {
                    var filePath = record;
                    zip.AddFile(filePath, "Files");
                }
                Response.Clear();
                Response.BufferOutput = false;
                string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
                Response.ContentType = "application/zip";
                Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                zip.Save(Response.OutputStream);
                Response.End();
            }
        }
    #endregion
  }

** __ Я создал проект настройки в Acumatica и включил приведенный выше код в окно редактора проекта настройки. Я использую Dotnetzip, чтобы сжать файлы, вложенные в каждую строку сетки acumatica, одним щелчком мыши, т.е. действие «Экспорт файлов».

...