Пример #1
0
 private ActionComponentSetup getExportAction(IEnumerable <object> headers, List <IEnumerable <object> > tableData) =>
 new ButtonSetup(
     "Export",
     behavior: new PostBackBehavior(
         postBack: PostBack.CreateFull(
             id: PostBack.GetCompositeId(setup.PostBackIdBase, "export"),
             actionGetter: () => new PostBackAction(
                 new PageReloadBehavior(
                     secondaryResponse: new SecondaryResponse(
                         () => EwfResponse.Create(
                             ContentTypes.Csv,
                             new EwfResponseBodyCreator(
                                 writer => {
     var csv = new CsvFileWriter();
     csv.AddValuesToLine(headers.ToArray());
     csv.WriteCurrentLineToFile(writer);
     foreach (var td in tableData)
     {
         csv.AddValuesToLine(td.ToArray());
         csv.WriteCurrentLineToFile(writer);
     }
 }),
                             () => "{0} {1}".FormatWith(
                                 setup.ExportFileName,
                                 AppRequestState.RequestTime.InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).ToDateTimeUnspecified()) +
                             FileExtensions.Csv)))))));
Пример #2
0
        private Block getExportButton(IEnumerable <object> headers, List <IEnumerable <object> > tableData)
        {
            var block =
                new Block(
                    new PostBackButton(
                        PostBack.CreateFull(
                            id: PostBack.GetCompositeId(setup.PostBackIdBase, "export"),
                            actionGetter: () => new PostBackAction(
                                new SecondaryResponse(
                                    () => EwfResponse.Create(
                                        ContentTypes.Csv,
                                        new EwfResponseBodyCreator(
                                            writer => {
                var csv = new CsvFileWriter();
                csv.AddValuesToLine(headers.ToArray());
                csv.WriteCurrentLineToFile(writer);
                foreach (var td in tableData)
                {
                    csv.AddValuesToLine(td.ToArray());
                    csv.WriteCurrentLineToFile(writer);
                }
            }),
                                        () => "{0} {1}".FormatWith(setup.ExportFileName, DateTime.Now) + FileExtensions.Csv)))),
                        new TextActionControlStyle("Export"),
                        usesSubmitBehavior: false));

            block.Style.Add("text-align", "right");
            return(block);
        }