Exemple #1
0
        public void PrintOrder(MainViewModel model)
        {
            var reportStream =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("HillStationPOS.Reports.Order.rdlc");

            var writer = new ReportWriter { ReportProcessingMode = ProcessingMode.Local };
            writer.DataSources.Clear();
            writer.DataSources.Add(new ReportDataSource { Name = "OrderItems", Value = model.OrderItems });
            writer.LoadReport(reportStream);

            var parameters = new List<ReportParameter>();
            foreach (var parameter in writer.GetParameters())
            {
                var param = new ReportParameter
                {
                    Prompt = parameter.Prompt,
                    Name = parameter.Name
                };
                switch (param.Name)
                {
                    case "OrderNumber":
                        param.Values.Add(model.OrderNumber);
                        break;

                    case "Address":
                        param.Values.Add(model.Address);
                        break;

                    default:
                        throw new InvalidEnumArgumentException(@"Invalid parameter name: " + param.Name);
                }
                parameters.Add(param);
            }

            writer.SetParameters(parameters);

            var stream = new MemoryStream();
            writer.Save(@"D:\Documents\xxx.pdf", WriterFormat.PDF);
            writer.Save(stream, WriterFormat.PDF);

            var pdf = new PdfDocument(stream);

            var size = pdf.Pages[0].Size;
            var paper = new PaperSize("Custom", (int)size.Width, (int)size.Height)
            {
                RawKind = (int)PaperKind.Custom
            };
            pdf.PageScaling = PdfPrintPageScaling.ActualSize;
            var printDocument = pdf.PrintDocument;
            //            printDocument.PrinterSettings.Copies = 2;
            printDocument.DefaultPageSettings.PaperSize = paper;

            //            printDocument.Print();
        }
Exemple #2
0
        public void PrintOrder(MainViewModel model)
        {
            var reportStream =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("HillStationPOS.Reports.Order.rdlc");

            var writer = new ReportWriter {
                ReportProcessingMode = ProcessingMode.Local
            };

            writer.DataSources.Clear();
            writer.DataSources.Add(new ReportDataSource {
                Name = "OrderItems", Value = model.OrderItems
            });
            writer.LoadReport(reportStream);

            var parameters = new List <ReportParameter>();

            foreach (var parameter in writer.GetParameters())
            {
                var param = new ReportParameter
                {
                    Prompt = parameter.Prompt,
                    Name   = parameter.Name
                };
                switch (param.Name)
                {
                case "OrderNumber":
                    param.Values.Add(model.OrderNumber);
                    break;

                case "Address":
                    param.Values.Add(model.Address);
                    break;

                default:
                    throw new InvalidEnumArgumentException(@"Invalid parameter name: " + param.Name);
                }
                parameters.Add(param);
            }

            writer.SetParameters(parameters);

            var stream = new MemoryStream();

            writer.Save(@"D:\Documents\xxx.pdf", WriterFormat.PDF);
            writer.Save(stream, WriterFormat.PDF);

            var pdf = new PdfDocument(stream);

            var size  = pdf.Pages[0].Size;
            var paper = new PaperSize("Custom", (int)size.Width, (int)size.Height)
            {
                RawKind = (int)PaperKind.Custom
            };

            pdf.PageScaling = PdfPrintPageScaling.ActualSize;
            var printDocument = pdf.PrintDocument;

            //            printDocument.PrinterSettings.Copies = 2;
            printDocument.DefaultPageSettings.PaperSize = paper;

            //            printDocument.Print();
        }
Exemple #3
0
        public IActionResult generate(string reportName, string type)
        {
            try
            {
                string       basePath = _hostingEnvironment.WebRootPath;
                string       fileName = reportName.Contains("-") ? getName(reportName) : (char.ToUpper(reportName[0]) + reportName.Substring(1));
                WriterFormat format;
                ReportWriter reportWriter = new ReportWriter();
                reportWriter.ReportProcessingMode          = ProcessingMode.Remote;
                reportWriter.ExportResources.UsePhantomJS  = true;
                reportWriter.ExportResources.PhantomJSPath = basePath + @"\PhantomJS\";

                FileStream inputStream = new FileStream(basePath + @"\Resources\Report\" + reportName + ".rdl", FileMode.Open, FileAccess.Read);
                reportWriter.LoadReport(inputStream);

                reportWriter.ExportResources.Scripts = new List <string>
                {
                    //Gauge component scripts
                    "../../scripts/bold-reports/common/ej2-base.min.js",
                    "../../scripts/bold-reports/common/ej2-pdf-export.min.js",
                    "../../scripts/bold-reports/common/ej2-svg-base.min.js",
                    "../../scripts/bold-reports/data-visualization/ej2-lineargauge.min.js",
                    "../../scripts/bold-reports/data-visualization/ej2-circulargauge.min.js",

                    "../../scripts/bold-reports/common/bold.reports.common.min.js",
                    "../../scripts/bold-reports/common/bold.reports.widgets.min.js",
                    //Chart component script
                    "../../scripts/bold-reports/data-visualization/ej.chart.min.js",
                    //Map component script
                    "../../scripts/bold-reports/data-visualization/ej.map.min.js",
                    //Report Viewer Script
                    "../../scripts/bold-reports/bold.report-viewer.min.js"
                };

                reportWriter.ExportResources.DependentScripts = new List <string>
                {
                    "../../scripts/dependent/jquery.min.js"
                };

                if (type == "pdf")
                {
                    fileName += ".pdf";
                    format    = WriterFormat.PDF;
                }
                else if (type == "word")
                {
                    fileName += ".doc";
                    format    = WriterFormat.Word;
                }
                else if (type == "csv")
                {
                    fileName += ".csv";
                    format    = WriterFormat.CSV;
                }
                else
                {
                    fileName += ".xls";
                    format    = WriterFormat.Excel;
                }
                MemoryStream memoryStream = new MemoryStream();
                reportWriter.Save(memoryStream, format);

                memoryStream.Position = 0;
                string           mimeType         = "application/" + type;
                FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, mimeType);
                fileStreamResult.FileDownloadName = fileName;
                return(fileStreamResult);
            }
            catch
            {
                return(null);
            }
        }