Exemplo n.º 1
0
 protected void SaveToFileCommand()
 {
     if (PrintResult == null)
     {
         var result = new SaveFileResult(new[] {
             Tuple.Create("Файл PNG (*.png)", ".png")
         });
         result.Execute(new ActionExecutionContext());
         if (result.Success)
         {
             if (result.Dialog.FilterIndex == 1)
             {
                 var paginator = Document.DocumentPaginator;
                 for (int i = 0; i < paginator.PageCount; i++)
                 {
                     var bitmap = PrintHelper.ToBitmap(paginator, i, true);
                     var bmf    = BitmapFrame.Create(bitmap);
                     var enc    = new PngBitmapEncoder();
                     enc.Frames.Add(bmf);
                     using (var fs = result.Stream($"_{i + 1}")) {
                         enc.Save(fs);
                     }
                 }
             }
         }
     }
     else
     {
         var result = new SaveFileResult(new[] {
             Tuple.Create("Файл PNG (*.png)", ".png"),
             Tuple.Create("Файл RTF (*.rtf)", ".rtf")
         });
         result.Execute(new ActionExecutionContext());
         if (result.Success)
         {
             if (result.Dialog.FilterIndex == 1)
             {
                 var paginator = PrintResult.GetPaginator(PageRangeSelection.AllPages, new PageRange(0)) as WrapDocumentPaginator;
                 paginator.ComputePageCount();
                 for (int i = 0; i < paginator.PageCount; i++)
                 {
                     var bitmap = PrintHelper.ToBitmap(paginator, i, true);
                     var bmf    = BitmapFrame.Create(bitmap);
                     var enc    = new PngBitmapEncoder();
                     enc.Frames.Add(bmf);
                     using (var fs = result.Stream($"_{i + 1}")) {
                         enc.Save(fs);
                     }
                 }
             }
             else if (result.Dialog.FilterIndex == 2)
             {
                 var printDoc = PrintResult.Docs.First().Value;
                 using (var writer = result.Writer()) {
                     var rtfString = PrintHelper.ToRtfString(printDoc.Item2.Build(), Orientation);
                     writer.WriteLine(rtfString);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public IEnumerable <IResult> Save()
        {
            var result = new SaveFileResult(new[] {
                Tuple.Create("Отчет (*.dbf)", ".dbf"),
                Tuple.Create("Excel (*.xls)", ".xls"),
                Tuple.Create("Расширенный Excel (*.xls)", ".xls"),
                Tuple.Create("Excel (*.scv)", ".csv"),
                Tuple.Create("Здоровые люди (*.scv)", ".csv"),
            });
            var lines = Lines.Value.Where(x => x.BatchLine != null);

            yield return(result);

            if (result.Dialog.FilterIndex == 1)
            {
                using (var writer = result.Writer()) {
                    var table  = new DataTable();
                    var column = table.Columns.Add("KOD");
                    column.ExtendedProperties.Add("scale", (byte)9);

                    column = table.Columns.Add("NAME");
                    column.ExtendedProperties.Add("scale", (byte)100);

                    column = table.Columns.Add("KOL", typeof(double));
                    column.ExtendedProperties.Add("presision", 17);
                    column.ExtendedProperties.Add("scale", 3);

                    column = table.Columns.Add("PRICE", typeof(double));
                    column.ExtendedProperties.Add("presision", 17);
                    column.ExtendedProperties.Add("scale", 3);

                    column = table.Columns.Add("NOM_ZAK");
                    column.ExtendedProperties.Add("scale", (byte)10);

                    column = table.Columns.Add("NOM_AU");
                    column.ExtendedProperties.Add("scale", (byte)6);

                    var goodLines = lines.Where(l => l.OrderLine != null);
                    foreach (var line in goodLines)
                    {
                        var parsedServiceFields = line.BatchLine.ParsedServiceFields.Select(f => f.Value).FirstOrDefault();
                        table.Rows.Add(
                            line.OrderLine.Code,
                            line.OrderLine.ProductSynonym,
                            line.OrderLine.Count,
                            line.OrderLine.ResultCost,
                            line.OrderLine.Id,
                            parsedServiceFields);
                    }
                    Dbf2.Save(table, writer);
                }
            }
            else if (result.Dialog.FilterIndex == 2 || result.Dialog.FilterIndex == 3)
            {
                var exportServiceFields = result.Dialog.FilterIndex == 3;
                using (var writer = result.Writer()) {
                    ExportExcel(writer.BaseStream, lines, exportServiceFields);
                }
            }
            else if (result.Dialog.FilterIndex == 4)
            {
                using (var writer = result.Writer()) {
                    ExportCsv(writer, lines);
                }
            }
            else
            {
                using (var writer = result.Writer()) {
                    writer.WriteLine("Номер;Аптека;Дата;Код;Товар;ЗаводШК;Производитель;Количество");
                    foreach (var line in ReportLines.Value.Where(x => x.BatchLine != null))
                    {
                        var reportLine = line.BatchLine.ParsedServiceFields.Where(f => f.Key == "ReportData")
                                         .Select(f => f.Value)
                                         .FirstOrDefault();
                        writer.WriteLine(reportLine);
                    }
                }
            }
        }